为 RepoItem 添加背景耐久变色
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using GeometryTD.Definition;
|
||||
|
||||
@@ -54,6 +55,73 @@ namespace GeometryTD.CustomUtility
|
||||
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();
|
||||
@@ -66,9 +134,11 @@ namespace GeometryTD.CustomUtility
|
||||
}
|
||||
sb.Append('\n');
|
||||
|
||||
sb.Append($"伤害浮动:{muzzleData.DamageRandomRate:P0}\n");
|
||||
sb.AppendLine($"伤害浮动:{muzzleData.DamageRandomRate:P0}");
|
||||
|
||||
sb.Append($"攻击方式:{ConvertAttackMethod(muzzleData.AttackMethodType)}\n");
|
||||
sb.AppendLine($"攻击方式:{ConvertAttackMethod(muzzleData.AttackMethodType)}");
|
||||
|
||||
sb.AppendLine($"当前耐久:{muzzleData.Endurance}");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -93,6 +163,8 @@ namespace GeometryTD.CustomUtility
|
||||
}
|
||||
sb.Append('\n');
|
||||
|
||||
sb.AppendLine($"当前耐久:{bearingData.Endurance}");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
@@ -108,7 +180,9 @@ namespace GeometryTD.CustomUtility
|
||||
}
|
||||
sb.Append('\n');
|
||||
|
||||
sb.Append($"伤害属性:{ConvertAttackProperty(baseData.AttackPropertyType)}\n");
|
||||
sb.AppendLine($"伤害属性:{ConvertAttackProperty(baseData.AttackPropertyType)}");
|
||||
|
||||
sb.AppendLine($"当前耐久:{baseData.Endurance}");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
@@ -118,7 +192,7 @@ namespace GeometryTD.CustomUtility
|
||||
return type switch
|
||||
{
|
||||
AttackMethodType.None => "无效",
|
||||
AttackMethodType.NormalBullet => "发射子弹",
|
||||
AttackMethodType.NormalBullet => "发送子弹",
|
||||
AttackMethodType.Range => "范围攻击",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
|
||||
};
|
||||
@@ -131,7 +205,7 @@ namespace GeometryTD.CustomUtility
|
||||
AttackPropertyType.None => "无效",
|
||||
AttackPropertyType.Physics => "<color=#ffff00ff>物理</color>", //yellow
|
||||
AttackPropertyType.Fire => "<color=#ff0000ff>火</color>", //red
|
||||
AttackPropertyType.Water => "<color=#00ffffff>水</color>", //cyan
|
||||
AttackPropertyType.Water => "<color=#00ffffff>水/color>", //cyan
|
||||
AttackPropertyType.Earth => "<color=#00ff00ff>自然</color>", //lime
|
||||
AttackPropertyType.Poison => "<color=#008000ff>毒</color>", //green
|
||||
AttackPropertyType.Ice => "<color=#0000a0ff>冰</color>", //darkblue
|
||||
@@ -139,4 +213,6 @@ namespace GeometryTD.CustomUtility
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user