🧠 Health Rules¶
📦 Folder Overview¶
This folder defines the rule contracts used by the damage and healing pipelines.
Rules allow behaviour to be extended without modifying core systems.
🎯 Purpose¶
Rules provide:
- A composable pipeline for damage and healing
- A way to inject behaviour externally
- Separation between data (Contracts) and behaviour (Rules)
🧩 What Lives Here¶
Pipeline Model¶
Damage and healing follow this structure:
PRE Rules → Core Processing → POST Observers
PRE Rules¶
Interfaces:
IDamageRuleIHealRule
Semantics:
- Run in ascending
Priority - Execute sequentially
- Receive a mutable context
They may:
- Modify values (
Multiplier,FlatDelta, etc.) - Set
Cancelled = trueto reject the operation - Return
falseto stop further rule execution
POST Observers¶
Interfaces:
IPostDamageRuleIPostHealRule
Semantics:
- Run after evaluation completes
- Receive the final context
- Act as observers only
They must not:
- Mutate internal health state directly
- Re-run pipeline logic
- Assume they run for rejected operations
Affinity — IDamageAffinity¶
Optional multiplier providers.
- Return
float? null= no opinion- Combined by the consumer
Used for:
- resistances
- weaknesses
- immunities
⚠️ Important Notes¶
Behaviour¶
ctx.Cancelled = truemarks the operation as rejectedreturn falsestops further PRE rule execution
These are not the same and may be used independently or together.
Constraints¶
PRE rules are expected to:
- Be suitable for hot paths
- Be designed to avoid allocations
- Avoid unintended side effects outside the context
Boundaries¶
Rules should not:
- Depend on
HealthSystem - Access internal state outside the context
- Perform direct mutation of health values
- Introduce gameplay systems outside rule scope
Rules operate on context only.
🧠 Usage Guidance¶
- Use rules to extend behaviour without modifying core systems
- Keep rules focused on a single responsibility
- Avoid coupling rules to specific implementations
🔗 Related Documentation¶
- Contracts
- Mutation
- Lifecycle
- Health System