Browse Source

Display prey spilling out of defeated preds; remove prey from original container when consuming

vintage
Fen Dweller 5 years ago
parent
commit
8e9097a24f
1 changed files with 30 additions and 4 deletions
  1. +30
    -4
      src/game/vore.ts

+ 30
- 4
src/game/vore.ts View File

@@ -39,16 +39,37 @@ export abstract class Vore implements Mortal {
[[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 => {

const released: Array<Vore> = this.containers.flatMap(container => {
return container.contents.map(prey => {
prey.containedIn = this.containedIn
if (this.containedIn !== null) {
this.containedIn.contents.push(prey)
}
return prey
})
})

return lines.run(this)
console.log(released)
console.log(released.reduce((list: Array<string>, prey: Vore) => list.concat([prey.name.toString()]), []))

const names = released.reduce((list: Array<string>, prey: Vore) => list.concat([prey.name.toString()]), []).joinGeneral(", ", " and ").join("")

if (released.length > 0) {
if (this.containedIn === null) {
return new LogLines(
lines.run(this),
new LogLine(names + ` spill out!`)
)
} else {
return new LogLines(
lines.run(this),
new LogLine(names + ` spill out into ${this.containedIn.owner.name}'s ${this.containedIn.name}!`)
)
}
} else {
return lines.run(this)
}
}
}

@@ -98,6 +119,9 @@ export abstract class NormalContainer implements Container {
}

consume (prey: Vore): LogEntry {
if (prey.containedIn !== null) {
prey.containedIn.contents = prey.containedIn.contents.filter(item => prey !== item)
}
this.contents.push(prey)
prey.containedIn = this
return this.consumeLines.run(this.owner, prey)
@@ -161,6 +185,9 @@ export abstract class NormalVoreContainer extends NormalContainer implements Vor
const scaled = this.damage.scale(dt / 60)

const damageResults: Array<LogEntry> = []

const tickedEntries = new LogLines(...this.contents.map(prey => this.tickLines.run(this.owner, prey, { damage: scaled })))

this.contents.forEach(prey => {
damageResults.push(prey.takeDamage(scaled))

@@ -171,7 +198,6 @@ export abstract class NormalVoreContainer extends NormalContainer implements Vor
}
})

const tickedEntries = new LogLines(...this.contents.map(prey => this.tickLines.run(this.owner, prey, { damage: scaled })))
const digestedEntries = this.digest(justDigested)

this.contents = this.contents.filter(prey => {


Loading…
Cancel
Save