52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using GeometryTD.Definition;
|
|
|
|
namespace GeometryTD.Procedure
|
|
{
|
|
public static class RunStateAdvanceService
|
|
{
|
|
public static bool TryCompleteCurrentNode(
|
|
RunState runState,
|
|
bool succeeded,
|
|
BackpackInventoryData inventorySnapshotAfterNode)
|
|
{
|
|
if (runState == null || runState.IsCompleted)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
RunNodeState currentNode = runState.CurrentNode;
|
|
if (currentNode == null || currentNode.Status != RunNodeStatus.Available)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
runState.ReplaceInventorySnapshot(inventorySnapshotAfterNode);
|
|
|
|
if (!succeeded)
|
|
{
|
|
currentNode.Status = RunNodeStatus.Failed;
|
|
return true;
|
|
}
|
|
|
|
currentNode.Status = RunNodeStatus.Completed;
|
|
|
|
int nextIndex = runState.CurrentNodeIndex + 1;
|
|
if (nextIndex >= runState.Nodes.Count)
|
|
{
|
|
runState.CurrentNodeIndex = runState.Nodes.Count;
|
|
runState.IsCompleted = true;
|
|
return true;
|
|
}
|
|
|
|
runState.CurrentNodeIndex = nextIndex;
|
|
RunNodeState nextNode = runState.CurrentNode;
|
|
if (nextNode != null && nextNode.Status == RunNodeStatus.Locked)
|
|
{
|
|
nextNode.Status = RunNodeStatus.Available;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|