diff options
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala')
-rw-r--r-- | src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala b/src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala new file mode 100644 index 0000000..56cb160 --- /dev/null +++ b/src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala @@ -0,0 +1,70 @@ + +package scalevalapokalypsi.Model.Entities.NPCs + +import scala.collection.mutable.Buffer +import scalevalapokalypsi.Model.* +import scalevalapokalypsi.Model.Entities.* +import scala.util.Random + +class Zombie( + adventure: Adventure, + identifier: String, + initialLocation: Area, + initialHP: Int = 20 +) extends NPC(adventure, identifier, initialLocation, initialHP, 20): + + private val damage = 10 + private val dialogs = Vector( + "örvlg", + "grr", + "äyyrrrgrlgb ww", + "aaak brzzzwff ååö", + "äkb glan abglum", + "öub gpa" + ) + + 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 z: Zombie => 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 = + if Random.nextBoolean() then + entity.takeDamage(this.damage) + Event( + Map.from(Vector(( + entity, + s"${this.name} puree sinua, hyi yäk!\n" + + s"${entity.condition(0)}" + ))), + s"${this.name} puree henkilöä ${entity.name}.\n" + + s"${entity.condition(1)}" + ) + else + Event( + Map.from(Vector(( + entity, + s"${this.name} yrittää purra sinua mutta kaatuu ohitsesi." + ))), + s"${this.name} yrittää purra henkilöä ${entity.name}, mutta epäonnistuu surkeasti." + ) + +end Zombie + |