diff --git a/Farmtronics/Bot/BotObject.cs b/Farmtronics/Bot/BotObject.cs index 1baa750..7c17350 100644 --- a/Farmtronics/Bot/BotObject.cs +++ b/Farmtronics/Bot/BotObject.cs @@ -199,14 +199,15 @@ public bool Harvest() { ModEntry.instance.Monitor.Log($"Harvest start: {tileLocation}"); - if (loc.isTerrainFeatureAt(absoluteLocation.GetIntX(), absoluteLocation.GetIntY())) { + TerrainFeature feature = null; + if (loc.terrainFeatures.TryGetValue(tileLocation, out feature)) { // If we can get a terrain feature, then have it do the "use" action, // by temporarily setting the bot farmer to be the Game1 player. ModEntry.instance.Monitor.Log("Harvesting: TerrainFeature"); var origPlayer = Game1.player; Game1.player = farmer; - bool result = loc.terrainFeatures[tileLocation].performUseAction(tileLocation, loc); + bool result = feature.performUseAction(tileLocation, loc); Game1.player = origPlayer; return result; } else if (loc.isObjectAtTile(tileLocation.GetIntX(), tileLocation.GetIntY())) { @@ -226,10 +227,10 @@ public bool Harvest() { if (dirtObj.crop.harvest(tileLocation.GetIntX(), tileLocation.GetIntY(), dirtObj)) { dirtObj.destroyCrop(tileLocation, true, farmer.currentLocation); return true; - } - } - } - } + } else ModEntry.instance.Monitor.Log("fail 1"); + } else ModEntry.instance.Monitor.Log("fail 2"); + } else ModEntry.instance.Monitor.Log("fail 3"); + } else ModEntry.instance.Monitor.Log("fail 4"); return false; } diff --git a/Farmtronics/assets/sysdisk/startup.ms b/Farmtronics/assets/sysdisk/startup.ms index 72095b3..486d0db 100644 --- a/Farmtronics/assets/sysdisk/startup.ms +++ b/Farmtronics/assets/sysdisk/startup.ms @@ -407,18 +407,24 @@ if me.isBot then if f == 3 then return here.tile(pos.x-1, pos.y) end function + me.currentToolName = function + item = me.inventory[me.currentToolIndex] + if not item then return "nothing" + return item.name + end function + me.select = function(toolNameOrIndex) inv = me.inventory if toolNameOrIndex isa number then me.currentToolIndex = toolNameOrIndex - print "Using " + inv[toolNameOrIndex].name + " (index " + toolNameOrIndex + ")" + print "Using " + me.currentToolName + " (index " + toolNameOrIndex + ")" return end if toolName = str(toolNameOrIndex).lower for i in inv.indexes if inv[i] and inv[i].name.lower == toolName then me.currentToolIndex = i - print "Using " + inv[i].name + " (index " + i + ")" + print "Using " + me.currentToolName + " (index " + i + ")" return end if end for