Procházet zdrojové kódy

Move bulk and prey-count into a new VoreStat enum

master
Fen Dweller před 5 roky
rodič
revize
e9dfaa5478
2 změnil soubory, kde provedl 48 přidání a 8 odebrání
  1. +37
    -5
      src/game/entity.ts
  2. +11
    -3
      src/game/vore.ts

+ 37
- 5
src/game/entity.ts Zobrazit soubor

@@ -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<Container> = []
actions: Array<Action> = [];
otherActions: Array<Action> = [];
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<VoreType>, public predPrefs: Set<VoreType>, bulk: number) {
constructor (public name: Noun, public pronouns: Pronoun, public stats: Stats, public preyPrefs: Set<VoreType>, public predPrefs: Set<VoreType>, 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 {


+ 11
- 3
src/game/vore.ts Zobrazit soubor

@@ -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<VoreType>;
abstract bulk: number;
abstract voreStats: VoreStats;
abstract containedIn: Container | null;
abstract predPrefs: Set<VoreType>;
abstract containers: Array<Container>;
@@ -78,11 +86,11 @@ abstract class NormalContainer implements Container {
abstract disposeLines: POVPair<Vore, Vore>

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)


Načítá se…
Zrušit
Uložit