Files
vampire-like/Assets/GameMain/Scripts/Presentation/Utility/ItemDescUtility.cs
T
2026-09-18 21:43:22 +08:00

164 lines
5.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using SepCore.Definition;
using SepCore.Entity;
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 =
{
"无效", // None = 0
"最大生命", // MaxHp = 1
"生命恢复", // HpRegen = 2
"生命窃取", // LifeSteal = 3
"伤害加成", // DamagePercent = 4
"近战伤害", // MeleeDamage = 5
"远程伤害", // RangedDamage = 6
"元素伤害", // ElementalDamage = 7
"攻击速度", // AttackSpeed = 8
"暴击率", // CritChance = 9
"工程学", // Engineering = 10
"攻击范围", // Range = 11
"护甲", // Armor = 12
"闪避率", // Dodge = 13
"移动速度", // MoveSpeed = 14
"收获", // Harvesting = 15
"幸运" // Luck = 16
};
public static string Describe(StatModifierConfig statModifierConfig)
{
if (statModifierConfig == null)
{
return string.Empty;
}
int index = (int)statModifierConfig.StatType;
string name = (index >= 0 && index < _statTypeNames.Length) ? _statTypeNames[index] : statModifierConfig.StatType.ToString();
string colorTag = statModifierConfig.Value >= 0 ? "green" : "red";
string sign = statModifierConfig.Value >= 0 ? "+" : "";
if (statModifierConfig.ModifierType == ModifierType.PercentAdd)
{
float displayPercent = statModifierConfig.Value * 100f;
return $"{name}: <color={colorTag}>{sign}{displayPercent:0.##}%</color>";
}
if (statModifierConfig.ModifierType == ModifierType.PercentMult)
{
return $"{name}: <color={colorTag}>x{statModifierConfig.Value:0.##}</color>";
}
return $"{name}: <color={colorTag}>{sign}{statModifierConfig.Value:0.##}</color>";
}
public static string CreatePropDescription(IEnumerable<StatModifierConfig> modifiers)
{
if (modifiers == null)
{
return null;
}
StringBuilder sb = new StringBuilder();
foreach (StatModifierConfig 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.StatModifierConfigs, 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<StatModifierConfig> 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();
}
}
}