Просмотр исходного кода

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.
master
Fen Dweller 5 лет назад
Родитель
Сommit
e38f67d539
3 измененных файлов: 36 добавлений и 12 удалений
  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 Просмотреть файл

@@ -6,6 +6,7 @@ import { VoreType, Stomach, Container } from '../vore'
import { AttackAction, FeedAction } from '../combat/actions' import { AttackAction, FeedAction } from '../combat/actions'
import { TogetherCondition } from '../combat/conditions' import { TogetherCondition } from '../combat/conditions'
import { InstantKill } from '../combat/effects' import { InstantKill } from '../combat/effects'
import * as Words from '../words'


const huge = new RandomWord([ const huge = new RandomWord([
new Adjective('massive'), new Adjective('massive'),
@@ -67,7 +68,7 @@ class DevourAllAction extends GroupAction {


executeGroup (user: Creature, targets: Array<Creature>): LogEntry { executeGroup (user: Creature, targets: Array<Creature>): LogEntry {
return new LogLines(...targets.map(target => this.execute(user, target)).concat( 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 Просмотреть файл

@@ -67,6 +67,7 @@ export interface Pluralizable {
interface WordOptions { interface WordOptions {
plural: boolean; plural: boolean;
capital: boolean; capital: boolean;
allCaps: boolean;
proper: boolean; proper: boolean;
kind: NounKind; kind: NounKind;
vowel: VowelSound; vowel: VowelSound;
@@ -74,6 +75,7 @@ interface WordOptions {
} }


const emptyConfig: WordOptions = { const emptyConfig: WordOptions = {
allCaps: false,
capital: false, capital: false,
count: false, count: false,
kind: NounKind.Specific, kind: NounKind.Specific,
@@ -117,6 +119,12 @@ export abstract class Word {
// These functions are pure; they don't mutate the original object. // These functions are pure; they don't mutate the original object.
// This is necessary to avoid causing chaos. // 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 { get capital (): this {
const opts: WordOptions = Object.assign({}, this.opt) const opts: WordOptions = Object.assign({}, this.opt)
opts.capital = true opts.capital = true
@@ -167,15 +175,14 @@ export abstract class Word {
} }


export class RandomWord extends 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) super(opt)
this.last = -1
this.history = history
} }


configure (opts: WordOptions): Word { configure (opts: WordOptions): Word {
return new RandomWord(this.choices, opts)
return new RandomWord(this.choices, opts, this.history)
} }


toString (): string { toString (): string {
@@ -183,9 +190,9 @@ export class RandomWord extends Word {


do { do {
choice = Math.floor(Math.random() * this.choices.length) 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() 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) result = result.slice(0, 1).toUpperCase() + result.slice(1)
} }


@@ -243,14 +252,14 @@ export class Noun extends Word {
} }


export class ImproperNoun extends Noun { 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 { export class ProperNoun extends Noun {
constructor (singularNoun: string) { 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 Просмотреть файл

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

Загрузка…
Отмена
Сохранить