⚙️ Health — Rules¶
📦 Folder Overview¶
This folder is the entry point for the Health rule system.
Rules define how damage and healing behave between incoming data (DamageContext / HealContext) and the core HealthSystem.
They are the primary extension surface for combat math, modifiers, and reactive behaviour.
🎯 Purpose¶
Rules provide:
- A composable pipeline for damage and healing
- External behaviour injection without modifying core systems
- Separation between data (contracts) and behaviour (rules)
🧩 What Lives Here¶
Priority Definitions¶
DamageRulePriority.csHealRulePriority.cs
Defines canonical ordering constants used by all rule families.
Use these to keep ordering consistent and debuggable.
🧩 Components¶
Pipeline Overview (Damage)¶
-
Guards
-
authority (optional)
- dead target
- invincibility
-
damage locks
-
PRE rules (
DamageRuleHub) [ascending Priority] -
mutate
DamageContext(RawAmount,Multiplier,FlatDelta,Cancelled,BypassRules) -
Fold damage
-
RawAmount * Multiplier + FlatDelta -
Shields (optional)
-
IShield.TryAbsorb(ref damage)unless bypassed -
Apply to HP
-
Current -= applied -
POST observers (
DamageRuleHub.NotifyPost) -
IPostDamageRuleobserve finalized context (FinalApplied) -
Execution for rejected attempts is implementation-defined
-
Death pipeline (if HP ≤ 0)
-
IBeforeDeathHandler[] IHealthDeathHandler- Events
POST observers run after evaluation completes and should be treated as observer hooks.
Pipeline Overview (Heal)¶
-
Guards
-
authority (optional)
- dead target
-
invalid amount
-
PRE heal rules (
HealRuleHub) [ascending Priority] -
mutate
HealContext(RawAmount,Multiplier,FlatDelta,Cancelled) -
Fold heal
-
RawAmount * Multiplier + FlatDelta -
Healing modifiers (
IHealingModifier) -
Apply to HP
-
Current += applied(clamped) -
POST observers (
HealRuleHub.NotifyPost) -
IPostHealRuleobserve finalized context (FinalApplied) - Execution for rejected attempts is implementation-defined
⚠️ Important Notes¶
Priority System¶
- Lower values run first
- Higher values run later
- POST observers run after evaluation
Use constants from:
DamageRulePriorityHealRulePriority
Avoid hardcoding numbers.
Boundaries¶
Rules should not:
- Mutate HP directly
- Rely on implicit ordering
- Encode networking or authority logic
- Treat helpers as guaranteed behaviour
Rules operate on context and act as extensions, not owners.
🧠 Usage Guidance¶
Quick Start¶
- Add
DamageRuleHuband/orHealRuleHubto the same GameObject asHealthSystem - Add rule components (PRE and/or POST)
- Use ordering constants
- Add shields if needed (run after PRE rules)
No rules are required by default.
Authoring Examples¶
Damage PRE rule
public sealed class MyRule : MonoBehaviour, IDamageRule
{
public int Priority => DamageRulePriority.Armor + 10;
public bool Apply(ref DamageContext ctx)
{
return true;
}
}
Damage POST observer
public sealed class MyObserver : MonoBehaviour, IPostDamageRule
{
public void OnDamageApplied(in DamageContext ctx)
{
if (ctx.FinalApplied <= 0) return;
}
}
Heal PRE rule
public sealed class MyHealGate : MonoBehaviour, IHealRule
{
public int Priority => HealRulePriority.AntiHeal + 10;
public bool Apply(ref HealContext ctx)
{
return true;
}
}
🔗 Related Documentation¶
- Rules Abstractions
- Damage Rules
- Heal Rules
- Rule Hubs
- Modifiers
- Authority