refactor 6:
- CombatInfoFormUseCase.cs 改成回调驱动:
- 不再直接读 GameEntry.CombatNode
- 由 CombatLoadSession.cs 在打开 CombatInfoForm 前注入 modelProvider 和 TryEndCombat 回调
- CombatSelectFormUseCase.cs 的默认 coin provider 改成返回 0,不再偷偷 fallback 到 GameEntry.CombatNode
- CombatFinishFormUseCase.cs 去掉了未准备 summary 时对 GameEntry.CombatNode 的兜底读取
- MapData.cs 进一步补充了战斗初始快照:
- InventorySnapshot
- ParticipantTowerSnapshot
- CombatLoadingState.cs 现在会把这些背包/参战塔快照也一起打进 MapData
- MapEntity.cs 配置建塔面板时不再直接读 PlayerInventory,改为用 MapData 里的快照
This commit is contained in:
@@ -12,6 +12,8 @@ namespace GeometryTD.Entity.EntityData
|
||||
[SerializeField] private int _levelId = 0;
|
||||
[SerializeField] private int _initialCoin = 0;
|
||||
[SerializeField] private TowerStatsData[] _buildTowerStatsSnapshot = Array.Empty<TowerStatsData>();
|
||||
[SerializeField] private BackpackInventoryData _inventorySnapshot;
|
||||
[SerializeField] private TowerItemData[] _participantTowerSnapshot = Array.Empty<TowerItemData>();
|
||||
|
||||
[NonSerialized] private Func<int, bool> _tryConsumeCoin;
|
||||
[NonSerialized] private Action<int> _addCoin;
|
||||
@@ -33,6 +35,8 @@ namespace GeometryTD.Entity.EntityData
|
||||
Vector3 position,
|
||||
int initialCoin,
|
||||
IReadOnlyList<TowerStatsData> buildTowerStatsSnapshot,
|
||||
BackpackInventoryData inventorySnapshot,
|
||||
IReadOnlyList<TowerItemData> participantTowerSnapshot,
|
||||
Func<int, bool> tryConsumeCoin,
|
||||
Action<int> addCoin) : base(entityId, typeId)
|
||||
{
|
||||
@@ -40,6 +44,10 @@ namespace GeometryTD.Entity.EntityData
|
||||
Position = position;
|
||||
_initialCoin = Mathf.Max(0, initialCoin);
|
||||
SetBuildTowerStatsSnapshot(buildTowerStatsSnapshot);
|
||||
_inventorySnapshot = inventorySnapshot != null
|
||||
? InventoryCloneUtility.CloneInventory(inventorySnapshot)
|
||||
: null;
|
||||
SetParticipantTowerSnapshot(participantTowerSnapshot);
|
||||
_tryConsumeCoin = tryConsumeCoin;
|
||||
_addCoin = addCoin;
|
||||
}
|
||||
@@ -57,6 +65,10 @@ namespace GeometryTD.Entity.EntityData
|
||||
}
|
||||
|
||||
public int CurrentBuildTowerCount => _buildTowerStatsSnapshot != null ? _buildTowerStatsSnapshot.Length : 0;
|
||||
public BackpackInventoryData InventorySnapshot => _inventorySnapshot != null
|
||||
? InventoryCloneUtility.CloneInventory(_inventorySnapshot)
|
||||
: null;
|
||||
public IReadOnlyList<TowerItemData> ParticipantTowerSnapshot => _participantTowerSnapshot;
|
||||
|
||||
public void BindCombatCallbacks(Func<int, bool> tryConsumeCoin, Action<int> addCoin)
|
||||
{
|
||||
@@ -128,8 +140,25 @@ namespace GeometryTD.Entity.EntityData
|
||||
position,
|
||||
_initialCoin,
|
||||
_buildTowerStatsSnapshot,
|
||||
_inventorySnapshot,
|
||||
_participantTowerSnapshot,
|
||||
_tryConsumeCoin,
|
||||
_addCoin);
|
||||
}
|
||||
|
||||
public void SetParticipantTowerSnapshot(IReadOnlyList<TowerItemData> participantTowerSnapshot)
|
||||
{
|
||||
if (participantTowerSnapshot == null || participantTowerSnapshot.Count <= 0)
|
||||
{
|
||||
_participantTowerSnapshot = Array.Empty<TowerItemData>();
|
||||
return;
|
||||
}
|
||||
|
||||
_participantTowerSnapshot = new TowerItemData[participantTowerSnapshot.Count];
|
||||
for (int i = 0; i < participantTowerSnapshot.Count; i++)
|
||||
{
|
||||
_participantTowerSnapshot[i] = InventoryCloneUtility.CloneTower(participantTowerSnapshot[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,12 +243,6 @@ namespace GeometryTD.Entity
|
||||
private void ConfigureCombatSelectUseCase()
|
||||
{
|
||||
_combatSelectFormUseCase.SetCoinProvider(GetCurrentCoin);
|
||||
BackpackInventoryData inventorySnapshot = GameEntry.PlayerInventory != null
|
||||
? GameEntry.PlayerInventory.GetInventorySnapshot()
|
||||
: null;
|
||||
IReadOnlyList<TowerItemData> participantTowers = GameEntry.PlayerInventory != null
|
||||
? GameEntry.PlayerInventory.GetParticipantTowerSnapshot()
|
||||
: null;
|
||||
_combatSelectUseCaseConfigurator?.Configure(
|
||||
_combatSelectFormUseCase,
|
||||
GetCurrentCoin,
|
||||
@@ -259,8 +253,8 @@ namespace GeometryTD.Entity
|
||||
_destroyGain,
|
||||
_buildTowerCosts,
|
||||
GetCurrentBuildTowerCount(),
|
||||
inventorySnapshot,
|
||||
participantTowers);
|
||||
_mapData != null ? _mapData.InventorySnapshot : null,
|
||||
_mapData != null ? _mapData.ParticipantTowerSnapshot : null);
|
||||
}
|
||||
|
||||
private void HandleCombatSelectInput()
|
||||
|
||||
Reference in New Issue
Block a user