From 302455bac062080bf197b44e07ed53a3454be4c5 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Wed, 27 Nov 2024 17:19:46 +0200 Subject: Finishing almost the adventure --- .../Model/Entities/NPCs/Tentacle.scala | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/scalevalapokalypsi/Model/Entities/NPCs/Tentacle.scala (limited to 'src/scalevalapokalypsi/Model/Entities/NPCs/Tentacle.scala') diff --git a/src/scalevalapokalypsi/Model/Entities/NPCs/Tentacle.scala b/src/scalevalapokalypsi/Model/Entities/NPCs/Tentacle.scala new file mode 100644 index 0000000..8535551 --- /dev/null +++ b/src/scalevalapokalypsi/Model/Entities/NPCs/Tentacle.scala @@ -0,0 +1,59 @@ + + +package scalevalapokalypsi.Model.Entities.NPCs + +import scala.collection.mutable.Buffer +import scalevalapokalypsi.Model.* +import scalevalapokalypsi.Model.Entities.* +import scala.util.Random + +class Tentacle( + adventure: Adventure, + identifier: String, + initialLocation: Area, +) extends NPC(adventure, identifier, initialLocation, 10, 10): + + private val damage = 5 + private val dialogs = Vector( + "splish", + "splosh" + ) + + override def getDialog: String = + val dialogIndex = Random.between(0, this.dialogs.length) + this.dialogs(dialogIndex) + + override def act(): Unit = + val possibleVictims = this.location + .getEntities + .filter(_ != this) + .filter(_ match + case t: Tentacle => false + case m: Miikkulainen => false + case c: Cthulthu => false + case other => true + ) + .toVector + val index: Int = + if possibleVictims.isEmpty then 0 + else Random.between(0, possibleVictims.length) + if !possibleVictims.isEmpty then + this.location.observeEvent( + this.attack(possibleVictims(index)) + ) + + + private def attack(entity: Entity): Event = + entity.takeDamage(this.damage) + Event( + Map.from(Vector(( + entity, + s"${this.name} iskee sinua!\n" + + s"${entity.condition(0)}" + ))), + s"${this.name} iskee henkilöä ${entity.name}.\n" + + s"${entity.condition(1)}" + ) + +end Tentacle + -- cgit v1.2.3