aboutsummaryrefslogtreecommitdiff
path: root/src/scalevalapokalypsi/Model/Entities/NPCs/Tentacle.scala
blob: 8535551db04f7b26849ac6099ad06703bc61a8fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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