From 38900e0b291d5e0f59afaaa239cd237f733b6588 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Tue, 26 Nov 2024 14:03:23 +0200 Subject: Dying properly --- src/scalevalapokalypsi/Model/Entities/Entity.scala | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/scalevalapokalypsi/Model/Entities/Entity.scala') diff --git a/src/scalevalapokalypsi/Model/Entities/Entity.scala b/src/scalevalapokalypsi/Model/Entities/Entity.scala index 336a6b1..aa2a2e2 100644 --- a/src/scalevalapokalypsi/Model/Entities/Entity.scala +++ b/src/scalevalapokalypsi/Model/Entities/Entity.scala @@ -12,6 +12,7 @@ import scala.collection.immutable * @param initialLocation the Area where the entity is instantiated */ class Entity( + val adventure: Adventure, val name: String, initialLocation: Area, initialHP: Int = 100, @@ -31,10 +32,24 @@ class Entity( */ def getVerseAgainst: String = "Esimerkkirivi laulettavaksi" + def isAlive = this.hp > 0 + def takeDamage(amount: Int): Unit = hp -= amount - if hp < 0 then - println("Voi ei, kuolin!") + val event = if this.isAlive then + Event( + Vector(this -> this.condition(0)).toMap, + this.condition(1) + ) + else + println(s"Could remove myself: ${this.adventure.removeEntity(this.name)}") + Event( + Vector(this -> + "Olet täysin menettänyt toimintakykysi. Kaadut elottomana maahan." + ).toMap, + s"${this.name} kaatuu elottomana maahan." + ) + this.location.observeEvent(event) /** Returns a description of the physical condition of this entity, * i.e. the damage it has taken. -- cgit v1.2.3