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/Adventure.scala | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/scalevalapokalypsi/Model/Adventure.scala') diff --git a/src/scalevalapokalypsi/Model/Adventure.scala b/src/scalevalapokalypsi/Model/Adventure.scala index ba45abe..b10f7d9 100644 --- a/src/scalevalapokalypsi/Model/Adventure.scala +++ b/src/scalevalapokalypsi/Model/Adventure.scala @@ -46,7 +46,7 @@ class Adventure(val playerNames: Vector[String]): ("Rotten zombie", tangle, 10) ) zombieAttrs.foreach(z => - val zombie = Zombie(z(0), z(1), z(2)) + val zombie = Zombie(this, z(0), z(1), z(2)) npcs += z(0) -> zombie z(1).addEntity(zombie) ) @@ -54,7 +54,7 @@ class Adventure(val playerNames: Vector[String]): def takeNpcTurns(): Unit = npcs.values.foreach(_.act()) - private val gruu = Entity("Gruu", northForest) + private val gruu = Entity(this, "Gruu", northForest) northForest.addEntity(gruu) this.entities += gruu.name -> gruu @@ -67,12 +67,29 @@ class Adventure(val playerNames: Vector[String]): * @return the created player entity */ def addPlayer(name: String): Player = - val newPlayer = Player(name, middle) + val newPlayer = Player(this, name, middle) middle.addEntity(newPlayer) this.entities += name -> newPlayer players += name -> newPlayer newPlayer - + + /** Removes the given entity without further observations. Makes sense in the + * game mostly if the entity's HP is nonpositive. + * + * Removes the entity both from the adventure and the game world + * (i.e. the entitys area). + * + * @param name the name of the entity to remove + * @return whether there was an entity to remove with the given name + */ + def removeEntity(name: String): Boolean = + this.players.remove(name) + this.entities.remove(name).orElse(this.npcs.remove(name)) match + case Some(e) => + e.location.removeEntity(name) + true + case None => false + /** Gets the player entity with the specified name. * * @param name name of the player to find -- cgit v1.2.3