Skip to content

Commit

Permalink
Fixed me.harvest (broken in 1.3); also fixed error that would appear …
Browse files Browse the repository at this point in the history
…when

using me.select with the index of an empty tool slot.
  • Loading branch information
JoeStrout committed Nov 3, 2022
1 parent efab855 commit 5ea37a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 7 additions & 6 deletions Farmtronics/Bot/BotObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -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;
}
Expand Down
10 changes: 8 additions & 2 deletions Farmtronics/assets/sysdisk/startup.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5ea37a6

Please sign in to comment.