219 lines
7.4 KiB
C#
219 lines
7.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using GeometryTD.Definition;
|
|
|
|
namespace GeometryTD.CustomUtility
|
|
{
|
|
public static class ItemDescUtility
|
|
{
|
|
public static string BuildTowerDesc(TowerStatsData towerData)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
// MuzzleComp
|
|
sb.Append("攻击伤害:");
|
|
for (int i = 0; i < towerData.AttackDamage.Length; i++)
|
|
{
|
|
if (i != 0) sb.Append("|");
|
|
sb.Append(towerData.AttackDamage[i]);
|
|
}
|
|
sb.Append('\n');
|
|
|
|
sb.Append($"伤害浮动:{towerData.DamageRandomRate:P0}\n");
|
|
|
|
sb.Append($"攻击方式:{ConvertAttackMethod(towerData.AttackMethodType)}\n");
|
|
|
|
// BearingComp
|
|
sb.Append("旋转速度:");
|
|
for (int i = 0; i < towerData.RotateSpeed.Length; i++)
|
|
{
|
|
if (i != 0) sb.Append("|");
|
|
sb.Append(towerData.RotateSpeed[i]);
|
|
}
|
|
sb.Append('\n');
|
|
|
|
sb.Append("攻击范围:");
|
|
for (int i = 0; i < towerData.AttackRange.Length; i++)
|
|
{
|
|
if (i != 0) sb.Append("|");
|
|
sb.Append(towerData.AttackRange[i]);
|
|
}
|
|
sb.Append('\n');
|
|
|
|
// BaseComp
|
|
sb.Append("攻击速度:");
|
|
for (int i = 0; i < towerData.AttackSpeed.Length; i++)
|
|
{
|
|
if (i != 0) sb.Append("|");
|
|
sb.Append(towerData.AttackSpeed[i]);
|
|
}
|
|
sb.Append('\n');
|
|
|
|
sb.Append($"伤害属性:{ConvertAttackProperty(towerData.AttackPropertyType)}\n");
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static string BuildTowerDesc(
|
|
TowerItemData tower,
|
|
IReadOnlyDictionary<long, MuzzleCompItemData> muzzleMap,
|
|
IReadOnlyDictionary<long, BearingCompItemData> bearingMap,
|
|
IReadOnlyDictionary<long, BaseCompItemData> baseMap)
|
|
{
|
|
if (tower == null)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.Append(BuildTowerDesc(tower.Stats ?? new TowerStatsData()));
|
|
float enduranceRate = ResolveTowerEnduranceRate(tower, muzzleMap, bearingMap, baseMap);
|
|
sb.AppendLine($"平均耐久: {enduranceRate * 100f:0.#}");
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static float ResolveComponentEnduranceRate(TowerCompItemData item)
|
|
{
|
|
if (item == null)
|
|
{
|
|
return 1f;
|
|
}
|
|
|
|
return UnityEngine.Mathf.Clamp01(item.Endurance / 100f);
|
|
}
|
|
|
|
public static float ResolveTowerEnduranceRate(
|
|
TowerItemData tower,
|
|
IReadOnlyDictionary<long, MuzzleCompItemData> muzzleMap,
|
|
IReadOnlyDictionary<long, BearingCompItemData> bearingMap,
|
|
IReadOnlyDictionary<long, BaseCompItemData> baseMap)
|
|
{
|
|
if (tower == null)
|
|
{
|
|
return 1f;
|
|
}
|
|
|
|
float sum = 0f;
|
|
int count = 0;
|
|
if (muzzleMap != null && muzzleMap.TryGetValue(tower.MuzzleComponentInstanceId, out MuzzleCompItemData muzzle))
|
|
{
|
|
sum += ResolveComponentEnduranceRate(muzzle);
|
|
count++;
|
|
}
|
|
|
|
if (bearingMap != null && bearingMap.TryGetValue(tower.BearingComponentInstanceId, out BearingCompItemData bearing))
|
|
{
|
|
sum += ResolveComponentEnduranceRate(bearing);
|
|
count++;
|
|
}
|
|
|
|
if (baseMap != null && baseMap.TryGetValue(tower.BaseComponentInstanceId, out BaseCompItemData baseComp))
|
|
{
|
|
sum += ResolveComponentEnduranceRate(baseComp);
|
|
count++;
|
|
}
|
|
|
|
if (count <= 0)
|
|
{
|
|
return 1f;
|
|
}
|
|
|
|
return UnityEngine.Mathf.Clamp01(sum / count);
|
|
}
|
|
|
|
public static string BuildMuzzleDesc(MuzzleCompItemData muzzleData)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.Append("攻击伤害:");
|
|
for (int i = 0; i < muzzleData.AttackDamage.Length; i++)
|
|
{
|
|
if (i != 0) sb.Append("|");
|
|
sb.Append(muzzleData.AttackDamage[i]);
|
|
}
|
|
sb.Append('\n');
|
|
|
|
sb.AppendLine($"伤害浮动:{muzzleData.DamageRandomRate:P0}");
|
|
|
|
sb.AppendLine($"攻击方式:{ConvertAttackMethod(muzzleData.AttackMethodType)}");
|
|
|
|
sb.AppendLine($"当前耐久:{muzzleData.Endurance}");
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static string BuildBearingDesc(BearingCompItemData bearingData)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.Append("旋转速度:");
|
|
for (int i = 0; i < bearingData.RotateSpeed.Length; i++)
|
|
{
|
|
if (i != 0) sb.Append("|");
|
|
sb.Append(bearingData.RotateSpeed[i]);
|
|
}
|
|
sb.Append('\n');
|
|
|
|
sb.Append("攻击范围:");
|
|
for (int i = 0; i < bearingData.AttackRange.Length; i++)
|
|
{
|
|
if (i != 0) sb.Append("|");
|
|
sb.Append(bearingData.AttackRange[i]);
|
|
}
|
|
sb.Append('\n');
|
|
|
|
sb.AppendLine($"当前耐久:{bearingData.Endurance}");
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static string BuildBaseDesc(BaseCompItemData baseData)
|
|
{
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.Append("攻击速度:");
|
|
for (int i = 0; i < baseData.AttackSpeed.Length; i++)
|
|
{
|
|
if (i != 0) sb.Append("|");
|
|
sb.Append(baseData.AttackSpeed[i]);
|
|
}
|
|
sb.Append('\n');
|
|
|
|
sb.AppendLine($"伤害属性:{ConvertAttackProperty(baseData.AttackPropertyType)}");
|
|
|
|
sb.AppendLine($"当前耐久:{baseData.Endurance}");
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static string ConvertAttackMethod(AttackMethodType type)
|
|
{
|
|
return type switch
|
|
{
|
|
AttackMethodType.None => "无效",
|
|
AttackMethodType.NormalBullet => "发送子弹",
|
|
AttackMethodType.Range => "范围攻击",
|
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
|
};
|
|
}
|
|
|
|
public static string ConvertAttackProperty(AttackPropertyType type)
|
|
{
|
|
return type switch
|
|
{
|
|
AttackPropertyType.None => "无效",
|
|
AttackPropertyType.Physics => "<color=#ffff00ff>物理</color>", //yellow
|
|
AttackPropertyType.Fire => "<color=#ff0000ff>火</color>", //red
|
|
AttackPropertyType.Water => "<color=#00ffffff>水/color>", //cyan
|
|
AttackPropertyType.Earth => "<color=#00ff00ff>自然</color>", //lime
|
|
AttackPropertyType.Poison => "<color=#008000ff>毒</color>", //green
|
|
AttackPropertyType.Ice => "<color=#0000a0ff>冰</color>", //darkblue
|
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
|
};
|
|
}
|
|
}
|
|
}
|
|
|
|
|