aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Entities/NPCs/Robber.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities/NPCs/Robber.scala')
-rw-r--r--src/scalevalapokalypsi/Model/Entities/NPCs/Robber.scala72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/scalevalapokalypsi/Model/Entities/NPCs/Robber.scala b/src/scalevalapokalypsi/Model/Entities/NPCs/Robber.scala
new file mode 100644
index 0000000..fc009a6
--- /dev/null
+++ b/src/scalevalapokalypsi/Model/Entities/NPCs/Robber.scala
@@ -0,0 +1,72 @@
+
+package scalevalapokalypsi.Model.Entities.NPCs
+
+import scala.collection.mutable.Buffer
+import scalevalapokalypsi.Model.*
+import scalevalapokalypsi.Model.Entities.*
+import scala.util.Random
+
+class Robber(
+ adventure: Adventure,
+ name: String,
+ val weaponName: String,
+ val weaponDamage: Int,
+ val hitChance: Float,
+ initialLocation: Area,
+ initialHP: Int = 20
+) extends NPC(adventure, name, initialLocation, initialHP, 20):
+
+ private val dialogs = Vector(
+ "Rahat tai henki!",
+ "Anna tänne!",
+ "Syödään se ryöstön jälkeen!",
+ "Vesihiisi sihisi hississä ja muumit laaksosta poissaolollaan."
+ )
+
+ 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: Robber => 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))
+ )
+ //else
+ // this.location.getNeighborNames.filter(this.location.neighbor(_).map(_.getEntities.size > 0).getOrElse(false))
+
+
+ private def attack(entity: Entity): Event =
+ if Random.nextFloat() < this.hitChance then
+ entity.takeDamage(this.weaponDamage)
+ Event(
+ Map.from(Vector((
+ entity,
+ s"${this.name} lyö sinua ${this.weaponName}\n" +
+ s"${entity.condition(0)}"
+ ))),
+ s"${this.name} lyö henkilöä ${entity.name} ${this.weaponName}.\n" +
+ s"${entity.condition(1)}"
+ )
+ else
+ Event(
+ Map.from(Vector((
+ entity,
+ s"${this.name} yrittää lyödä sinua mutta väistät."
+ ))),
+ s"${this.name} yrittää lyödä henkilöä ${entity.name}, mutta tämä väistää."
+ )
+
+end Robber
+