Removed ability to attack players, added an option to have a whitelist or a blacklist mode.

This commit is contained in:
Milutinke 2022-09-27 14:23:19 +02:00
parent 58b171cec0
commit 932d25f125
4 changed files with 32 additions and 21 deletions

View file

@ -24,8 +24,8 @@ namespace MinecraftClient.ChatBots
private InteractType interactMode;
private bool attackHostile = true;
private bool attackPassive = false;
private bool attackPlayers = false;
private List<EntityType> blacklistedEntityTypes = new();
private string listMode = "blacklist";
private List<EntityType> listedEntites = new();
public AutoAttack(
string mode, string priority, bool overrideAttackSpeed = false, double cooldownSeconds = 1, InteractType interaction = InteractType.Attack)
@ -60,18 +60,28 @@ namespace MinecraftClient.ChatBots
this.attackHostile = Settings.AutoAttack_Attack_Hostile;
this.attackPassive = Settings.AutoAttack_Attack_Passive;
this.attackPlayers = Settings.AutoAttack_Attack_Players;
if (File.Exists(Settings.AutoAttack_Blacklist))
if (Settings.AutoAttack_ListMode.Length > 0)
{
string[] blacklist = LoadDistinctEntriesFromFile(Settings.AutoAttack_Blacklist);
listMode = Settings.AutoAttack_ListMode.ToLower();
if (blacklist.Length > 0)
if (!(listMode.Equals("whitelist", StringComparison.OrdinalIgnoreCase) || listMode.Equals("blacklist", StringComparison.OrdinalIgnoreCase)))
{
foreach (var item in blacklist)
LogToConsole(Translations.TryGet("bot.autoAttack.invalidlist"));
listMode = "blacklist";
}
}
if (File.Exists(Settings.AutoAttack_ListFile))
{
string[] entityList = LoadDistinctEntriesFromFile(Settings.AutoAttack_ListFile);
if (entityList.Length > 0)
{
foreach (var item in entityList)
{
if (Enum.TryParse(item, true, out EntityType resultingType))
blacklistedEntityTypes.Add(resultingType);
listedEntites.Add(resultingType);
}
}
}
@ -195,11 +205,11 @@ namespace MinecraftClient.ChatBots
if (attackPassive && entity.Type.IsPassive())
result = true;
if (attackPlayers && entity.Type == EntityType.Player)
result = true;
if (blacklistedEntityTypes.Contains(entity.Type))
result = false;
if (listedEntites.Count > 0)
{
bool inList = listedEntites.Contains(entity.Type);
result = listMode.Equals("blacklist") ? (inList ? false : result) : (inList ? true : false);
}
return result;
}

View file

@ -204,11 +204,11 @@ cooldownseconds=auto # How long to wait between each attack. Use a
interaction=Attack # Possible values: Interact, Attack (default), InteractAt (Interact and Attack)
attackhostile=true # Allow attacking hostile mobs
attackpassive=false # Allow attacking passive mobs
attackplayers=false # Allow attacking players
# A path to the file which contains blacklisted entities (will not attack them), entity types are written on a new line
listmode=blacklist # Wether to treat the list from the file bellow as a whitelist or as a blacklist
# A path to the file which contains blacklisted or whitelisted entities, entity types are written on a new line
# All entity types can be found here: https://bit.ly/3Rg68lp
# The file is not created by default.
blacklist=autoattack-blacklist.txt
listfile=autoattack-list.txt
[AutoFishing]
# Automatically catch fish using a fishing rod

View file

@ -431,6 +431,7 @@ cmd.useitem.use=Used an item
bot.autoAttack.mode=Unknown attack mode: {0}. Using single mode as default.
bot.autoAttack.priority=Unknown priority: {0}. Using distance priority as default.
bot.autoAttack.invalidcooldown=Attack cooldown value cannot be smaller than 0. Using auto as default
bot.autoAttack.invalidlist=Invalid list type provided, using the default list mode of: 'blacklist'
# AutoCraft
bot.autoCraft.cmd=Auto-crafting ChatBot command

View file

@ -206,8 +206,8 @@ namespace MinecraftClient
public static InteractType AutoAttack_Interaction = InteractType.Attack;
public static bool AutoAttack_Attack_Hostile = true;
public static bool AutoAttack_Attack_Passive = false;
public static bool AutoAttack_Attack_Players = false;
public static string AutoAttack_Blacklist = "attack-blacklist.txt";
public static string AutoAttack_ListMode = "blacklist";
public static string AutoAttack_ListFile = "autoattack-list.txt";
//Auto Fishing
public static bool AutoFishing_Enabled = false;
@ -735,10 +735,10 @@ namespace MinecraftClient
AutoAttack_Attack_Hostile = str2bool(argValue); return true;
case "attackpassive":
AutoAttack_Attack_Passive = str2bool(argValue); return true;
case "attackplayers":
AutoAttack_Attack_Players = str2bool(argValue); return true;
case "listmode":
AutoAttack_ListMode = argValue; return true;
case "blacklist":
AutoAttack_Blacklist = argValue; return true;
AutoAttack_ListFile = argValue; return true;
}
break;