From 70a490bf261783a195a2b731b33c7edac955e36d Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sun, 19 Jul 2020 17:09:00 -0400 Subject: [PATCH] Allow damage formulas to be explained with just the user's info --- src/game/combat.ts | 9 +++++++++ src/game/creatures/withers.ts | 15 ++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/game/combat.ts b/src/game/combat.ts index f8db6a9..a969573 100644 --- a/src/game/combat.ts +++ b/src/game/combat.ts @@ -161,6 +161,7 @@ export class Damage { export interface DamageFormula { calc (user: Creature, target: Creature): Damage; describe (user: Creature, target: Creature): LogEntry; + explain (user: Creature): LogEntry; } /** @@ -176,6 +177,10 @@ export class ConstantDamageFormula implements DamageFormula { } describe (user: Creature, target: Creature): LogEntry { + return this.explain(user) + } + + explain (user: Creature): LogEntry { return new LogLine('Deal ', this.damage.renderShort(), ' damage') } } @@ -193,6 +198,10 @@ export class UniformRandomDamageFormula implements DamageFormula { } describe (user: Creature, target: Creature): LogEntry { + return this.explain(user) + } + + explain (user: Creature): LogEntry { return new LogLine('Deal between ', this.damage.scale(1 - this.variance).renderShort(), ' and ', this.damage.scale(1 + this.variance).renderShort(), ' damage.') } } diff --git a/src/game/creatures/withers.ts b/src/game/creatures/withers.ts index 448eb07..810d35d 100644 --- a/src/game/creatures/withers.ts +++ b/src/game/creatures/withers.ts @@ -1,5 +1,5 @@ import { Creature, POV } from '../entity' -import { Damage, DamageType, ConstantDamageFormula, Vigor, Side, GroupAction, CombatTest, Stat, Action } from '../combat' +import { Damage, DamageType, ConstantDamageFormula, Vigor, Side, GroupAction, CombatTest, Stat, Action, DamageFormula, UniformRandomDamageFormula } from '../combat' import { ImproperNoun, POVPair, ProperNoun, FemalePronouns, RandomWord, Adjective, POVPairArgs, POVSoloArgs, Verb } from '../language' import { LogLine, LogLines, LogEntry, Newline } from '../interface' import { VoreType, Stomach, VoreContainer, Vore, NormalContainer, Container } from '../vore' @@ -63,14 +63,15 @@ class ChewAction extends GroupAction { ]) describeGroup (user: Creature, targets: Creature[]): LogEntry { - return new LogLine('CRUNCH') + return new LogLine('Crunch \'em all. ', this.damage.explain(user)) } execute (user: Creature, target: Creature): LogEntry { + const damage = this.damage.calc(user, target) const results: Array = [] - results.push(this.lines.run(user, target, { damage: this.damage })) + results.push(this.lines.run(user, target, { damage: damage })) results.push(new LogLine(' ')) - results.push(target.takeDamage(this.damage)) + results.push(target.takeDamage(damage)) if (target.vigors.Health <= 0) { if (this.killAction.allowed(user, target)) { @@ -86,7 +87,7 @@ class ChewAction extends GroupAction { return new LogLine('Do the crunch') } - constructor (private damage: Damage, container: Container, private killAction: Action) { + constructor (private damage: DamageFormula, container: Container, private killAction: Action) { super('Chew', 'Give them the big chew', [ new ContainerCondition(container) ]) @@ -206,9 +207,9 @@ export class Withers extends Creature { this.otherContainers.push(grapple) - this.actions.push(new ChewAction(new Damage( + this.actions.push(new ChewAction(new UniformRandomDamageFormula(new Damage( { target: Vigor.Health, type: DamageType.Crush, amount: 10000 } - ), + ), 0.5), grapple, new TransferAction(grapple, stomach))) }