102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
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
|
||
{
|
||
/// <summary>
|
||
/// 衰变加速线圈 / Decay Acceleration Coil (Passive, Graham)
|
||
/// 玩家光环范围(15m)内的敌人,其 Decay 伤害间隔缩短 50%。离开光环后恢复。
|
||
/// </summary>
|
||
public class DecayAccelerationCoil : PassiveEquipmentBase
|
||
{
|
||
private const string EventKey = nameof(DecayAccelerationCoil);
|
||
|
||
/// <summary>
|
||
/// 记录已被修改 Decay 间隔的敌人及其原始间隔值,用于离开光环时恢复。
|
||
/// </summary>
|
||
private readonly Dictionary<CharacterBase, float> _modifiedEnemies = new();
|
||
|
||
public override void OnObtained()
|
||
{
|
||
base.OnObtained();
|
||
|
||
auraSm = new AuraSubmodule(this, passiveAttributeSm.GetItemAttribute("AuraRadius"));
|
||
|
||
Action<CharacterBase> onEnter = OnEnemyEnterAura;
|
||
Action<CharacterBase> onExit = OnEnemyExitAura;
|
||
Action<CharacterBase> 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);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 敌人进入光环时,尝试加速其 Decay 间隔。
|
||
/// </summary>
|
||
private void OnEnemyEnterAura(CharacterBase enemy)
|
||
{
|
||
TryAccelerateDecay(enemy);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 敌人持续处于光环内时,检查是否有新施加的 Decay 需要加速。
|
||
/// </summary>
|
||
private void OnEnemyStayAura(CharacterBase enemy)
|
||
{
|
||
if (_modifiedEnemies.ContainsKey(enemy)) return;
|
||
TryAccelerateDecay(enemy);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 敌人离开光环时,恢复其 Decay 间隔。
|
||
/// </summary>
|
||
private void OnEnemyExitAura(CharacterBase enemy)
|
||
{
|
||
RestoreDecayInterval(enemy);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 尝试加速目标身上的 Decay 伤害间隔。
|
||
/// </summary>
|
||
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);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 恢复目标身上的 Decay 伤害间隔至原始值。
|
||
/// </summary>
|
||
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);
|
||
}
|
||
}
|
||
}
|