From 7ec0dc8ec14791a2e3ce94f94bd8433e7a0127f8 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Sat, 25 Jul 2020 17:10:17 -0400 Subject: [PATCH] Move most of the actions over to the new line style --- src/game/combat.ts | 8 ++- src/game/combat/actions.ts | 94 +++++++++++++++-------------------- src/game/creatures/cafat.ts | 9 ++-- src/game/creatures/withers.ts | 11 ++-- src/game/entity.ts | 2 + src/game/vore.ts | 10 ++-- 6 files changed, 61 insertions(+), 73 deletions(-) diff --git a/src/game/combat.ts b/src/game/combat.ts index 905f15c..164e034 100644 --- a/src/game/combat.ts +++ b/src/game/combat.ts @@ -1,8 +1,6 @@ -import { Creature, POV, Entity } from './entity' -import { POVPair, POVPairArgs, TextLike, DynText, LiveText } from './language' -import { VoreContainer } from './vore' -import { LogEntry, LogLines, CompositeLog, FAElem, LogLine, FormatEntry, FormatOpt, PropElem } from './interface' -import { StatTest, StatVigorTest } from './combat/tests' +import { Creature } from './entity' +import { TextLike } from './language' +import { LogEntry, LogLines, FAElem, LogLine, FormatEntry, FormatOpt, PropElem } from './interface' export enum DamageType { Pierce = "Pierce", diff --git a/src/game/combat/actions.ts b/src/game/combat/actions.ts index 1f4d4f5..17ea865 100644 --- a/src/game/combat/actions.ts +++ b/src/game/combat/actions.ts @@ -1,5 +1,5 @@ import { StatTest, StatVigorTest } from './tests' -import { POVPairArgs, POVPair, DynText, LiveText, TextLike, Verb } from '../language' +import { POVPairArgs, POVPair, DynText, LiveText, TextLike, Verb, PairLine, PairLineArgs } from '../language' import { Entity, POV, Creature } from '../entity' import { Damage, DamageFormula, Stat, Vigor, Action } from '../combat' import { LogLine, LogLines, LogEntry, CompositeLog } from '../interface' @@ -9,26 +9,14 @@ import { CapableCondition, UserDrainedVigorCondition, TogetherCondition, EnemyCo export class AttackAction extends Action { protected test: StatTest - protected successLines: POVPairArgs = new POVPairArgs([ - [[POV.Second, POV.Third], (user, target, args) => new LogLine( - `You ${this.verb} ${target.name} for `, - args.damage.renderShort() - )], - [[POV.Third, POV.Second], (user, target, args) => new LogLine( - `${user.name.capital} ${this.verb.singular} you for `, - args.damage.renderShort() - )], - [[POV.Third, POV.Third], (user, target, args) => new LogLine( - `${user.name.capital} ${this.verb.singular} ${target.name} for `, - args.damage.renderShort() - )] - ]) - - protected failLines: POVPair = new POVPair([ - [[POV.Second, POV.Third], (user, target) => new LogLine(`You try to ${this.verb.present} ${target.name}, but you miss`)], - [[POV.Third, POV.Second], (user, target) => new LogLine(`${user.name.capital} misses you`)], - [[POV.Third, POV.Third], (user, target) => new LogLine(`${user.name.capital} misses ${target.name}`)] - ]) + protected successLine: PairLineArgs = (user, target, args) => new LogLine( + `${user.name.capital} ${user.name.conjugate(this.verb)} ${target.name.objective} for `, + args.damage.renderShort() + ) + + protected failLine: PairLine = (user, target) => new LogLine( + `${user.name.capital} ${user.name.conjugate(new Verb('miss', 'misses'))} ${target.name.objective}` + ) constructor (protected damage: DamageFormula, protected verb: Verb = new Verb('smack')) { super( @@ -43,10 +31,10 @@ export class AttackAction extends Action { if (this.test.test(user, target)) { const damage = this.damage.calc(user, target) const targetResult = target.takeDamage(damage) - const ownResult = this.successLines.run(user, target, { damage: damage }) + const ownResult = this.successLine(user, target, { damage: damage }) return new CompositeLog(ownResult, targetResult) } else { - return this.failLines.run(user, target) + return this.failLine(user, target) } } @@ -58,11 +46,9 @@ export class AttackAction extends Action { export class DevourAction extends Action { private test: StatVigorTest - protected failLines: POVPairArgs = new POVPairArgs([ - [[POV.Second, POV.Third], (user, target, args) => new LogLine(`You fail to ${args.container.consumeVerb} ${target.name}`)], - [[POV.Third, POV.Second], (user, target, args) => new LogLine(`${user.name.capital} tries to ${args.container.consumeVerb} you, but fails`)], - [[POV.Third, POV.Third], (user, target, args) => new LogLine(`${user.name.capital} unsuccessfully tries to ${args.container.consumeVerb} ${target.name}`)] - ]) + protected failLine: PairLineArgs = (user, target, args) => new LogLine( + `${user.name.capital} ${user.name.conjugate(new Verb('fail'))} to ${args.container.consumeVerb} ${target.name.objective}.` + ) allowed (user: Creature, target: Creature): boolean { const owner = this.container.owner === user @@ -89,7 +75,7 @@ export class DevourAction extends Action { if (this.test.test(user, target)) { return this.container.consume(target) } else { - return this.failLines.run(user, target, { container: this.container }) + return this.failLine(user, target, { container: this.container }) } } @@ -101,16 +87,18 @@ export class DevourAction extends Action { export class FeedAction extends Action { private test: StatTest - protected failLines: POVPair = new POVPair([ - [[POV.Second, POV.Third], (user, target) => new LogLine(`You fail to feed yourself to ${target.name}`)], - [[POV.Third, POV.Second], (user, target) => new LogLine(`${user.name.capital} tries to feed ${user.pronouns.possessive} to you, but fails`)], - [[POV.Third, POV.Third], (user, target) => new LogLine(`${user.name.capital} unsuccessfully tries to feed ${user.pronouns.possessive} to ${target.name}`)] - ]) + protected successLine: PairLine = (user, target) => new LogLine( + `${user.name.capital} ${user.name.conjugate(new Verb('feed'))} ${user.pronouns.reflexive} to ${target.name}. ` + ) + + protected failLine: PairLine = (user, target) => new LogLine( + `${user.name.capital} ${user.name.conjugate(new Verb('fail'))} to feed ${user.pronouns.reflexive} to ${target.name}. ` + ) allowed (user: Creature, target: Creature): boolean { const owner = this.container.owner === target - const predOk = Array.from(this.container.voreTypes).every(pref => user.predPrefs.has(pref)) - const preyOk = Array.from(this.container.voreTypes).every(pref => target.preyPrefs.has(pref)) + const predOk = Array.from(this.container.voreTypes).every(pref => user.preyPrefs.has(pref)) + const preyOk = Array.from(this.container.voreTypes).every(pref => target.predPrefs.has(pref)) if (owner && predOk && preyOk) { return super.allowed(user, target) @@ -130,7 +118,7 @@ export class FeedAction extends Action { } execute (user: Creature, target: Creature): LogEntry { - return this.container.consume(user) + return new LogLines(this.successLine(user, target), this.container.consume(user)) } describe (user: Creature, target: Creature): LogEntry { @@ -141,11 +129,13 @@ export class FeedAction extends Action { export class StruggleAction extends Action { private test: StatVigorTest - protected failLines: POVPair = new POVPair([ - [[POV.Second, POV.Third], (user, target) => new LogLine(`You fail to escape from ${target.name}`)], - [[POV.Third, POV.Second], (user, target) => new LogLine(`${user.name.capital} tries to escape from you, but fails`)], - [[POV.Third, POV.Third], (user, target) => new LogLine(`${user.name.capital} unsuccessfully struggles against ${target.name}`)] - ]) + protected successLine: PairLineArgs = (prey, pred, args) => new LogLine( + `${prey.name.capital} ${prey.name.conjugate(new Verb('escape'))} from ${pred.name.possessive} ${args.container.name}.` + ) + + protected failLine: PairLineArgs = (prey, pred, args) => new LogLine( + `${prey.name.capital} ${prey.name.conjugate(new Verb('fail'))} to escape from ${pred.name.possessive} ${args.container.name}.` + ) constructor (public container: Container) { super( @@ -159,9 +149,9 @@ export class StruggleAction extends Action { execute (user: Creature, target: Creature): LogEntry { if (user.containedIn !== null) { if (this.test.test(user, target)) { - return user.containedIn.release(user) + return new LogLines(this.successLine(user, target, { container: this.container }), user.containedIn.release(user)) } else { - return this.failLines.run(user, target) + return this.failLine(user, target, { container: this.container }) } } else { return new LogLine("Vore's bugged!") @@ -174,8 +164,6 @@ export class StruggleAction extends Action { } export abstract class EatenAction extends Action { - protected lines: POVPair = new POVPair([]) - allowed (user: Creature, target: Creature) { if (target.containedIn === this.container) { return super.allowed(user, target) @@ -194,8 +182,6 @@ export abstract class EatenAction extends Action { } export class DigestAction extends Action { - protected lines: POVPair = new POVPair([]) - allowed (user: Creature, target: Creature) { if (this.container.owner === user && this.container.contents.length > 0) { return super.allowed(user, target) @@ -249,11 +235,11 @@ export class ReleaseAction extends Action { } export class TransferAction extends Action { - lines: POVPairArgs = new POVPairArgs([ - [[POV.Second, POV.Third], (user, target, args) => new LogLine(`You squeeze ${target.name} from your ${args.from.name} to your ${args.to.name}`)], - [[POV.Third, POV.Second], (user, target, args) => new LogLine(`You're squeezed from ${user.name}'s ${args.from.name} to ${user.pronouns.possessive} ${args.to.name}`)], - [[POV.Third, POV.Third], (user, target, args) => new LogLine(`${user.name} sends ${target.name} from ${user.pronouns.possessive} ${args.from.name.all} to ${user.pronouns.possessive} ${args.to.name.all}`)] - ]) + verb: Verb = new Verb('send') + + line: PairLineArgs = (user, target, args) => new LogLine( + `${user.name.capital} ${user.name.conjugate(this.verb)} ${target.name.objective} from ${user.pronouns.possessive} ${args.from.name} to ${user.pronouns.possessive} ${args.to.name}` + ) allowed (user: Creature, target: Creature) { if (target.containedIn === this.from && this.from.contents.includes(target)) { @@ -274,7 +260,7 @@ export class TransferAction extends Action { execute (user: Creature, target: Creature): LogEntry { this.from.release(target) this.to.consume(target) - return this.lines.run(user, target, { from: this.from, to: this.to }) + return this.line(user, target, { from: this.from, to: this.to }) } describe (user: Creature, target: Creature): LogEntry { diff --git a/src/game/creatures/cafat.ts b/src/game/creatures/cafat.ts index 5ed1732..68223e5 100644 --- a/src/game/creatures/cafat.ts +++ b/src/game/creatures/cafat.ts @@ -1,6 +1,6 @@ import { Creature, POV, Entity } from '../entity' import { Stat, Damage, DamageType, Vigor, ConstantDamageFormula } from '../combat' -import { ProperNoun, TheyPronouns, ImproperNoun, POVPair, FemalePronouns, POVPairArgs } from '../language' +import { ProperNoun, TheyPronouns, ImproperNoun, POVPair, FemalePronouns, POVPairArgs, Verb } from '../language' import { VoreType, Stomach, InnerStomach, VoreContainer, NormalContainer, Vore } from '../vore' import { LogLine, LogLines, LogEntry, FAElem, CompositeLog, ImgElem } from '../interface' import { AttackAction, EatenAction, TransferAction, FeedAction } from '../combat/actions' @@ -116,11 +116,8 @@ export class Cafat extends Creature { const transfer = new TransferAction(stomach, lowerStomach) - transfer.lines = new POVPairArgs([ - [[POV.Second, POV.Third], (user, target, args) => new LogLine(`You squeeze ${target.name} from your ${args.from.name} to your ${args.to.name}`)], - [[POV.Third, POV.Second], (user, target, args) => new CompositeLog(new LogLine(`You're squeezed from ${user.name}'s ${args.from.name} to ${user.pronouns.possessive} ${args.to.name}`), new ImgElem('./media/cafat/images/lower-stomach.webp'))], - [[POV.Third, POV.Third], (user, target, args) => new LogLine(`${user.name} squeezes ${target.name} from ${user.pronouns.possessive} ${args.from.name} to ${user.pronouns.possessive} ${args.to.name}`)] - ]) + transfer.verb = new Verb('gulp') + this.actions.push(transfer) this.actions.push(new TransferAction(lowerStomach, stomach)) diff --git a/src/game/creatures/withers.ts b/src/game/creatures/withers.ts index 81e70a9..8204f67 100644 --- a/src/game/creatures/withers.ts +++ b/src/game/creatures/withers.ts @@ -104,7 +104,9 @@ class MawContainer extends NormalContainer { constructor (owner: Vore, stomach: VoreContainer) { super(new ImproperNoun('maw'), owner, new Set([VoreType.Oral]), 50) - this.actions.push(new TransferAction(this, stomach)) + const transfer = new TransferAction(this, stomach) + transfer.verb = new Verb('gulp') + this.actions.push(transfer) } } @@ -163,7 +165,7 @@ class BootContainer extends NormalContainer { { target: Stat.Toughness, type: DamageType.Crush, amount: 10 }, { target: Stat.Power, type: DamageType.Crush, amount: 10 }, { target: Stat.Speed, type: DamageType.Crush, amount: 10 }, - { target: Stat.Willpower, type: DamageType.Crush, amount: 10 }, + { target: Stat.Willpower, type: DamageType.Crush, amount: 30 }, { target: Stat.Charm, type: DamageType.Crush, amount: 10 } ), 0.5), this @@ -369,12 +371,15 @@ export class Withers extends Creature { this.otherContainers.push(maw) + const transfer = new TransferAction(maw, stomach) + transfer.verb = new Verb('gulp') + this.actions.push(new ChewAction( new UniformRandomDamageFormula(new Damage( { target: Vigor.Health, type: DamageType.Crush, amount: 10000 } ), 0.5), maw, - new TransferAction(maw, stomach) + transfer )) const boot = new BootContainer(this) diff --git a/src/game/entity.ts b/src/game/entity.ts index 28e29a4..f995457 100644 --- a/src/game/entity.ts +++ b/src/game/entity.ts @@ -181,7 +181,9 @@ export class Creature extends Vore implements Combatant { if (this.containedIn !== null) { choices = choices.concat(this.containedIn.actions) } + console.log(this, target) return choices.filter(action => { + console.log(action, action.allowed(this, target)) return action.allowed(this, target) }) } diff --git a/src/game/vore.ts b/src/game/vore.ts index 39e3bd5..8568334 100644 --- a/src/game/vore.ts +++ b/src/game/vore.ts @@ -1,7 +1,7 @@ -import { Entity, Mortal, POV, Creature } from './entity' +import { Mortal, POV } from './entity' import { Damage, DamageType, Stats, Actionable, Action, Vigor, VoreStats } from './combat' -import { LogLines, LogEntry, CompositeLog, LogLine } from './interface' -import { Noun, Pronoun, POVPair, POVPairArgs, ImproperNoun, POVSolo, TextLike, Verb, SecondPersonPronouns, PronounAsNoun, FirstPersonPronouns, PairLine, PairLineArgs } from './language' +import { LogLines, LogEntry, LogLine } from './interface' +import { Noun, Pronoun, ImproperNoun, POVSolo, TextLike, Verb, SecondPersonPronouns, PronounAsNoun, FirstPersonPronouns, PairLineArgs } from './language' import { DigestAction, DevourAction, ReleaseAction, StruggleAction } from './combat/actions' import * as Words from './words' @@ -57,7 +57,7 @@ export abstract class Vore implements Mortal { abstract otherContainers: Array; destroy (): LogEntry { const lines = new POVSolo([ - [[POV.Second], (target: Vore) => new LogLine('You die!')], + [[POV.Second], () => new LogLine('You die!')], [[POV.Third], (target: Vore) => new LogLine(`${target.name.capital} dies!`)] ]) @@ -125,7 +125,7 @@ export abstract class NormalContainer implements Container { return new LogLine(`${user.name.capital} ${user.name.conjugate(new Verb('hork'))} ${target.name.objective} up from ${user.pronouns.possessive} ${args.container.name}.`) } - struggleLine: PairLineArgs = (user, target, args) => { + struggleLine: PairLineArgs = () => { return new LogLine(`struggle`) }