From 75f7cfe36a5b5706b69ede97b6d155847caf8702 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 23 Jul 2020 10:53:38 -0400 Subject: [PATCH] Calculate max vigors automatically --- src/game/entity.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/game/entity.ts b/src/game/entity.ts index a1bc214..e627770 100644 --- a/src/game/entity.ts +++ b/src/game/entity.ts @@ -1,4 +1,4 @@ -import { DamageType, Damage, Combatant, Stats, Action, Vigor, VoreStats, VoreStat, Stat, Side, GroupAction } from './combat' +import { DamageType, Damage, Combatant, Stats, Action, Vigor, VoreStats, VoreStat, Stat, Side, GroupAction, Vigors } from './combat' import { Noun, Pronoun, Adjective, ImproperNoun, TextLike } from './language' import { LogEntry, LogLine } from './interface' import { Vore, VoreContainer, VoreType, Container } from './vore' @@ -17,7 +17,7 @@ export interface Entity { export interface Mortal extends Entity { kind: Noun; vigors: {[key in Vigor]: number}; - maxVigors: {[key in Vigor]: number}; + maxVigors: Readonly<{[key in Vigor]: number}>; disabled: boolean; resistances: Map; takeDamage: (damage: Damage) => void; @@ -36,10 +36,12 @@ export class Creature extends Vore implements Combatant { [Vigor.Resolve]: 100 } - maxVigors = { - [Vigor.Health]: 100, - [Vigor.Stamina]: 100, - [Vigor.Resolve]: 100 + get maxVigors (): Readonly { + return { + Health: this.stats.Toughness * 10 + this.stats.Power * 5, + Resolve: this.stats.Willpower * 10 + this.stats.Charm * 5, + Stamina: this.stats.Speed * 10 + this.stats.Power * 2.5 + this.stats.Charm * 2.5 + } } baseStats: Stats @@ -70,10 +72,9 @@ export class Creature extends Vore implements Combatant { super() const containers = this.containers - this.vigors.Health = this.maxVigors.Health = stats.Toughness * 10 + stats.Power * 5 - this.vigors.Stamina = this.maxVigors.Stamina = stats.Toughness * 3 + stats.Speed * 10 + stats.Willpower * 3 - this.vigors.Resolve = this.maxVigors.Resolve = stats.Willpower * 10 + stats.Charm * 5 - + Object.entries(this.maxVigors).forEach(([key, val]) => { + this.vigors[key as Vigor] = val + }) this.baseStats = Object.keys(Stat).reduce((base: any, key) => { base[key] = stats[key as Stat]; return base }, {}) this.side = Side.Heroes this.voreStats = {