Building an RPG Combat Runtime
8. Apply Damage and Buffs
Use instant effects for damage and duration effects for buffs.
The example uses effect payloads to carry caller-owned meaning:
enum EffectPayload {
Damage { amount: f64 },
AttackSpeedBonus { amount: f64 },
MaxHealthBonus { amount: f64 },
Bleed { damage_per_tick: f64 },
Cooldown,
}Slash applies an instant effect. The effect action mutates current health and only then emits an executed fact.
Quickened Strikes and Fortify apply duration effects. They do not directly mutate attack speed or max health. Instead, the derived attribute calculators read active effect instances and compute the current values.
In the compiled demo:
- enemy health falls from
80to68 - attack speed rises from
1.0to1.5 - max health rises from
100to125