实现单局 Run 模型的基础落地
- 核心改动在 RunModel.cs、RunStateFactory.cs 和 RunStateAdvanceService.cs。现在项目里有了 RunNodeType / RunNodeStatus / RunNodeSeed / RunNodeState / RunState,并支持用预置节点序列创建 Run,以及在节点完成后推进、更新局内库存快照、标记通关或失败。 - 库存边界也补上了。PlayerInventoryComponent.cs 新增了 ReplaceInventorySnapshot(...),底层通过 PlayerInventoryStateStore.cs 重建工作副本,避免后续把 Run 真值硬塞回 PlayerInventory 内部状态。 - 节点事件载体已经扩展为可承载 Run 上下文,同时保留原来的无参 Create() 以兼容现有调用点。相关改动在 NodeEnterEventArgs.cs 和 NodeCompleteEventArgs.cs。 - 我还补了纯模型编辑器测试,覆盖 Run 创建、节点推进、失败标记和事件快照克隆,文件在 RunStateTests.cs。
This commit is contained in:
@@ -0,0 +1,131 @@
|
||||
using System.Collections.Generic;
|
||||
using GeometryTD.CustomEvent;
|
||||
using GeometryTD.Definition;
|
||||
using GeometryTD.Procedure;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace GeometryTD.Tests.Editor
|
||||
{
|
||||
public sealed class RunStateTests
|
||||
{
|
||||
[Test]
|
||||
public void Factory_Creates_RunState_With_First_Node_Available()
|
||||
{
|
||||
BackpackInventoryData sourceInventory = new BackpackInventoryData
|
||||
{
|
||||
Gold = 120
|
||||
};
|
||||
sourceInventory.ParticipantTowerInstanceIds.Add(11);
|
||||
|
||||
RunState runState = RunStateFactory.Create(
|
||||
LevelThemeType.Plain,
|
||||
sourceInventory,
|
||||
new List<RunNodeSeed>
|
||||
{
|
||||
new RunNodeSeed { NodeType = RunNodeType.Combat, LinkedLevelId = 1 },
|
||||
new RunNodeSeed { NodeType = RunNodeType.Event },
|
||||
new RunNodeSeed { NodeType = RunNodeType.BossCombat, LinkedLevelId = 4 }
|
||||
},
|
||||
"run-test");
|
||||
|
||||
Assert.That(runState.RunId, Is.EqualTo("run-test"));
|
||||
Assert.That(runState.ThemeType, Is.EqualTo(LevelThemeType.Plain));
|
||||
Assert.That(runState.CurrentNodeIndex, Is.EqualTo(0));
|
||||
Assert.That(runState.IsCompleted, Is.False);
|
||||
Assert.That(runState.Nodes.Count, Is.EqualTo(3));
|
||||
Assert.That(runState.Nodes[0].Status, Is.EqualTo(RunNodeStatus.Available));
|
||||
Assert.That(runState.Nodes[1].Status, Is.EqualTo(RunNodeStatus.Locked));
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(120));
|
||||
|
||||
sourceInventory.Gold = 1;
|
||||
sourceInventory.ParticipantTowerInstanceIds[0] = 99;
|
||||
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(120));
|
||||
Assert.That(runState.RunInventorySnapshot.ParticipantTowerInstanceIds[0], Is.EqualTo(11));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AdvanceService_Completes_Run_And_Unlocks_Next_Node()
|
||||
{
|
||||
RunState runState = RunStateFactory.Create(
|
||||
LevelThemeType.Plain,
|
||||
new BackpackInventoryData { Gold = 50 },
|
||||
new[]
|
||||
{
|
||||
new RunNodeSeed { NodeId = 101, NodeType = RunNodeType.Combat, LinkedLevelId = 1 },
|
||||
new RunNodeSeed { NodeId = 102, NodeType = RunNodeType.Shop },
|
||||
new RunNodeSeed { NodeId = 103, NodeType = RunNodeType.BossCombat, LinkedLevelId = 4 }
|
||||
});
|
||||
|
||||
bool firstCompleted = RunStateAdvanceService.TryCompleteCurrentNode(
|
||||
runState,
|
||||
true,
|
||||
new BackpackInventoryData { Gold = 80 });
|
||||
|
||||
Assert.That(firstCompleted, Is.True);
|
||||
Assert.That(runState.Nodes[0].Status, Is.EqualTo(RunNodeStatus.Completed));
|
||||
Assert.That(runState.CurrentNodeIndex, Is.EqualTo(1));
|
||||
Assert.That(runState.Nodes[1].Status, Is.EqualTo(RunNodeStatus.Available));
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(80));
|
||||
|
||||
RunStateAdvanceService.TryCompleteCurrentNode(runState, true, new BackpackInventoryData { Gold = 95 });
|
||||
RunStateAdvanceService.TryCompleteCurrentNode(runState, true, new BackpackInventoryData { Gold = 130 });
|
||||
|
||||
Assert.That(runState.IsCompleted, Is.True);
|
||||
Assert.That(runState.CurrentNodeIndex, Is.EqualTo(3));
|
||||
Assert.That(runState.CompletedNodeCount, Is.EqualTo(3));
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(130));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AdvanceService_Failure_Marks_Current_Node_Failed_Without_Completing_Run()
|
||||
{
|
||||
RunState runState = RunStateFactory.Create(
|
||||
LevelThemeType.Plain,
|
||||
new BackpackInventoryData { Gold = 20 },
|
||||
new[]
|
||||
{
|
||||
new RunNodeSeed { NodeType = RunNodeType.Combat }
|
||||
});
|
||||
|
||||
bool result = RunStateAdvanceService.TryCompleteCurrentNode(
|
||||
runState,
|
||||
false,
|
||||
new BackpackInventoryData { Gold = 5 });
|
||||
|
||||
Assert.That(result, Is.True);
|
||||
Assert.That(runState.IsCompleted, Is.False);
|
||||
Assert.That(runState.CurrentNodeIndex, Is.EqualTo(0));
|
||||
Assert.That(runState.CurrentNode.Status, Is.EqualTo(RunNodeStatus.Failed));
|
||||
Assert.That(runState.RunInventorySnapshot.Gold, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NodeCompleteEventArgs_Clones_Inventory_And_Clears_State()
|
||||
{
|
||||
BackpackInventoryData inventory = new BackpackInventoryData { Gold = 66 };
|
||||
NodeCompleteEventArgs eventArgs = NodeCompleteEventArgs.Create(
|
||||
"run-1",
|
||||
7,
|
||||
RunNodeType.Shop,
|
||||
true,
|
||||
inventory);
|
||||
|
||||
inventory.Gold = 1;
|
||||
|
||||
Assert.That(eventArgs.RunId, Is.EqualTo("run-1"));
|
||||
Assert.That(eventArgs.NodeId, Is.EqualTo(7));
|
||||
Assert.That(eventArgs.NodeType, Is.EqualTo(RunNodeType.Shop));
|
||||
Assert.That(eventArgs.Succeeded, Is.True);
|
||||
Assert.That(eventArgs.InventorySnapshotAfterNode.Gold, Is.EqualTo(66));
|
||||
|
||||
eventArgs.Clear();
|
||||
|
||||
Assert.That(eventArgs.RunId, Is.Null);
|
||||
Assert.That(eventArgs.NodeId, Is.EqualTo(0));
|
||||
Assert.That(eventArgs.NodeType, Is.EqualTo(RunNodeType.None));
|
||||
Assert.That(eventArgs.Succeeded, Is.False);
|
||||
Assert.That(eventArgs.InventorySnapshotAfterNode, Is.Null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d3e6fd8ec274118b59f66c6efc41405
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user