-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnight.rb
More file actions
53 lines (34 loc) · 1.18 KB
/
night.rb
File metadata and controls
53 lines (34 loc) · 1.18 KB
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
require_relative 'player.rb'
class Night < Phase
def start
send_all("@bThe night begins.@d")
@players.each do |player|
player.brief_night(@players) unless player.dead
end
EM.add_timer(@game.time) do
# Night is over. Call all of the end callbacks.
send_all("@YThe sun comes up.@d")
@end_callbacks.each(&:call)
# tell the game that the night is over
@game.night_over
end
@actions = ACTIONS.dup
core_callbacks
end
def core_callbacks # These are the ones that are essential to EVERY mafia game
# deaths of players killed by mafia at end of night:
at_end do
votes = {}
@players.each do |player| # tally up the votes
if player.is_a?(Mafia) && @player_status[player]
votes[@player_status[player][:mafia_kill_vote]] ||= 0
votes[@player_status[player][:mafia_kill_vote]] += 1
end
end
next if votes == {}
most_votes = votes.max_by { |(player, number)| number }.first
kill(most_votes, :mafia, 'During the night, %s died')
end
end
end
require_relative 'night_actions.rb'