using System; using GameFramework.DataTable; using GeometryTD.DataTable; using GeometryTD.Definition; namespace GeometryTD.Factory { public sealed class OutGameDropItemBuilder { private readonly IDataTable _muzzleCompTable; private readonly IDataTable _bearingCompTable; private readonly IDataTable _baseCompTable; public OutGameDropItemBuilder( IDataTable muzzleCompTable, IDataTable bearingCompTable, IDataTable baseCompTable) { _muzzleCompTable = muzzleCompTable; _bearingCompTable = bearingCompTable; _baseCompTable = baseCompTable; } public bool TryBuildItem( DROutGameDropPool row, RarityType rarity, InventoryGenerationRandomContext randomContext, out TowerCompItemData droppedItem) { droppedItem = null; if (row.ItemId <= 0 || string.IsNullOrWhiteSpace(row.ItemType)) { return false; } string itemType = row.ItemType.Trim(); if (itemType.Equals("MuzzleComp", StringComparison.OrdinalIgnoreCase)) { DRMuzzleComp config = _muzzleCompTable.GetDataRow(row.ItemId); if (config == null) { return false; } droppedItem = ComponentItemFactory.CreateMuzzle( config, randomContext.CreateStableItemInstanceId(), rarity, randomContext.CreateTagRandomContext(config.Id)); return true; } if (itemType.Equals("BearingComp", StringComparison.OrdinalIgnoreCase)) { DRBearingComp config = _bearingCompTable.GetDataRow(row.ItemId); if (config == null) { return false; } droppedItem = ComponentItemFactory.CreateBearing( config, randomContext.CreateStableItemInstanceId(), rarity, randomContext.CreateTagRandomContext(config.Id)); return true; } if (itemType.Equals("BaseComp", StringComparison.OrdinalIgnoreCase)) { DRBaseComp config = _baseCompTable.GetDataRow(row.ItemId); if (config == null) { return false; } droppedItem = ComponentItemFactory.CreateBase( config, randomContext.CreateStableItemInstanceId(), rarity, randomContext.CreateTagRandomContext(config.Id)); return true; } return false; } } }