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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
*/
|