第一批重构,主要是物理迁移脚本和部分命名空间的调整
- 结构上迁移文件,将脚本分成 Base/Runtime/Presentation/Procedure/Editor 五大文件夹 - 调整 DataTable 和 Definition 下脚本的命名空间 - 依据 UI-5层架构设计规范 拆分原先的 UI 到 Runtime 和 Presentation 下
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SepCore.DataTable;
|
||||
using SepCore.Definition;
|
||||
using GameFramework;
|
||||
|
||||
namespace Entity.EntityData
|
||||
{
|
||||
[Serializable]
|
||||
public class WeaponData : AccessoryObjectData
|
||||
{
|
||||
private DRWeapon _drWeapon;
|
||||
|
||||
private int _entityTypeId = 0;
|
||||
|
||||
public WeaponData(int entityId, WeaponType weaponType, int ownerId, CampType ownerCamp)
|
||||
: base(entityId, (int)weaponType, ownerId, ownerCamp)
|
||||
{
|
||||
_drWeapon = GameEntry.DataTable.GetDataTableRow<DRWeapon>((int)weaponType);
|
||||
|
||||
if (_drWeapon == null)
|
||||
{
|
||||
throw new Exception($"Weapon data table row is missing, WeaponType='{weaponType}'.");
|
||||
}
|
||||
|
||||
_entityTypeId = _drWeapon.EntityTypeId;
|
||||
}
|
||||
|
||||
public WeaponType WeaponType => (WeaponType)_drWeapon.Id;
|
||||
|
||||
public bool TryGetParam(string key, out string value)
|
||||
{
|
||||
value = null;
|
||||
if (string.IsNullOrEmpty(key) || Params == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Params.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
protected TParams ParseParams<TParams>() where TParams : new()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_drWeapon.ParamsJson))
|
||||
{
|
||||
return new TParams();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
TParams parsed = Utility.Json.ToObject<TParams>(_drWeapon.ParamsJson);
|
||||
return parsed ?? new TParams();
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
throw new Exception(
|
||||
$"Failed to parse weapon params, WeaponType='{WeaponType}', Json='{_drWeapon.ParamsJson}'.",
|
||||
exception);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 攻击力。
|
||||
/// </summary>
|
||||
public int Attack => _drWeapon.Attack;
|
||||
|
||||
public int EntityTypeId => _entityTypeId;
|
||||
|
||||
/// <summary>
|
||||
/// 武器名称。
|
||||
/// </summary>
|
||||
public string Title => _drWeapon.Title;
|
||||
|
||||
/// <summary>
|
||||
/// 图标资源名称。
|
||||
/// </summary>
|
||||
public string IconAssetName => _drWeapon.IconAssetName;
|
||||
|
||||
public ItemRarity Rarity => _drWeapon.Rarity;
|
||||
|
||||
public int Price => _drWeapon.Price;
|
||||
|
||||
/// <summary>
|
||||
/// 攻击间隔。
|
||||
/// </summary>
|
||||
public float Cooldown => _drWeapon.Cooldown;
|
||||
|
||||
/// <summary>
|
||||
/// 攻击范围。
|
||||
/// </summary>
|
||||
public float AttackRange => _drWeapon.AttackRange;
|
||||
|
||||
/// <summary>
|
||||
/// 攻击音效。
|
||||
/// </summary>
|
||||
public int AttackSoundId => _drWeapon.AttackSoundId;
|
||||
|
||||
/// <summary>
|
||||
/// 额外参数。
|
||||
/// </summary>
|
||||
public Dictionary<string, string> Params => _drWeapon.Pramas;
|
||||
|
||||
public string ParamsJson => _drWeapon.ParamsJson;
|
||||
|
||||
/// <summary>
|
||||
/// 额外属性。
|
||||
/// </summary>
|
||||
public StatModifier[] Modifiers => _drWeapon.Modifiers;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user