Added resource harvesting to DSL.
This commit is contained in:
@@ -8,7 +8,7 @@ public class GameResource
|
||||
bool isEndless;
|
||||
float extractionSpeed;
|
||||
double timeSinceLastExtraction;
|
||||
ItemData item;
|
||||
public ItemData item;
|
||||
|
||||
public GameResource(string name)
|
||||
{
|
||||
@@ -34,4 +34,9 @@ public class GameResource
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanExtract()
|
||||
{
|
||||
return isEndless || currentAmount > 0;
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ public class Inventory
|
||||
Item inventoryItem = inventory.Find(x => x.data.Id == item.data.Id && x.currentAmount + amount <= x.data.StackSize);
|
||||
if (inventoryItem != null)
|
||||
{
|
||||
GD.Print(inventory.IndexOf(inventoryItem) + ": " + inventoryItem.currentAmount);
|
||||
inventoryItem.currentAmount += amount;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -4,6 +4,7 @@ using Godot;
|
||||
|
||||
public partial class GameData
|
||||
{
|
||||
public static bool DEBUGMODE = true;
|
||||
public static Random rand = new Random(seed);
|
||||
public static Layer[] map;
|
||||
//Current layer the player wants to see
|
||||
|
||||
@@ -21,12 +21,12 @@ public partial class Robot : Node3D
|
||||
switch (currentNode.Execute(this, delta))
|
||||
{
|
||||
case NodeResult.SUCCESS:
|
||||
GD.Print(currentNode.lastExecutionMessage);
|
||||
currentNode = currentNode.nextNode;
|
||||
if (currentNode == null)
|
||||
{
|
||||
isExecuting = false;
|
||||
}
|
||||
GD.Print(currentNode.lastExecutionMessage);
|
||||
break;
|
||||
case NodeResult.FAILURE:
|
||||
isExecuting = false;
|
||||
|
||||
@@ -62,7 +62,7 @@ public partial class Map : PanelContainer
|
||||
continue;
|
||||
}
|
||||
texture = new TextureRect();
|
||||
if (tiles[x, z].wasVisited)
|
||||
if (tiles[x, z].wasVisited || GameData.DEBUGMODE)
|
||||
{
|
||||
if (tiles[x, z].containsResource)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user