Files
SoulliesOfficial 649b7a5ddc 更新
2026-05-23 08:27:50 -04:00

92 lines
3.2 KiB
C#
Raw Permalink 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.Characters;
using SLSUtilities.General;
using UnityEngine;
namespace Cielonos.MainGame.Inventory.Collections
{
/// <summary>
/// 记忆外骨骼 / Memory Exoskeleton
/// 记录并调校玩家的动作模式每击杀一个敌人获得1%攻击速度加成(叠层)。
/// 切换主武器时,外骨骼需要重新适配,叠层归零。
/// </summary>
public class MemoryExoskeleton : PassiveEquipmentBase
{
private const string EventKey = "MemoryExoskeleton";
private int _currentStacks;
public override void OnObtained()
{
base.OnObtained();
_currentStacks = 0;
Action<AttackAreaBase, CharacterBase, Attack.Result> onFinishAttack = OnFinishAttack;
player.eventSm.onFinishAttack.Add(EventKey, onFinishAttack.ToPrioritized());
Action<MainWeaponBase> onMainWeaponChanged = OnMainWeaponChanged;
player.eventSm.onMainWeaponChanged.Add(EventKey, onMainWeaponChanged.ToPrioritized());
}
public override void OnDiscarded()
{
player.eventSm.onMainWeaponChanged.Remove(EventKey);
player.eventSm.onFinishAttack.Remove(EventKey);
// 清除已施加的攻击速度加成
if (_currentStacks > 0)
{
_currentStacks = 0;
ApplyAttackSpeed(0f);
}
base.OnDiscarded();
}
/// <summary>
/// 攻击结算完成时检查是否击杀目标,是则叠加攻击速度。
/// </summary>
private void OnFinishAttack(AttackAreaBase attackArea, CharacterBase target, Attack.Result result)
{
if (!result.causedDeath) return;
float attackSpeedPerKill = passiveAttributeSm.GetItemAttribute("AttackSpeedPerKill");
float maxAttackSpeed = passiveAttributeSm.GetItemAttribute("MaxAttackSpeed");
_currentStacks++;
float newAttackSpeed = _currentStacks * attackSpeedPerKill;
newAttackSpeed = Mathf.Min(newAttackSpeed, maxAttackSpeed);
ApplyAttackSpeed(newAttackSpeed);
}
/// <summary>
/// 切换主武器时,外骨骼需要重新适配当前武器,叠层归零。
/// </summary>
private void OnMainWeaponChanged(MainWeaponBase newWeapon)
{
if (_currentStacks <= 0) return;
_currentStacks = 0;
ApplyAttackSpeed(0f);
MainGameBaseCollection.Instance.InfoText()?.Spawn(player.centerPosition, "Exo Reset");
}
/// <summary>
/// 将攻击速度加成写入属性系统并刷新。
/// </summary>
private void ApplyAttackSpeed(float bonus)
{
if (bonus > 0f)
{
passiveAttributeSm.charAttrNumericChange[CharacterAttribute.AttackSpeed] = bonus;
}
else
{
passiveAttributeSm.charAttrNumericChange.Remove(CharacterAttribute.AttackSpeed);
}
player.attributeSm.RefreshAttribute(CharacterAttribute.AttackSpeed);
}
}
}