Files
RuinAdventurer/Scripts/DSL/Nodes/IfNode.cs
T

60 lines
1.4 KiB
C#

using Godot;
public class IfNode : ProgramNode
{
public Item selectedItem;
public int amount;
public string comparator;
public IfNode()
{
DisplayText = "If";
}
public override NodeResult Execute(Robot robot, double delta)
{
if (selectedItem == null)
{
lastExecutionMessage = "No Item selected";
return NodeResult.FAILURE;
}
bool isConditionFulfilled = DetermineCondition();
return isConditionFulfilled? NodeResult.SUCCESS : NodeResult.CONDITIONFALSE;
}
private bool DetermineCondition()
{
int inventoryAmount = GameData.inventory.GetItemAmount(selectedItem.data.Id);
switch (comparator)
{
case "is bigger than":
return inventoryAmount > amount;
case "is less than":
return inventoryAmount < amount;
case "is not":
return inventoryAmount != amount;
case "is less than or equal to":
return inventoryAmount <= amount;
case "is bigger than or equal to":
return inventoryAmount >= amount;
default:
return inventoryAmount == amount;
}
}
public override ProgramNode Duplicate()
{
IfNode duplicate = new IfNode()
{
selectedItem = selectedItem,
amount = amount,
comparator = comparator
};
return duplicate;
}
public override string Save()
{
return $"Name: {DisplayText}, Item: {(selectedItem == null ? "Empty" : selectedItem.data.Id)}, Comparator: {comparator}, Amount: {amount}";
}
}