92 lines
3.2 KiB
C#
92 lines
3.2 KiB
C#
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);
|
||
}
|
||
}
|
||
}
|