using System; using System.Collections.Generic; using GameFramework.DataTable; using GeometryTD.DataTable; using GeometryTD.Definition; using GeometryTD.UI; using UnityGameFramework.Runtime; namespace GeometryTD.CustomComponent { public sealed class InventoryGenerationComponent : GameFrameworkComponent { private long _nextTempInstanceId = 1000000; private readonly List _shopPriceRows = new(); private IDataTable _shopPriceTable; private IDataTable _muzzleCompTable; private IDataTable _bearingCompTable; private IDataTable _baseCompTable; private ShopGoodsBuilder _shopGoodsBuilder; public List BuildShopGoods(int goodsCount, int runSeed = 0, int sequenceIndex = -1) { EnsureShopBuilder(); return _shopGoodsBuilder.BuildGoods(goodsCount, runSeed, sequenceIndex, AllocateTempInstanceId); } public EnemyDropResult ResolveEnemyDrop(in EnemyDropContext context) { throw new NotImplementedException( "InventoryGenerationComponent.ResolveEnemyDrop() will be implemented in G2."); } public IReadOnlyList BuildRewardCandidates( int displayPhaseIndex, LevelThemeType themeType, int candidateCount) { throw new NotImplementedException( "InventoryGenerationComponent.BuildRewardCandidates() will be implemented in G2."); } private void EnsureShopTables() { _shopPriceTable ??= GameEntry.DataTable.GetDataTable(); _muzzleCompTable ??= GameEntry.DataTable.GetDataTable(); _bearingCompTable ??= GameEntry.DataTable.GetDataTable(); _baseCompTable ??= GameEntry.DataTable.GetDataTable(); if (_shopPriceTable == null || _muzzleCompTable == null || _bearingCompTable == null || _baseCompTable == null) { throw new InvalidOperationException( "InventoryGenerationComponent requires ShopPrice, MuzzleComp, BearingComp, and BaseComp data tables."); } if (_shopPriceRows.Count > 0) { return; } DRShopPrice[] rows = _shopPriceTable.GetAllDataRows(); if (rows == null || rows.Length <= 0) { throw new InvalidOperationException( "InventoryGenerationComponent requires at least one shop price row."); } foreach (var row in rows) { if (row != null) { _shopPriceRows.Add(row); } } if (_shopPriceRows.Count <= 0) { throw new InvalidOperationException("InventoryGenerationComponent requires non-null shop price rows."); } } private void EnsureShopBuilder() { EnsureShopTables(); _shopGoodsBuilder ??= new ShopGoodsBuilder( _shopPriceRows, _muzzleCompTable, _bearingCompTable, _baseCompTable); } private long AllocateTempInstanceId() { return _nextTempInstanceId++; } } }