Pārlūkot izejas kodu

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.
vintage
Fen Dweller pirms 5 gadiem
vecāks
revīzija
e38f67d539
3 mainītis faili ar 36 papildinājumiem un 12 dzēšanām
  1. +2
    -1
      src/game/creatures/withers.ts
  2. +20
    -11
      src/game/language.ts
  3. +14
    -0
      src/game/words.ts

+ 2
- 1
src/game/creatures/withers.ts Parādīt failu

@@ -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<Creature>): 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`)]
))
}



+ 20
- 11
src/game/language.ts Parādīt failu

@@ -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<Word>, opt: WordOptions = emptyConfig) {
private history: { last: number }
constructor (public choices: Array<Word>, 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 })
}
}



+ 14
- 0
src/game/words.ts Parādīt failu

@@ -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')
])

Notiek ielāde…
Atcelt
Saglabāt