Added resource harvesting to DSL.
This commit is contained in:
@@ -8,15 +8,30 @@ public class HarvestNode : ProgramNode
|
||||
}
|
||||
public override NodeResult Execute(Robot robot, double delta)
|
||||
{
|
||||
GD.Print("Harvest");
|
||||
if (nextNode != null)
|
||||
Vector3I mapIndex = Pathfinding.GetClosestStartPoint(robot.Position);
|
||||
Tile tile = GameData.map[mapIndex.Y].tiles[mapIndex.X, mapIndex.Z];
|
||||
|
||||
if (!tile.containsResource)
|
||||
{
|
||||
return nextNode.Execute(robot, delta);
|
||||
lastExecutionMessage = "No resource on this tile";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
else
|
||||
|
||||
if (!tile.resource.CanExtract())
|
||||
{
|
||||
lastExecutionMessage = "Resource is depleted and not endless";
|
||||
return NodeResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (tile.resource.Extract(delta))
|
||||
{
|
||||
if (!GameData.inventory.AddItem(new Item {data = tile.resource.item}, 1))
|
||||
{
|
||||
lastExecutionMessage = "Not enough space";
|
||||
return NodeResult.FAILURE;
|
||||
}
|
||||
}
|
||||
return NodeResult.RUNNING;
|
||||
}
|
||||
|
||||
public override void ReadParameters(NodeDisplay display)
|
||||
|
||||
Reference in New Issue
Block a user