Browse Source

Add a damage formula that combines other formulas

master
Fen Dweller 5 years ago
parent
commit
0f35aa64dd
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      src/game/combat.ts

+ 18
- 0
src/game/combat.ts View File

@@ -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.
*/


Loading…
Cancel
Save