From 37642859de186f5fd94b62f6e9d9a88ac9745d1e Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Tue, 17 Nov 2020 17:51:43 -0500 Subject: [PATCH] Add a drain consequence and a prey targeter --- src/game/combat.ts | 3 ++- src/game/combat/consequences.ts | 28 +++++++++++++++++++++++- src/game/combat/targeters.ts | 11 ++++++++++ src/game/creatures/characters/inazuma.ts | 25 ++++++++++++++++++--- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/game/combat.ts b/src/game/combat.ts index 0224fca..be353e3 100644 --- a/src/game/combat.ts +++ b/src/game/combat.ts @@ -4,6 +4,7 @@ import { LogEntry, LogLines, FAElem, LogLine, FormatEntry, FormatOpt, PropElem, import { World } from '@/game/world' import { TestCategory } from '@/game/combat/tests' import { VoreContainer } from '@/game/vore' +import { SoloTargeter } from '@/game/combat/targeters' export enum DamageType { Pierce = "Pierce", @@ -464,7 +465,7 @@ export class CompositionAction extends Action { super(name, desc, properties.conditions ?? [], properties.tests ?? []) this.consequences = properties.consequences ?? [] this.groupConsequences = properties.groupConsequences ?? [] - this.targeters = properties.targeters ?? [] + this.targeters = properties.targeters ?? [new SoloTargeter()] } execute (user: Creature, target: Creature): LogEntry { diff --git a/src/game/combat/consequences.ts b/src/game/combat/consequences.ts index 9c3fd5a..80131c3 100644 --- a/src/game/combat/consequences.ts +++ b/src/game/combat/consequences.ts @@ -1,4 +1,4 @@ -import { Consequence, DamageFormula, Condition, StatusEffect } from '@/game/combat' +import { Consequence, DamageFormula, Condition, StatusEffect, Damage, DamageType } from '@/game/combat' import { Creature } from '@/game/creature' import { LogEntry, LogLines, LogLine, nilLog } from '@/game/interface' import { Verb, PairLine } from '@/game/language' @@ -82,6 +82,32 @@ export class HealingConsequence extends Consequence { } } +/** + * Deals damage to the target and heals the user + */ +export class DrainConsequence extends Consequence { + constructor (private damageFormula: DamageFormula, conditions: Condition[] = []) { + super(conditions) + } + + apply (user: Creature, target: Creature): LogEntry { + const damage = this.damageFormula.calc(user, target) + const heal = new Damage(...damage.damages.map(instance => ({ amount: instance.amount, type: DamageType.Heal, target: instance.target }))) + console.log(heal) + return new LogLines( + new LogLine(`${user.name.capital} ${user.name.conjugate(new Verb("drain"))} `, damage.renderShort(), ` from ${target.name.objective}.`), + target.takeDamage(damage), + user.takeDamage(heal) + ) + } + + describe (user: Creature, target: Creature): LogEntry { + return new LogLine( + this.damageFormula.describe(user, target) + ) + } +} + /** * Applies a status effect */ diff --git a/src/game/combat/targeters.ts b/src/game/combat/targeters.ts index 65f3423..a96ae7f 100644 --- a/src/game/combat/targeters.ts +++ b/src/game/combat/targeters.ts @@ -1,5 +1,6 @@ import { Encounter, Targeter } from '../combat' import { Creature } from '../creature' +import { Container } from '../vore' export class SoloTargeter implements Targeter { targets (primary: Creature, encounter: Encounter): Array { @@ -12,3 +13,13 @@ export class SideTargeter implements Targeter { return encounter.combatants.filter(combatant => primary.side === combatant.side) } } + +export class PreyTargeter implements Targeter { + constructor (private container: Container) { + + } + + targets (primary: Creature, encounter: Encounter): Array { + return this.container.contents + } +} diff --git a/src/game/creatures/characters/inazuma.ts b/src/game/creatures/characters/inazuma.ts index da367de..40b3288 100644 --- a/src/game/creatures/characters/inazuma.ts +++ b/src/game/creatures/characters/inazuma.ts @@ -1,9 +1,9 @@ import { FavorEscapedPrey, VoreAI } from '@/game/ai' -import { CompositionAction, DamageType, Side, Stat, StatDamageFormula, Vigor } from '@/game/combat' +import { CompositionAction, ConstantDamageFormula, Damage, DamageType, FractionDamageFormula, Side, Stat, StatDamageFormula, Vigor } from '@/game/combat' import { PairCondition, TogetherCondition } from '@/game/combat/conditions' -import { ConsumeConsequence } from '@/game/combat/consequences' +import { ConsumeConsequence, DamageConsequence, DrainConsequence, StatusConsequence } from '@/game/combat/consequences' import { LogGroupConsequence } from '@/game/combat/groupConsequences' -import { SideTargeter } from '@/game/combat/targeters' +import { PreyTargeter, SideTargeter, SoloTargeter } from '@/game/combat/targeters' import { Creature } from '@/game/creature' import { LogLine } from '@/game/interface' import { ImproperNoun, MalePronouns, ProperNoun } from '@/game/language' @@ -54,6 +54,25 @@ export default class Inazuma extends Creature { } )) + this.actions.push(new CompositionAction( + "Level Drain", + "Steal stats from prey", + { + conditions: [new PairCondition()], + targeters: [new PreyTargeter(stomach)], + consequences: [new DrainConsequence( + new FractionDamageFormula([ + { fraction: 0.25, target: Stat.Power, type: DamageType.Pure }, + { fraction: 0.25, target: Stat.Toughness, type: DamageType.Pure }, + { fraction: 0.25, target: Stat.Agility, type: DamageType.Pure }, + { fraction: 0.25, target: Stat.Reflexes, type: DamageType.Pure }, + { fraction: 0.25, target: Stat.Charm, type: DamageType.Pure }, + { fraction: 0.25, target: Stat.Willpower, type: DamageType.Pure } + ]) + )] + } + )) + this.addVoreContainer(stomach) this.ai = null