aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Entities
diff options
context:
space:
mode:
authorJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-27 17:19:46 +0200
committerJoel Kronqvist <joel.kronqvist@iki.fi>2024-11-27 17:19:46 +0200
commit302455bac062080bf197b44e07ed53a3454be4c5 (patch)
tree8b189ba41699c9a095d27bf00d1114a65aaa420a /src/scalevalapokalypsi/Model/Entities
parent98407b35ff477f372baa92bf582b90a961d4ad16 (diff)
downloadscalevalapokalypsi-302455bac062080bf197b44e07ed53a3454be4c5.tar.gz
scalevalapokalypsi-302455bac062080bf197b44e07ed53a3454be4c5.zip
Finishing almost the adventure
Diffstat (limited to 'src/scalevalapokalypsi/Model/Entities')
-rw-r--r--src/scalevalapokalypsi/Model/Entities/Entity.scala7
-rw-r--r--src/scalevalapokalypsi/Model/Entities/NPCs/Cthulthu.scala48
-rw-r--r--src/scalevalapokalypsi/Model/Entities/NPCs/Cultist.scala13
-rw-r--r--src/scalevalapokalypsi/Model/Entities/NPCs/Miikkulainen.scala33
-rw-r--r--src/scalevalapokalypsi/Model/Entities/NPCs/Tentacle.scala59
-rw-r--r--src/scalevalapokalypsi/Model/Entities/NPCs/Villager.scala79
-rw-r--r--src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala6
7 files changed, 242 insertions, 3 deletions
diff --git a/src/scalevalapokalypsi/Model/Entities/Entity.scala b/src/scalevalapokalypsi/Model/Entities/Entity.scala
index 6a2072d..c3be227 100644
--- a/src/scalevalapokalypsi/Model/Entities/Entity.scala
+++ b/src/scalevalapokalypsi/Model/Entities/Entity.scala
@@ -31,7 +31,10 @@ class Entity(
* @return the verse to sing against this entity
*/
def getVerseAgainst: Vector[String] =
- Vector("Esimerkkirivi laulettavaksi")
+ Vector(
+ "Suohon sinut juuri laulan",
+ "saat maistaa mudan sekä taulan"
+ )
def isAlive = this.hp > 0
@@ -127,7 +130,7 @@ class Entity(
this.items += i.name -> (1, i)
Event(
Vector((this, s"Poimit esineen ${i.name}")).toMap,
- s"$name poimi esineen ${i.name}"
+ s"$name poimi esineen ${i.name}."
)
case None =>
Event(
diff --git a/src/scalevalapokalypsi/Model/Entities/NPCs/Cthulthu.scala b/src/scalevalapokalypsi/Model/Entities/NPCs/Cthulthu.scala
new file mode 100644
index 0000000..a8384f2
--- /dev/null
+++ b/src/scalevalapokalypsi/Model/Entities/NPCs/Cthulthu.scala
@@ -0,0 +1,48 @@
+
+
+package scalevalapokalypsi.Model.Entities.NPCs
+
+import scala.collection.mutable.Buffer
+import scalevalapokalypsi.Model.*
+import scalevalapokalypsi.Model.Entities.*
+import scala.util.Random
+
+class Cthulthu(
+ adventure: Adventure,
+ initialLocation: Area,
+ initialHP: Int = 100
+) extends NPC(adventure, "Leijuva lonkero-otus", initialLocation, initialHP, 100):
+
+ private var tentacleIndex = 0
+ private var hp = this.maxHP
+ override def isAlive = this.hp > 0
+
+ def heal(): Boolean =
+ if this.hp < this.maxHP then
+ this.hp = this.maxHP
+ true
+ else
+ false
+
+ override def getDialog: String =
+ "sxaCHReeaaaAAARRR!!"
+
+ override def act(): Unit =
+ val playersExist = this.location
+ .getEntities
+ .exists(_ match
+ case p: Player => true
+ case other => false
+ )
+ if playersExist then
+ this.location.addEntity(Tentacle(
+ adventure,
+ s"Lonkero #$tentacleIndex",
+ this.location
+ ))
+ this.location.observeEvent(
+ Event(Map.empty, s"${this.name} ärjyy. Maasta ilmestyy uusi lonkero.")
+ )
+
+end Cthulthu
+
diff --git a/src/scalevalapokalypsi/Model/Entities/NPCs/Cultist.scala b/src/scalevalapokalypsi/Model/Entities/NPCs/Cultist.scala
index fa5602e..c5c8789 100644
--- a/src/scalevalapokalypsi/Model/Entities/NPCs/Cultist.scala
+++ b/src/scalevalapokalypsi/Model/Entities/NPCs/Cultist.scala
@@ -11,7 +11,7 @@ class Cultist(
identifier: String,
initialLocation: Area,
initialHP: Int = 100,
- maxHP: Int = 100
+ maxHP: Int = 50
) extends NPC(adventure, identifier, initialLocation, initialHP, maxHP):
private val damage = 20
@@ -25,6 +25,7 @@ class Cultist(
.filter(_ != this)
.filter(_ match
case c: Cultist => false
+ case z: Zombie => false
case other => true
)
.toVector
@@ -35,6 +36,16 @@ class Cultist(
this.location.observeEvent(
this.curse(possibleVictims(index))
)
+ else
+ val possibleDirections = this.location.getNeighborNames
+ if possibleDirections.size != 0 then
+ val directionIndex = Random.between(
+ 0,
+ possibleDirections.size
+ )
+ this.go(possibleDirections.toVector(directionIndex)).foreach(
+ this.location.observeEvent(_)
+ )
private def curse(entity: Entity): Event =
diff --git a/src/scalevalapokalypsi/Model/Entities/NPCs/Miikkulainen.scala b/src/scalevalapokalypsi/Model/Entities/NPCs/Miikkulainen.scala
new file mode 100644
index 0000000..afaf702
--- /dev/null
+++ b/src/scalevalapokalypsi/Model/Entities/NPCs/Miikkulainen.scala
@@ -0,0 +1,33 @@
+
+
+
+package scalevalapokalypsi.Model.Entities.NPCs
+
+import scala.collection.mutable.Buffer
+import scalevalapokalypsi.Model.*
+import scalevalapokalypsi.Model.Entities.*
+import scala.util.Random
+
+class Miikkulainen(
+ adventure: Adventure,
+ initialLocation: Area,
+ initialHP: Int = 50
+) extends NPC(adventure, "Kultisti Miikkulainen", initialLocation, initialHP, 50):
+
+ override def getDialog: String =
+ "Koskaan ei tuhota Miikkulaisen päitä"
+
+ override def act(): Unit =
+ val cthulthu = this.location
+ .getEntities
+ .foreach(_ match
+ case c: Cthulthu =>
+ if c.heal() then
+ this.location.observeEvent(
+ Event(Map.empty, s"${this.name} vuodattaa verta ranteestaan. ${c.name} näyttää virkistyvän.")
+ )
+ case other => ()
+ )
+
+end Miikkulainen
+
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
+
diff --git a/src/scalevalapokalypsi/Model/Entities/NPCs/Villager.scala b/src/scalevalapokalypsi/Model/Entities/NPCs/Villager.scala
new file mode 100644
index 0000000..1b9629f
--- /dev/null
+++ b/src/scalevalapokalypsi/Model/Entities/NPCs/Villager.scala
@@ -0,0 +1,79 @@
+
+package scalevalapokalypsi.Model.Entities.NPCs
+
+import scalevalapokalypsi.Model.{Area,Event,Item,Adventure}
+
+class Villager(
+ adventure: Adventure,
+ name: String,
+ initialLocation: Area,
+ dialogs: Vector[(String, Option[Villager => Event])]
+) extends NPC(adventure, name, initialLocation, 100, 100):
+
+ private var dialogIndex = 0
+
+ def getDialog: String =
+ val (dialog, effect) = this.dialogs(dialogIndex)
+ effect.map(_(this)).map(this.location.observeEvent(_))
+ this.dialogIndex +=
+ (if dialogIndex < this.dialogs.length-1
+ then 1
+ else 0)
+ dialog
+
+ def act(): Unit = ()
+
+end Villager
+
+/*
+package scalevalapokalypsi.Model.Entities.NPCs
+
+import scalevalapokalypsi.Model.{Area,Event,Item,Adventure}
+import scala.math.min
+
+class Bartender(
+ adventure: Adventure,
+ initialLocation: Area
+) extends NPC(
+ adventure,
+ "baarimikko",
+ initialLocation,
+ 100,
+ 100
+):
+
+
+ private var dialogIndex = 0
+
+ private val dialogs = Vector(
+ "Onnea matkaan. Tarjoan sinulle tuopin olutta rohkaisuksi.",
+ "Onnea matkaan."
+ )
+
+ def getDialog: String =
+
+ if dialogIndex == 0 then
+ this.location.addItem(Item(
+ "oluttuoppi",
+ "Tuopillinen kuohuvaa ja raikasta olutta. Se tuoksuu aika vahvalta.",
+ 1
+ ))
+ this.location.observeEvent(
+ Event(
+ Map.empty,
+ "Baarimikko kaataa tuoppiin olutta ja asettaa oluttuopin pöydälle."
+ )
+ )
+
+ dialogIndex = min(dialogIndex + 1, this.dialogs.length)
+
+ dialogs(dialogIndex - 1)
+
+ end getDialog
+
+
+ def act(): Unit = ()
+
+
+end Bartender
+*/
diff --git a/src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala b/src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala
index 56cb160..0c9ee84 100644
--- a/src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala
+++ b/src/scalevalapokalypsi/Model/Entities/NPCs/Zombie.scala
@@ -23,6 +23,12 @@ class Zombie(
"öub gpa"
)
+ override def getVerseAgainst =
+ Vector(
+ "Suohon sula kuvajainen",
+ "maahan maadu paisenaama"
+ )
+
override def getDialog: String =
val dialogIndex = Random.between(0, this.dialogs.length)
this.dialogs(dialogIndex)