From 0f35aa64ddc1892e19ddad22e242ce3da43c0c6d Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Fri, 7 Aug 2020 09:30:53 -0400 Subject: [PATCH] Add a damage formula that combines other formulas --- src/game/combat.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/game/combat.ts b/src/game/combat.ts index 122142d..c02c022 100644 --- a/src/game/combat.ts +++ b/src/game/combat.ts @@ -165,6 +165,24 @@ export interface DamageFormula { explain (user: Creature): LogEntry; } +export class CompositeDamageFormula implements DamageFormula { + constructor (private formulas: DamageFormula[]) { + + } + + calc (user: Creature, target: Creature): Damage { + return this.formulas.reduce((total: Damage, next: DamageFormula) => total.combine(next.calc(user, target)), new Damage()) + } + + describe (user: Creature, target: Creature): LogEntry { + return new LogLines(...this.formulas.map(formula => formula.describe(user, target))) + } + + explain (user: Creature): LogEntry { + return new LogLines(...this.formulas.map(formula => formula.explain(user))) + } +} + /** * Simply returns the damage it was given. */