89 lines
2.9 KiB
C#
89 lines
2.9 KiB
C#
using System;
|
|
using GameFramework.DataTable;
|
|
using GeometryTD.DataTable;
|
|
using GeometryTD.Definition;
|
|
|
|
namespace GeometryTD.Factory
|
|
{
|
|
public sealed class OutGameDropItemBuilder
|
|
{
|
|
private readonly IDataTable<DRMuzzleComp> _muzzleCompTable;
|
|
private readonly IDataTable<DRBearingComp> _bearingCompTable;
|
|
private readonly IDataTable<DRBaseComp> _baseCompTable;
|
|
|
|
public OutGameDropItemBuilder(
|
|
IDataTable<DRMuzzleComp> muzzleCompTable,
|
|
IDataTable<DRBearingComp> bearingCompTable,
|
|
IDataTable<DRBaseComp> 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;
|
|
}
|
|
}
|
|
}
|