159 lines
4.7 KiB
C#
159 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using SepCore.Definition;
|
|
using SepCore.Entity;
|
|
using SepCore.Entity.Weapon;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace SepCore.CustomUtility
|
|
{
|
|
public static class ItemDescUtility
|
|
{
|
|
private static readonly Dictionary<ParamType, string> _paramTypeNames = new()
|
|
{
|
|
{ ParamType.HitRadius, "攻击半宽" },
|
|
{ ParamType.SectorAngle, "攻击角度" },
|
|
{ ParamType.HitHalfWidth, "横向半宽" },
|
|
{ ParamType.PierceLength, "前戳距离" },
|
|
{ ParamType.HitHeight, "判定高度" },
|
|
};
|
|
|
|
private static readonly string[] _statTypeNames =
|
|
{
|
|
"无效",
|
|
"最大生命",
|
|
"移动速度",
|
|
"伤害",
|
|
"防御",
|
|
"冷却",
|
|
"暴击率",
|
|
"暴击伤害",
|
|
"闪避",
|
|
"金币/经验吸收范围"
|
|
};
|
|
|
|
public static string Describe(modifier modifier)
|
|
{
|
|
if (modifier == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
string name = _statTypeNames[(int)modifier.Key];
|
|
string colorTag = modifier.Value > 0 ? "green" : "red";
|
|
string suffix = modifier.IsPercent ? "%" : string.Empty;
|
|
float displayValue;
|
|
if (modifier.IsPercent)
|
|
{
|
|
displayValue = modifier.Value / 10f;
|
|
}
|
|
else if (modifier.Key == StatType.MovementSpeed)
|
|
{
|
|
displayValue = modifier.Value / 1000f;
|
|
}
|
|
else
|
|
{
|
|
displayValue = modifier.Value;
|
|
}
|
|
|
|
return $"{name}: <color={colorTag}>+{displayValue:0.##}{suffix}</color>";
|
|
}
|
|
|
|
public static string CreatePropDescription(IEnumerable<modifier> modifiers)
|
|
{
|
|
if (modifiers == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (modifier modifier in modifiers)
|
|
{
|
|
sb.Append(Describe(modifier));
|
|
sb.Append('\n');
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static string CreateWeaponDescription(WeaponConfig weaponConfig)
|
|
{
|
|
if (weaponConfig == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return CreateWeaponDescription(weaponConfig.Attack, weaponConfig.Cooldown / 1000f,
|
|
weaponConfig.AttackRange / 1000f, weaponConfig.Modifiers, weaponConfig.Parameters);
|
|
}
|
|
|
|
public static string CreateWeaponDescription(WeaponBase weapon)
|
|
{
|
|
if (weapon == null || weapon.WeaponData == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return CreateWeaponDescription(weapon.WeaponData);
|
|
}
|
|
|
|
public static string CreateWeaponDescription(WeaponData weaponData)
|
|
{
|
|
if (weaponData == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return CreateWeaponDescription(weaponData.Attack, weaponData.Cooldown,
|
|
weaponData.AttackRange, weaponData.Modifiers, weaponData.Parameters);
|
|
}
|
|
|
|
public static string CreatePropDescription(PropItem prop)
|
|
{
|
|
if (prop == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return CreatePropDescription(prop.Modifiers);
|
|
}
|
|
|
|
private static string CreateWeaponDescription(int attack, float cooldown, float attackRange,
|
|
IEnumerable<modifier> modifiers, IReadOnlyDictionary<ParamType, int> parameters)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.AppendLine($"攻击: {attack}");
|
|
sb.AppendLine($"冷却: {cooldown}");
|
|
sb.AppendLine($"范围: {attackRange}");
|
|
|
|
string modifiersDesc = CreatePropDescription(modifiers);
|
|
if (!string.IsNullOrEmpty(modifiersDesc))
|
|
{
|
|
sb.Append(modifiersDesc);
|
|
}
|
|
|
|
if (parameters == null || parameters.Count == 0)
|
|
{
|
|
return sb.ToString();
|
|
}
|
|
|
|
foreach (var kvp in parameters)
|
|
{
|
|
if (!_paramTypeNames.TryGetValue(kvp.Key, out string paramName))
|
|
{
|
|
paramName = kvp.Key.ToString();
|
|
}
|
|
|
|
string valStr = kvp.Key == ParamType.SectorAngle
|
|
? kvp.Value.ToString()
|
|
: (kvp.Value / 1000f).ToString("0.##");
|
|
|
|
sb.AppendLine($"{paramName}: {valStr}");
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|