149 lines
4.5 KiB
C#
149 lines
4.5 KiB
C#
using System.Collections.Generic;
|
|
using System.Text;
|
|
using SepCore.DataTable;
|
|
using SepCore.Definition;
|
|
using SepCore.Entity;
|
|
using SepCore.Entity.Weapon;
|
|
using System;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace SepCore.CustomUtility
|
|
{
|
|
public static class ItemDescUtility
|
|
{
|
|
private static readonly Dictionary<string, string> _paramsDict = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
{"hitHalfWidth", "横向半宽"},
|
|
{"hitRadius", "攻击半宽"},
|
|
{"hitHeight", "判定高度"},
|
|
{"hitCenterYOffset", "判定高度偏移"},
|
|
{"sectorAngle", "攻击角度"},
|
|
{"pierceLength", "前戳距离"},
|
|
{"thrustDistance", "前戳距离(旧)"},
|
|
{"forwardOffset", "前置偏移"},
|
|
{"rotateSpeed", "转向速度"},
|
|
{"attackDuration", "突刺时长"},
|
|
{"returnDuration", "收枪时长"}
|
|
};
|
|
|
|
private static readonly string[] _statTypeNames =
|
|
{
|
|
"无效",
|
|
"最大生命",
|
|
"移动速度",
|
|
"伤害",
|
|
"防御",
|
|
"冷却",
|
|
"暴击率",
|
|
"暴击伤害",
|
|
"闪避",
|
|
"金币/经验吸收范围"
|
|
};
|
|
|
|
public static string Describe(StatModifier modifier)
|
|
{
|
|
if (modifier == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
string name = _statTypeNames[(int)modifier.StatType];
|
|
string colorTag = modifier.Value > 0 ? "green" : "red";
|
|
string suffix = modifier.IsPercent ? "%" : string.Empty;
|
|
float displayValue = modifier.IsPercent ? modifier.Value * 100 : modifier.Value;
|
|
return $"{name}: <color={colorTag}>+{displayValue}{suffix}</color>";
|
|
}
|
|
|
|
public static string CreatePropDescription(StatModifier[] modifiers)
|
|
{
|
|
if (modifiers == null || modifiers.Length == 0)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (StatModifier modifier in modifiers)
|
|
{
|
|
sb.Append(Describe(modifier));
|
|
sb.Append('\n');
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static string CreateWeaponDescription(DRWeapon drWeapon)
|
|
{
|
|
if (drWeapon == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
return CreateWeaponDescription(drWeapon.Attack, drWeapon.Cooldown, drWeapon.AttackRange, drWeapon.Modifiers,
|
|
drWeapon.Pramas);
|
|
}
|
|
|
|
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.Params);
|
|
}
|
|
|
|
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,
|
|
StatModifier[] modifiers, Dictionary<string, string> @params)
|
|
{
|
|
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 (@params == null || @params.Count == 0)
|
|
{
|
|
return sb.ToString();
|
|
}
|
|
|
|
foreach (var kvp in @params)
|
|
{
|
|
if (!_paramsDict.TryGetValue(kvp.Key, out string value))
|
|
{
|
|
value = kvp.Key;
|
|
Log.Warning($"{kvp.Key} is not defined.");
|
|
}
|
|
sb.AppendLine($"{value}: {kvp.Value}");
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
}
|
|
}
|