45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
using Godot;
|
|
|
|
public class MaintainNode : ProgramNode
|
|
{
|
|
private const float MaintenancePerGear = 10f;
|
|
|
|
public MaintainNode()
|
|
{
|
|
DisplayText = "Maintain";
|
|
TooltipText = "Repairs the robot by consuming one matching gear and restoring a small amount of maintenance.";
|
|
}
|
|
|
|
public override NodeResult Execute(Robot robot, double delta)
|
|
{
|
|
string gearId = GetGearId(robot);
|
|
|
|
if (!GameData.inventory.TryRemoveItem(gearId, 1))
|
|
{
|
|
lastExecutionMessage = $"Missing {ItemData.GetReadableName(gearId)}";
|
|
return NodeResult.FAILURE;
|
|
}
|
|
|
|
robot.Maintain(MaintenancePerGear);
|
|
lastExecutionMessage = "";
|
|
return NodeResult.SUCCESS;
|
|
}
|
|
|
|
public override ProgramNode Duplicate()
|
|
{
|
|
MaintainNode duplicate = new MaintainNode();
|
|
return duplicate;
|
|
}
|
|
|
|
public override string Save()
|
|
{
|
|
return $"Name: {DisplayText}";
|
|
}
|
|
|
|
public static string GetGearId(Robot robot)
|
|
{
|
|
string robotType = robot == null ? "stone_robot" : robot.robotType;
|
|
return robotType.Replace("_robot", "_gear");
|
|
}
|
|
}
|