57 lines
1.7 KiB
C#
57 lines
1.7 KiB
C#
using GeometryTD.Definition;
|
|
|
|
namespace GeometryTD.Procedure
|
|
{
|
|
public static class RunStateAdvanceService
|
|
{
|
|
public static bool TryCompleteCurrentNode(
|
|
RunState runState,
|
|
RunNodeCompletionStatus completionStatus,
|
|
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 (completionStatus == RunNodeCompletionStatus.Exception)
|
|
{
|
|
currentNode.Status = RunNodeStatus.Exception;
|
|
return true;
|
|
}
|
|
|
|
if (completionStatus != RunNodeCompletionStatus.Completed)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|