Skip to content

Commit

Permalink
Merge pull request #91 from arannya/unofficial-battery-recharge
Browse files Browse the repository at this point in the history
[Enhancement] Addresses recharging bots with batteries: issue #25
  • Loading branch information
JoeStrout authored May 12, 2024
2 parents ec64c74 + b263c92 commit 142fdf8
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Farmtronics/Bot/BotObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,20 @@ public override bool placementAction(GameLocation location, int x, int y, Farmer
// Apply the currently-selected item as a tool (or weapon) on
// the square in front of the bot.
public void UseTool() {
float oldStamina = farmer.stamina;
if (farmer.CurrentTool == null &&
farmer.Items[farmer.CurrentToolIndex].QualifiedItemId.Equals("(O)787"))
{
if (farmer.stamina >= Farmer.startingStamina) {
ModEntry.instance.Monitor.Log($"UseBattery called: Stamina already full, battery not used.", LogLevel.Trace);
return;
}
farmer.stamina = Math.Min(Farmer.startingStamina, farmer.stamina + 100);
ModEntry.instance.Monitor.Log($"UseBattery called: Stamina increased from {oldStamina} to {farmer.stamina}", LogLevel.Trace);
farmer.removeFirstOfThisItemFromInventory("(O)787");
return;
}

if (farmer == null || inventory == null || farmer.CurrentTool == null) return;
Vector2 toolLocation = farmer.GetToolLocation(true);
ModEntry.instance.Monitor.Log($"UseTool called: {farmer.CurrentTool.Name}[{farmer.CurrentToolIndex}] {toolLocation}", LogLevel.Trace);
Expand All @@ -178,13 +192,13 @@ public void UseTool() {
return;
}

float oldStamina = farmer.stamina;
if (farmer.CurrentTool is not MeleeWeapon) {
ModEntry.instance.Monitor.Log($"farmer.CurrentTool.DoFunction", LogLevel.Trace);
farmer.CurrentTool.DoFunction(farmer.currentLocation, toolLocation.GetIntX(), toolLocation.GetIntY(), 1, farmer);
farmer.checkForExhaustion(oldStamina);
data.Update();
} else {
}
else {
// Special case for using the Scythe
farmer.CurrentTool.beginUsing(currentLocation, toolLocation.GetIntX(), toolLocation.GetIntY(), farmer);
Farmer.showToolSwipeEffect(farmer);
Expand Down

0 comments on commit 142fdf8

Please sign in to comment.