Files
Cielonos/Assets/Scripts/MainGame/Items/PassiveEquipments/ArmorPiercingRound.cs
SoulliesOfficial 39b43680a9 爆更
2026-07-18 03:16:20 -04:00

87 lines
3.1 KiB
C#
Raw 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 System;
using Cielonos.MainGame.Buffs;
using Cielonos.MainGame.Buffs.Character;
using Cielonos.MainGame.Characters;
using SLSUtilities.General;
using UnityEngine;
namespace Cielonos.MainGame.Inventory.Collections
{
/// <summary>
/// 穿甲弹头 / Armor Piercing Round
/// Kinetics 攻击命中时降低目标护甲。
/// </summary>
public partial class ArmorPiercingRound : PassiveEquipmentBase
{
private const string EventKey = nameof(ArmorPiercingRound);
public override void OnObtained()
{
base.OnObtained();
Action<AttackAreaBase, CharacterBase, Attack.Result> onBeforeDamageApplied = OnBeforeDamageApplied;
player.eventSm.onBeforeDamageApplied.Add(EventKey, onBeforeDamageApplied.ToPrioritized());
}
public override void OnDiscarded()
{
player.eventSm.onBeforeDamageApplied.Remove(EventKey);
base.OnDiscarded();
}
private void OnBeforeDamageApplied(AttackAreaBase attackArea, CharacterBase target, Attack.Result result)
{
if (result.value.type != Attack.Type.Kinetics)
{
return;
}
int armorReduction = Mathf.RoundToInt(passiveAttributeSm.GetItemAttribute("ArmorReduction"));
new ArmorReduction(5f, armorReduction).Apply(target, player, this);
}
}
public partial class ArmorPiercingRound
{
/// <summary>
/// 穿甲弹头的Buff默认降低目标等于unitedStack层数的护甲持续5秒
/// </summary>
public class ArmorReduction : CharacterBuffBase
{
public ArmorReduction(float duration, int stack)
{
Initialize(BuffType.Positive, BuffDispelLevel.Basic);
this.contentSubmodule = new ContentSubmodule(this);
this.timeSubmodule = new TimeSubmodule(this, duration);
this.unitedStackSubmodule = new UnitedStackSubmodule(this, stack);
this.attributeSubmodule = new AttributeSubmodule(this);
}
public override bool OnBuffApply(out CharacterBuffBase existingBuff)
{
if (FindExistingSameBuff(out ArmorReduction existing))
{
existingBuff = existing;
existing.timeSubmodule.RefreshDuration();
existing.unitedStackSubmodule.PickHigherStack(this.unitedStackSubmodule);
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;
attributeSubmodule.RefreshAllModifiedAttributes();
}
}
}
}