-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmafia_state.röd
51 lines (50 loc) · 1.39 KB
/
mafia_state.röd
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
{
/* Role Party */
roles["MAFIA"] = "MAFIA"
}
record MafiaState(session) : State(session) {
name : string = "MAFIA KILLS"
vote : list = []
function pushMafia {
session.pushPlayers | { push p for p if [ p.role = "MAFIA" ] }
}
function gmText {
return `It's night. The mafia wakes up and kills.`
}
function killTexts {
return "Kill vote.", "Unanimous decision required."
}
function onIntro {
if self.pushMafia | [ _.state = "DEAD" ] do
session.broadcasts += "The mafia is dead."
session.substate = "END"
else
session.broadcasts += "The mafia wakes up."
self.pushMafia | p.state = "KILL" for p if [ p.state != "DEAD" ]
session.substate = "KILL"
done
}
function onKill player, target {
return FALSE if [ player.state != "KILL" ]
player.state = "WAIT"
self.vote += target
n_mafia := #[session.pushPlayers() | filter { |p|; [p.role = "MAFIA" and p.state != "DEAD"] }]
errprint "Mafia kills: "..self.vote..", n="..n_mafia
if [ #self.vote = n_mafia ] do
self.vote | unorderedCount | pull p, i
if [ i = n_mafia ] do
session.kill_list += p
session.substate = "OUTRO"
else
self.pushMafia | p.state = "KILL" for p if [ p.state != "DEAD" ]
done
self.vote = []
done
return TRUE
}
function onOutro {
self.pushMafia | p.state = "SLEEP" for p if [ p.state != "DEAD" ]
session.broadcasts += "The mafia sleeps."
session.substate = "END"
}
}