using GeometryTD.CustomUtility; using GeometryTD.Definition; namespace GeometryTD.UI { public class RepoFormUseCase : IUIUseCase { private const int MaxParticipantCount = 4; private BackpackInventoryData _fallbackInventory; public RepoFormRawData CreateInitialModel() { BackpackInventoryData sample = GameEntry.PlayerInventory != null ? GameEntry.PlayerInventory.GetInventorySnapshot() : GetOrCreateFallbackInventory(); return new RepoFormRawData { Inventory = sample }; } public bool TryAssembleTower(long muzzleItemId, long bearingItemId, long baseItemId) { if (GameEntry.PlayerInventory == null) { return false; } return GameEntry.PlayerInventory.TryAssembleTower( muzzleItemId, bearingItemId, baseItemId, out _); } public bool TryAddParticipantTower(long towerItemId) { if (GameEntry.PlayerInventory == null) { BackpackInventoryData fallbackInventory = GetOrCreateFallbackInventory(); return InventoryParticipantUtility.TryAddParticipantTower( fallbackInventory, towerItemId, MaxParticipantCount); } return GameEntry.PlayerInventory.TryAddParticipantTower(towerItemId, 4); } public bool TryRemoveParticipantTower(long towerItemId) { if (GameEntry.PlayerInventory == null) { BackpackInventoryData fallbackInventory = GetOrCreateFallbackInventory(); return InventoryParticipantUtility.TryRemoveParticipantTower( fallbackInventory, towerItemId, MaxParticipantCount); } return GameEntry.PlayerInventory.TryRemoveParticipantTower(towerItemId); } private BackpackInventoryData GetOrCreateFallbackInventory() { _fallbackInventory ??= InventorySeedUtility.CreateSampleInventory(); InventoryParticipantUtility.NormalizeParticipantState(_fallbackInventory, MaxParticipantCount); return _fallbackInventory; } } }