From 60757e3005a5adf52422cc28ce55234e5db030e3 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Tue, 14 Jul 2020 20:18:09 -0400 Subject: [PATCH] Track digested prey properly; show text for dying prey --- src/game/combat/actions.ts | 2 +- src/game/entity.ts | 17 ++++------------- src/game/interface.ts | 2 +- src/game/vore.ts | 34 +++++++++++++++++----------------- 4 files changed, 23 insertions(+), 32 deletions(-) diff --git a/src/game/combat/actions.ts b/src/game/combat/actions.ts index 6ef2ee2..9a9e335 100644 --- a/src/game/combat/actions.ts +++ b/src/game/combat/actions.ts @@ -235,7 +235,7 @@ export class TransferAction extends PairAction { ]) allowed (user: Creature, target: Creature) { - if (target.containedIn === this.from) { + if (target.containedIn === this.from && this.from.contents.includes(target)) { return super.allowed(user, target) } else { return false diff --git a/src/game/entity.ts b/src/game/entity.ts index 49dfc88..2ca987f 100644 --- a/src/game/entity.ts +++ b/src/game/entity.ts @@ -71,7 +71,7 @@ export class Creature extends Vore implements Combatant { } }) - if (this.vigors.Health <= -100) { + if (this.vigors.Health <= 0) { return this.destroy() } else { return new LogLine() @@ -79,23 +79,14 @@ export class Creature extends Vore implements Combatant { } get status (): string { - if (this.vigors[Vigor.Health] <= -100) { - return "Dead" - } - if (this.vigors[Vigor.Stamina] <= -100) { - return "Unconscious" - } - if (this.vigors[Vigor.Resolve] <= -100) { - return "Broken" - } if (this.vigors[Vigor.Health] <= 0) { - return "Unconscious" + return "Dead" } if (this.vigors[Vigor.Stamina] <= 0) { - return "Exhausted" + return "Unconscious" } if (this.vigors[Vigor.Resolve] <= 0) { - return "Overpowered" + return "Broken" } if (this.containedIn !== null) { return "Devoured" diff --git a/src/game/interface.ts b/src/game/interface.ts index 8ea4317..704fd5c 100644 --- a/src/game/interface.ts +++ b/src/game/interface.ts @@ -16,7 +16,7 @@ export class LogLines implements LogEntry { this.parts.forEach(part => { if (typeof part === "string") { - const partDiv = document.createElement("span") + const partDiv = document.createElement("div") partDiv.innerText = part div.appendChild(partDiv) } else { diff --git a/src/game/vore.ts b/src/game/vore.ts index b08a186..91edfd3 100644 --- a/src/game/vore.ts +++ b/src/game/vore.ts @@ -1,7 +1,7 @@ import { Entity, Mortal, POV, Creature } from './entity' import { Damage, DamageType, Stats, Actionable, Action, Vigor } from './combat' import { LogLines, LogEntry, CompositeLog, LogLine } from './interface' -import { Noun, Pronoun, POVPair, POVPairArgs, ImproperNoun } from './language' +import { Noun, Pronoun, POVPair, POVPairArgs, ImproperNoun, POVSolo } from './language' import { DigestAction, DevourAction, ReleaseAction, StruggleAction } from './combat/actions' export enum VoreType { @@ -19,7 +19,7 @@ export abstract class Vore implements Mortal { abstract maxVigors: {[key in Vigor]: number}; abstract disabled: boolean; abstract resistances: Map; - abstract takeDamage (damage: Damage): void; + abstract takeDamage (damage: Damage): LogEntry; abstract stats: Stats; abstract status: string; abstract preyPrefs: Set; @@ -28,6 +28,10 @@ export abstract class Vore implements Mortal { abstract predPrefs: Set; abstract containers: Array; destroy (): LogEntry { + const lines = new POVSolo([ + [[POV.First], (target: Vore) => new LogLine('You die!')], + [[POV.Third], (target: Vore) => new LogLine(`${target.name.capital} dies!`)] + ]) this.containers.map(container => { container.contents.map(prey => { prey.containedIn = this.containedIn @@ -37,7 +41,7 @@ export abstract class Vore implements Mortal { }) }) - return new LogLine(`${this.name.capital} dies!`) + return lines.run(this) } } @@ -46,6 +50,7 @@ export interface Container extends Actionable { owner: Vore; voreTypes: Set; contents: Array; + digested: Array; capacity: number; fullness: number; canTake: (prey: Vore) => boolean; @@ -62,6 +67,7 @@ export interface Container extends Actionable { abstract class NormalContainer implements Container { contents: Array + digested: Array abstract consumeLines: POVPair abstract releaseLines: POVPair @@ -107,33 +113,26 @@ abstract class NormalContainer implements Container { tick (dt: number): LogEntry { const digested: Array = [] - const absorbed: Array = [] const scaled = this.damage.scale(dt / 60) + const damageResults: Array = [] this.contents.forEach(prey => { - const start = prey.vigors[Vigor.Health] - prey.takeDamage(scaled) - const end = prey.vigors[Vigor.Health] + damageResults.push(prey.takeDamage(scaled)) - if (start > 0 && end <= 0) { + if (prey.vigors[Vigor.Health] <= 0) { digested.push(prey) } - - if (start > -100 && end <= -100) { - absorbed.push(prey) - } }) - const tickedEntries = new CompositeLog(...this.contents.map(prey => this.tickLines.run(this.owner, prey, { damage: scaled }))) - const digestedEntries = new CompositeLog(...digested.map(prey => this.digest(prey))) - const absorbedEntries = new CompositeLog(...absorbed.map(prey => this.absorb(prey))) + const tickedEntries = new LogLines(...this.contents.map(prey => this.tickLines.run(this.owner, prey, { damage: scaled }))) + const digestedEntries = new LogLines(...digested.map(prey => this.digest(prey))) this.contents = this.contents.filter(prey => { - return prey.vigors[Vigor.Health] > -100 + return prey.vigors[Vigor.Health] > 0 }) - return new CompositeLog(tickedEntries, digestedEntries, absorbedEntries) + return new LogLines(tickedEntries, new LogLines(...damageResults), digestedEntries) } describe (): LogEntry { @@ -162,6 +161,7 @@ abstract class NormalContainer implements Container { constructor (public name: Noun, public owner: Vore, public voreTypes: Set, public capacity: number, private damage: Damage) { this.contents = [] + this.digested = [] this.actions = []