refactor 7:
- 拆分 CombatScheduler,将公用方法与字段拆分为:
- FlowCoordinator
- RuntimeContext
- 地图侧现在收口为“MapData 初始快照 + CombatCoinChangedEventArgs 同步 + 独立命令桥接”
This commit is contained in:
@@ -15,9 +15,6 @@ namespace GeometryTD.Entity.EntityData
|
||||
[SerializeField] private BackpackInventoryData _inventorySnapshot;
|
||||
[SerializeField] private TowerItemData[] _participantTowerSnapshot = Array.Empty<TowerItemData>();
|
||||
|
||||
[NonSerialized] private Func<int, bool> _tryConsumeCoin;
|
||||
[NonSerialized] private Action<int> _addCoin;
|
||||
|
||||
public MapData(int entityId, int levelId, Vector3 position) : this(entityId, 0, levelId, position)
|
||||
{
|
||||
}
|
||||
@@ -36,9 +33,7 @@ namespace GeometryTD.Entity.EntityData
|
||||
int initialCoin,
|
||||
IReadOnlyList<TowerStatsData> buildTowerStatsSnapshot,
|
||||
BackpackInventoryData inventorySnapshot,
|
||||
IReadOnlyList<TowerItemData> participantTowerSnapshot,
|
||||
Func<int, bool> tryConsumeCoin,
|
||||
Action<int> addCoin) : base(entityId, typeId)
|
||||
IReadOnlyList<TowerItemData> participantTowerSnapshot) : base(entityId, typeId)
|
||||
{
|
||||
_levelId = levelId;
|
||||
Position = position;
|
||||
@@ -48,8 +43,6 @@ namespace GeometryTD.Entity.EntityData
|
||||
? InventoryCloneUtility.CloneInventory(inventorySnapshot)
|
||||
: null;
|
||||
SetParticipantTowerSnapshot(participantTowerSnapshot);
|
||||
_tryConsumeCoin = tryConsumeCoin;
|
||||
_addCoin = addCoin;
|
||||
}
|
||||
|
||||
public int LevelId
|
||||
@@ -70,34 +63,6 @@ namespace GeometryTD.Entity.EntityData
|
||||
: null;
|
||||
public IReadOnlyList<TowerItemData> ParticipantTowerSnapshot => _participantTowerSnapshot;
|
||||
|
||||
public void BindCombatCallbacks(Func<int, bool> tryConsumeCoin, Action<int> addCoin)
|
||||
{
|
||||
_tryConsumeCoin = tryConsumeCoin;
|
||||
_addCoin = addCoin;
|
||||
}
|
||||
|
||||
public bool TryConsumeCoin(int coin)
|
||||
{
|
||||
int requiredCoin = Mathf.Max(0, coin);
|
||||
if (requiredCoin <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return _tryConsumeCoin != null && _tryConsumeCoin.Invoke(requiredCoin);
|
||||
}
|
||||
|
||||
public void AddCoin(int coin)
|
||||
{
|
||||
int amount = Mathf.Max(0, coin);
|
||||
if (amount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_addCoin?.Invoke(amount);
|
||||
}
|
||||
|
||||
public bool TryGetBuildTowerStats(int buildIndex, out TowerStatsData stats)
|
||||
{
|
||||
stats = null;
|
||||
@@ -141,9 +106,7 @@ namespace GeometryTD.Entity.EntityData
|
||||
_initialCoin,
|
||||
_buildTowerStatsSnapshot,
|
||||
_inventorySnapshot,
|
||||
_participantTowerSnapshot,
|
||||
_tryConsumeCoin,
|
||||
_addCoin);
|
||||
_participantTowerSnapshot);
|
||||
}
|
||||
|
||||
public void SetParticipantTowerSnapshot(IReadOnlyList<TowerItemData> participantTowerSnapshot)
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace GeometryTD.Entity.EntityData
|
||||
{
|
||||
public sealed class MapEntityLoadContext
|
||||
{
|
||||
public MapEntityLoadContext(MapData initialMapData, Func<int, bool> tryConsumeCoin, Action<int> addCoin)
|
||||
{
|
||||
InitialMapData = initialMapData;
|
||||
TryConsumeCoin = tryConsumeCoin;
|
||||
AddCoin = addCoin;
|
||||
}
|
||||
|
||||
public MapData InitialMapData { get; }
|
||||
public Func<int, bool> TryConsumeCoin { get; }
|
||||
public Action<int> AddCoin { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4ba39a6e9c0948b386b8b0189e3541da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user