-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_state.röd
83 lines (80 loc) · 2.28 KB
/
day_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
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
80
81
82
83
{
/* Role Party */
roles["TOWN"] = "TOWN"
}
record DayState(session) : State(session) {
name : string = "DAY"
vote : list = []
message : list = []
n_victims : integer = 0
function newVictims broadcast_nobody {
new_victims := session.victims[self.n_victims:]
push `${v.name} is dead. Their role was ${v.role}.` for v in new_victims
push `Nobody was killed.` if [ #new_victims = 0 and broadcast_nobody ]
}
function checkWin {
for party in ["KILLER", "MAFIA", "TOWN"] do
if session.pushPlayers | [ p.party() = party or p.state = "DEAD" ] for p do
session.pushPlayers | for p do
p.state = "VICTORY" if [ p.party() = party ]
p.state = "DEFEAT" if [ p.party() != party ]
done
session.broadcasts += `The $party has won.`
session.state = "OUTRO"
return TRUE
done
done
return FALSE
}
function gmText {
return `It's day. ${[self.newVictims(FALSE)]&" "}`
}
function killTexts {
return "Lynch vote.", "Over 1/2 majority required."
}
function onIntro {
/* Kill players that were chosen during the night */
for p in session.kill_list do
unless [ p in session.heal_list ] do
p.state = "DEAD"
session.victims += p unless [ p in session.victims ]
done
done
del session.kill_list[:]
del session.heal_list[:]
session.broadcasts += `Everybody wakes up. ${[self.newVictims(TRUE)]&" "}`
self.message = []
session.actions += { self.n_victims = #session.victims }
unless self.checkWin do
session.pushPlayers | 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_live := #session.players - #session.victims
if [ #self.vote = n_live ] do
self.vote | unorderedCount | for p, i do
if [ i > n_live/2 ] do
p.state = "DEAD"
session.victims += p
self.message += `${p.name} was killed. Their role was ${p.role}.`
break
done
done
session.substate = "OUTRO"
self.vote = []
done
return TRUE
}
function onOutro {
session.broadcasts += self.message&" "
unless self.checkWin do
session.pushPlayers | p.state = "SLEEP" for p if [ p.state != "DEAD" ]
session.broadcasts += "Everybody sleeps."
session.substate = "END"
done
}
}