99 lines
3.7 KiB
C#
99 lines
3.7 KiB
C#
using System;
|
||
using Cielonos.MainGame.Buffs;
|
||
using Cielonos.MainGame.Buffs.Character;
|
||
using SLSUtilities.General;
|
||
|
||
namespace Cielonos.MainGame.Inventory.Collections
|
||
{
|
||
/// <summary>
|
||
/// 自适应装甲 / Adaptive Armor
|
||
/// 玩家受到伤害时,获得一个持续10秒的(护甲+5)的Buff,最高可叠加5层,每次叠加刷新持续时间。
|
||
/// </summary>
|
||
public partial class AdaptiveArmor : PassiveEquipmentBase
|
||
{
|
||
private const string EventKey = "AdaptiveArmor";
|
||
|
||
public override void OnObtained()
|
||
{
|
||
base.OnObtained();
|
||
|
||
Action<AttackAreaBase, Attack.Result> onAfterGetAttacked = OnAfterGetAttacked;
|
||
player.eventSm.onAfterGetAttacked.Add(EventKey, onAfterGetAttacked.ToPrioritized());
|
||
}
|
||
|
||
public override void OnDiscarded()
|
||
{
|
||
player.eventSm.onAfterGetAttacked.Remove(EventKey);
|
||
|
||
// 移除残留的 Buff
|
||
if (player.buffSm.TryGetBuff(out TemporaryArmor existingBuff))
|
||
{
|
||
existingBuff.Remove();
|
||
}
|
||
|
||
base.OnDiscarded();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 玩家被攻击后触发,施加或叠加临时护甲 Buff。
|
||
/// </summary>
|
||
private void OnAfterGetAttacked(AttackAreaBase attackArea, Attack.Result result)
|
||
{
|
||
float armorPerStack = passiveAttributeSm.GetItemAttribute("ArmorPerStack");
|
||
float duration = passiveAttributeSm.GetItemAttribute("BuffDuration");
|
||
int maxStacks = (int)passiveAttributeSm.GetItemAttribute("BuffMaxStacks");
|
||
|
||
if (armorPerStack <= 0f || duration <= 0f || maxStacks <= 0) return;
|
||
new TemporaryArmor(armorPerStack, duration, maxStacks).Apply(player, player, this);
|
||
}
|
||
}
|
||
|
||
public partial class AdaptiveArmor
|
||
{
|
||
/// <summary>
|
||
/// 自适应装甲的Buff。
|
||
/// 默认持续时间为10秒,每层提供指定点护甲,最多叠加指定层。每次受到伤害时,如果已经有该Buff,则刷新持续时间并增加一层。
|
||
/// </summary>
|
||
public class TemporaryArmor : CharacterBuffBase
|
||
{
|
||
private readonly float _armorPerStack;
|
||
|
||
public TemporaryArmor(float armorPerStack, float duration, int maxStacks)
|
||
{
|
||
Initialize(BuffType.Positive, BuffDispelLevel.Basic);
|
||
_armorPerStack = armorPerStack;
|
||
|
||
this.contentSubmodule = new ContentSubmodule(this);
|
||
this.timeSubmodule = new TimeSubmodule(this, duration);
|
||
this.unitedStackSubmodule = new UnitedStackSubmodule(this, true, maxStacks);
|
||
this.attributeSubmodule = new AttributeSubmodule(this);
|
||
}
|
||
|
||
public override bool OnBuffApply(out CharacterBuffBase existingBuff)
|
||
{
|
||
if (FindExistingSameBuff(out TemporaryArmor existing))
|
||
{
|
||
existingBuff = existing;
|
||
existing.timeSubmodule.RefreshDuration();
|
||
existing.unitedStackSubmodule.AddStack(1);
|
||
existing.UpdateArmorValue(existing.unitedStackSubmodule.stackAmount);
|
||
return false;
|
||
}
|
||
|
||
existingBuff = null;
|
||
UpdateArmorValue(unitedStackSubmodule.stackAmount);
|
||
return true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据当前层数更新护甲加成数值。
|
||
/// </summary>
|
||
private void UpdateArmorValue(int stacks)
|
||
{
|
||
attributeSubmodule.numericChange[CharacterAttribute.Armor] = stacks * _armorPerStack;
|
||
attributeSubmodule.RefreshAllModifiedAttributes();
|
||
}
|
||
}
|
||
}
|
||
}
|