124 lines
6.8 KiB
C#
124 lines
6.8 KiB
C#
using Entity;
|
||
|
||
namespace Data
|
||
{
|
||
public class AttributesOffsetDef : Define
|
||
{
|
||
// ======================================================================
|
||
// 绝对值偏移 (Added/Subtracted directly)
|
||
// ======================================================================
|
||
public float healthOffset = 0f;
|
||
public float moveSpeedOffset = 0f;
|
||
public float attackOffset = 0f;
|
||
public float defenseOffset = 0f;
|
||
public float attackSpeedOffset = 0f;
|
||
public float attackRangeOffset = 0f;
|
||
|
||
public float attackTargetCountOffset = 0f;
|
||
|
||
// ======================================================================
|
||
// 百分比偏移 (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;
|
||
public float defensePercentOffset = 0f;
|
||
public float attackSpeedPercentOffset = 0f;
|
||
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实例上。
|
||
/// </summary>
|
||
/// <param name="baseAttributes">要应用偏移的基础Attributes。</param>
|
||
/// <returns>应用偏移后的新Attributes实例。</returns>
|
||
public Attributes ApplyTo(Attributes baseAttributes)
|
||
{
|
||
// 创建一个新的Attributes实例以避免修改原始实例
|
||
// 或者如果需要直接修改,可以返回 void
|
||
Attributes modifiedAttributes = new Attributes
|
||
{
|
||
health = baseAttributes.health,
|
||
moveSpeed = baseAttributes.moveSpeed,
|
||
attack = baseAttributes.attack,
|
||
defense = baseAttributes.defense,
|
||
attackSpeed = baseAttributes.attackSpeed,
|
||
attackRange = baseAttributes.attackRange,
|
||
attackTargetCount = baseAttributes.attackTargetCount
|
||
};
|
||
// 首先应用百分比偏移
|
||
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;
|
||
}
|
||
}
|
||
} |