mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Improve AutoAttack (#1218)
* Improve AutoAttack - New attack mode - Fix abnormally low attack damage * Add document for AutoCraft * Improve code style and user feedback * Correct spelling mistakes
This commit is contained in:
parent
2fd610aa65
commit
e71d0e2383
4 changed files with 133 additions and 11 deletions
|
|
@ -19,6 +19,23 @@ namespace MinecraftClient.ChatBots
|
||||||
private int attackRange = 4;
|
private int attackRange = 4;
|
||||||
private Double serverTPS;
|
private Double serverTPS;
|
||||||
private float health = 100;
|
private float health = 100;
|
||||||
|
private bool singleMode = true;
|
||||||
|
private bool priorityDistance = true;
|
||||||
|
|
||||||
|
public AutoAttack(string mode, string priority)
|
||||||
|
{
|
||||||
|
if (mode == "single")
|
||||||
|
singleMode = true;
|
||||||
|
else if (mode == "multi")
|
||||||
|
singleMode = false;
|
||||||
|
else LogToConsole("Unknown attack mode: " + mode + ". Using single mode as default.");
|
||||||
|
|
||||||
|
if (priority == "distance")
|
||||||
|
priorityDistance = true;
|
||||||
|
else if (priority == "health")
|
||||||
|
priorityDistance = false;
|
||||||
|
else LogToConsole("Unknown priority: " + priority + ". Using distance priority as default.");
|
||||||
|
}
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
|
|
@ -40,15 +57,52 @@ namespace MinecraftClient.ChatBots
|
||||||
attackCooldownCounter = attackCooldown;
|
attackCooldownCounter = attackCooldown;
|
||||||
if (entitiesToAttack.Count > 0)
|
if (entitiesToAttack.Count > 0)
|
||||||
{
|
{
|
||||||
SendAnimation(Inventory.Hand.MainHand); // Arm animation
|
if (singleMode)
|
||||||
foreach (KeyValuePair<int, Entity> entity in entitiesToAttack)
|
|
||||||
{
|
{
|
||||||
// check that we are in range once again.
|
int priorityEntity = 0;
|
||||||
bool shouldAttack = handleEntity(entity.Value);
|
if (priorityDistance) // closest distance priority
|
||||||
if (shouldAttack)
|
|
||||||
{
|
{
|
||||||
InteractEntity(entity.Key, 1); // hit the entity!
|
double distance = 5;
|
||||||
|
foreach (var entity in entitiesToAttack)
|
||||||
|
{
|
||||||
|
var tmp = GetCurrentLocation().Distance(entity.Value.Location);
|
||||||
|
if (tmp < distance)
|
||||||
|
{
|
||||||
|
priorityEntity = entity.Key;
|
||||||
|
distance = tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else // low health priority
|
||||||
|
{
|
||||||
|
float health = int.MaxValue;
|
||||||
|
foreach (var entity in entitiesToAttack)
|
||||||
|
{
|
||||||
|
if (entity.Value.Health < health)
|
||||||
|
{
|
||||||
|
priorityEntity = entity.Key;
|
||||||
|
health = entity.Value.Health;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// check entity distance and health again
|
||||||
|
if (shouldAttackEntity(entitiesToAttack[priorityEntity]))
|
||||||
|
{
|
||||||
|
InteractEntity(priorityEntity, 1); // hit the entity!
|
||||||
|
SendAnimation(Inventory.Hand.MainHand); // Arm animation
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<int, Entity> entity in entitiesToAttack)
|
||||||
|
{
|
||||||
|
// check that we are in range once again.
|
||||||
|
if (shouldAttackEntity(entity.Value))
|
||||||
|
{
|
||||||
|
InteractEntity(entity.Key, 1); // hit the entity!
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SendAnimation(Inventory.Hand.MainHand); // Arm animation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -60,7 +114,7 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
public override void OnEntitySpawn(Entity entity)
|
public override void OnEntitySpawn(Entity entity)
|
||||||
{
|
{
|
||||||
handleEntity(entity);
|
shouldAttackEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnEntityDespawn(Entity entity)
|
public override void OnEntityDespawn(Entity entity)
|
||||||
|
|
@ -73,7 +127,7 @@ namespace MinecraftClient.ChatBots
|
||||||
|
|
||||||
public override void OnEntityMove(Entity entity)
|
public override void OnEntityMove(Entity entity)
|
||||||
{
|
{
|
||||||
handleEntity(entity);
|
shouldAttackEntity(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void OnHealthUpdate(float health, int food)
|
public override void OnHealthUpdate(float health, int food)
|
||||||
|
|
@ -113,7 +167,7 @@ namespace MinecraftClient.ChatBots
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="entity">The entity to handle</param>
|
/// <param name="entity">The entity to handle</param>
|
||||||
/// <returns>If the entity should be attacked</returns>
|
/// <returns>If the entity should be attacked</returns>
|
||||||
public bool handleEntity(Entity entity)
|
public bool shouldAttackEntity(Entity entity)
|
||||||
{
|
{
|
||||||
if (!entity.Type.IsHostile() || entity.Health <= 0)
|
if (!entity.Type.IsHostile() || entity.Health <= 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ namespace MinecraftClient
|
||||||
if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); }
|
if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); }
|
||||||
if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); }
|
if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); }
|
||||||
if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches)); }
|
if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches)); }
|
||||||
if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack()); }
|
if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack(Settings.AutoAttack_Mode, Settings.AutoAttack_Priority)); }
|
||||||
if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); }
|
if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); }
|
||||||
if (Settings.AutoEat_Enabled) { BotLoad(new ChatBots.AutoEat(Settings.AutoEat_hungerThreshold)); }
|
if (Settings.AutoEat_Enabled) { BotLoad(new ChatBots.AutoEat(Settings.AutoEat_hungerThreshold)); }
|
||||||
if (Settings.Mailer_Enabled) { BotLoad(new ChatBots.Mailer()); }
|
if (Settings.Mailer_Enabled) { BotLoad(new ChatBots.Mailer()); }
|
||||||
|
|
|
||||||
|
|
@ -155,6 +155,8 @@ namespace MinecraftClient
|
||||||
|
|
||||||
//Auto Attack
|
//Auto Attack
|
||||||
public static bool AutoAttack_Enabled = false;
|
public static bool AutoAttack_Enabled = false;
|
||||||
|
public static string AutoAttack_Mode = "single";
|
||||||
|
public static string AutoAttack_Priority = "distance";
|
||||||
|
|
||||||
//Auto Fishing
|
//Auto Fishing
|
||||||
public static bool AutoFishing_Enabled = false;
|
public static bool AutoFishing_Enabled = false;
|
||||||
|
|
@ -498,6 +500,8 @@ namespace MinecraftClient
|
||||||
switch (argName.ToLower())
|
switch (argName.ToLower())
|
||||||
{
|
{
|
||||||
case "enabled": AutoAttack_Enabled = str2bool(argValue); break;
|
case "enabled": AutoAttack_Enabled = str2bool(argValue); break;
|
||||||
|
case "mode": AutoAttack_Mode = argValue.ToLower(); break;
|
||||||
|
case "priority": AutoAttack_Priority = argValue.ToLower(); break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -745,6 +749,8 @@ namespace MinecraftClient
|
||||||
+ "[AutoAttack]\r\n"
|
+ "[AutoAttack]\r\n"
|
||||||
+ "# Entity Handling NEED to be enabled first\r\n"
|
+ "# Entity Handling NEED to be enabled first\r\n"
|
||||||
+ "enabled=false\r\n"
|
+ "enabled=false\r\n"
|
||||||
|
+ "mode=single # single or multi. single target one mob per attack. multi target all mobs in range per attack\r\n"
|
||||||
|
+ "priority=distance # health or distance. Only needed when using single mode\r\n"
|
||||||
+ "\r\n"
|
+ "\r\n"
|
||||||
+ "[AutoFishing]\r\n"
|
+ "[AutoFishing]\r\n"
|
||||||
+ "# Entity Handling NEED to be enabled first\r\n"
|
+ "# Entity Handling NEED to be enabled first\r\n"
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ In scripts and remote control, no slash is needed to perform the command.
|
||||||
- quit or exit: disconnect from the server and close the application
|
- quit or exit: disconnect from the server and close the application
|
||||||
- reco [account] : disconnect and reconnect to the server
|
- reco [account] : disconnect and reconnect to the server
|
||||||
- connect <server> [account] : go to the given server and resume the script
|
- connect <server> [account] : go to the given server and resume the script
|
||||||
- script <script name> : run a script containing a list of commands
|
- script <script name\> : run a script containing a list of commands
|
||||||
- send <text> : send a message or a command to the server
|
- send <text> : send a message or a command to the server
|
||||||
- respawn : Use this to respawn if you are dead (like clicking "respawn" ingame)
|
- respawn : Use this to respawn if you are dead (like clicking "respawn" ingame)
|
||||||
- log <text> : display some text in the console (useful for scripts)
|
- log <text> : display some text in the console (useful for scripts)
|
||||||
|
|
@ -277,6 +277,68 @@ Never write something to the bot you wouldn't say in the normal chat (You have b
|
||||||
To set up a network of two or more bots, launch several instances with the bot activated and the same database.
|
To set up a network of two or more bots, launch several instances with the bot activated and the same database.
|
||||||
If you launch two instances from one .exe they should syncronize automatically to the same file.
|
If you launch two instances from one .exe they should syncronize automatically to the same file.
|
||||||
|
|
||||||
|
Using the AutoCraft bot
|
||||||
|
------
|
||||||
|
|
||||||
|
The AutoCraft bot can automatically craft items for you as long as you have defined the item recipe.
|
||||||
|
You can get the default config by running the bot at lease once.
|
||||||
|
|
||||||
|
Useful commands description:
|
||||||
|
* /autocraft reload: Reload the config from disk. You can load your edited AutoCraft config without restarting the client.
|
||||||
|
* /autocraft resetcfg: Reset your AutoCraft config back to default. Use with care!
|
||||||
|
* /autocraft list: List all loaded recipes.
|
||||||
|
* /autocraft start <name\>: Start the crafting process with the given recipe name you had defined.
|
||||||
|
* /autocraft stop: Stop the crafting process.
|
||||||
|
* /autocraft help: In-game help command.
|
||||||
|
|
||||||
|
|
||||||
|
How to define a recipe?
|
||||||
|
|
||||||
|
_Example_
|
||||||
|
```md
|
||||||
|
[Recipe]
|
||||||
|
name=whatever # name could be whatever you like. This field must be defined first
|
||||||
|
type=player # crafting table type: player or table
|
||||||
|
result=StoneButton # the resulting item
|
||||||
|
|
||||||
|
# define slots with their deserved item
|
||||||
|
slot1=stone # slot start with 1, count from left to right, top to bottom
|
||||||
|
# For the naming of the items, please see
|
||||||
|
# https://github.com/ORelio/Minecraft-Console-Client/blob/master/MinecraftClient/Inventory/ItemType.cs
|
||||||
|
```
|
||||||
|
|
||||||
|
1. You need to give your recipe a **name** so that you could start them later by name.
|
||||||
|
2. The size of crafting area needed for your recipe, 2x2(player inventory) or 3x3(crafting table). If you need to use the crafting table, make sure to set the **table coordinate** in the `[AutoCraft]` section.
|
||||||
|
3. The expected crafting result.
|
||||||
|
|
||||||
|
Then you need to define the position of each crafting materials.
|
||||||
|
Slots are indexed as follow:
|
||||||
|
|
||||||
|
2x2
|
||||||
|
```
|
||||||
|
╔═══╦═══╗
|
||||||
|
║ 1 ║ 2 ║
|
||||||
|
╠═══╬═══╣
|
||||||
|
║ 3 ║ 4 ║
|
||||||
|
╚═══╩═══╝
|
||||||
|
```
|
||||||
|
3x3
|
||||||
|
```
|
||||||
|
╔═══╦═══╦═══╗
|
||||||
|
║ 1 ║ 2 ║ 3 ║
|
||||||
|
╠═══╬═══╬═══╣
|
||||||
|
║ 4 ║ 5 ║ 6 ║
|
||||||
|
╠═══╬═══╬═══╣
|
||||||
|
║ 7 ║ 8 ║ 9 ║
|
||||||
|
╚═══╩═══╩═══╝
|
||||||
|
```
|
||||||
|
Simply use `slotIndex=MaterialName` to define material.
|
||||||
|
e.g. `slot1=coal` and `slot3=stick` will craft a torch.
|
||||||
|
|
||||||
|
For the naming of items, please see [ItemType.cs](https://github.com/ORelio/Minecraft-Console-Client/blob/master/MinecraftClient/Inventory/ItemType.cs).
|
||||||
|
|
||||||
|
After you finished writing your config, you can use `/autocraft start <recipe name>` to start crafting. Make sure to provide materials for your bot.
|
||||||
|
|
||||||
Disclaimer
|
Disclaimer
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue