From e38f67d539d469b5d7ba698149a10b8dbc6f64a2 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Thu, 16 Jul 2020 09:58:54 -0400 Subject: [PATCH] Add some pre-made word lists; fix random-word history Each RandomWord instance now shares its history with anything derived from it (e.g. by getting the capitalized version of that instance). This ensures that repetition doesn't occur. --- src/game/creatures/withers.ts | 3 ++- src/game/language.ts | 31 ++++++++++++++++++++----------- src/game/words.ts | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 src/game/words.ts diff --git a/src/game/creatures/withers.ts b/src/game/creatures/withers.ts index 1c1fa52..ab2006a 100644 --- a/src/game/creatures/withers.ts +++ b/src/game/creatures/withers.ts @@ -6,6 +6,7 @@ import { VoreType, Stomach, Container } from '../vore' import { AttackAction, FeedAction } from '../combat/actions' import { TogetherCondition } from '../combat/conditions' import { InstantKill } from '../combat/effects' +import * as Words from '../words' const huge = new RandomWord([ new Adjective('massive'), @@ -67,7 +68,7 @@ class DevourAllAction extends GroupAction { executeGroup (user: Creature, targets: Array): LogEntry { return new LogLines(...targets.map(target => this.execute(user, target)).concat( - [new LogLine(`All ${targets.length} of them are ${user.kind} chow now`)] + [new LogLine(`${Words.SwallowSound.allCaps}! All ${targets.length} of them pour down ${user.name}'s ${Words.Slick} gullet; they're just ${user.kind.all} chow now`)] )) } diff --git a/src/game/language.ts b/src/game/language.ts index 2fc99f1..ae42685 100644 --- a/src/game/language.ts +++ b/src/game/language.ts @@ -67,6 +67,7 @@ export interface Pluralizable { interface WordOptions { plural: boolean; capital: boolean; + allCaps: boolean; proper: boolean; kind: NounKind; vowel: VowelSound; @@ -74,6 +75,7 @@ interface WordOptions { } const emptyConfig: WordOptions = { + allCaps: false, capital: false, count: false, kind: NounKind.Specific, @@ -117,6 +119,12 @@ export abstract class Word { // These functions are pure; they don't mutate the original object. // This is necessary to avoid causing chaos. + get allCaps (): this { + const opts: WordOptions = Object.assign({}, this.opt) + opts.allCaps = true + return this.configure(opts) as this + } + get capital (): this { const opts: WordOptions = Object.assign({}, this.opt) opts.capital = true @@ -167,15 +175,14 @@ export abstract class Word { } export class RandomWord extends Word { - private last: number - - constructor (public choices: Array, opt: WordOptions = emptyConfig) { + private history: { last: number } + constructor (public choices: Array, opt: WordOptions = emptyConfig, history: { last: number } = { last: -1 }) { super(opt) - this.last = -1 + this.history = history } configure (opts: WordOptions): Word { - return new RandomWord(this.choices, opts) + return new RandomWord(this.choices, opts, this.history) } toString (): string { @@ -183,9 +190,9 @@ export class RandomWord extends Word { do { choice = Math.floor(Math.random() * this.choices.length) - } while (choice === this.last) + } while (choice === this.history.last) - this.last = choice + this.history.last = choice return this.choices[choice].configure(this.opt).toString() } } @@ -234,7 +241,9 @@ export class Noun extends Word { } } - if (this.options.capital) { + if (this.options.allCaps) { + result = result.toUpperCase() + } else if (this.options.capital) { result = result.slice(0, 1).toUpperCase() + result.slice(1) } @@ -243,14 +252,14 @@ export class Noun extends Word { } export class ImproperNoun extends Noun { - constructor (singularNoun: string, pluralNoun: string) { - super(singularNoun, pluralNoun, { plural: false, capital: false, proper: false, kind: NounKind.Specific, vowel: VowelSound.Default, count: true }) + constructor (singularNoun: string, pluralNoun: string = singularNoun) { + super(singularNoun, pluralNoun, { plural: false, allCaps: false, capital: false, proper: false, kind: NounKind.Specific, vowel: VowelSound.Default, count: true }) } } export class ProperNoun extends Noun { constructor (singularNoun: string) { - super(singularNoun, null, { plural: false, capital: false, proper: true, kind: NounKind.Specific, vowel: VowelSound.Default, count: true }) + super(singularNoun, null, { plural: false, allCaps: false, capital: false, proper: true, kind: NounKind.Specific, vowel: VowelSound.Default, count: true }) } } diff --git a/src/game/words.ts b/src/game/words.ts new file mode 100644 index 0000000..26eede6 --- /dev/null +++ b/src/game/words.ts @@ -0,0 +1,14 @@ +import { RandomWord, ImproperNoun, Adjective } from './language' + +export const SwallowSound = new RandomWord([ + new ImproperNoun('gulp'), + new ImproperNoun('glurk'), + new ImproperNoun('glrkh') +]).all + +export const Slick = new RandomWord([ + new Adjective('slick'), + new Adjective('slippery'), + new Adjective('slimy'), + new Adjective('glistening') +])