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 { /// /// 穿甲弹头 / Armor Piercing Round /// Kinetics 攻击命中时降低目标护甲。 /// public partial class ArmorPiercingRound : PassiveEquipmentBase { private const string EventKey = nameof(ArmorPiercingRound); public override void OnObtained() { base.OnObtained(); Action 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 { /// /// 穿甲弹头的Buff,默认降低目标等于unitedStack层数的护甲,持续5秒 /// 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; } /// /// 根据当前层数更新护甲加成数值。 /// private void UpdateArmorValue(int stacks) { attributeSubmodule.numericChange[CharacterAttribute.Armor] = -stacks; attributeSubmodule.RefreshAllModifiedAttributes(); } } } }