From e9dfaa5478ebcd7b2115bdc002d85e096bcc9010 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Wed, 15 Jul 2020 10:58:30 -0400 Subject: [PATCH] Move bulk and prey-count into a new VoreStat enum --- src/game/entity.ts | 42 +++++++++++++++++++++++++++++++++++++----- src/game/vore.ts | 14 +++++++++++--- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/game/entity.ts b/src/game/entity.ts index 2ca987f..cca3f12 100644 --- a/src/game/entity.ts +++ b/src/game/entity.ts @@ -1,7 +1,7 @@ import { DamageType, Damage, Combatant, Stats, Action, Vigor } from './combat' import { Noun, Pronoun } from './language' import { LogEntry, LogLine } from './interface' -import { Vore, Container, VoreType } from './vore' +import { Vore, Container, VoreType, VoreStat, VoreStats } from './vore' export enum POV {First, Third} @@ -35,6 +35,8 @@ export class Creature extends Vore implements Combatant { [Vigor.Resolve]: 100 } + voreStats: VoreStats + get disabled (): boolean { return Object.values(this.vigors).some(val => val <= 0) } @@ -44,17 +46,47 @@ export class Creature extends Vore implements Combatant { containers: Array = [] actions: Array = []; otherActions: Array = []; - private baseBulk: number; get bulk (): number { - return this.baseBulk + this.containers.reduce((total, conatiner) => { return total + conatiner.contents.reduce((total, prey) => total + prey.bulk, 0) }, 0) + return this.voreStats.Mass + this.containers.reduce((total, conatiner) => { return total + conatiner.contents.reduce((total, prey) => total + prey.voreStats.Bulk, 0) }, 0) } containedIn: Container|null = null; - constructor (public name: Noun, public pronouns: Pronoun, public stats: Stats, public preyPrefs: Set, public predPrefs: Set, bulk: number) { + constructor (public name: Noun, public pronouns: Pronoun, public stats: Stats, public preyPrefs: Set, public predPrefs: Set, mass: number) { super() - this.baseBulk = bulk + const containers = this.containers + + this.voreStats = { + get [VoreStat.Bulk] () { + console.log(containers) + return containers.reduce( + (total: number, container: Container) => { + return total + container.contents.reduce( + (total: number, prey: Vore) => { + return total + prey.voreStats.Bulk + }, + 0 + ) + }, + this.Mass + ) + }, + [VoreStat.Mass]: mass, + get [VoreStat.PreyCount] () { + return containers.reduce( + (total: number, container: Container) => { + return total + container.contents.reduce( + (total: number, prey: Vore) => { + return total + prey.voreStats[VoreStat.PreyCount] + }, + 0 + ) + }, + 0 + ) + } + } } toString (): string { diff --git a/src/game/vore.ts b/src/game/vore.ts index 91edfd3..6d8a966 100644 --- a/src/game/vore.ts +++ b/src/game/vore.ts @@ -11,6 +11,14 @@ export enum VoreType { Unbirth = "Unbirthing" } +export enum VoreStat { + Mass = "Mass", + Bulk = "Bulk", + PreyCount = "Prey Count" +} + +export type VoreStats = {[key in VoreStat]: number} + export abstract class Vore implements Mortal { abstract name: Noun; abstract pronouns: Pronoun; @@ -23,7 +31,7 @@ export abstract class Vore implements Mortal { abstract stats: Stats; abstract status: string; abstract preyPrefs: Set; - abstract bulk: number; + abstract voreStats: VoreStats; abstract containedIn: Container | null; abstract predPrefs: Set; abstract containers: Array; @@ -78,11 +86,11 @@ abstract class NormalContainer implements Container { abstract disposeLines: POVPair get fullness (): number { - return Array.from(this.contents.values()).reduce((total: number, prey: Vore) => total + prey.bulk, 0) + return Array.from(this.contents.values()).reduce((total: number, prey: Vore) => total + prey.voreStats.Bulk, 0) } canTake (prey: Vore): boolean { - const fits = this.capacity - this.fullness >= prey.bulk + const fits = this.capacity - this.fullness >= prey.voreStats.Bulk const permitted = Array.from(this.voreTypes).every(voreType => { return prey.preyPrefs.has(voreType)