(client) feat:状态UI
This commit is contained in:
@ -19,10 +19,6 @@ namespace Data
|
||||
// ======================================================================
|
||||
// 百分比偏移 (Multiplied as a factor, e.g., 0.1 for +10%)
|
||||
// ======================================================================
|
||||
// 注意:百分比偏移通常是乘法因子。
|
||||
// 0f 表示没有百分比变化,0.1f 表示增加10%,-0.1f 表示减少10%。
|
||||
// 应用时: baseValue * (1 + percentageOffset)
|
||||
// 或者对于更直接的乘法,可以直接用 multiplyRatio,例如 1.1 表示增加 10%。
|
||||
public float healthPercentOffset = 0f; // 例如 0.1 表示 +10%
|
||||
public float moveSpeedPercentOffset = 0f;
|
||||
public float attackPercentOffset = 0f;
|
||||
@ -31,94 +27,39 @@ namespace Data
|
||||
public float attackRangePercentOffset = 0f;
|
||||
|
||||
public float attackTargetCountPercentOffset = 0f;
|
||||
|
||||
// ======================================================================
|
||||
// 数组偏移 / 集合偏移 (更复杂的情况,如果原始属性是数组/集合)
|
||||
// 因为你的Attributes类目前都是单一值,所以这里先按单一值处理。
|
||||
// 如果 future Attributes.attackTargets 变成 List<string> 或者 int[],
|
||||
// 这里就需要 List<string> addedAttackTargets 或 List<int> addedAttackTargetCounts
|
||||
// 来表示要添加/移除的元素。
|
||||
// 示例:如果将来有一个属性是效果列表,这里可以定义要添加的效果
|
||||
// public List<string> addedEffects = new List<string>();
|
||||
// public List<string> removedEffects = new List<string>();
|
||||
// 如果 `attackTargetCount` 实际代表可以攻击的目标ID数组,那么:
|
||||
// public List<int> addedAttackTargets = new List<int>();
|
||||
// public List<int> removedAttackTargets = new List<int>();
|
||||
// 注意:对于 `attackTargetCount` 来说,它本身是一个 int,
|
||||
// 上面的 `attackTargetCountOffset` 已经足够处理“增加攻击目标数量”的需求。
|
||||
// "数组偏移"通常指的是当原始属性本身是一个集合时,你想要修改这个集合的元素。
|
||||
// 如果 `Attributes` 类保持其当前形式 (都是单一数值),那么不需要专门的数组偏移。
|
||||
// ======================================================================
|
||||
// 构造函数 (可选,用于方便初始化)
|
||||
// ======================================================================
|
||||
public AttributesOffsetDef()
|
||||
{
|
||||
}
|
||||
|
||||
// 可以添加带参数的构造函数,方便快速设置
|
||||
public AttributesOffsetDef(float healthAbs = 0f, float moveSpeedAbs = 0f, float attackAbs = 0f,
|
||||
float defenseAbs = 0f, float attackSpeedAbs = 0f, float attackRangeAbs = 0f,
|
||||
float attackTargetCountAbs = 0f,
|
||||
float healthPct = 0f, float moveSpeedPct = 0f, float attackPct = 0f,
|
||||
float defensePct = 0f, float attackSpeedPct = 0f, float attackRangePct = 0f,
|
||||
float attackTargetCountPct = 0f)
|
||||
{
|
||||
healthOffset = healthAbs;
|
||||
moveSpeedOffset = moveSpeedAbs;
|
||||
attackOffset = attackAbs;
|
||||
defenseOffset = defenseAbs;
|
||||
attackSpeedOffset = attackSpeedAbs;
|
||||
attackRangeOffset = attackRangeAbs;
|
||||
attackTargetCountOffset = attackTargetCountAbs;
|
||||
healthPercentOffset = healthPct;
|
||||
moveSpeedPercentOffset = moveSpeedPct;
|
||||
attackPercentOffset = attackPct;
|
||||
defensePercentOffset = defensePct;
|
||||
attackSpeedPercentOffset = attackSpeedPct;
|
||||
attackRangePercentOffset = attackRangePct;
|
||||
attackTargetCountPercentOffset = attackTargetCountPct;
|
||||
}
|
||||
|
||||
// ======================================================================
|
||||
// 应用偏移的方法
|
||||
// ======================================================================
|
||||
|
||||
/// <summary>
|
||||
/// 将此偏移应用到给定的Attributes实例上。
|
||||
/// 重载 + 操作符,用于合并两个 AttributesOffsetDef 实例。
|
||||
/// </summary>
|
||||
/// <param name="baseAttributes">要应用偏移的基础Attributes。</param>
|
||||
/// <returns>应用偏移后的新Attributes实例。</returns>
|
||||
public Attributes ApplyTo(Attributes baseAttributes)
|
||||
/// <param name="a">第一个属性修正定义。</param>
|
||||
/// <param name="b">第二个属性修正定义。</param>
|
||||
/// <returns>一个新的 AttributesOffsetDef 实例,包含两个输入的累加值。</returns>
|
||||
public static AttributesOffsetDef operator +(AttributesOffsetDef a, AttributesOffsetDef b)
|
||||
{
|
||||
// 创建一个新的Attributes实例以避免修改原始实例
|
||||
// 或者如果需要直接修改,可以返回 void
|
||||
Attributes modifiedAttributes = new Attributes
|
||||
// 处理 null 情况,如果其中一个为 null,则返回另一个的副本(或一个空实例如果两者都为 null)。
|
||||
if (a == null && b == null) return new AttributesOffsetDef();
|
||||
if (a == null) return b; // 如果 a 是 null,返回 b 的值
|
||||
if (b == null) return a; // 如果 b 是 null,返回 a 的值
|
||||
var combined = new AttributesOffsetDef
|
||||
{
|
||||
health = baseAttributes.health,
|
||||
moveSpeed = baseAttributes.moveSpeed,
|
||||
attack = baseAttributes.attack,
|
||||
defense = baseAttributes.defense,
|
||||
attackSpeed = baseAttributes.attackSpeed,
|
||||
attackRange = baseAttributes.attackRange,
|
||||
attackTargetCount = baseAttributes.attackTargetCount
|
||||
// 绝对值偏移累加
|
||||
healthOffset = a.healthOffset + b.healthOffset,
|
||||
moveSpeedOffset = a.moveSpeedOffset + b.moveSpeedOffset,
|
||||
attackOffset = a.attackOffset + b.attackOffset,
|
||||
defenseOffset = a.defenseOffset + b.defenseOffset,
|
||||
attackSpeedOffset = a.attackSpeedOffset + b.attackSpeedOffset,
|
||||
attackRangeOffset = a.attackRangeOffset + b.attackRangeOffset,
|
||||
attackTargetCountOffset = a.attackTargetCountOffset + b.attackTargetCountOffset,
|
||||
// 百分比偏移累加
|
||||
healthPercentOffset = a.healthPercentOffset + b.healthPercentOffset,
|
||||
moveSpeedPercentOffset = a.moveSpeedPercentOffset + b.moveSpeedPercentOffset,
|
||||
attackPercentOffset = a.attackPercentOffset + b.attackPercentOffset,
|
||||
defensePercentOffset = a.defensePercentOffset + b.defensePercentOffset,
|
||||
attackSpeedPercentOffset = a.attackSpeedPercentOffset + b.attackSpeedPercentOffset,
|
||||
attackRangePercentOffset = a.attackRangePercentOffset + b.attackRangePercentOffset,
|
||||
attackTargetCountPercentOffset = a.attackTargetCountPercentOffset + b.attackTargetCountPercentOffset
|
||||
};
|
||||
// 首先应用百分比偏移
|
||||
modifiedAttributes.health = (int)(modifiedAttributes.health * (1f + healthPercentOffset));
|
||||
modifiedAttributes.moveSpeed *= (1f + moveSpeedPercentOffset);
|
||||
modifiedAttributes.attack = (int)(modifiedAttributes.attack * (1f + attackPercentOffset));
|
||||
modifiedAttributes.defense = (int)(modifiedAttributes.defense * (1f + defensePercentOffset));
|
||||
modifiedAttributes.attackSpeed = (int)(modifiedAttributes.attackSpeed * (1f + attackSpeedPercentOffset));
|
||||
modifiedAttributes.attackRange = (int)(modifiedAttributes.attackRange * (1f + attackRangePercentOffset));
|
||||
modifiedAttributes.attackTargetCount =
|
||||
(int)(modifiedAttributes.attackTargetCount * (1f + attackTargetCountPercentOffset));
|
||||
// 然后应用绝对值偏移
|
||||
modifiedAttributes.health += (int)healthOffset;
|
||||
modifiedAttributes.moveSpeed += moveSpeedOffset;
|
||||
modifiedAttributes.attack += (int)attackOffset;
|
||||
modifiedAttributes.defense += (int)defenseOffset;
|
||||
modifiedAttributes.attackSpeed += (int)attackSpeedOffset;
|
||||
modifiedAttributes.attackRange += (int)attackRangeOffset;
|
||||
modifiedAttributes.attackTargetCount += (int)attackTargetCountOffset;
|
||||
return modifiedAttributes;
|
||||
return combined;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user