Files
Gen_Hack-and-Slash-Roguelit…/Client/Assets/Scripts/Data/AttributesOffsetDef.cs
2025-09-02 11:08:15 +08:00

65 lines
3.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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%)
// ======================================================================
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;
/// <summary>
/// 重载 + 操作符,用于合并两个 AttributesOffsetDef 实例。
/// </summary>
/// <param name="a">第一个属性修正定义。</param>
/// <param name="b">第二个属性修正定义。</param>
/// <returns>一个新的 AttributesOffsetDef 实例,包含两个输入的累加值。</returns>
public static AttributesOffsetDef operator +(AttributesOffsetDef a, AttributesOffsetDef b)
{
// 处理 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
{
// 绝对值偏移累加
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
};
return combined;
}
}
}