diff --git a/MinecraftClient/ChatBots/AutoAttack.cs b/MinecraftClient/ChatBots/AutoAttack.cs index 6ba10223..dd45f9b4 100644 --- a/MinecraftClient/ChatBots/AutoAttack.cs +++ b/MinecraftClient/ChatBots/AutoAttack.cs @@ -15,14 +15,15 @@ namespace MinecraftClient.ChatBots private int attackCooldown = 6; private int attackCooldownCounter = 6; private Double attackSpeed = 4; - private Double attackCooldownSecond; + private Double attackCooldownSeconds; + private bool overrideAttackSpeed = false; private int attackRange = 4; private Double serverTPS; private float health = 100; private bool singleMode = true; private bool priorityDistance = true; - public AutoAttack(string mode, string priority) + public AutoAttack(string mode, string priority, bool overrideAttackSpeed = false, double cooldownSeconds = 1) { if (mode == "single") singleMode = true; @@ -35,6 +36,20 @@ namespace MinecraftClient.ChatBots else if (priority == "health") priorityDistance = false; else LogToConsoleTranslated("bot.autoAttack.priority", priority); + + if (overrideAttackSpeed) + { + if (cooldownSeconds <= 0) + { + LogToConsoleTranslated("bot.autoAttack.invalidcooldown"); + } + else + { + this.overrideAttackSpeed = overrideAttackSpeed; + this.attackCooldownSeconds = cooldownSeconds; + attackCooldown = Convert.ToInt32(Math.Truncate(attackCooldownSeconds / 0.1) + 1); + } + } } public override void Initialize() @@ -137,6 +152,8 @@ namespace MinecraftClient.ChatBots public override void OnPlayerProperty(Dictionary prop) { + if (overrideAttackSpeed) + return; foreach (var attackSpeedKey in new[] { "generic.attackSpeed", "minecraft:generic.attack_speed" }) { // adjust auto attack cooldown for maximum attack damage @@ -146,8 +163,8 @@ namespace MinecraftClient.ChatBots { serverTPS = GetServerTPS(); attackSpeed = prop[attackSpeedKey]; - attackCooldownSecond = 1 / attackSpeed * (serverTPS / 20.0); // server tps will affect the cooldown - attackCooldown = Convert.ToInt32(Math.Truncate(attackCooldownSecond / 0.1) + 1); + attackCooldownSeconds = 1 / attackSpeed * (serverTPS / 20.0); // server tps will affect the cooldown + attackCooldown = Convert.ToInt32(Math.Truncate(attackCooldownSeconds / 0.1) + 1); } } } @@ -155,10 +172,12 @@ namespace MinecraftClient.ChatBots public override void OnServerTpsUpdate(double tps) { + if (overrideAttackSpeed) + return; serverTPS = tps; // re-calculate attack speed - attackCooldownSecond = 1 / attackSpeed * (serverTPS / 20.0); // server tps will affect the cooldown - attackCooldown = Convert.ToInt32(Math.Truncate(attackCooldownSecond / 0.1) + 1); + attackCooldownSeconds = 1 / attackSpeed * (serverTPS / 20.0); // server tps will affect the cooldown + attackCooldown = Convert.ToInt32(Math.Truncate(attackCooldownSeconds / 0.1) + 1); } /// diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 8259b031..fe24eadf 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -204,7 +204,7 @@ namespace MinecraftClient if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); } if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); } if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches)); } - if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack(Settings.AutoAttack_Mode, Settings.AutoAttack_Priority)); } + if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack(Settings.AutoAttack_Mode, Settings.AutoAttack_Priority, Settings.AutoAttack_OverrideAttackSpeed, Settings.AutoAttack_CooldownSeconds)); } if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); } if (Settings.AutoEat_Enabled) { BotLoad(new ChatBots.AutoEat(Settings.AutoEat_hungerThreshold)); } if (Settings.Mailer_Enabled) { BotLoad(new ChatBots.Mailer()); } diff --git a/MinecraftClient/Resources/config/MinecraftClient.ini b/MinecraftClient/Resources/config/MinecraftClient.ini index 1e27a8c9..6315c9cf 100644 --- a/MinecraftClient/Resources/config/MinecraftClient.ini +++ b/MinecraftClient/Resources/config/MinecraftClient.ini @@ -138,6 +138,7 @@ matchesfile=matches.ini enabled=false mode=single # single or multi. single target one mob per attack. multi target all mobs in range per attack priority=distance # health or distance. Only needed when using single mode +cooldownseconds=auto # How long to wait between each attack. Use auto to let MCC calculate it [AutoFishing] # Entity Handling NEED to be enabled first diff --git a/MinecraftClient/Resources/lang/en.ini b/MinecraftClient/Resources/lang/en.ini index 8da998ac..c1aaea6a 100644 --- a/MinecraftClient/Resources/lang/en.ini +++ b/MinecraftClient/Resources/lang/en.ini @@ -338,6 +338,7 @@ cmd.useitem.use=Used an item # AutoAttack 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 # AutoCraft bot.autoCraft.cmd=Auto-crafting ChatBot command diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index c5c8921e..6eed90e7 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -173,6 +173,8 @@ namespace MinecraftClient public static bool AutoAttack_Enabled = false; public static string AutoAttack_Mode = "single"; public static string AutoAttack_Priority = "distance"; + public static bool AutoAttack_OverrideAttackSpeed = false; + public static double AutoAttack_CooldownSeconds = 1; //Auto Fishing public static bool AutoFishing_Enabled = false; @@ -577,6 +579,17 @@ namespace MinecraftClient case "enabled": AutoAttack_Enabled = str2bool(argValue); break; case "mode": AutoAttack_Mode = argValue.ToLower(); break; case "priority": AutoAttack_Priority = argValue.ToLower(); break; + case "cooldownseconds": + if (argValue.ToLower() == "auto") + { + AutoAttack_OverrideAttackSpeed = false; + } + else + { + AutoAttack_OverrideAttackSpeed = true; + AutoAttack_CooldownSeconds = str2float(argValue); + } + break; } break; @@ -726,6 +739,23 @@ namespace MinecraftClient } } + /// + /// Convert the specified string to a float number, defaulting to zero if invalid argument + /// + /// String to parse as a float number + /// Float number + public static float str2float(string str) + { + float f; + if (float.TryParse(str.Trim(), out f)) + return f; + else + { + ConsoleIO.WriteLogLine(Translations.Get("error.setting.str2int", str)); + return 0; + } + } + /// /// Convert the specified string to a boolean value, defaulting to false if invalid argument ///