59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using UnityEngine;
|
|
using BaseGames.Parry;
|
|
|
|
namespace BaseGames.Combat
|
|
{
|
|
/// <summary>
|
|
/// 可被玩家弹反的抛射物。
|
|
/// 触发时优先检测弹反窗口;若成功弹反则反向飞行并可切换伤害源;
|
|
/// 否则走正常伤害流水线。
|
|
/// </summary>
|
|
public class ParryableProjectile : LinearProjectile
|
|
{
|
|
[SerializeField] private DamageSourceSO _reflectSource;
|
|
|
|
private bool _reflected;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
// 禁用子 HitBox 的自动检测,改由本组件的 OnTriggerEnter2D 手动处理,
|
|
// 以便在命中前插入弹反判断。
|
|
_hitBox.Deactivate();
|
|
_rb.velocity = Direction * _config.Speed;
|
|
}
|
|
|
|
private void OnTriggerEnter2D(Collider2D other)
|
|
{
|
|
// ── 弹反判断 ────────────────────────────────────────────────
|
|
if (!_reflected)
|
|
{
|
|
var parrySystem = other.GetComponentInParent<ParrySystem>();
|
|
if (parrySystem != null && parrySystem.IsParrying && parrySystem.ConsumeParry())
|
|
{
|
|
_reflected = true;
|
|
Direction = -Direction;
|
|
_rb.velocity = Direction * _config.Speed * _config.ParrySpeedMultiplier;
|
|
|
|
if (_reflectSource != null)
|
|
DamageInfo = DamageInfo.From(_reflectSource);
|
|
return;
|
|
}
|
|
}
|
|
|
|
// ── 正常命中 ─────────────────────────────────────────────────
|
|
var hurtBox = other.GetComponent<HurtBox>();
|
|
if (hurtBox != null)
|
|
{
|
|
hurtBox.ReceiveDamage(DamageInfo);
|
|
ReturnToPool();
|
|
}
|
|
}
|
|
|
|
protected override void OnDisable()
|
|
{
|
|
base.OnDisable();
|
|
_reflected = false;
|
|
}
|
|
}
|
|
}
|