摄像机区域的架构改动
This commit is contained in:
27
Assets/_Game/Scripts/Combat/ArcProjectile.cs
Normal file
27
Assets/_Game/Scripts/Combat/ArcProjectile.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 抛物线抛射物。以 <see cref="ProjectileConfigSO.LaunchAngleDeg"/> 指定抛射角,
|
||||
/// 并启用重力缩放,使子弹呈弧线飞行。
|
||||
/// </summary>
|
||||
public class ArcProjectile : Projectile
|
||||
{
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
float rad = _config.LaunchAngleDeg * Mathf.Deg2Rad;
|
||||
float vX = Mathf.Cos(rad) * _config.Speed * Mathf.Sign(Direction.x == 0f ? 1f : Direction.x);
|
||||
float vY = Mathf.Sin(rad) * _config.Speed;
|
||||
|
||||
_rb.velocity = new Vector2(vX, vY);
|
||||
_rb.gravityScale = _config.GravityScale;
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
_rb.gravityScale = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/ArcProjectile.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/ArcProjectile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f43e5039135c2f84682862a9249e2688
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
18
Assets/_Game/Scripts/Combat/BaseGames.Combat.asmdef
Normal file
18
Assets/_Game/Scripts/Combat/BaseGames.Combat.asmdef
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"precompiledReferences": [],
|
||||
"name": "BaseGames.Combat",
|
||||
"defineConstraints": [],
|
||||
"noEngineReferences": false,
|
||||
"versionDefines": [],
|
||||
"rootNamespace": "BaseGames.Combat",
|
||||
"references": [
|
||||
"BaseGames.Core",
|
||||
"BaseGames.Core.Events",
|
||||
"BaseGames.Parry"
|
||||
],
|
||||
"autoReferenced": true,
|
||||
"overrideReferences": false,
|
||||
"includePlatforms": []
|
||||
}
|
||||
7
Assets/_Game/Scripts/Combat/BaseGames.Combat.asmdef.meta
Normal file
7
Assets/_Game/Scripts/Combat/BaseGames.Combat.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8746e0f9f33d5d84ea0b598962cc36ae
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/_Game/Scripts/Combat/ClashConfigSO.cs
Normal file
24
Assets/_Game/Scripts/Combat/ClashConfigSO.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 拼刀系统参数配置(架构 06_CombatModule §15)。
|
||||
/// 资产路径: Assets/ScriptableObjects/Config/Combat/ClashConfig.asset
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "BaseGames/Combat/ClashConfig")]
|
||||
public class ClashConfigSO : ScriptableObject
|
||||
{
|
||||
[Header("HitStop")]
|
||||
[Tooltip("拼刀冻帧数(比普通命中的 2 帧更短)")]
|
||||
public int ClashFreezeFrames = 1;
|
||||
|
||||
[Header("弹开")]
|
||||
[Tooltip("拼刀弹开力度(Impulse 模式)")]
|
||||
public float ClashKnockbackForce = 6.0f;
|
||||
|
||||
[Header("Camera Impulse")]
|
||||
[Tooltip("Cinemachine Impulse 强度(轻微震感)")]
|
||||
public float ClashImpulseStrength = 0.3f;
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/ClashConfigSO.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/ClashConfigSO.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2dce4002cf4f99429388b2038fa2f60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
70
Assets/_Game/Scripts/Combat/ClashResolver.cs
Normal file
70
Assets/_Game/Scripts/Combat/ClashResolver.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 拼刀系统单例服务(架构 06_CombatModule §15)。
|
||||
/// 常驻 Persistent 场景,由 GameManager 持有。
|
||||
/// 当玩家与敌人的近战 HitBox 同时激活并相互重叠时触发拼刀:双方均不扣血,各自弹开。
|
||||
/// </summary>
|
||||
[DefaultExecutionOrder(-500)]
|
||||
public class ClashResolver : MonoBehaviour, IClashService
|
||||
{
|
||||
[SerializeField] private VoidEventChannelSO _onNailClash; // EVT_NailClash
|
||||
[SerializeField] private ClashConfigSO _config;
|
||||
|
||||
// 防止同一碰撞在同帧被双方 HitBox 各触发一次(去重)
|
||||
// Key = (min(idA,idB), max(idA,idB)),顺序无关且无 XOR 哈希碰撞风险
|
||||
private readonly HashSet<(int, int)> _processedThisFrame = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (ServiceLocator.GetOrDefault<IClashService>() != null)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
ServiceLocator.Register<IClashService>(this);
|
||||
Debug.Assert(_config != null, "[ClashResolver] _config 未赋值,请在 Inspector 中指定 ClashConfigSO。", this);
|
||||
}
|
||||
|
||||
private void LateUpdate() => _processedThisFrame.Clear();
|
||||
|
||||
/// <summary>
|
||||
/// 由 HitBox.OnTriggerEnter2D 调用。
|
||||
/// 对同一对 HitBox 每帧只处理一次(HashSet 去重)。
|
||||
/// </summary>
|
||||
public void ResolveClash(HitBox hitBoxA, HitBox hitBoxB)
|
||||
{
|
||||
int idA = hitBoxA.GetInstanceID();
|
||||
int idB = hitBoxB.GetInstanceID();
|
||||
(int, int) key = (System.Math.Min(idA, idB), System.Math.Max(idA, idB));
|
||||
if (!_processedThisFrame.Add(key)) return;
|
||||
|
||||
// 1. 拼刀冻帧(比普通命中的 2 帧更短,强化拼刀手感)
|
||||
ServiceLocator.GetOrDefault<IHitStopService>()?.FreezeFrames(_config.ClashFreezeFrames);
|
||||
|
||||
// 2. 双方弹开
|
||||
ApplyClashKnockback(hitBoxA.OwnerRigidbody, hitBoxB.transform.position);
|
||||
ApplyClashKnockback(hitBoxB.OwnerRigidbody, hitBoxA.transform.position);
|
||||
|
||||
// 3. 广播事件(VFX / Audio / CameraImpulse 订阅)
|
||||
_onNailClash?.Raise();
|
||||
}
|
||||
|
||||
private void ApplyClashKnockback(Rigidbody2D rb, Vector2 oppositePos)
|
||||
{
|
||||
if (rb == null) return;
|
||||
Vector2 dir = ((Vector2)rb.transform.position - oppositePos).normalized;
|
||||
rb.AddForce(dir * _config.ClashKnockbackForce, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ServiceLocator.Unregister<IClashService>(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/ClashResolver.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/ClashResolver.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df7a93b79e446e24dbb27d2971c85f39
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
82
Assets/_Game/Scripts/Combat/CombatEnums.cs
Normal file
82
Assets/_Game/Scripts/Combat/CombatEnums.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
// ── 元素/物理属性 ───────────────────────────────────────────────────────
|
||||
public enum DamageType { Normal, True, Fire, Poison, Ice, Lightning, Void }
|
||||
|
||||
// ── 来源分类 ────────────────────────────────────────────────────────────
|
||||
public enum DamageCategory
|
||||
{
|
||||
NormalAttack = 0,
|
||||
SoulSkill = 1,
|
||||
SpiritSkill = 2,
|
||||
Projectile = 3,
|
||||
EnvironmentTrap = 4,
|
||||
StatusEffect = 5,
|
||||
FallDamage = 6,
|
||||
Reflected = 7,
|
||||
}
|
||||
|
||||
// ── 行为标志 ────────────────────────────────────────────────────────────
|
||||
[Flags]
|
||||
public enum DamageFlags
|
||||
{
|
||||
None = 0,
|
||||
Unblockable = 1 << 0,
|
||||
CanBeParried = 1 << 1,
|
||||
IgnoreIFrame = 1 << 2,
|
||||
PerfectParryOnly = 1 << 3,
|
||||
IsProjectile = 1 << 4,
|
||||
CanClash = 1 << 5,
|
||||
ForceBreak = 1 << 6,
|
||||
NoKnockback = 1 << 7,
|
||||
}
|
||||
|
||||
// ── 交互标签 ────────────────────────────────────────────────────────────
|
||||
[Flags]
|
||||
public enum DamageTags : uint
|
||||
{
|
||||
None = 0,
|
||||
MeleeHit = 1 << 0,
|
||||
RangedHit = 1 << 1,
|
||||
SkillHit = 1 << 2,
|
||||
ElementFire = 1 << 3,
|
||||
ElementPoison = 1 << 4,
|
||||
ElementVoid = 1 << 5,
|
||||
AfterParry = 1 << 6,
|
||||
ChargedAttack = 1 << 7,
|
||||
SkyFormOnly = 1 << 8,
|
||||
EarthFormOnly = 1 << 9,
|
||||
DeathFormOnly = 1 << 10,
|
||||
BreakLight = 1 << 11,
|
||||
BreakMedium = 1 << 12,
|
||||
BreakHeavy = 1 << 13,
|
||||
BreakBreaker = 1 << 14,
|
||||
}
|
||||
|
||||
public enum HitFxType { Spark, Slash, Blood, Magic, Heavy, Crit, Void, Heal, Parry, Fire, Ice }
|
||||
|
||||
// ── 攻击方打断等级 ──────────────────────────────────────────────────────
|
||||
public enum BreakLevel
|
||||
{
|
||||
None = 0,
|
||||
Light = 1,
|
||||
Medium = 2,
|
||||
Heavy = 3,
|
||||
Breaker = 4,
|
||||
}
|
||||
|
||||
// ── 承受方霸体等级 ──────────────────────────────────────────────────────
|
||||
public enum PoiseLevel
|
||||
{
|
||||
None = 0,
|
||||
Light = 1,
|
||||
Medium = 2,
|
||||
Heavy = 3,
|
||||
Unbreakable = 100,
|
||||
}
|
||||
|
||||
// ── 攻击方向(PlayerCombat / WeaponSO 使用)────────────────────────────
|
||||
public enum AttackDirection { Ground, Up, Down, Air }
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/CombatEnums.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/CombatEnums.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca3858c58d2156f4fbc2d295c444bd40
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
49
Assets/_Game/Scripts/Combat/CombatInterfaces.cs
Normal file
49
Assets/_Game/Scripts/Combat/CombatInterfaces.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 可受击实体接口。PlayerController 和 EnemyBase 实现此接口。
|
||||
/// HurtBox.Awake 通过 GetComponentInParent<IDamageable>() 注入。
|
||||
/// </summary>
|
||||
public interface IDamageable
|
||||
{
|
||||
bool IsAlive { get; }
|
||||
bool IsInvincible { get; }
|
||||
int Defense { get; }
|
||||
void TakeDamage(DamageInfo info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可持有霸体的实体接口。HurtBox 在 ReceiveDamage 中做等级比较。
|
||||
/// </summary>
|
||||
public interface IPoiseSource
|
||||
{
|
||||
PoiseLevel GetCurrentPoiseLevel();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 护盾接口(玩家专属)。由 PlayerController.Awake() 注入 HurtBox。
|
||||
/// AbsorbDamage 返回穿透量(0 = 全部吸收,>0 = 穿透量继续走 TakeDamage 流程)。
|
||||
/// </summary>
|
||||
public interface IShieldable
|
||||
{
|
||||
bool HasShield { get; }
|
||||
int AbsorbDamage(int amount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可破坏机关/障碍物接口。HitBox 在命中非 HurtBox 对象时尝试调用。
|
||||
/// </summary>
|
||||
public interface IBreakable
|
||||
{
|
||||
void TryInteract(DamageInfo info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 可施加状态效果的实体接口(避免 Combat 直接引用 StatusEffects 程序集)。
|
||||
/// StatusEffectManager 实现此接口;HurtBox.ReceiveDamage 步骤 8 通过此接口调用。
|
||||
/// </summary>
|
||||
public interface IStatusEffectable
|
||||
{
|
||||
void ApplyStatusEffect(DamageType type);
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/CombatInterfaces.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/CombatInterfaces.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7881dd1e194f2944a87ec5d50686740e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
125
Assets/_Game/Scripts/Combat/DamageInfo.cs
Normal file
125
Assets/_Game/Scripts/Combat/DamageInfo.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 单次伤害信息。流水线:RawDamage → Amount(护盾修改)→ FinalDamage(防御减免后)。
|
||||
/// ⚠️ 保留为可变 struct:HurtBox 流水线需要在方法内修改本地副本的 Amount / FinalDamage。
|
||||
/// Builder 通过独立字段构造,不直接修改 DamageInfo 实例。
|
||||
/// </summary>
|
||||
[System.Serializable]
|
||||
public struct DamageInfo
|
||||
{
|
||||
public int RawDamage; // HitBox 设定的原始值(工厂/Builder 写入一次)
|
||||
public int Amount; // 流水线中被护盾/防御修改
|
||||
public int FinalDamage; // HurtBox 写入,最终 HP 扣除量
|
||||
public Vector2 KnockbackDirection;
|
||||
public float KnockbackForce;
|
||||
public float HitStunDuration;
|
||||
public DamageType Type;
|
||||
public DamageCategory Category;
|
||||
public DamageFlags Flags;
|
||||
public DamageTags Tags;
|
||||
public Vector2 SourcePosition;
|
||||
public int SourceLayer;
|
||||
public HitFxType FxType;
|
||||
public BreakLevel Break;
|
||||
public string SourceId;
|
||||
public string SkillId;
|
||||
|
||||
// ── Builder ──────────────────────────────────────────────────────────
|
||||
/// <summary>
|
||||
/// 通过独立字段构造 DamageInfo,避免直接持有可变 DamageInfo 实例。
|
||||
/// </summary>
|
||||
public class Builder
|
||||
{
|
||||
private int _raw;
|
||||
private DamageType _type;
|
||||
private DamageCategory _category;
|
||||
private DamageFlags _flags;
|
||||
private DamageTags _tags;
|
||||
private string _skillId;
|
||||
private string _sourceId;
|
||||
private Vector2 _knockbackDirection;
|
||||
private float _knockbackForce;
|
||||
private float _hitStunDuration;
|
||||
private HitFxType _fxType;
|
||||
private BreakLevel _break;
|
||||
private Vector2 _sourcePosition;
|
||||
private int _sourceLayer;
|
||||
|
||||
public Builder() { }
|
||||
|
||||
// SetRaw 同步初始化 Amount(Amount 始终以 RawDamage 为起点)
|
||||
public Builder SetRaw(int v) { _raw = v; return this; }
|
||||
public Builder SetType(DamageType v) { _type = v; return this; }
|
||||
public Builder SetCategory(DamageCategory v) { _category = v; return this; }
|
||||
public Builder SetFlags(DamageFlags v) { _flags = v; return this; }
|
||||
public Builder SetTags(DamageTags v) { _tags = v; return this; }
|
||||
public Builder SetSkillId(string v) { _skillId = v; return this; }
|
||||
public Builder SetSourceId(string v) { _sourceId = v; return this; }
|
||||
public Builder SetKnockback(Vector2 dir, float force) { _knockbackDirection = dir; _knockbackForce = force; return this; }
|
||||
public Builder SetStun(float dur) { _hitStunDuration = dur; return this; }
|
||||
public Builder SetFx(HitFxType v) { _fxType = v; return this; }
|
||||
public Builder SetBreak(BreakLevel v) { _break = v; return this; }
|
||||
public Builder SetSourcePos(Vector2 v) { _sourcePosition = v; return this; }
|
||||
public Builder SetLayer(int v) { _sourceLayer = v; return this; }
|
||||
|
||||
public DamageInfo Build() => new DamageInfo
|
||||
{
|
||||
RawDamage = _raw,
|
||||
Amount = _raw,
|
||||
Type = _type,
|
||||
Category = _category,
|
||||
Flags = _flags,
|
||||
Tags = _tags,
|
||||
SkillId = _skillId,
|
||||
SourceId = _sourceId,
|
||||
KnockbackDirection = _knockbackDirection,
|
||||
KnockbackForce = _knockbackForce,
|
||||
HitStunDuration = _hitStunDuration,
|
||||
FxType = _fxType,
|
||||
Break = _break,
|
||||
SourcePosition = _sourcePosition,
|
||||
SourceLayer = _sourceLayer,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ⚡ 零堆分配工厂(热路径首选)。从 DamageSourceSO 填入所有静态字段;
|
||||
/// 可选传入运行时字段(knockbackDir、sourcePos、sourceLayer),
|
||||
/// 无需调用方事后就地赋值。
|
||||
/// </summary>
|
||||
public static DamageInfo From(
|
||||
DamageSourceSO so,
|
||||
Vector2 knockbackDir = default,
|
||||
Vector2 sourcePos = default,
|
||||
int sourceLayer = 0)
|
||||
{
|
||||
int baseAmt = Mathf.RoundToInt(so.BaseDamage * so.DamageMultiplier);
|
||||
return new DamageInfo
|
||||
{
|
||||
RawDamage = baseAmt,
|
||||
Amount = baseAmt,
|
||||
Type = so.Type,
|
||||
Category = so.Category,
|
||||
Flags = so.Flags,
|
||||
Tags = so.Tags,
|
||||
HitStunDuration = so.HitStunDuration,
|
||||
FxType = so.FxType,
|
||||
Break = so.BreakLevel,
|
||||
SourceId = so.sourceId,
|
||||
SkillId = so.skillId,
|
||||
KnockbackDirection = knockbackDir,
|
||||
KnockbackForce = so.KnockbackForce,
|
||||
SourcePosition = sourcePos,
|
||||
SourceLayer = sourceLayer,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>伤害事件频道(EVT_DamageDealt)。</summary>
|
||||
[UnityEngine.CreateAssetMenu(menuName = "Events/DamageDealt")]
|
||||
public class DamageInfoEventChannelSO : BaseEventChannelSO<DamageInfo> { }
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/DamageInfo.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/DamageInfo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78a4c2420f838e74aa97697d5da09b72
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
52
Assets/_Game/Scripts/Combat/DamageSourceSO.cs
Normal file
52
Assets/_Game/Scripts/Combat/DamageSourceSO.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 攻击数据源 SO。描述单次攻击的基础伤害参数。
|
||||
/// ⚡ 热路径使用零分配工厂:DamageInfo.From(sourceSO)。
|
||||
/// 仅需链式覆盖多字段时才使用 CreateBuilder()。
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "BaseGames/Combat/DamageSource")]
|
||||
public class DamageSourceSO : ScriptableObject
|
||||
{
|
||||
[Header("Identity")]
|
||||
public string sourceId;
|
||||
public string skillId;
|
||||
|
||||
[Header("Base")]
|
||||
public int BaseDamage = 10;
|
||||
public float DamageMultiplier = 1.0f;
|
||||
public DamageType Type = DamageType.Normal;
|
||||
public DamageCategory Category = DamageCategory.NormalAttack;
|
||||
public DamageFlags Flags = DamageFlags.CanBeParried;
|
||||
public DamageTags Tags = DamageTags.MeleeHit;
|
||||
|
||||
[Header("Physics")]
|
||||
public float KnockbackForce = 5f;
|
||||
public float HitStunDuration = 0.1f;
|
||||
public BreakLevel BreakLevel = BreakLevel.Light;
|
||||
|
||||
[Header("FX")]
|
||||
public HitFxType FxType = HitFxType.Slash;
|
||||
|
||||
[Header("Combo")]
|
||||
public float ComboWindowDuration = 0.4f;
|
||||
public float CancelWindowEnd = 0.5f;
|
||||
|
||||
/// <summary>
|
||||
/// 链式 Builder(特殊场景使用,热路径改用 DamageInfo.From(this))。
|
||||
/// </summary>
|
||||
public DamageInfo.Builder CreateBuilder() => new DamageInfo.Builder()
|
||||
.SetRaw(Mathf.RoundToInt(BaseDamage * DamageMultiplier))
|
||||
.SetType(Type)
|
||||
.SetCategory(Category)
|
||||
.SetFlags(Flags)
|
||||
.SetTags(Tags)
|
||||
.SetStun(HitStunDuration)
|
||||
.SetFx(FxType)
|
||||
.SetBreak(BreakLevel)
|
||||
.SetSourceId(sourceId)
|
||||
.SetSkillId(skillId);
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/DamageSourceSO.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/DamageSourceSO.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96b10c11e6173394a8fa8d9c614b0035
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
290
Assets/_Game/Scripts/Combat/HitBox.cs
Normal file
290
Assets/_Game/Scripts/Combat/HitBox.cs
Normal file
@@ -0,0 +1,290 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 攻击判定盒。挂载在武器 Prefab 或技能 HitBox Prefab 的子节点上。
|
||||
/// 直接挂在 Player Prefab 子节点 [HitBoxGround/Up/Down/Air]。
|
||||
/// Collider2D 需设 IsTrigger = true,Layer = PlayerHitBox 或 EnemyHitBox。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
public class HitBox : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private DamageSourceSO _defaultSource;
|
||||
[SerializeField] private float _hitCooldown = 0.1f;
|
||||
|
||||
/// <summary>
|
||||
/// HitBox 标识符,供 PlayerAnimationEvents / EnemyAnimationEvents 按名称精确激活特定判定盒。
|
||||
/// 留空表示"无 Id";事件 payload 为空时将操作所有 HitBox。
|
||||
/// </summary>
|
||||
[SerializeField] private string _id = "";
|
||||
public string Id => _id;
|
||||
|
||||
/// <summary>
|
||||
/// 对立阵营 HitBox 所在的 Layer 掩码(用于拼刀检测)。
|
||||
/// Inspector 中将 PlayerHitBox 与 EnemyHitBox 两个 Layer 均勾选。
|
||||
/// </summary>
|
||||
[SerializeField] private LayerMask _rivalHitBoxMask;
|
||||
|
||||
private DamageSourceSO _currentSource;
|
||||
private Transform _attackerTransform;
|
||||
private Rigidbody2D _ownerRigidbody;
|
||||
private bool _isActive;
|
||||
private IClashService _clashService;
|
||||
private Collider2D _collider;
|
||||
|
||||
/// <summary>HitBox 当前是否激活(供 ClashResolver 查询)。</summary>
|
||||
public bool IsActive => _isActive;
|
||||
|
||||
/// <summary>当前 Source 是否携带 CanClash 标记(供 ClashResolver 查询)。</summary>
|
||||
public bool CanClash => _currentSource != null && _currentSource.Flags.HasFlag(DamageFlags.CanClash);
|
||||
|
||||
/// <summary>宿主角色的 Rigidbody2D(用于拼刀弹开力计算)。</summary>
|
||||
public Rigidbody2D OwnerRigidbody => _ownerRigidbody;
|
||||
|
||||
// 拼刀检测所需的对立层掩码(Inspector 配置)
|
||||
|
||||
/// <summary>命中确认委托(PlayerCombat / EnemyCombat 订阅)。</summary>
|
||||
public event System.Action<DamageInfo> OnHitConfirmed;
|
||||
|
||||
/// <summary>
|
||||
/// 激活 HitBox。source/attacker 均可选,未传则使用 Inspector 默认值。
|
||||
/// ⚠️ 不存在 Activate(float duration) 重载。
|
||||
/// </summary>
|
||||
public void Activate(DamageSourceSO source = null, Transform attacker = null)
|
||||
{
|
||||
_currentSource = source ?? _defaultSource;
|
||||
_attackerTransform = attacker ?? transform;
|
||||
_isActive = true;
|
||||
// 缓存宿主 Rigidbody2D(沿父层级向上查找)
|
||||
_ownerRigidbody = _attackerTransform.GetComponentInParent<Rigidbody2D>();
|
||||
// 每次激活清空当前激活期已命中目标集合(防止连击连段导致同一阶段多次命中目标)
|
||||
_hitThisActivation.Clear();
|
||||
_hitCooldownTimers.Clear();
|
||||
}
|
||||
|
||||
public void Deactivate()
|
||||
{
|
||||
_isActive = false;
|
||||
_hitThisActivation.Clear();
|
||||
_hitCooldownTimers.Clear();
|
||||
}
|
||||
|
||||
/// <summary>仅替换当前 DamageSource(不改变激活状态,供 PlayerCombat 连击段切换)。</summary>
|
||||
public void SetDamageSource(DamageSourceSO source)
|
||||
{
|
||||
if (source != null) _currentSource = source;
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 确保 Collider2D 是 Trigger
|
||||
_collider = GetComponent<Collider2D>();
|
||||
if (!_collider.isTrigger)
|
||||
Debug.LogWarning($"[HitBox] {name}: Collider2D.isTrigger 应为 true。", this);
|
||||
// 缓存 IClashService:OnTriggerEnter2D 为物理热路径,避免每次调用 Dictionary 查找
|
||||
_clashService = ServiceLocator.GetOrDefault<IClashService>();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_isActive = false;
|
||||
_hitThisActivation.Clear();
|
||||
_hitCooldownTimers.Clear();
|
||||
}
|
||||
|
||||
private void OnTriggerExit2D(Collider2D other)
|
||||
{
|
||||
// 目标离开判定区域时清除其冷却记录,防止持续激活的 HitBox(环境危险等)
|
||||
// 因有效目标持续流动而无限积累已离场对象。
|
||||
// 注意:_hitThisActivation 刻意保留,确保同一激活期内不重复命中。
|
||||
_hitCooldownTimers.Remove(other);
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other) {
|
||||
if (!_isActive) return;
|
||||
if (_currentSource == null)
|
||||
{
|
||||
Debug.LogWarning($"[HitBox] {name}: 无 DamageSourceSO,跳过命中。", this);
|
||||
return;
|
||||
}
|
||||
// 同一激活期防止对同一 Collider 重复命中(一次攻击每个目标至多命中一次)
|
||||
if (!_hitThisActivation.Add(other)) return;
|
||||
if (!CheckCooldown(other)) return;
|
||||
// 排除自身:攻击方与受击方属于同一根 GameObject 时跳过(防止近战 EnemyHitBox 命中同一敌人的 EnemyHurtBox)
|
||||
if (other.transform.root == _attackerTransform.root) return;
|
||||
|
||||
Vector2 knockDir = ((Vector2)other.bounds.center
|
||||
- (Vector2)_attackerTransform.position).normalized;
|
||||
|
||||
// ⚡ 零 GC:struct 工厂,运行时字段内联传入
|
||||
var info = DamageInfo.From(
|
||||
_currentSource,
|
||||
knockDir,
|
||||
_attackerTransform.position,
|
||||
_attackerTransform.gameObject.layer);
|
||||
|
||||
// ① 拼刀检测:当前 HitBox 携带 CanClash 标记,且碰到对立阵营的 HitBox 层
|
||||
int otherLayer = other.gameObject.layer;
|
||||
bool isRivalHitBoxLayer = (_rivalHitBoxMask.value & (1 << otherLayer)) != 0;
|
||||
if (isRivalHitBoxLayer && CanClash)
|
||||
{
|
||||
var rivalHitBox = other.GetComponent<HitBox>();
|
||||
if (rivalHitBox != null && rivalHitBox.IsActive && rivalHitBox.CanClash)
|
||||
{
|
||||
_clashService?.ResolveClash(this, rivalHitBox);
|
||||
return; // 拼刀,中止伤害流水线
|
||||
}
|
||||
}
|
||||
|
||||
// ② 命中 HurtBox
|
||||
var hurtBox = other.GetComponent<HurtBox>();
|
||||
if (hurtBox != null)
|
||||
{
|
||||
// 用 HitBox 自身碰撞盒中心在 HurtBox 表面上的最近点作为受击位置。
|
||||
// 对大体积/长条形受击体(如地刺),此点远比 HurtBox 节点中心更准确。
|
||||
Vector3 hitPoint = other.ClosestPoint(_collider.bounds.center);
|
||||
hurtBox.ReceiveDamage(info, hitPoint);
|
||||
OnHitConfirmed?.Invoke(info);
|
||||
return;
|
||||
}
|
||||
|
||||
// ③ 命中 IBreakable(机关/障碍物)
|
||||
other.GetComponent<IBreakable>()?.TryInteract(info);
|
||||
}
|
||||
|
||||
// ── 当前激活期已命中目标集合(防止复合子 Collider 导致同帧多次命中)────────────
|
||||
private readonly HashSet<Collider2D> _hitThisActivation = new(8);
|
||||
// ── 同目标多帧命中冷却(防止 Trigger 处于重叠状态时重入等殊情导致的连击)──
|
||||
private readonly Dictionary<Collider2D, float> _hitCooldownTimers = new(8);
|
||||
|
||||
private bool CheckCooldown(Collider2D other)
|
||||
{
|
||||
float now = Time.time;
|
||||
if (_hitCooldownTimers.TryGetValue(other, out float last) && now - last < _hitCooldown)
|
||||
return false;
|
||||
_hitCooldownTimers[other] = now;
|
||||
return true;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
var col = GetComponent<Collider2D>();
|
||||
if (col == null) return;
|
||||
// HitBox:激活 = 鲜红,非激活 = 极淡红轮廓
|
||||
Gizmos.color = _isActive
|
||||
? new Color(1f, 0.15f, 0.15f, 1f)
|
||||
: new Color(1f, 0.15f, 0.15f, 0.2f);
|
||||
DrawCollider2DWire(col);
|
||||
}
|
||||
|
||||
// ────────────────────────────────────────────────────
|
||||
// Gizmo 辅助(内联,不依赖外部工具类)
|
||||
// ────────────────────────────────────────────────────
|
||||
/// <summary>
|
||||
/// 根据 Collider2D 类型绘制正确的 wire 轮廓。
|
||||
/// 使用 <see cref="Gizmos.matrix"/> 统一应用 Transform 的移动/旋转/缩放。
|
||||
/// </summary>
|
||||
public static void DrawCollider2DWire(Collider2D col)
|
||||
{
|
||||
var prev = Gizmos.matrix;
|
||||
Gizmos.matrix = col.transform.localToWorldMatrix;
|
||||
|
||||
switch (col)
|
||||
{
|
||||
case BoxCollider2D box:
|
||||
DrawWireRect2D(box.offset, box.size);
|
||||
break;
|
||||
|
||||
case CapsuleCollider2D caps:
|
||||
DrawWireCapsule2D(caps.offset, caps.size, caps.direction);
|
||||
break;
|
||||
|
||||
case PolygonCollider2D poly:
|
||||
for (int p = 0; p < poly.pathCount; p++)
|
||||
{
|
||||
var pts = poly.GetPath(p);
|
||||
for (int i = 0; i < pts.Length; i++)
|
||||
Gizmos.DrawLine(pts[i], pts[(i + 1) % pts.Length]);
|
||||
}
|
||||
break;
|
||||
|
||||
case CircleCollider2D circle:
|
||||
DrawWireCircle2D(circle.offset, circle.radius);
|
||||
break;
|
||||
|
||||
default:
|
||||
// 其他类型回退到 bounds 近似(恢复矩阵后在世界空间绘制)
|
||||
Gizmos.matrix = prev;
|
||||
DrawWireRect2D(col.bounds.center, col.bounds.size);
|
||||
return;
|
||||
}
|
||||
|
||||
Gizmos.matrix = prev;
|
||||
}
|
||||
|
||||
/// <summary>在当前 Gizmos 坐标系中绘制轴对齐矩形(2D 线框,兼容透视相机)。</summary>
|
||||
public static void DrawWireRect2D(Vector2 center, Vector2 size)
|
||||
{
|
||||
float hx = size.x * 0.5f, hy = size.y * 0.5f;
|
||||
Vector3 tl = new Vector3(center.x - hx, center.y + hy, 0f);
|
||||
Vector3 tr = new Vector3(center.x + hx, center.y + hy, 0f);
|
||||
Vector3 br = new Vector3(center.x + hx, center.y - hy, 0f);
|
||||
Vector3 bl = new Vector3(center.x - hx, center.y - hy, 0f);
|
||||
Gizmos.DrawLine(tl, tr);
|
||||
Gizmos.DrawLine(tr, br);
|
||||
Gizmos.DrawLine(br, bl);
|
||||
Gizmos.DrawLine(bl, tl);
|
||||
}
|
||||
|
||||
/// <summary>用线段近似绘制 2D 圆周(不使用 DrawWireSphere,兼容透视相机)。</summary>
|
||||
public static void DrawWireCircle2D(Vector3 center, float radius, int segs = 32)
|
||||
{
|
||||
float step = 360f / segs;
|
||||
Vector3 prevPt = center + new Vector3(radius, 0f, 0f);
|
||||
for (int i = 1; i <= segs; i++)
|
||||
{
|
||||
float a = i * step * Mathf.Deg2Rad;
|
||||
Vector3 nextPt = center + new Vector3(Mathf.Cos(a) * radius, Mathf.Sin(a) * radius, 0f);
|
||||
Gizmos.DrawLine(prevPt, nextPt);
|
||||
prevPt = nextPt;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>绘制 2D 胶囊轮廓(在 col.transform 局部坐标系中)。</summary>
|
||||
private static void DrawWireCapsule2D(Vector2 offset, Vector2 size, CapsuleDirection2D dir)
|
||||
{
|
||||
bool vert = dir == CapsuleDirection2D.Vertical;
|
||||
float radius = vert ? size.x * 0.5f : size.y * 0.5f;
|
||||
float half = Mathf.Max(0f, (vert ? size.y : size.x) * 0.5f - radius);
|
||||
Vector2 axis = vert ? Vector2.up : Vector2.right;
|
||||
Vector2 perp = vert ? Vector2.right : Vector2.up;
|
||||
Vector2 capA = offset + axis * half;
|
||||
Vector2 capB = offset - axis * half;
|
||||
|
||||
Gizmos.DrawLine(capA + perp * radius, capB + perp * radius);
|
||||
Gizmos.DrawLine(capA - perp * radius, capB - perp * radius);
|
||||
DrawArc2D(capA, radius, vert ? 0f : -90f, 180f);
|
||||
DrawArc2D(capB, radius, vert ? 180f : 90f, 180f);
|
||||
}
|
||||
|
||||
/// <summary>用多段直线近似绘制 2D 圆弧。</summary>
|
||||
private static void DrawArc2D(Vector2 c, float r, float startDeg, float spanDeg, int segs = 20)
|
||||
{
|
||||
float step = spanDeg / segs;
|
||||
var prev = c + new Vector2(Mathf.Cos(startDeg * Mathf.Deg2Rad) * r,
|
||||
Mathf.Sin(startDeg * Mathf.Deg2Rad) * r);
|
||||
for (int i = 1; i <= segs; i++)
|
||||
{
|
||||
float a = (startDeg + step * i) * Mathf.Deg2Rad;
|
||||
var next = c + new Vector2(Mathf.Cos(a) * r, Mathf.Sin(a) * r);
|
||||
Gizmos.DrawLine(prev, next);
|
||||
prev = next;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/HitBox.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/HitBox.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a655e2461396a8348a32a13144438e8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
using BaseGames.Core.Events;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
[CreateAssetMenu(menuName = "BaseGames/Events/HitConfirmed")]
|
||||
public class HitConfirmedEventChannelSO : BaseEventChannelSO<HitInfo> { }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86e5ffa3ce0537845b1b601c267d76ef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/_Game/Scripts/Combat/HitInfo.cs
Normal file
17
Assets/_Game/Scripts/Combat/HitInfo.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 命中信息(HurtBox.ReceiveDamage 广播给 VFX/Audio/Feedback)。
|
||||
/// </summary>
|
||||
public struct HitInfo
|
||||
{
|
||||
public DamageInfo DamageInfo;
|
||||
public Vector3 HitPoint;
|
||||
public Vector3 HitNormal;
|
||||
public Transform HitTransform;
|
||||
}
|
||||
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/HitInfo.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/HitInfo.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5933018bd81bef48be815337eef02af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
102
Assets/_Game/Scripts/Combat/HitStopManager.cs
Normal file
102
Assets/_Game/Scripts/Combat/HitStopManager.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 命中冻帧服务接口。
|
||||
/// </summary>
|
||||
public interface IHitStopService
|
||||
{
|
||||
/// <summary>冻帧 <paramref name="frames"/> 帧(以 fixedDeltaTime 换算为实际时长)。</summary>
|
||||
void FreezeFrames(int frames);
|
||||
/// <summary>冻帧指定时长(Unscaled 秒)。</summary>
|
||||
void FreezeDuration(float unscaledSeconds);
|
||||
/// <summary>游戏正常时间缩放(默认 1);子弹时间等功能修改此属性。</summary>
|
||||
float BaseTimeScale { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 命中冻帧服务(HitStop)(架构 06_CombatModule §16)。
|
||||
/// 通过短暂将 Time.timeScale 设为 0 实现"冻帧"效果,强化打击感。
|
||||
/// 常驻 Persistent 场景,由 GameManager 持有;通过 ServiceLocator 注册访问。
|
||||
///
|
||||
/// 设计说明:
|
||||
/// - 多次并发请求取最长持续时间(StopCoroutine + 重启)
|
||||
/// - 使用 WaitForSecondsRealtime 确保 timeScale=0 时协程仍能恢复
|
||||
/// - OnDestroy 强制还原 timeScale,防止异常退出导致游戏卡死
|
||||
/// </summary>
|
||||
[DefaultExecutionOrder(-400)]
|
||||
public class HitStopManager : MonoBehaviour, IHitStopService
|
||||
{
|
||||
/// <summary>游戏正常时间缩放(默认 1);通过属性读取以便外部修改子弹时间时保留基准值。</summary>
|
||||
public float BaseTimeScale
|
||||
{
|
||||
get => _baseTimeScale;
|
||||
set => _baseTimeScale = Mathf.Clamp(value, 0.01f, 10f);
|
||||
}
|
||||
private float _baseTimeScale = 1f;
|
||||
|
||||
private Coroutine _activeRoutine;
|
||||
private float _freezeEndTime;
|
||||
|
||||
// ── 生命周期 ──────────────────────────────────────────────────────
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (ServiceLocator.GetOrDefault<IHitStopService>() != null) { Destroy(gameObject); return; }
|
||||
ServiceLocator.Register<IHitStopService>(this);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// 安全恢复:防止场景卸载/异常退出时 timeScale 永久为 0
|
||||
Time.timeScale = _baseTimeScale;
|
||||
ServiceLocator.Unregister<IHitStopService>(this);
|
||||
}
|
||||
|
||||
// ── 公共 API ──────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// 冻帧 <paramref name="frames"/> 帧(以 fixedDeltaTime 换算为实际时长)。
|
||||
/// 若已有冻帧进行中,取两者中持续时间较长的(避免短请求截断较长的冻帧)。
|
||||
/// </summary>
|
||||
/// <param name="frames">冻帧帧数(fixedDeltaTime 单位)。0 或负数无效。</param>
|
||||
public void FreezeFrames(int frames)
|
||||
{
|
||||
if (frames <= 0) return;
|
||||
FreezeDuration(frames * Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 冻帧指定时长(Unscaled 实际秒数)。
|
||||
/// 若已有冻帧进行中,取两者中较长的。
|
||||
/// </summary>
|
||||
/// <param name="unscaledSeconds">实际时长(秒),不受 timeScale 影响。</param>
|
||||
public void FreezeDuration(float unscaledSeconds)
|
||||
{
|
||||
if (unscaledSeconds <= 0f) return;
|
||||
|
||||
float newEndTime = Time.unscaledTime + unscaledSeconds;
|
||||
// 已有更长的冻帧进行中,放弃短请求,避免截断
|
||||
if (_activeRoutine != null && newEndTime <= _freezeEndTime) return;
|
||||
|
||||
_freezeEndTime = newEndTime;
|
||||
if (_activeRoutine != null)
|
||||
StopCoroutine(_activeRoutine);
|
||||
|
||||
_activeRoutine = StartCoroutine(FreezeRoutine(unscaledSeconds));
|
||||
}
|
||||
|
||||
// ── 内部实现 ──────────────────────────────────────────────────────
|
||||
|
||||
private IEnumerator FreezeRoutine(float unscaledSeconds)
|
||||
{
|
||||
Time.timeScale = 0f;
|
||||
yield return new WaitForSecondsRealtime(unscaledSeconds);
|
||||
Time.timeScale = _baseTimeScale;
|
||||
_activeRoutine = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/HitStopManager.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/HitStopManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9aace2ae37bf9d0459a4cdeb34595885
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
40
Assets/_Game/Scripts/Combat/HomingProjectile.cs
Normal file
40
Assets/_Game/Scripts/Combat/HomingProjectile.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 追踪抛射物。初始以 Direction 发射后,每帧向目标转向,
|
||||
/// 转向力由 <see cref="ProjectileConfigSO.HomingStrength"/> 控制。
|
||||
/// </summary>
|
||||
public class HomingProjectile : Projectile
|
||||
{
|
||||
private Transform _target;
|
||||
|
||||
/// <summary>注入追踪目标(由 ProjectileManager 在生成时调用)。</summary>
|
||||
public void SetTarget(Transform t) => _target = t;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_rb.velocity = Direction * _config.Speed;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
if (_target == null || _config == null) return;
|
||||
|
||||
Vector2 toTarget = ((Vector2)_target.position - _rb.position).normalized;
|
||||
_rb.velocity += toTarget * (_config.HomingStrength * Time.deltaTime);
|
||||
|
||||
float maxSpeed = _config.Speed * 1.5f;
|
||||
if (_rb.velocity.sqrMagnitude > maxSpeed * maxSpeed)
|
||||
_rb.velocity = _rb.velocity.normalized * maxSpeed;
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
_target = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/HomingProjectile.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/HomingProjectile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb4a2de7e8deb224db43f89dbe62748d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
129
Assets/_Game/Scripts/Combat/HurtBox.cs
Normal file
129
Assets/_Game/Scripts/Combat/HurtBox.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Parry;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 受击盒组件。实现完整 8 步伤害流水线(架构 06_CombatModule §5)。
|
||||
/// 挂载在角色根节点或指定子节点上,Collider2D 需设 IsTrigger = true,
|
||||
/// Layer = PlayerHurtBox 或 EnemyHurtBox。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
public class HurtBox : MonoBehaviour
|
||||
{
|
||||
// ── 伤害接受方(Awake 注入)──────────────────────────────────────────
|
||||
private IDamageable _owner;
|
||||
private IShieldable _shieldable; // 由 PlayerController.Awake() 注入
|
||||
private ParrySystem _parrySystem; // 由 PlayerController.Awake() 注入
|
||||
private IPoiseSource _poiseSource; // 由 EnemyBase.Awake() 注入
|
||||
private IStatusEffectable _statusEffectable; // Awake 缓存,避免每次受击调用 GetComponent
|
||||
|
||||
private bool _isHurtBoxInvincible;
|
||||
private bool _isActive = true;
|
||||
|
||||
// ── 事件频道 ──────────────────────────────────────────────────────────
|
||||
[SerializeField] private DamageInfoEventChannelSO _onDamageDealt;
|
||||
[SerializeField] private HitConfirmedEventChannelSO _onHitConfirmed;
|
||||
|
||||
// ── 注入接口 ──────────────────────────────────────────────────────────
|
||||
public void SetShieldable(IShieldable shieldable) => _shieldable = shieldable;
|
||||
public void SetParrySystem(ParrySystem ps) => _parrySystem = ps;
|
||||
public void SetPoiseSource(IPoiseSource src) => _poiseSource = src;
|
||||
public void SetInvincible(bool value) => _isHurtBoxInvincible = value;
|
||||
public void SetActive(bool value) => _isActive = value;
|
||||
#if UNITY_EDITOR
|
||||
// 付给编辑器的只读属性——避免反射并限制编辑器与运行时字段名耐合性。
|
||||
public object EditorOwner => _owner;
|
||||
public object EditorShieldable => _shieldable;
|
||||
public object EditorParrySystem => _parrySystem;
|
||||
public object EditorPoiseSource => _poiseSource;
|
||||
public object EditorStatusEffectable => _statusEffectable;
|
||||
#endif
|
||||
private void Awake()
|
||||
{
|
||||
_owner = GetComponentInParent<IDamageable>();
|
||||
_statusEffectable = GetComponentInParent<IStatusEffectable>();
|
||||
if (_owner == null)
|
||||
Debug.LogWarning($"[HurtBox] {name}: 父节点中未找到 IDamageable 实现。", this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 接受伤害(由 HitBox.OnTriggerEnter2D 直接调用)。
|
||||
/// <param name="hitPoint">弹击点世界坐标;不传则默认使用 HurtBox 节点中心。</param>
|
||||
/// ⚠️ 方法名必须为 ReceiveDamage。
|
||||
/// </summary>
|
||||
public void ReceiveDamage(DamageInfo info, Vector3? hitPoint = null)
|
||||
{
|
||||
Vector3 resolvedHitPoint = hitPoint ?? transform.position;
|
||||
if (!_isActive || _owner == null) return;
|
||||
|
||||
// 1. 无敌帧检查
|
||||
if ((_owner.IsInvincible || _isHurtBoxInvincible)
|
||||
&& !info.Flags.HasFlag(DamageFlags.IgnoreIFrame)) return;
|
||||
|
||||
// 2. 弹反检查(_parrySystem == null 时跳过)
|
||||
// ParrySystem 只暴露窗口状态,伤害数据留在 Combat 层,无跨程序集数据依赖。
|
||||
if (_parrySystem != null && info.Flags.HasFlag(DamageFlags.CanBeParried))
|
||||
if (_parrySystem.ConsumeParry()) return;
|
||||
|
||||
// 3. 霸体检查(_poiseSource == null 时跳过)
|
||||
if (!info.Flags.HasFlag(DamageFlags.ForceBreak) && _poiseSource != null)
|
||||
{
|
||||
PoiseLevel curPoise = _poiseSource.GetCurrentPoiseLevel();
|
||||
if (curPoise == PoiseLevel.Unbreakable) return;
|
||||
if ((int)info.Break < (int)curPoise)
|
||||
{
|
||||
_onHitConfirmed?.Raise(new HitInfo
|
||||
{
|
||||
DamageInfo = info,
|
||||
HitPoint = resolvedHitPoint,
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 护盾层拦截(玩家专属,在防御减免前)
|
||||
if (_shieldable != null && _shieldable.HasShield)
|
||||
{
|
||||
int passThrough = _shieldable.AbsorbDamage(info.Amount);
|
||||
if (passThrough <= 0) return;
|
||||
info.Amount = passThrough;
|
||||
}
|
||||
|
||||
// 5. 计算 FinalDamage(防御减免,最低 1)
|
||||
int finalDamage = UnityEngine.Mathf.Max(1, info.Amount - _owner.Defense);
|
||||
info.Amount = finalDamage;
|
||||
info.FinalDamage = finalDamage;
|
||||
|
||||
// 6. 调用 _owner.TakeDamage
|
||||
_owner.TakeDamage(info);
|
||||
|
||||
// 7. 全局广播
|
||||
_onDamageDealt?.Raise(info);
|
||||
_onHitConfirmed?.Raise(new HitInfo
|
||||
{
|
||||
DamageInfo = info,
|
||||
HitPoint = resolvedHitPoint,
|
||||
});
|
||||
|
||||
// 8. 状态效果触发(DoT — Fire / Poison)
|
||||
// _statusEffectable 已在 Awake 中缓存,无需每次受击调用 GetComponent
|
||||
_statusEffectable?.ApplyStatusEffect(info.Type);
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
var col = GetComponent<Collider2D>();
|
||||
if (col == null) return;
|
||||
// HurtBox:正常激活 = 青色,无敌 = 黄色,非激活 = 极淡青
|
||||
Gizmos.color = !_isActive
|
||||
? new Color(0f, 0.85f, 1f, 0.15f)
|
||||
: _isHurtBoxInvincible
|
||||
? new Color(1f, 1f, 0f, 1f )
|
||||
: new Color(0f, 0.85f, 1f, 1f );
|
||||
HitBox.DrawCollider2DWire(col);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/HurtBox.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/HurtBox.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7b7a233d7f70aa4f86b473412b826de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/_Game/Scripts/Combat/IClashService.cs
Normal file
11
Assets/_Game/Scripts/Combat/IClashService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
// Assets/Scripts/Combat/IClashService.cs
|
||||
// 拼刀服务接口,通过 ServiceLocator 注册与查询。
|
||||
// ClashResolver 实现此接口;HitBox 等调用方通过接口解耦。
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
public interface IClashService
|
||||
{
|
||||
void ResolveClash(HitBox hitBoxA, HitBox hitBoxB);
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/IClashService.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/IClashService.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7df722a95e7dc7f4b808256877e44af7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/_Game/Scripts/Combat/IProjectileService.cs
Normal file
17
Assets/_Game/Scripts/Combat/IProjectileService.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 抛射物服务接口。通过 ServiceLocator 注册,供敌人 AI 生成追踪弹使用。
|
||||
/// </summary>
|
||||
public interface IProjectileService
|
||||
{
|
||||
/// <summary>当前缓存的玩家 Transform,生成追踪弹时注入目标。</summary>
|
||||
Transform PlayerTransform { get; }
|
||||
|
||||
/// <summary>完整初始化一枚 HomingProjectile 并注入追踪目标。</summary>
|
||||
void LaunchHoming(HomingProjectile proj, Vector2 direction,
|
||||
ProjectileConfigSO config, DamageInfo damageInfo, int ownerLayer = 0);
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/IProjectileService.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/IProjectileService.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7d8b713a91da1d408f02c68e666f8fa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
105
Assets/_Game/Scripts/Combat/LethalTrap.cs
Normal file
105
Assets/_Game/Scripts/Combat/LethalTrap.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using BaseGames.Core.Events;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 致命陷阱(地刺、深渊等)——对齐空洞骑士地刺行为:
|
||||
///
|
||||
/// ① 玩家 HurtBox 触碰时,通过 HurtBox.ReceiveDamage() 造成一次伤害
|
||||
/// 并携带 IgnoreIFrame 标记(无视翻滚/受击无敌帧,与空洞骑士一致)。
|
||||
/// ② 若伤害导致玩家死亡 → PlayerController.TakeDamage 已 Raise EVT_PlayerDied,
|
||||
/// 走完整死亡流程(死亡动画 → 重载场景)。
|
||||
/// ③ 若玩家存活 → 本组件 Raise EVT_PlayerDied,强制返回最近检查点,
|
||||
/// 同样触发 DeathRespawnService(无死亡演出,只是重新加载)。
|
||||
///
|
||||
/// 可下劈(Pogo):
|
||||
/// - 将 _canPogo = true,并在地刺顶部添加子 GameObject:
|
||||
/// · 挂 HurtBox 组件(EnemyHurtBox 层)
|
||||
/// · 父链上无 IDamageable → ReceiveDamage 无副作用(HP 不扣除)
|
||||
/// · 玩家下劈 HitBox 命中该 HurtBox → HitBox.OnHitConfirmed →
|
||||
/// WeaponHitBoxInstance.OnDownHitConfirmed → DownAttackState.OnDownHitConfirmed
|
||||
/// → Move.Jump() 完成弹跳,无需额外代码。
|
||||
/// - _canPogo = false 则不添加顶部 HurtBox,下劈时玩家仍受地刺伤害。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Collider2D))]
|
||||
public class LethalTrap : MonoBehaviour
|
||||
{
|
||||
[Header("伤害")]
|
||||
[Tooltip("每次触碰造成的伤害量(对齐空洞骑士 = 1 格血)")]
|
||||
[SerializeField] private int _damage = 1;
|
||||
|
||||
[Header("检测")]
|
||||
[Tooltip("勾选 PlayerHurtBox 层")]
|
||||
[SerializeField] private LayerMask _playerLayers;
|
||||
|
||||
[Header("事件")]
|
||||
[Tooltip("EVT_PlayerDied — 触发后由 DeathRespawnService 接管回到检查点")]
|
||||
[SerializeField] private VoidEventChannelSO _onPlayerDied;
|
||||
|
||||
[Header("设计")]
|
||||
[Tooltip("true = 顶部有 HurtBox 子节点可下劈弹跳(需手动添加 Pogo Surface 子节点)")]
|
||||
[SerializeField] private bool _canPogo = true;
|
||||
|
||||
private bool _triggered;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
var col = GetComponent<Collider2D>();
|
||||
if (!col.isTrigger)
|
||||
{
|
||||
col.isTrigger = true;
|
||||
Debug.LogWarning($"[LethalTrap] {name}: Collider2D.isTrigger 已自动设为 true。", this);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable() => _triggered = false;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (_triggered) return;
|
||||
if ((_playerLayers.value & (1 << other.gameObject.layer)) == 0) return;
|
||||
|
||||
_triggered = true;
|
||||
|
||||
// ── 1. 通过 HurtBox 流水线造成伤害(含防御计算,携带 IgnoreIFrame)────────
|
||||
bool playerDiedFromDamage = false;
|
||||
if (_damage > 0)
|
||||
{
|
||||
var hurtBox = other.GetComponent<HurtBox>();
|
||||
if (hurtBox != null)
|
||||
{
|
||||
var info = new DamageInfo.Builder()
|
||||
.SetRaw(_damage)
|
||||
.SetFlags(DamageFlags.IgnoreIFrame) // 无视无敌帧(翻滚/受击)
|
||||
.SetSourceId("lethal_trap")
|
||||
.Build();
|
||||
|
||||
hurtBox.ReceiveDamage(info);
|
||||
|
||||
// 检测伤害后玩家存活状态:
|
||||
// 若已死亡,PlayerController.TakeDamage 已在同帧内 Raise EVT_PlayerDied;
|
||||
// 若存活,需由本组件 Raise 使其回到检查点。
|
||||
var damageable = other.transform.root.GetComponentInParent<IDamageable>();
|
||||
playerDiedFromDamage = damageable != null && !damageable.IsAlive;
|
||||
}
|
||||
}
|
||||
|
||||
// ── 2. 若玩家存活(或无 HurtBox / damage=0),强制触发检查点回溯 ───────────
|
||||
if (!playerDiedFromDamage)
|
||||
_onPlayerDied?.Raise();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[UnityEngine.ContextMenu("打印 Pogo 提示")]
|
||||
private void PrintPogoInfo()
|
||||
{
|
||||
Debug.Log(
|
||||
_canPogo
|
||||
? $"[LethalTrap] {name}: _canPogo=true。请在顶部添加子 GO + HurtBox(EnemyHurtBox 层) + Collider2D(isTrigger=true),父链上无 IDamageable。"
|
||||
: $"[LethalTrap] {name}: _canPogo=false,无下劈弹跳。",
|
||||
this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/LethalTrap.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/LethalTrap.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03c34fc042c310942a02cfa075dcd981
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Assets/_Game/Scripts/Combat/LinearProjectile.cs
Normal file
13
Assets/_Game/Scripts/Combat/LinearProjectile.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 直线抛射物。以固定速度沿 Direction 方向飞行,无重力。
|
||||
/// </summary>
|
||||
public class LinearProjectile : Projectile
|
||||
{
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
_rb.velocity = Direction * _config.Speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/LinearProjectile.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/LinearProjectile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e7b0c1c571010c4c9f65f953274086d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
58
Assets/_Game/Scripts/Combat/ParryableProjectile.cs
Normal file
58
Assets/_Game/Scripts/Combat/ParryableProjectile.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/ParryableProjectile.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/ParryableProjectile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 075db832266507d40bc71389d6d3f333
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
31
Assets/_Game/Scripts/Combat/PoiseWindowConfig.cs
Normal file
31
Assets/_Game/Scripts/Combat/PoiseWindowConfig.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 描述某个状态/技能在特定动画时间段内拥有的霸体等级(架构 06_CombatModule §13)。
|
||||
/// 在状态机的 Update() 或 AnimancerEvent 中与动画归一化时间对比,决定当前霸体等级。
|
||||
/// 使用示例:
|
||||
/// <code>
|
||||
/// [SerializeField] private PoiseWindowConfig[] _poiseWindows;
|
||||
/// public PoiseLevel GetCurrentPoiseLevel()
|
||||
/// {
|
||||
/// float t = _animancer.States.Current?.NormalizedTime ?? 0f;
|
||||
/// foreach (var w in _poiseWindows)
|
||||
/// if (t >= w.NormalizedStart && t <= w.NormalizedEnd)
|
||||
/// return w.Level;
|
||||
/// return PoiseLevel.None;
|
||||
/// }
|
||||
/// </code>
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public struct PoiseWindowConfig
|
||||
{
|
||||
/// <summary>此时间窗口期间的霸体等级。</summary>
|
||||
public PoiseLevel Level;
|
||||
/// <summary>动画归一化时间起点(0~1)。</summary>
|
||||
public float NormalizedStart;
|
||||
/// <summary>动画归一化时间终点(0~1)。</summary>
|
||||
public float NormalizedEnd;
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/PoiseWindowConfig.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/PoiseWindowConfig.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aaa68ed270c340743958655059e74cfd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
78
Assets/_Game/Scripts/Combat/Projectile.cs
Normal file
78
Assets/_Game/Scripts/Combat/Projectile.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Pool;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 抛射物基类。子类通过重写 <see cref="OnInitialized"/> 设定初速度。
|
||||
/// 依赖 <see cref="HitBox"/> 子组件进行碰撞伤害检测。
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(Rigidbody2D), typeof(HitBox))]
|
||||
public abstract class Projectile : MonoBehaviour
|
||||
{
|
||||
[HideInInspector] public DamageInfo DamageInfo;
|
||||
[HideInInspector] public Vector2 Direction;
|
||||
|
||||
protected ProjectileConfigSO _config;
|
||||
protected Rigidbody2D _rb;
|
||||
protected HitBox _hitBox;
|
||||
protected float _aliveTimer;
|
||||
|
||||
private PooledObject _pooledObject;
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
_rb = GetComponent<Rigidbody2D>();
|
||||
_hitBox = GetComponent<HitBox>();
|
||||
_pooledObject = GetComponent<PooledObject>();
|
||||
}
|
||||
|
||||
/// <summary>从对象池取出后的初始化入口。</summary>
|
||||
public virtual void Initialize(ProjectileConfigSO config, DamageInfo damageInfo, Vector2 direction, int ownerLayer = 0)
|
||||
{
|
||||
_config = config;
|
||||
DamageInfo = damageInfo;
|
||||
Direction = direction.normalized;
|
||||
_aliveTimer = 0f;
|
||||
|
||||
SetFactionLayer(ownerLayer);
|
||||
_hitBox.Activate(config.DamageSource);
|
||||
OnInitialized();
|
||||
}
|
||||
|
||||
/// <summary>根据发射方所在 Layer 切换到对应的 PlayerProjectile / EnemyProjectile 层。</summary>
|
||||
private void SetFactionLayer(int ownerLayer)
|
||||
{
|
||||
int playerLayer = LayerMask.NameToLayer("Player");
|
||||
int playerProjLayer = LayerMask.NameToLayer("PlayerProjectile");
|
||||
int enemyProjLayer = LayerMask.NameToLayer("EnemyProjectile");
|
||||
if (playerProjLayer < 0 || enemyProjLayer < 0) return; // Layer 尚未创建,保留现有层
|
||||
gameObject.layer = (ownerLayer == playerLayer) ? playerProjLayer : enemyProjLayer;
|
||||
}
|
||||
|
||||
/// <summary>子类在此设定初速度或附加初始化逻辑。</summary>
|
||||
protected virtual void OnInitialized() { }
|
||||
|
||||
protected virtual void Update()
|
||||
{
|
||||
_aliveTimer += Time.deltaTime;
|
||||
if (_config != null && _aliveTimer >= _config.Lifetime)
|
||||
ReturnToPool();
|
||||
}
|
||||
|
||||
/// <summary>停用并归还对象池。</summary>
|
||||
protected void ReturnToPool()
|
||||
{
|
||||
_hitBox.Deactivate();
|
||||
gameObject.SetActive(false);
|
||||
if (_pooledObject != null && _config != null)
|
||||
ServiceLocator.GetOrDefault<IObjectPoolService>()?.Despawn(_config.PoolKey, _pooledObject);
|
||||
}
|
||||
|
||||
protected virtual void OnDisable()
|
||||
{
|
||||
_aliveTimer = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/Projectile.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/Projectile.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3be0438f9175ab4f989693a8b01fdc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Assets/_Game/Scripts/Combat/ProjectileConfigSO.cs
Normal file
28
Assets/_Game/Scripts/Combat/ProjectileConfigSO.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 抛射物配置 ScriptableObject。描述一类抛射物的运动、伤害与对象池参数。
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "BaseGames/Combat/ProjectileConfig")]
|
||||
public class ProjectileConfigSO : ScriptableObject
|
||||
{
|
||||
[Header("伤害")]
|
||||
public DamageSourceSO DamageSource;
|
||||
|
||||
[Header("运动")]
|
||||
public float Speed = 12f;
|
||||
public float Lifetime = 5f;
|
||||
public float LaunchAngleDeg = 45f;
|
||||
public float GravityScale = 1f;
|
||||
public float HomingStrength = 4f;
|
||||
|
||||
[Header("对象池")]
|
||||
public string PoolKey;
|
||||
|
||||
[Header("弹反")]
|
||||
public float ParrySpeedMultiplier = 1.2f;
|
||||
public float ParryDamageMultiplier = 2.0f;
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/ProjectileConfigSO.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/ProjectileConfigSO.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34d03fe23f5830b4e8abbe28bfbb5e52
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
55
Assets/_Game/Scripts/Combat/ProjectileManager.cs
Normal file
55
Assets/_Game/Scripts/Combat/ProjectileManager.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Core;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 抛射物管理器(单例 MonoBehaviour)。
|
||||
/// 缓存玩家 Transform,供追踪类抛射物注入目标引用。
|
||||
/// </summary>
|
||||
public class ProjectileManager : MonoBehaviour, IProjectileService
|
||||
{
|
||||
[SerializeField] private TransformEventChannelSO _onPlayerSpawned;
|
||||
|
||||
private Transform _playerTransform;
|
||||
private readonly CompositeDisposable _subs = new();
|
||||
|
||||
/// <summary>当前缓存的玩家 Transform,生成追踪弹时使用。</summary>
|
||||
public Transform PlayerTransform => _playerTransform;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (ServiceLocator.GetOrDefault<IProjectileService>() != null) { Destroy(gameObject); return; }
|
||||
ServiceLocator.Register<IProjectileService>(this);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
ServiceLocator.Unregister<IProjectileService>(this);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
_onPlayerSpawned?.Subscribe(OnPlayerSpawned).AddTo(_subs);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_subs.Clear();
|
||||
}
|
||||
|
||||
private void OnPlayerSpawned(Transform player) => _playerTransform = player;
|
||||
|
||||
/// <summary>
|
||||
/// 完整初始化一枚 <see cref="HomingProjectile"/> 并注入追踪目标。
|
||||
/// </summary>
|
||||
public void LaunchHoming(HomingProjectile proj, Vector2 direction,
|
||||
ProjectileConfigSO config, DamageInfo damageInfo, int ownerLayer = 0)
|
||||
{
|
||||
if (proj == null || config == null) return;
|
||||
proj.Initialize(config, damageInfo, direction, ownerLayer);
|
||||
proj.SetTarget(_playerTransform);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/ProjectileManager.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/ProjectileManager.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac14f526cd2afcd4d8cdd44780805472
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
139
Assets/_Game/Scripts/Combat/ShieldComponent.cs
Normal file
139
Assets/_Game/Scripts/Combat/ShieldComponent.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 护盾组件。实现 IShieldable 接口供 HurtBox 注入。
|
||||
/// 护盾参数通过 ShieldConfigSO 集中配置。
|
||||
/// </summary>
|
||||
public class ShieldComponent : MonoBehaviour, IShieldable
|
||||
{
|
||||
[Header("配置资产")]
|
||||
[SerializeField] private ShieldConfigSO _config;
|
||||
|
||||
[Header("VFX 事件频道")]
|
||||
[SerializeField] private VoidEventChannelSO _onShieldBrokenChannel; // 护盾破碎 → 播放破碎 VFX
|
||||
[SerializeField] private VoidEventChannelSO _onShieldRestoredChannel; // 护盾恢复 → 播放恢复 VFX
|
||||
|
||||
// ── 运行时属性 ────────────────────────────────────────────────────────
|
||||
private int _maxShieldHP;
|
||||
public int MaxShieldHP => _maxShieldHP;
|
||||
public int CurrentShieldHP { get; private set; }
|
||||
/// <summary>当前是否能吸收伤害(护盾 HP > 0 且不在破碎惩罚期)。</summary>
|
||||
public bool HasShield => CurrentShieldHP > 0 && _brokenPenaltyTimer <= 0f;
|
||||
|
||||
private float AbsorptionRatio => _config.DamageAbsorptionRatio;
|
||||
private float RechargeDelay => _config.RechargeDelay;
|
||||
private float RechargeRate => _config.RechargeRate;
|
||||
private float BrokenPenaltyDur => _config.BrokenPenaltyDuration;
|
||||
private float ParryRestoreRatio => _config.ParryRestoreRatio;
|
||||
|
||||
public event Action<int, int> OnShieldChanged; // (current, max)
|
||||
public event Action OnShieldBroken;
|
||||
|
||||
private float _regenDelayTimer;
|
||||
private float _brokenPenaltyTimer;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Debug.Assert(_config != null, "[ShieldComponent] _config 未赋值,请在 Inspector 中指定 ShieldConfigSO。", this);
|
||||
_maxShieldHP = _config != null ? _config.MaxShieldHP : 0;
|
||||
CurrentShieldHP = MaxShieldHP;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
int maxHP = MaxShieldHP;
|
||||
if (maxHP <= 0) return;
|
||||
|
||||
// 破碎惩罚计时
|
||||
if (_brokenPenaltyTimer > 0f)
|
||||
{
|
||||
_brokenPenaltyTimer -= Time.deltaTime;
|
||||
// 破碎惩罚结束 → 广播护盾恢复事件(VFX 钩子)
|
||||
if (_brokenPenaltyTimer <= 0f)
|
||||
_onShieldRestoredChannel?.Raise();
|
||||
return;
|
||||
}
|
||||
|
||||
if (CurrentShieldHP >= maxHP) return;
|
||||
if (RechargeRate <= 0f) return;
|
||||
|
||||
if (_regenDelayTimer > 0f)
|
||||
{
|
||||
_regenDelayTimer -= Time.deltaTime;
|
||||
return;
|
||||
}
|
||||
|
||||
int prev = CurrentShieldHP;
|
||||
CurrentShieldHP = Mathf.Min(CurrentShieldHP + Mathf.CeilToInt(RechargeRate * Time.deltaTime), maxHP);
|
||||
if (CurrentShieldHP != prev)
|
||||
OnShieldChanged?.Invoke(CurrentShieldHP, maxHP);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试以护盾吸收伤害。返回穿透量(0=全部吸收,>0=穿透量继续走 TakeDamage 流程)。
|
||||
/// </summary>
|
||||
public int AbsorbDamage(int amount)
|
||||
{
|
||||
if (!HasShield) return amount;
|
||||
|
||||
_regenDelayTimer = RechargeDelay;
|
||||
|
||||
int maxHP = MaxShieldHP;
|
||||
// 按吸收比例计算实际由护盾承担的伤害
|
||||
int toAbsorb = Mathf.FloorToInt(amount * AbsorptionRatio);
|
||||
toAbsorb = Mathf.Min(toAbsorb, CurrentShieldHP);
|
||||
int passthrough = amount - toAbsorb;
|
||||
|
||||
CurrentShieldHP -= toAbsorb;
|
||||
OnShieldChanged?.Invoke(CurrentShieldHP, maxHP);
|
||||
|
||||
if (CurrentShieldHP <= 0)
|
||||
{
|
||||
CurrentShieldHP = 0;
|
||||
_brokenPenaltyTimer = BrokenPenaltyDur;
|
||||
OnShieldBroken?.Invoke();
|
||||
_onShieldBrokenChannel?.Raise(); // VFX 钩子:播放护盾破碎特效
|
||||
}
|
||||
|
||||
return passthrough;
|
||||
}
|
||||
|
||||
/// <summary>存档点 / 复活时调用:完全恢复护盾并清除惩罚状态。</summary>
|
||||
public void FullRecharge()
|
||||
{
|
||||
bool wasBroken = _brokenPenaltyTimer > 0f || CurrentShieldHP <= 0;
|
||||
_brokenPenaltyTimer = 0f;
|
||||
_regenDelayTimer = 0f;
|
||||
CurrentShieldHP = MaxShieldHP;
|
||||
OnShieldChanged?.Invoke(CurrentShieldHP, MaxShieldHP);
|
||||
if (wasBroken)
|
||||
_onShieldRestoredChannel?.Raise(); // VFX 钩子:护盾已满血恢复
|
||||
}
|
||||
|
||||
/// <summary>弹反成功时调用:按 ParryRestoreRatio 恢复护盾(会清除惩罚状态)。</summary>
|
||||
public void OnParrySuccess()
|
||||
{
|
||||
int maxHP = MaxShieldHP;
|
||||
if (maxHP <= 0) return;
|
||||
|
||||
_brokenPenaltyTimer = 0f;
|
||||
_regenDelayTimer = 0f;
|
||||
int restore = Mathf.CeilToInt(maxHP * ParryRestoreRatio);
|
||||
CurrentShieldHP = Mathf.Min(CurrentShieldHP + restore, maxHP);
|
||||
OnShieldChanged?.Invoke(CurrentShieldHP, maxHP);
|
||||
}
|
||||
|
||||
/// <summary>Inspector / 道具系统调用:设置最大护盾并重置当前值。</summary>
|
||||
public void SetMaxShieldHP(int max)
|
||||
{
|
||||
_maxShieldHP = Mathf.Max(0, max);
|
||||
_brokenPenaltyTimer = 0f;
|
||||
CurrentShieldHP = MaxShieldHP;
|
||||
OnShieldChanged?.Invoke(CurrentShieldHP, MaxShieldHP);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/ShieldComponent.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/ShieldComponent.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f362045054d7c1945841c4ccbcb356e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
29
Assets/_Game/Scripts/Combat/ShieldConfigSO.cs
Normal file
29
Assets/_Game/Scripts/Combat/ShieldConfigSO.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 护盾配置资产(架构 06_CombatModule §6 ShieldSystem)。
|
||||
/// 可通过 Assets/Create/Combat/ShieldConfig 创建。
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "BaseGames/Combat/ShieldConfig", fileName = "ShieldConfig")]
|
||||
public class ShieldConfigSO : ScriptableObject
|
||||
{
|
||||
[Header("护盾数值")]
|
||||
public int MaxShieldHP = 0; // 0 = 无护盾(默认禁用)
|
||||
[Range(0f, 1f)]
|
||||
public float DamageAbsorptionRatio = 1.0f; // 1.0 = 全吸收;<1.0 = 部分穿透
|
||||
public float RechargeDelay = 2.0f; // 受击后延迟多久才开始再生(秒)
|
||||
public float RechargeRate = 20f; // 每秒再生 HP
|
||||
|
||||
[Header("破碎惩罚")]
|
||||
public float BrokenPenaltyDuration = 3.0f; // 护盾破碎后不可再生的惩罚时长(秒)
|
||||
|
||||
[Header("存档点")]
|
||||
public bool FullRechargeOnSavePoint = true; // 抵达存档点时是否完全恢复护盾
|
||||
|
||||
[Header("弹反加成")]
|
||||
[Range(0f, 1f)]
|
||||
public float ParryRestoreRatio = 0.3f; // 弹反成功后恢复护盾比例(占 MaxShieldHP)
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/ShieldConfigSO.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/ShieldConfigSO.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2e617a47cdc4b64383a6a907023b3e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
48
Assets/_Game/Scripts/Combat/SkillHitBoxInstance.cs
Normal file
48
Assets/_Game/Scripts/Combat/SkillHitBoxInstance.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Combat;
|
||||
|
||||
namespace BaseGames.Combat
|
||||
{
|
||||
/// <summary>
|
||||
/// 技能 HitBox 实例(架构 09_ProgressionModule §9 SkillHitBoxInstance)。
|
||||
/// 挂载于技能 HitBox Prefab 根节点。
|
||||
/// 命名规范: Assets/Prefabs/Skills/SKL_{skillId}_HitBox.prefab
|
||||
///
|
||||
/// Prefab 内部层级示例(近战 AoE 技能):
|
||||
/// [SKL_SkySlash_HitBox]
|
||||
/// └── [HitBox] ← 扇形/圆形 PolygonCollider2D
|
||||
/// └── HitBox.cs
|
||||
/// </summary>
|
||||
public class SkillHitBoxInstance : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private HitBox[] _hitBoxes; // 技能可有多个 HitBox(多段伤害)
|
||||
|
||||
public event System.Action<DamageInfo> OnHitConfirmed;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
foreach (var hb in _hitBoxes)
|
||||
{
|
||||
if (hb == null) continue;
|
||||
hb.OnHitConfirmed += info => OnHitConfirmed?.Invoke(info);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>激活所有 HitBox,传入伤害数据源和攻击者 Transform。</summary>
|
||||
public void Activate(DamageSourceSO source, Transform attacker)
|
||||
{
|
||||
foreach (var hb in _hitBoxes)
|
||||
hb?.Activate(source, attacker);
|
||||
}
|
||||
|
||||
/// <summary>duration 秒后自动销毁此 GameObject。</summary>
|
||||
public void AutoDestroyAfter(float duration)
|
||||
=> Destroy(gameObject, Mathf.Max(0f, duration));
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
foreach (var hb in _hitBoxes)
|
||||
hb?.Deactivate();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/SkillHitBoxInstance.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/SkillHitBoxInstance.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 776f1908eabcca546937010169b91efc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Assets/_Game/Scripts/Combat/StatusEffects.meta
Normal file
8
Assets/_Game/Scripts/Combat/StatusEffects.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37363fb905d771d45b74c104305f07dd
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"precompiledReferences": [],
|
||||
"name": "BaseGames.Combat.StatusEffects",
|
||||
"defineConstraints": [],
|
||||
"noEngineReferences": false,
|
||||
"versionDefines": [],
|
||||
"rootNamespace": "BaseGames.Combat.StatusEffects",
|
||||
"references": [
|
||||
"BaseGames.Combat",
|
||||
"BaseGames.Core.Events"
|
||||
],
|
||||
"autoReferenced": true,
|
||||
"overrideReferences": false,
|
||||
"includePlatforms": []
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd947c06a464c1b4492d0417d28a8ccb
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/_Game/Scripts/Combat/StatusEffects/FireEffect.cs
Normal file
47
Assets/_Game/Scripts/Combat/StatusEffects/FireEffect.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace BaseGames.Combat.StatusEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// 燃烧效果(架构 06_CombatModule §11)。
|
||||
/// 规则:不可叠加(MaxStacks = 1);重复施加刷新持续时间;每 0.5 秒造成 1 点 True 伤害。
|
||||
/// </summary>
|
||||
public class FireEffect : StatusEffect
|
||||
{
|
||||
private const float BaseDuration = 3.0f; // 持续 3 秒
|
||||
private const float DotInterval = 0.5f; // 每 0.5 秒一次
|
||||
|
||||
public override StatusEffectType EffectType => StatusEffectType.Fire;
|
||||
public override int MaxStacks => 1;
|
||||
/// <summary>施加燃烧时移除冻结(火冰互斥)。</summary>
|
||||
public override StatusEffectType[] MutualExclusions => new[] { StatusEffectType.Freeze };
|
||||
|
||||
public FireEffect()
|
||||
{
|
||||
TickInterval = DotInterval;
|
||||
}
|
||||
|
||||
public override void OnApply(StatusEffectManager owner)
|
||||
{
|
||||
base.OnApply(owner);
|
||||
owner?.SetShaderParam("_FireGlow", 1f);
|
||||
}
|
||||
|
||||
/// <summary>每次 DoT Tick 造成 1 点 True 伤害(绕过护盾,无敌帧不免疫)。</summary>
|
||||
public override void OnTick()
|
||||
{
|
||||
var info = new DamageInfo.Builder()
|
||||
.SetRaw(1)
|
||||
.SetType(DamageType.True)
|
||||
.SetFlags(DamageFlags.IgnoreIFrame)
|
||||
.Build();
|
||||
Owner?.ApplyDirectDamage(info);
|
||||
}
|
||||
|
||||
public override void OnExpire()
|
||||
{
|
||||
Owner?.SetShaderParam("_FireGlow", 0f);
|
||||
}
|
||||
|
||||
protected override float GetBaseDuration() => BaseDuration;
|
||||
public override string GetDisplayName() => "燃烧";
|
||||
}
|
||||
}
|
||||
11
Assets/_Game/Scripts/Combat/StatusEffects/FireEffect.cs.meta
Normal file
11
Assets/_Game/Scripts/Combat/StatusEffects/FireEffect.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d692ae17737ac54bb0940c3487a59be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
54
Assets/_Game/Scripts/Combat/StatusEffects/PoisonEffect.cs
Normal file
54
Assets/_Game/Scripts/Combat/StatusEffects/PoisonEffect.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
namespace BaseGames.Combat.StatusEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// 中毒效果(架构 06_CombatModule §11)。
|
||||
/// 规则:最多叠加 3 层;每层叠加伤害 +1;每 1 秒造成 StackCount 点 True 伤害。
|
||||
/// </summary>
|
||||
public class PoisonEffect : StatusEffect
|
||||
{
|
||||
private const float BaseDuration = 5.0f; // 持续 5 秒
|
||||
private const float DotInterval = 1.0f; // 每 1 秒一次
|
||||
|
||||
public override StatusEffectType EffectType => StatusEffectType.Poison;
|
||||
public override int MaxStacks => 3;
|
||||
|
||||
public PoisonEffect()
|
||||
{
|
||||
TickInterval = DotInterval;
|
||||
}
|
||||
|
||||
public override void OnApply(StatusEffectManager owner)
|
||||
{
|
||||
base.OnApply(owner);
|
||||
UpdateShader();
|
||||
}
|
||||
|
||||
public override void OnStack()
|
||||
{
|
||||
base.OnStack();
|
||||
UpdateShader();
|
||||
}
|
||||
|
||||
public override void OnTick()
|
||||
{
|
||||
var info = new DamageInfo.Builder()
|
||||
.SetRaw(StackCount) // 叠层越多伤害越高
|
||||
.SetType(DamageType.True)
|
||||
.SetFlags(DamageFlags.IgnoreIFrame)
|
||||
.Build();
|
||||
Owner?.ApplyDirectDamage(info);
|
||||
}
|
||||
|
||||
public override void OnExpire()
|
||||
{
|
||||
StackCount = 0;
|
||||
Owner?.SetShaderParam("_PoisonGlow", 0f);
|
||||
}
|
||||
|
||||
private void UpdateShader()
|
||||
=> Owner?.SetShaderParam("_PoisonGlow", StackCount / (float)MaxStacks);
|
||||
|
||||
protected override float GetBaseDuration() => BaseDuration;
|
||||
public override string GetDisplayName() => $"中毒 ×{StackCount}";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97257dbfc13b78441a89c652f51310cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Assets/_Game/Scripts/Combat/StatusEffects/StaggerEffect.cs
Normal file
35
Assets/_Game/Scripts/Combat/StatusEffects/StaggerEffect.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
namespace BaseGames.Combat.StatusEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// 硬直效果(架构 06_CombatModule §11)。
|
||||
/// 规则:不可叠加(MaxStacks = 1);施加期间宿主无法执行动作。
|
||||
/// 外部查询:entity.GetComponent<StatusEffectManager>()?.HasEffect(StatusEffectType.Stagger)
|
||||
/// </summary>
|
||||
public class StaggerEffect : StatusEffect
|
||||
{
|
||||
private const float BaseDuration = 0.5f; // 默认硬直持续时间(秒)
|
||||
|
||||
private readonly float _overrideDuration;
|
||||
|
||||
/// <param name="duration">自定义持续时间(<= 0 使用默认值)。</param>
|
||||
public StaggerEffect(float duration = 0f)
|
||||
{
|
||||
_overrideDuration = duration > 0f ? duration : BaseDuration;
|
||||
TickInterval = 0f; // 无 DoT Tick
|
||||
}
|
||||
|
||||
public override StatusEffectType EffectType => StatusEffectType.Stagger;
|
||||
public override int MaxStacks => 1;
|
||||
/// <summary>眼晕(Stun)优先级高于硬直,眼晕状态下硬直不可施加。</summary>
|
||||
public override StatusEffectType[] BlockedBy => new[] { StatusEffectType.Stun };
|
||||
|
||||
public override void OnApply(StatusEffectManager owner)
|
||||
{
|
||||
Owner = owner;
|
||||
Duration = _overrideDuration;
|
||||
}
|
||||
|
||||
protected override float GetBaseDuration() => _overrideDuration;
|
||||
public override string GetDisplayName() => "硬直";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23c67d6324b88a1468bd20baa4f109c3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
104
Assets/_Game/Scripts/Combat/StatusEffects/StatusEffect.cs
Normal file
104
Assets/_Game/Scripts/Combat/StatusEffects/StatusEffect.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat.StatusEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态效果抽象基类(架构 06_CombatModule §11)。
|
||||
/// ⚠️ 类名为 StatusEffect(非 StatusEffectBase)。
|
||||
///
|
||||
/// 生命周期:
|
||||
/// OnApply(owner) → Update(delta) × N [内部调用 OnTick()] → OnExpire()
|
||||
///
|
||||
/// 叠加规则:同类型再次施加时调用 OnStack();Manager 保证每种类型只有一个实例。
|
||||
/// </summary>
|
||||
public abstract class StatusEffect
|
||||
{
|
||||
/// <summary>效果类型标识(用作 Dictionary key)。</summary>
|
||||
public abstract StatusEffectType EffectType { get; }
|
||||
|
||||
/// <summary>最大叠加层数(1 = 不可叠加,重复施加只刷新持续时间)。</summary>
|
||||
public abstract int MaxStacks { get; }
|
||||
|
||||
/// <summary>当前叠加层数。</summary>
|
||||
public int StackCount { get; protected set; } = 1;
|
||||
|
||||
/// <summary>当前剩余持续时间(秒)。</summary>
|
||||
public float Duration { get; protected set; }
|
||||
|
||||
/// <summary>每次 Tick 的间隔(秒)。</summary>
|
||||
public float TickInterval { get; protected set; }
|
||||
|
||||
/// <summary>是否已过期(由 Manager 每帧检查)。</summary>
|
||||
public virtual bool IsExpired => Duration <= 0f;
|
||||
|
||||
/// <summary>
|
||||
/// 施加此效果时将被净化的互斥效果类型列表。
|
||||
/// 例:FireEffect 返回 [Freeze],表示施加燃烧时会同时移除冻结。
|
||||
/// </summary>
|
||||
public virtual StatusEffectType[] MutualExclusions => System.Array.Empty<StatusEffectType>();
|
||||
|
||||
/// <summary>
|
||||
/// 阻止此效果施加的效果类型列表。
|
||||
/// 宿主当前存在列表中任意效果时,本效果将被拒绝施加。
|
||||
/// 例:StaggerEffect 返回 [Stun],表示眩晕状态下无法再施加硬直。
|
||||
/// </summary>
|
||||
public virtual StatusEffectType[] BlockedBy => System.Array.Empty<StatusEffectType>();
|
||||
|
||||
private float _tickTimer;
|
||||
|
||||
/// <summary>宿主 Manager(OnApply 时注入,OnTick/OnExpire 中可访问)。</summary>
|
||||
public StatusEffectManager Owner { get; protected set; }
|
||||
|
||||
// ── 生命周期回调(可重写)─────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// 效果施加时调用(Owner 在此注入)。
|
||||
/// ⚠️ 参数为 StatusEffectManager(非 IDamageable),架构 06 §11。
|
||||
/// </summary>
|
||||
public virtual void OnApply(StatusEffectManager owner)
|
||||
{
|
||||
Owner = owner;
|
||||
Duration = GetBaseDuration();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同类型效果再次施加时调用(叠层 / 刷新持续时间)。
|
||||
/// 默认行为:刷新持续时间并叠加层数(若未达上限)。
|
||||
/// </summary>
|
||||
public virtual void OnStack()
|
||||
{
|
||||
Duration = GetBaseDuration();
|
||||
StackCount = Mathf.Min(StackCount + 1, MaxStacks);
|
||||
}
|
||||
|
||||
/// <summary>每个 TickInterval 秒调用一次(DoT 等周期效果)。</summary>
|
||||
public virtual void OnTick() { }
|
||||
|
||||
/// <summary>效果到期 / 被净化时调用。⚠️ 名称 OnExpire(非 OnRemove)。</summary>
|
||||
public virtual void OnExpire() { }
|
||||
|
||||
// ── 框架驱动(由 Manager.Update 调用,每帧执行)──────────────────
|
||||
|
||||
/// <summary>递减持续时间并在到达 Tick 间隔时触发 OnTick。</summary>
|
||||
public void Update(float delta)
|
||||
{
|
||||
Duration -= delta;
|
||||
if (TickInterval <= 0f) return;
|
||||
|
||||
_tickTimer += delta;
|
||||
if (_tickTimer >= TickInterval)
|
||||
{
|
||||
_tickTimer -= TickInterval;
|
||||
OnTick();
|
||||
}
|
||||
}
|
||||
|
||||
// ── 子类必须实现 ──────────────────────────────────────────────────
|
||||
|
||||
/// <summary>返回本类型效果的基础持续时间(秒)。</summary>
|
||||
protected abstract float GetBaseDuration();
|
||||
|
||||
/// <summary>返回本效果的本地化显示名称。</summary>
|
||||
public abstract string GetDisplayName();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4490046c0c848054e9a6846dc272f9f6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using UnityEngine;
|
||||
using BaseGames.Core.Events;
|
||||
|
||||
namespace BaseGames.Combat.StatusEffects
|
||||
{
|
||||
/// <summary>状态效果事件(应用 / 到期时广播,可用于 UI 更新)。</summary>
|
||||
public struct StatusEffectEvent
|
||||
{
|
||||
/// <summary>效果类型。</summary>
|
||||
public StatusEffectType EffectType;
|
||||
|
||||
/// <summary>当前叠加层数(到期时为 0)。</summary>
|
||||
public int StackCount;
|
||||
|
||||
/// <summary>剩余持续时间(到期时为 0)。</summary>
|
||||
public float RemainingDuration;
|
||||
}
|
||||
|
||||
[CreateAssetMenu(menuName = "BaseGames/Events/StatusEffect")]
|
||||
public class StatusEffectEventChannelSO : BaseEventChannelSO<StatusEffectEvent> { }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2aa7161466b28442acab31ae092166b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
185
Assets/_Game/Scripts/Combat/StatusEffects/StatusEffectManager.cs
Normal file
185
Assets/_Game/Scripts/Combat/StatusEffects/StatusEffectManager.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BaseGames.Combat.StatusEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态效果管理器。
|
||||
///
|
||||
/// 架构 06_CombatModule §11:
|
||||
/// - 双结构:List(Update 遍历)+ Dictionary(O(1) 类型查找)
|
||||
/// - 实现 IStatusEffectable,接受来自 HurtBox 的 DamageType 并映射到具体效果
|
||||
/// - DealDotDamage:StatusEffect 子类通过 Owner 调用,绕过无敌帧造成 DoT
|
||||
/// - CleanseEffect:净化指定类型效果(道具/技能使用)
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(SpriteRenderer))]
|
||||
public class StatusEffectManager : MonoBehaviour, IStatusEffectable
|
||||
{
|
||||
[Header("事件频道(可选)")]
|
||||
[SerializeField] private StatusEffectEventChannelSO _onStatusEffectApplied;
|
||||
[SerializeField] private StatusEffectEventChannelSO _onStatusEffectExpired;
|
||||
|
||||
// ── 双结构 ─────────────────────────────────────────────────────────
|
||||
private readonly List<StatusEffect> _activeList = new();
|
||||
private readonly Dictionary<StatusEffectType, StatusEffect> _activeIndex = new();
|
||||
|
||||
// ── Shader 渲染(MaterialPropertyBlock,不修改共享材质)─────────
|
||||
private SpriteRenderer _renderer;
|
||||
private MaterialPropertyBlock _propBlock;
|
||||
|
||||
// ── DoT 伤害代理(由 StatusEffect.OnTick 通过 Owner 调用)──────────
|
||||
private IDamageable _damageable;
|
||||
|
||||
// ── 效果工厂字典(可在 Awake 后动态注册)─────────────────────
|
||||
private readonly Dictionary<DamageType, Func<StatusEffect>> _effectFactories = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_renderer = GetComponent<SpriteRenderer>();
|
||||
_propBlock = new MaterialPropertyBlock();
|
||||
_damageable = GetComponentInParent<IDamageable>();
|
||||
|
||||
// 默认标准效果注册(子类或外部模块可调用 RegisterEffectFactory 覆盖或扩展)
|
||||
RegisterEffectFactory(DamageType.Fire, () => new FireEffect());
|
||||
RegisterEffectFactory(DamageType.Poison, () => new PoisonEffect());
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float delta = Time.deltaTime;
|
||||
|
||||
// 逆序遍历,避免移除时索引错位
|
||||
for (int i = _activeList.Count - 1; i >= 0; i--)
|
||||
{
|
||||
StatusEffect effect = _activeList[i];
|
||||
effect.Update(delta);
|
||||
|
||||
if (effect.IsExpired)
|
||||
RemoveAt(i, effect);
|
||||
}
|
||||
}
|
||||
|
||||
// ── IStatusEffectable 实现 ─────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// HurtBox 调用入口:将 DamageType 映射为具体 StatusEffect 实例并施加。
|
||||
/// </summary>
|
||||
public void ApplyStatusEffect(DamageType type)
|
||||
{
|
||||
StatusEffect effect = CreateEffect(type);
|
||||
if (effect != null)
|
||||
ApplyEffect(effect);
|
||||
}
|
||||
/// <summary>
|
||||
/// 注册或覆盖一个 DamageType 对应的效果工厂。
|
||||
/// Boss 或特殊游玩法式可在运行时注册自定义效果。
|
||||
/// </summary>
|
||||
public void RegisterEffectFactory(DamageType type, Func<StatusEffect> factory)
|
||||
=> _effectFactories[type] = factory;
|
||||
// ── 公开 API ───────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>直接施加一个具体效果(供技能/Boss 使用)。</summary>
|
||||
public void ApplyEffect(StatusEffect effect)
|
||||
{
|
||||
// 检查是否被现有效果阻断
|
||||
foreach (var blockerType in effect.BlockedBy)
|
||||
if (_activeIndex.ContainsKey(blockerType)) return;
|
||||
|
||||
// 净化与新效果互斥的现有效果
|
||||
foreach (var excludedType in effect.MutualExclusions)
|
||||
if (_activeIndex.ContainsKey(excludedType))
|
||||
CleanseEffect(excludedType);
|
||||
|
||||
if (_activeIndex.TryGetValue(effect.EffectType, out StatusEffect existing))
|
||||
{
|
||||
existing.OnStack();
|
||||
BroadcastApplied(existing);
|
||||
}
|
||||
else
|
||||
{
|
||||
effect.OnApply(this);
|
||||
_activeList.Add(effect);
|
||||
_activeIndex[effect.EffectType] = effect;
|
||||
BroadcastApplied(effect);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>净化指定类型效果(净化道具/技能调用)。</summary>
|
||||
public void CleanseEffect(StatusEffectType type)
|
||||
{
|
||||
if (!_activeIndex.TryGetValue(type, out StatusEffect effect)) return;
|
||||
|
||||
effect.OnExpire();
|
||||
_activeIndex.Remove(type);
|
||||
_activeList.Remove(effect);
|
||||
BroadcastExpired(effect);
|
||||
}
|
||||
|
||||
/// <summary>查询是否存在指定类型效果(供状态机/UI 轮询)。</summary>
|
||||
public bool HasEffect(StatusEffectType type) => _activeIndex.ContainsKey(type);
|
||||
|
||||
/// <summary>获取指定类型效果(可为 null)。</summary>
|
||||
public StatusEffect GetEffect(StatusEffectType type)
|
||||
=> _activeIndex.TryGetValue(type, out var e) ? e : null;
|
||||
|
||||
/// <summary>
|
||||
/// DoT 伤害代理(架构 06 §10)。StatusEffect.OnTick() 调用此方法,传入已构建好的 DamageInfo。
|
||||
/// </summary>
|
||||
public void ApplyDirectDamage(DamageInfo info)
|
||||
{
|
||||
_damageable?.TakeDamage(info);
|
||||
}
|
||||
|
||||
/// <summary>设置 Sprite Shader 参数(MaterialPropertyBlock,不修改共享材质)。</summary>
|
||||
public void SetShaderParam(string param, float value)
|
||||
{
|
||||
if (_renderer == null) return;
|
||||
_renderer.GetPropertyBlock(_propBlock);
|
||||
_propBlock.SetFloat(param, value);
|
||||
_renderer.SetPropertyBlock(_propBlock);
|
||||
}
|
||||
|
||||
/// <summary>净化所有状态效果(存档点激活 / 返回城镇等调用)。</summary>
|
||||
public void CleanseAll()
|
||||
{
|
||||
foreach (var e in _activeList) e.OnExpire();
|
||||
_activeList.Clear();
|
||||
_activeIndex.Clear();
|
||||
}
|
||||
|
||||
// ── 私有辅助 ───────────────────────────────────────────────────────
|
||||
|
||||
private StatusEffect CreateEffect(DamageType type)
|
||||
=> _effectFactories.TryGetValue(type, out var factory) ? factory() : null;
|
||||
|
||||
private void RemoveAt(int index, StatusEffect effect)
|
||||
{
|
||||
effect.OnExpire();
|
||||
_activeList.RemoveAt(index);
|
||||
_activeIndex.Remove(effect.EffectType);
|
||||
BroadcastExpired(effect);
|
||||
}
|
||||
|
||||
private void BroadcastApplied(StatusEffect effect)
|
||||
{
|
||||
_onStatusEffectApplied?.Raise(new StatusEffectEvent
|
||||
{
|
||||
EffectType = effect.EffectType,
|
||||
StackCount = effect.StackCount,
|
||||
RemainingDuration = effect.Duration,
|
||||
});
|
||||
}
|
||||
|
||||
private void BroadcastExpired(StatusEffect effect)
|
||||
{
|
||||
_onStatusEffectExpired?.Raise(new StatusEffectEvent
|
||||
{
|
||||
EffectType = effect.EffectType,
|
||||
StackCount = 0,
|
||||
RemainingDuration = 0f,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 708938b7c3d75b244abcbd30ed589461
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace BaseGames.Combat.StatusEffects
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态效果类型枚举(架构 06_CombatModule §11)。
|
||||
/// 用于状态机索引(Dictionary key)和事件载荷,与 DamageType 相互独立。
|
||||
/// </summary>
|
||||
public enum StatusEffectType
|
||||
{
|
||||
Fire, // 燃烧(DoT,不可叠加,重复施加刷新持续时间)
|
||||
Poison, // 中毒(DoT,最多 3 层叠加)
|
||||
Stagger, // 硬直(无法行动 N 秒)
|
||||
Freeze, // 冻结(减速 / 固化)
|
||||
Stun, // 眩晕(无法行动)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a5502c061dc69b4b82113ed5b282740
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user