99 lines
3.4 KiB
C#
99 lines
3.4 KiB
C#
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<DRShopPrice> _shopPriceRows = new();
|
|
private IDataTable<DRShopPrice> _shopPriceTable;
|
|
private IDataTable<DRMuzzleComp> _muzzleCompTable;
|
|
private IDataTable<DRBearingComp> _bearingCompTable;
|
|
private IDataTable<DRBaseComp> _baseCompTable;
|
|
private ShopGoodsBuilder _shopGoodsBuilder;
|
|
|
|
public List<GoodsItemRawData> 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<TowerCompItemData> BuildRewardCandidates(
|
|
int displayPhaseIndex,
|
|
LevelThemeType themeType,
|
|
int candidateCount)
|
|
{
|
|
throw new NotImplementedException(
|
|
"InventoryGenerationComponent.BuildRewardCandidates() will be implemented in G2.");
|
|
}
|
|
|
|
private void EnsureShopTables()
|
|
{
|
|
_shopPriceTable ??= GameEntry.DataTable.GetDataTable<DRShopPrice>();
|
|
_muzzleCompTable ??= GameEntry.DataTable.GetDataTable<DRMuzzleComp>();
|
|
_bearingCompTable ??= GameEntry.DataTable.GetDataTable<DRBearingComp>();
|
|
_baseCompTable ??= GameEntry.DataTable.GetDataTable<DRBaseComp>();
|
|
|
|
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++;
|
|
}
|
|
}
|
|
}
|