using System; using System.Collections.Generic; using Cielonos.MainGame.Buffs.Character; using Cielonos.MainGame.Characters; using SLSUtilities.General; using UnityEngine; namespace Cielonos.MainGame.Inventory.Collections { /// /// 衰变加速线圈 / Decay Acceleration Coil (Passive, Graham) /// 玩家光环范围(15m)内的敌人,其 Decay 伤害间隔缩短 50%。离开光环后恢复。 /// public class DecayAccelerationCoil : PassiveEquipmentBase { private const string EventKey = nameof(DecayAccelerationCoil); /// /// 记录已被修改 Decay 间隔的敌人及其原始间隔值,用于离开光环时恢复。 /// private readonly Dictionary _modifiedEnemies = new(); public override void OnObtained() { base.OnObtained(); auraSm = new AuraSubmodule(this, passiveAttributeSm.GetItemAttribute("AuraRadius")); Action onEnter = OnEnemyEnterAura; Action onExit = OnEnemyExitAura; Action onStay = OnEnemyStayAura; auraSm.onOtherEnterAura.Add(EventKey, onEnter.ToPrioritized()); auraSm.onOtherExitAura.Add(EventKey, onExit.ToPrioritized()); auraSm.onOtherStayAura.Add(EventKey, onStay.ToPrioritized()); } public override void OnDiscarded() { // 恢复所有被修改的 Decay 间隔 auraSm?.Dispose(); _modifiedEnemies.Clear(); base.OnDiscarded(); } protected override void Update() { base.Update(); auraSm?.Update(player.selfTimeSm.DeltaTime); } /// /// 敌人进入光环时,尝试加速其 Decay 间隔。 /// private void OnEnemyEnterAura(CharacterBase enemy) { TryAccelerateDecay(enemy); } /// /// 敌人持续处于光环内时,检查是否有新施加的 Decay 需要加速。 /// private void OnEnemyStayAura(CharacterBase enemy) { if (_modifiedEnemies.ContainsKey(enemy)) return; TryAccelerateDecay(enemy); } /// /// 敌人离开光环时,恢复其 Decay 间隔。 /// private void OnEnemyExitAura(CharacterBase enemy) { RestoreDecayInterval(enemy); } /// /// 尝试加速目标身上的 Decay 伤害间隔。 /// private void TryAccelerateDecay(CharacterBase enemy) { if (!enemy.buffSm.TryGetBuff(out Decay decay)) return; if (_modifiedEnemies.ContainsKey(enemy)) return; _modifiedEnemies[enemy] = decay.Interval; float acceleratedInterval = decay.Interval * passiveAttributeSm.GetItemAttribute("IntervalMultiplier"); decay.timeSubmodule.intervalActions[0].SetInterval(acceleratedInterval); } /// /// 恢复目标身上的 Decay 伤害间隔至原始值。 /// private void RestoreDecayInterval(CharacterBase enemy) { if (!_modifiedEnemies.Remove(enemy, out float originalInterval)) return; if (!enemy.buffSm.TryGetBuff(out Decay decay)) return; decay.timeSubmodule.intervalActions[0].SetInterval(originalInterval); } } }