aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Entities/Entity.scala
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-26 14:03:23 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-26 14:10:45 +0200
commit38900e0b291d5e0f59afaaa239cd237f733b6588 (patch)
treeee04f697ab17a75c9563ee87763cbcdcde8d297b /src/scalevalapokalypsi/Model/Entities/Entity.scala
parent27dd937617cce1e43df1c16e12050f6e88763d54 (diff)
downloadscalevalapokalypsi-38900e0b291d5e0f59afaaa239cd237f733b6588.tar.gz
scalevalapokalypsi-38900e0b291d5e0f59afaaa239cd237f733b6588.zip
Dying properly
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities/Entity.scala')
-rw-r--r--src/scalevalapokalypsi/Model/Entities/Entity.scala19
1 files changed, 17 insertions, 2 deletions
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.