using System; using System.Collections.Generic; using DataTable; using Definition.DataStruct; using Definition.Enum; 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((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.ToLower(), out value); } protected TParams ParseParams() where TParams : new() { if (string.IsNullOrWhiteSpace(_drWeapon.ParamsJson)) { return new TParams(); } try { TParams parsed = Utility.Json.ToObject(_drWeapon.ParamsJson); return parsed ?? new TParams(); } catch (Exception exception) { throw new Exception( $"Failed to parse weapon params, WeaponType='{WeaponType}', Json='{_drWeapon.ParamsJson}'.", exception); } } /// /// 攻击力。 /// public int Attack => _drWeapon.Attack; public int EntityTypeId => _entityTypeId; /// /// 武器名称。 /// public string Title => _drWeapon.Title; /// /// 图标资源名称。 /// public string IconAssetName => _drWeapon.IconAssetName; public ItemRarity Rarity => _drWeapon.Rarity; public int Price => _drWeapon.Price; /// /// 攻击间隔。 /// public float Cooldown => _drWeapon.Cooldown; /// /// 攻击范围。 /// public float AttackRange => _drWeapon.AttackRange; /// /// 攻击音效。 /// public int AttackSoundId => _drWeapon.AttackSoundId; /// /// 额外参数。 /// public Dictionary Params => _drWeapon.Pramas; public string ParamsJson => _drWeapon.ParamsJson; /// /// 额外属性。 /// public StatModifier[] Modifiers => _drWeapon.Modifiers; } }