Skip to content

Commit

Permalink
[Enhancement] Addresses recharging bots with batteries: issue JoeStro…
Browse files Browse the repository at this point in the history
  • Loading branch information
arannya committed May 1, 2024
1 parent 68ca09d commit 17d15e0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Farmtronics/Bot/BotObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This class is a stardew valley Object subclass that represents a Bot.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Farmtronics.M1;
using Farmtronics.Utils;
using Microsoft.Xna.Framework;
Expand Down Expand Up @@ -163,7 +165,20 @@ public override bool placementAction(GameLocation location, int x, int y, Farmer
location.playSound("hammer");
return true;
}

public bool UseBattery() {
if (farmer == null || inventory == null || farmer.CurrentTool == null)
return false;

if (farmer.Items.Any(b => b is not null && b.QualifiedItemId.Equals("(O)787")))
{
farmer.stamina = Math.Min(Farmer.startingStamina, farmer.stamina + 100);
farmer.removeFirstOfThisItemFromInventory("(O)787");
return true;
}
return false;
}

// Apply the currently-selected item as a tool (or weapon) on
// the square in front of the bot.
public void UseTool() {
Expand Down
10 changes: 10 additions & 0 deletions Farmtronics/M1/M1API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,16 @@ public static ValMap MeModule() {
return result ? Intrinsic.Result.True : Intrinsic.Result.False;
};
meModule["harvest"] = f.GetFunc();

f = Intrinsic.Create("");
f.code = (context, partialResult) => {
Shell sh = context.interpreter.hostData as Shell;
if (RequireBot(sh, "useBattery")) return Intrinsic.Result.Null;

bool result = sh.bot.UseBattery();
return result ? Intrinsic.Result.True : Intrinsic.Result.False;
};
meModule["useBattery"] = f.GetFunc();

botProtectedKeys = new HashSet<string>();
foreach (Value key in meModule.Keys) {
Expand Down

0 comments on commit 17d15e0

Please sign in to comment.