From 0ab5b201c100d2fc36dc6de3165e13ab72207635 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 30 Jul 2020 17:01:21 -0400 Subject: [PATCH] Add a damage calculator that does a percentage of the target's stats/vigors --- src/game/combat.ts | 53 +++++++++++++++++++++++++++++++++++- src/game/creatures/shingo.ts | 32 ++++++++++++++++++---- 2 files changed, 78 insertions(+), 7 deletions(-) diff --git a/src/game/combat.ts b/src/game/combat.ts index 3a5b92c..091f716 100644 --- a/src/game/combat.ts +++ b/src/game/combat.ts @@ -9,7 +9,8 @@ export enum DamageType { Acid = "Acid", Seduction = "Seduction", Dominance = "Dominance", - Heal = "Heal" + Heal = "Heal", + Pure = "Pure" } export interface DamageInstance { @@ -258,6 +259,56 @@ export class StatDamageFormula implements DamageFormula { } } +/** + * Deals a percentage of the target's current vigors/stats + */ +export class FractionDamageFormula implements DamageFormula { + constructor (private factors: Array<{ fraction: number; target: Vigor|Stat; type: DamageType }>) { + + } + + calc (user: Creature, target: Creature): Damage { + const instances: Array = this.factors.map(factor => { + if (factor.target in Stat) { + return { + amount: Math.max(0, factor.fraction * target.stats[factor.target as Stat]), + target: factor.target, + type: factor.type + } + } else if (factor.target in Vigor) { + return { + amount: Math.max(factor.fraction * user.vigors[factor.target as Vigor]), + target: factor.target, + type: factor.type + } + } else { + // should be impossible; .target is Stat|Vigor + return { + amount: 0, + target: Vigor.Health, + type: DamageType.Heal + } + } + }) + + return new Damage(...instances) + } + + describe (user: Creature, target: Creature): LogEntry { + return this.explain(user) + } + + explain (user: Creature): LogEntry { + return new LogLine( + `Deal damage equal to `, + ...this.factors.map(factor => new LogLine( + `${factor.fraction * 100}% of your target's `, + new PropElem(factor.target) + )).joinGeneral(new LogLine(`, `), new LogLine(` and `)) + ) + } +} + export enum Side { Heroes, Monsters diff --git a/src/game/creatures/shingo.ts b/src/game/creatures/shingo.ts index 96e795e..52c0538 100644 --- a/src/game/creatures/shingo.ts +++ b/src/game/creatures/shingo.ts @@ -1,21 +1,21 @@ import { Creature } from "../creature" -import { Damage, DamageType, ConstantDamageFormula, Vigor, Side, StatDamageFormula, Stat, Action, DamageFormula } from '../combat' +import { Damage, DamageType, ConstantDamageFormula, Vigor, Side, StatDamageFormula, Stat, Action, DamageFormula, Condition, FractionDamageFormula } from '../combat' import { ImproperNoun, ProperNoun, FemalePronouns, MalePronouns, Verb, PairLineArgs, PairLine, TextLike } from '../language' import { VoreType, Stomach, Bowels, NormalContainer, InnerContainer, VoreContainer, Container, Vore } from '../vore' import { AttackAction, TransferAction, FeedAction, StruggleAction, DamageAction } from '../combat/actions' import { LogLine, LogEntry, LogLines } from '../interface' -import { ContainsCondition, CapableCondition, EnemyCondition } from '../combat/conditions' +import { ContainsCondition, CapableCondition, EnemyCondition, TargetDrainedVigorCondition } from '../combat/conditions' import { StatTest } from '../combat/tests' export class TrappedAction extends DamageAction { protected test: StatTest - constructor (name: TextLike, desc: TextLike, protected verb: Verb, protected damage: DamageFormula, container: Container) { + constructor (name: TextLike, desc: TextLike, protected verb: Verb, protected damage: DamageFormula, container: Container, conditions: Condition[] = []) { super( name, desc, damage, - [new CapableCondition(), new ContainsCondition(container), new EnemyCondition()] + [new CapableCondition(), new ContainsCondition(container), new EnemyCondition()].concat(conditions) ) this.test = new StatTest(Stat.Power) } @@ -77,13 +77,33 @@ class Paw extends NormalContainer { ), new ConstantDamageFormula( new Damage( - { amount: 10, target: Stat.Toughness, type: DamageType.Crush }, - { amount: 10, target: Stat.Power, type: DamageType.Crush }, + { amount: 100, target: Vigor.Stamina, type: DamageType.Crush }, + { amount: 3, target: Stat.Toughness, type: DamageType.Crush }, + { amount: 5, target: Stat.Power, type: DamageType.Crush }, { amount: 10, target: Stat.Speed, type: DamageType.Crush } ) ), this )) + this.actions.push(new TrappedAction( + "Crush", + "Finish them off", + new Verb( + 'crush', + 'crushes' + ), + new FractionDamageFormula( + [ + { fraction: 1, target: Stat.Toughness, type: DamageType.Pure }, + { fraction: 1, target: Stat.Power, type: DamageType.Pure }, + { fraction: 1, target: Stat.Speed, type: DamageType.Pure }, + { fraction: 1, target: Stat.Willpower, type: DamageType.Pure }, + { fraction: 1, target: Stat.Charm, type: DamageType.Pure } + ] + ), + this, + [new TargetDrainedVigorCondition(Vigor.Stamina)] + )) } consumeLine: PairLineArgs = (user, target, args) => {