调整 convert.py 转换逻辑 + 规划后续开发

This commit is contained in:
2026-03-17 13:21:49 +08:00
parent 59f1d02a18
commit c5d113b35f
15 changed files with 572 additions and 123 deletions
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using DataTable;
using Definition.DataStruct;
using Definition.Enum;
using GameFramework;
namespace Entity.EntityData
{
@@ -39,6 +40,26 @@ namespace Entity.EntityData
return Params.TryGetValue(key.ToLower(), 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>
@@ -80,9 +101,11 @@ namespace Entity.EntityData
/// </summary>
public Dictionary<string, string> Params => _drWeapon.Pramas;
public string ParamsJson => _drWeapon.ParamsJson;
/// <summary>
/// 额外属性。
/// </summary>
public StatModifier[] Modifiers => _drWeapon.Modifiers;
}
}
}
@@ -1,12 +1,21 @@
using System;
using Definition.Enum;
namespace Entity.EntityData
{
[Serializable]
public sealed class WeaponHandgunParamsData
{
}
public class WeaponHandgunData : WeaponData
{
public WeaponHandgunParamsData ParamsData { get; }
public WeaponHandgunData(int entityId, int ownerId, CampType ownerCamp)
: base(entityId, WeaponType.WeaponHandgun, ownerId, ownerCamp)
{
ParamsData = ParseParams<WeaponHandgunParamsData>();
}
}
}
@@ -1,12 +1,22 @@
using System;
using Definition.Enum;
namespace Entity.EntityData
{
[Serializable]
public sealed class WeaponKnifeParamsData
{
public float HitRadius { get; set; }
}
public class WeaponKnifeData : WeaponData
{
public WeaponKnifeParamsData ParamsData { get; }
public WeaponKnifeData(int entityId, int ownerId, CampType ownerCamp) : base(entityId, WeaponType.WeaponKnife,
ownerId, ownerCamp)
{
ParamsData = ParseParams<WeaponKnifeParamsData>();
}
}
}
}
@@ -1,12 +1,23 @@
using System;
using Definition.Enum;
namespace Entity.EntityData
{
[Serializable]
public sealed class WeaponLightningParamsData
{
public float HitRadius { get; set; }
public float HoverHeight { get; set; }
}
public class WeaponLightningData : WeaponData
{
public WeaponLightningParamsData ParamsData { get; }
public WeaponLightningData(int entityId, int ownerId, CampType ownerCamp)
: base(entityId, WeaponType.WeaponLightning, ownerId, ownerCamp)
{
ParamsData = ParseParams<WeaponLightningParamsData>();
}
}
}
@@ -1,12 +1,22 @@
using System;
using Definition.Enum;
namespace Entity.EntityData
{
[Serializable]
public sealed class WeaponSlashParamsData
{
public float SectorAngle { get; set; }
}
public class WeaponSlashData : WeaponData
{
public WeaponSlashParamsData ParamsData { get; }
public WeaponSlashData(int entityId, int ownerId, CampType ownerCamp)
: base(entityId, WeaponType.WeaponSlash, ownerId, ownerCamp)
{
ParamsData = ParseParams<WeaponSlashParamsData>();
}
}
}
}
@@ -11,8 +11,6 @@ namespace Entity.Weapon
{
public partial class WeaponKnife : WeaponBase
{
private const string HitRadiusParamKey = "HitRadius";
private WeaponKnifeData _weaponData;
private Quaternion _cachedRotation;
@@ -157,14 +155,8 @@ namespace Entity.Weapon
_sqrRange = _weaponData.AttackRange * _weaponData.AttackRange;
_cachedRotation = CachedTransform.rotation;
if (_weaponData.TryGetParam(HitRadiusParamKey, out string hitRadiusRaw))
{
_hitRadius = Mathf.Max(0.1f, float.Parse(hitRadiusRaw));
}
else
{
_hitRadius = _weaponData.AttackRange;
}
float configuredHitRadius = _weaponData.ParamsData != null ? _weaponData.ParamsData.HitRadius : 0f;
_hitRadius = configuredHitRadius > 0f ? Mathf.Max(0.1f, configuredHitRadius) : _weaponData.AttackRange;
_hitRadiusSqr = _hitRadius * _hitRadius;
_attackEffect = new KnifeRangeAttackEffect();
@@ -11,8 +11,6 @@ namespace Entity.Weapon
{
public partial class WeaponLightning : WeaponBase
{
private const string HitRadiusParamKey = "HitRadius";
private WeaponLightningData _weaponData;
private Quaternion _cachedRotation;
@@ -178,8 +176,14 @@ namespace Entity.Weapon
_sqrRange = _weaponData.AttackRange * _weaponData.AttackRange;
_cachedRotation = CachedTransform.rotation;
_hitRadius = ReadPositiveParam(HitRadiusParamKey, _weaponData.AttackRange);
float configuredHitRadius = _weaponData.ParamsData != null ? _weaponData.ParamsData.HitRadius : 0f;
_hitRadius = configuredHitRadius > 0f ? Mathf.Max(0.1f, configuredHitRadius) : _weaponData.AttackRange;
_hitRadiusSqr = _hitRadius * _hitRadius;
float configuredHoverHeight = _weaponData.ParamsData != null ? _weaponData.ParamsData.HoverHeight : 0f;
if (configuredHoverHeight > 0f)
{
_hoverHeight = Mathf.Max(0.1f, configuredHoverHeight);
}
int colliderCapacity = Mathf.Max(1, _maxHitColliders);
if (_hitResults == null || _hitResults.Length != colliderCapacity)
@@ -228,18 +232,6 @@ namespace Entity.Weapon
}
}
private float ReadPositiveParam(string paramName, float defaultValue)
{
if (_weaponData.Params != null &&
_weaponData.Params.TryGetValue(paramName.ToLower(), out string rawValue) &&
float.TryParse(rawValue, out float parsedValue))
{
return Mathf.Max(0.1f, parsedValue);
}
return Mathf.Max(0.1f, defaultValue);
}
private void StopAttackTween(bool resetTransform)
{
if (_attackSequence != null)
@@ -13,8 +13,6 @@ namespace Entity.Weapon
{
#region Property
private const string SectorAngleParamKey = "SectorAngle";
private WeaponSlashData _weaponData;
private Quaternion _cachedRotation;
@@ -184,15 +182,8 @@ namespace Entity.Weapon
_attackRadius = Mathf.Max(0.1f, _weaponData.AttackRange);
_attackRadiusSqr = _attackRadius * _attackRadius;
_sectorAngle = 90f;
if (_weaponData.Params != null &&
_weaponData.Params.TryGetValue(SectorAngleParamKey.ToLower(), out string rawAngle))
{
if (float.TryParse(rawAngle, out float parsedAngle))
{
_sectorAngle = Mathf.Clamp(parsedAngle, 1f, 360f);
}
}
float configuredSectorAngle = _weaponData.ParamsData != null ? _weaponData.ParamsData.SectorAngle : 0f;
_sectorAngle = configuredSectorAngle > 0f ? Mathf.Clamp(configuredSectorAngle, 1f, 360f) : 90f;
int capacity = Mathf.Max(1, _maxHitColliders);
if (_hitResults == null || _hitResults.Length != capacity)