迁移 EntityData 到 Base 中
- 新增 EntityDataFactory 工厂类,提供创建 EntityData 的统一入口 - 移出 EntityData 及派生类对 GameEntry 的依赖并移入 SepCore.Base 程序集中
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using SepCore.DataTable;
|
||||
using Entity.EntityData;
|
||||
using SepCore.Definition;
|
||||
|
||||
namespace SepCore.Utility
|
||||
{
|
||||
public static class EntityDataFactory
|
||||
{
|
||||
public static EnemyData Create(int entityId, EnemyType enemyType, int level)
|
||||
{
|
||||
var dr = GameEntry.DataTable.GetDataTableRow<DREnemy>((int)enemyType);
|
||||
return new EnemyData(entityId, dr, level);
|
||||
}
|
||||
|
||||
public static WeaponData Create(int entityId, WeaponType weaponType, int ownerId, CampType ownerCamp)
|
||||
{
|
||||
var dr = GameEntry.DataTable.GetDataTableRow<DRWeapon>((int)weaponType);
|
||||
return weaponType switch
|
||||
{
|
||||
WeaponType.WeaponHandgun => new WeaponHandgunData(entityId, dr, ownerId, ownerCamp),
|
||||
WeaponType.WeaponKnife => new WeaponKnifeData(entityId, dr, ownerId, ownerCamp),
|
||||
WeaponType.WeaponSlash => new WeaponSlashData(entityId, dr, ownerId, ownerCamp),
|
||||
WeaponType.WeaponLightning => new WeaponLightningData(entityId, dr, ownerId, ownerCamp),
|
||||
WeaponType.WeaponLance => new WeaponLanceData(entityId, dr, ownerId, ownerCamp),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
}
|
||||
|
||||
public static WeaponData Create(int entityId, DRWeapon dr, int ownerId, CampType ownerCamp)
|
||||
{
|
||||
WeaponType type = (WeaponType)dr.Id;
|
||||
return type switch
|
||||
{
|
||||
WeaponType.WeaponHandgun => new WeaponHandgunData(entityId, dr, ownerId, ownerCamp),
|
||||
WeaponType.WeaponKnife => new WeaponKnifeData(entityId, dr, ownerId, ownerCamp),
|
||||
WeaponType.WeaponSlash => new WeaponSlashData(entityId, dr, ownerId, ownerCamp),
|
||||
WeaponType.WeaponLightning => new WeaponLightningData(entityId, dr, ownerId, ownerCamp),
|
||||
WeaponType.WeaponLance => new WeaponLanceData(entityId, dr, ownerId, ownerCamp),
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user