diff --git a/src/App.vue b/src/App.vue index 92345a1..58d2769 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,8 +1,6 @@ @@ -10,14 +8,12 @@ diff --git a/src/components/Combat.vue b/src/components/Combat.vue index 3dc557c..60fcd00 100644 --- a/src/components/Combat.vue +++ b/src/components/Combat.vue @@ -1,9 +1,12 @@ @@ -13,8 +14,13 @@ import { Component, Prop, Vue, Watch, Emit } from 'vue-property-decorator' import { Creature, POV } from '@/game/entity' import { Stats, Stat } from '@/game/combat' +import ContainerView from './ContainerView.vue' -@Component +@Component({ + components: { + ContainerView + } +}) export default class Statblock extends Vue { @Prop({ type: Creature, required: true }) subject!: Creature diff --git a/src/game/combat.ts b/src/game/combat.ts index 355b30c..aa611e2 100644 --- a/src/game/combat.ts +++ b/src/game/combat.ts @@ -51,15 +51,14 @@ export interface Combatant { } export abstract class Action { - public name: string; allowed (user: Creature, target: Creature) { return this.userStates.has(user.state) && this.targetStates.has(target.state) } abstract execute(user: Creature, target: Creature): LogEntry - constructor (name: string, public userStates: Set, public targetStates: Set) { - this.name = name + constructor (public name: string, public desc: string, public userStates: Set, public targetStates: Set) { + } toString (): string { @@ -100,7 +99,7 @@ export class AttackAction extends PairAction { } constructor (protected damage: Damage) { - super('Attack', new Set([State.Normal]), new Set([State.Normal])) + super('Attack', 'Attack the enemy', new Set([State.Normal]), new Set([State.Normal])) } execute (user: Creature, target: Creature): LogEntry { @@ -122,7 +121,7 @@ export class DevourAction extends PairAction { } constructor (protected container: Container) { - super('Devour', new Set([State.Normal]), new Set([State.Normal])) + super('Devour', 'Try to consume your foe', new Set([State.Normal]), new Set([State.Normal])) } execute (user: Creature, target: Creature): LogEntry { @@ -144,7 +143,7 @@ export class StruggleAction extends PairAction { } constructor () { - super('Struggle', new Set([State.Eaten]), new Set([State.Normal])) + super('Struggle', 'Try to escape your predator', new Set([State.Eaten]), new Set([State.Normal])) } execute (user: Creature, target: Creature): LogEntry { @@ -168,8 +167,8 @@ export class DigestAction extends SelfAction { } allowed (user: Creature, target: Creature) { - if (Array.from(user.containers).some(container => { - return container.contents.size > 0 + if (user.containers.some(container => { + return container.contents.length > 0 })) { return super.allowed(user, target) } else { @@ -178,11 +177,11 @@ export class DigestAction extends SelfAction { } constructor () { - super('Digest', new Set([State.Normal]), new Set([State.Normal])) + super('Digest', 'Digest all of your current prey', new Set([State.Normal]), new Set([State.Normal])) } execute (user: Creature, target: Creature): LogEntry { - const results = new CompositeLog(...Array.from(user.containers).map(container => container.tick(60))) + const results = new CompositeLog(...user.containers.map(container => container.tick(60))) return new CompositeLog(this.lines[user.perspective][target.perspective](user, target), results) } } diff --git a/src/game/creatures/player.ts b/src/game/creatures/player.ts index 0fa2717..369ed11 100644 --- a/src/game/creatures/player.ts +++ b/src/game/creatures/player.ts @@ -10,7 +10,7 @@ export class Player extends Creature { const stomach = new Stomach(this, 100, new Damage({ amount: 10, type: DamageType.Acid }, { amount: 10, type: DamageType.Crush })) - this.containers.add(stomach) + this.containers.push(stomach) this.actions.push(new DevourAction(stomach)) this.perspective = POV.First diff --git a/src/game/creatures/wolf.ts b/src/game/creatures/wolf.ts index 018190d..0d67665 100644 --- a/src/game/creatures/wolf.ts +++ b/src/game/creatures/wolf.ts @@ -20,7 +20,7 @@ export class Wolf extends Creature { const stomach = new Stomach(this, 50, new Damage({ amount: 50, type: DamageType.Acid }, { amount: 500, type: DamageType.Crush })) - this.containers.add(stomach) + this.containers.push(stomach) this.actions.push(new DevourAction(stomach)) this.actions.push(new StruggleAction()) this.actions.push(new DigestAction()) diff --git a/src/game/entity.ts b/src/game/entity.ts index bc06f5d..8b9e759 100644 --- a/src/game/entity.ts +++ b/src/game/entity.ts @@ -13,6 +13,7 @@ export interface Entity { export interface Mortal extends Entity { health: number; + maxHealth: number; resistances: Map; takeDamage: (damage: Damage) => void; stats: Stats; @@ -20,15 +21,22 @@ export interface Mortal extends Entity { export class Creature implements Mortal, Pred, Prey, Combatant { health = 100 + maxHealth = 100 resistances: Map = new Map() perspective: POV = POV.Third state: State = State.Normal - containers: Set = new Set(); + containers: Array = [] actions: Array = []; - containedIn: Container|null = null; + private baseBulk: number; + + get bulk (): number { + return this.baseBulk + } - constructor (public name: Noun, public pronouns: Pronoun, public stats: Stats, public preyPrefs: Set, public predPrefs: Set, public bulk: number) { + containedIn: Container|null = null; + constructor (public name: Noun, public pronouns: Pronoun, public stats: Stats, public preyPrefs: Set, public predPrefs: Set, bulk: number) { + this.baseBulk = bulk } toString (): string { @@ -37,8 +45,9 @@ export class Creature implements Mortal, Pred, Prey, Combatant { takeDamage (damage: Damage): void { damage.damages.forEach(instance => { - if (this.resistances.has(instance.type)) { - this.health -= instance.amount * this.resistances.get(instance.type)! + const resistance: number|undefined = this.resistances.get(instance.type) + if (resistance !== undefined) { + this.health -= instance.amount * resistance } else { this.health -= instance.amount } @@ -46,7 +55,6 @@ export class Creature implements Mortal, Pred, Prey, Combatant { } validActions (target: Creature): Array { - console.log(this) return this.actions.filter(action => { return action.allowed(this, target) }) diff --git a/src/game/interface.ts b/src/game/interface.ts index 52ae454..c7acde8 100644 --- a/src/game/interface.ts +++ b/src/game/interface.ts @@ -34,5 +34,10 @@ export class CompositeLog implements LogEntry { } export function log (entry: LogEntry): void { - entry.render().forEach(elem => document.querySelector('#log')?.appendChild(elem)) + entry.render().forEach(elem => { + document.querySelector('#log')!.insertBefore(elem, document?.querySelector('#log > *')) + }) + + const entries: Array = Array.from(document.querySelectorAll('#log > *')) + entries.slice(5).forEach(element => element.remove()) } diff --git a/src/game/vore.ts b/src/game/vore.ts index 1b5e01f..7cc4f58 100644 --- a/src/game/vore.ts +++ b/src/game/vore.ts @@ -1,6 +1,7 @@ import { Entity, Mortal, POV } from './entity' import { Damage } from './combat' import { LogLines, LogEntry, CompositeLog } from './interface' +import { ProperNoun } from './language' export enum VoreType {Oral} export interface Prey extends Mortal { @@ -11,13 +12,13 @@ export interface Prey extends Mortal { export interface Pred extends Entity { predPrefs: Set; - containers: Set; + containers: Array; } export interface Container { name: string; voreTypes: Set; - contents: Set; + contents: Array; capacity: number; fullness: number; canTake: (prey: Prey) => boolean; @@ -32,7 +33,7 @@ export interface Container { } abstract class NormalContainer implements Container { - contents: Set + contents: Array get fullness (): number { return Array.from(this.contents.values()).reduce((total: number, prey: Prey) => total + prey.bulk, 0) @@ -49,14 +50,14 @@ abstract class NormalContainer implements Container { } consume (prey: Prey): LogEntry { - this.contents.add(prey) + this.contents.push(prey) prey.containedIn = this return new LogLines('MUNCH') } release (prey: Prey): LogEntry { prey.containedIn = null - this.contents.delete(prey) + this.contents = this.contents.filter(victim => victim !== prey) return new LogLines('ANTI-MUNCH') } @@ -82,9 +83,9 @@ abstract class NormalContainer implements Container { const digestedEntries = new CompositeLog(...digested.map(prey => this.digest(prey))) const absorbedEntries = new CompositeLog(...digested.map(prey => this.absorb(prey))) - this.contents = new Set(Array.from(this.contents.values()).filter(prey => { - return prey.health > 0 - })) + this.contents = this.contents.filter(prey => { + return prey.health > -100 + }) return new CompositeLog(digestedEntries, absorbedEntries) } @@ -112,7 +113,7 @@ abstract class NormalContainer implements Container { } constructor (public name: string, protected owner: Pred, public voreTypes: Set, public capacity: number, private damage: Damage) { - this.contents = new Set() + this.contents = [] } }