blib/lib/Mafia.pm

filter: Statementstmt 65.1% 170 / 261 Branchbran 48.5% 33 / 68 Conditioncond 41.7% 28 / 67 MC/DCmcdc 11.4% 4 / 35 Subroutinesub 59.6% 34 / 57 Podpod 65.3% 17 / 26 totaltotal 55.6% 286 / 514 CC 65 SCAR 24.1
CC
65
Cov
58%
doaction
53.2
__ANON__
17.2
__ANON__
12.0
CRAP 11.1
↑ Summary
1 package Mafia;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use parent qw/Exporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Storable qw/dclone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '0.001003';
12  
13 5 ▶sub defconst { constant->import($_ => $_) for @_ }
Subroutine defconst: called CC=2 SCAR=6.9
Pod undocumented
14  
15 BEGIN {
16 # Roles
17 1 ▶ defconst qw/vanilla goon doctor vigilante roleblocker jailkeeper gunsmith tracker watcher bodyguard rolecop cop sk hider/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # Factions
20 1 defconst qw/mafia town/;
21  
22 # Extra traits
23 1 defconst qw/miller godfather weak macho bulletproof/;
24  
25 # Messages
26 1 defconst qw/MSG_NIGHT MSG_DAY MSG_PLAYERS_ALIVE MSG_DEATH MSG_GUNCHECK MSG_NORESULT MSG_TRACK MSG_WATCH MSG_COP MSG_ROLECOP/;
27  
28 # Action types
29 1 defconst qw/ACT_KILL ACT_LYNCH ACT_PROTECT ACT_GUARD ACT_ROLEBLOCK ACT_GUNCHECK ACT_TRACK ACT_WATCH ACT_ROLECOP ACT_COP ACT_TRACK_RESULT ACT_WATCH_RESULT ACT_HIDE/;
30 }
31  
32 use constant +{ ## no critic (Capitalization)
33 1 townie => town,
34 ROLE => [vanilla, goon, doctor, vigilante, roleblocker, jailkeeper, gunsmith, tracker, watcher, bodyguard, rolecop, cop, sk, hider],
35 FACTION => [mafia, town],
36 FLAG => [miller, godfather, weak, macho, bulletproof],
37 ACTION_ORDER => [ACT_HIDE, ACT_ROLEBLOCK, ACT_PROTECT, ACT_GUARD, ACT_GUNCHECK, ACT_ROLECOP, ACT_COP, ACT_TRACK, ACT_WATCH, ACT_KILL, ACT_LYNCH, ACT_TRACK_RESULT, ACT_WATCH_RESULT],
38 INVESTIGATIVE_ACTIONS => [ACT_GUNCHECK, ACT_TRACK, ACT_WATCH, ACT_ROLECOP, ACT_COP],
39 GUNROLES => [vigilante, gunsmith],
40 1 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 my %ROLE_HASH = map { $_ => 1 } @{ROLE()};
43 1 my %FACTION_HASH = map { $_ => 1 } @{FACTION()};
44 1 my %FLAG_HASH = map { $_ => 1 } @{FLAG()};
45 1 my %INVESTIGATIVE_ACTIONS_HASH = map { $_ => 1 } @{INVESTIGATIVE_ACTIONS()};
46 1 my %GUNROLES_HASH = map { $_ => 1 } @{GUNROLES()};
47  
48 1 our @EXPORT = do {
49 1 ▶ no strict 'refs'; ## no critic (ProhibitNoStrict)
Subroutine BEGIN: called CC=1 SCAR=0.0
50 1 ▶ grep { $_ !~ [qw/import/] and exists &$_ } keys %{__PACKAGE__ . '::'};
Branch: 1 branch
BranchTrueFalseTotal
not $_ =~ ["import"] and exists &$_ 84 0 84
51 };
52  
53 ################################################## Helper subs
54  
55 sub import {
56 6 ▶ strict->import;
Subroutine import: called CC=1 SCAR=0.0
57 6 goto &Exporter::import;
58 }
59  
60 1 my (%players, %tplayers, @actions);
61 1 my $daycnt = 0;
62 1 my $nightcnt = 0;
63 1 my $isday = 0;
64 1 my $first = 1;
65  
66 sub clean{
67 5 ▶ %players = ();
Subroutine clean: called CC=1 SCAR=0.0
Pod undocumented
68 5 %tplayers = ();
69 5 @actions = ();
70 5 $daycnt = 0;
71 5 $nightcnt = 0;
72 5 $isday = 0;
73 5 $first = 1;
74 }
75  
76 sub uniq {
77 0 ▶ my %hash = map { $_ => 1 } @_;
Subroutine uniq: not called CC=1 SCAR=6.9
Pod undocumented
78 0 keys %hash
79 }
80  
81 sub phase {
82 17 ▶ return "Day $daycnt" if $isday;
Subroutine phase: called CC=3 SCAR=11.1
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
if $isday 11 6 17
83 6 ▶ return "Night $nightcnt" unless $isday;
Branch: 1 branch
BranchTrueFalseTotal
unless $isday 6 0 6
84 }
85  
86 sub rolename { ## no critic (RequireArgUnpacking)
87 17 ▶ my %player = %{$players{$_[0]}};
Subroutine rolename: called CC=9 SCAR=22.2
Pod undocumented
88 17 my ($faction, $role) = ($player{faction}, $player{role});
89 17 ▶ if (defined $faction && $faction eq town && $role eq vanilla) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $faction and $faction eq "town" and $role eq "vanilla") 8 9 17
Condition83%5/6
defined $faction and $faction eq "town" and $role eq "vanilla"
!ll&&!rl&&r
368
defined $faction and $faction eq "town"
!ll&&!rl&&r
0314
MC/DC66%2/3
defined $faction and $faction eq "town" and $role eq "vanilla"
defined $faction $faction eq "town" $role eq "vanilla"
Truth table75%3/4
A and B and C
A= defined $factionB= $faction eq "town"C= $role eq "vanilla"
ABCresult
0XX0
10X0
1100
1111
90 8 undef $faction;
91 8 $role = 'Vanilla Townie';
92 }
93 17 my @tokens = ();
94 17 ▶ push @tokens, ucfirst $faction if $faction;
Branch: 1 branch
BranchTrueFalseTotal
if $faction 9 8 17
95 17 for my $flag (@{FLAG()}) {
96 85 ▶ push @tokens, ucfirst $flag if $player{$flag}
Branch: 1 branch
BranchTrueFalseTotal
if $player{$flag} 0 85 85
97 }
98 17 ▶ push @tokens, ucfirst $role unless $role eq goon && $player{godfather};
Branch: 1 branch
BranchTrueFalseTotal
unless $role eq "goon" and $player{"godfather"} 17 0 17
Condition66%2/3
$role eq "goon" and $player{"godfather"}
!ll&&!rl&&r
1430
MC/DC0%0/2
$role eq "goon" and $player{"godfather"}
$role eq "goon" $player{"godfather"}
Truth table66%2/3
A and B
A= $role eq "goon"B= $player{"godfather"}
ABresult
0X0
100
111
99 17 "@tokens"
100 }
101  
102 sub msg {
103 67 ▶ my ($type, @args) = @_;
Subroutine msg: called CC=1 SCAR=1.9
Pod undocumented
104 my %msg_lut = (
105 MSG_NIGHT => sub {
106 11 ▶ my ($night) = @args;
Subroutine __ANON__: called CC=2 SCAR=7.0
107 11 ▶ say '' unless $first;
Branch: 1 branch
BranchTrueFalseTotal
unless $first 11 0 11
108 11 $first = 0;
109 11 say "It is Night $night";
110 },
111  
112 MSG_DAY => sub {
113 11 ▶ my ($day) = @args;
Subroutine __ANON__: called CC=2 SCAR=6.9
114 11 ▶ say '' unless $first;
Branch: 1 branch
BranchTrueFalseTotal
unless $first 6 5 11
115 11 $first = 0;
116 11 say "It is Day $day";
117 },
118  
119 MSG_PLAYERS_ALIVE => sub {
120 22 ▶ @args = sort @args;
Subroutine __ANON__: called CC=1 SCAR=0.0
121 22 say 'Players alive: ', join ', ', @args
122 },
123  
124 MSG_DEATH => sub {
125 17 ▶ my %args = @args;
Subroutine __ANON__: called CC=1 SCAR=0.0
126 17 my ($who, $reason) = @args{'target', 'reason'};
127 17 my $phase = phase;
128 17 my $rolename = rolename $who;
129 17 say "$who ($rolename) — $reason $phase";
130 },
131  
132 MSG_GUNCHECK => sub {
133 0 ▶ my %args = @args;
Subroutine __ANON__: not called CC=3 SCAR=24.8
134 0 my ($gunsmith, $who, $hasgun) = @args{'source', 'target', 'result'};
135 0 ▶ say "$gunsmith: $who has a gun" if $hasgun;
Branch: 1 branch
BranchTrueFalseTotal
if $hasgun 0 0 0
136 0 ▶ say "$gunsmith: $who does not have a gun" unless $hasgun;
Branch: 1 branch
BranchTrueFalseTotal
unless $hasgun 0 0 0
137 },
138  
139 MSG_NORESULT => sub {
140 0 ▶ my %args = @args;
Subroutine __ANON__: not called CC=1 SCAR=6.9
141 0 my ($who) = $args{'source'};
142 0 say "$who: No result"
143 },
144  
145 MSG_TRACK => sub {
146 0 ▶ my %args = @args;
Subroutine __ANON__: not called CC=3 SCAR=24.8
147 0 my ($tracker, $who, $result) = @args{'source', 'target', 'result'};
148 0 my @result = @{$result};
149 0 local $, = ', ';
150 0 ▶ say "$tracker: $who did not visit anyone" unless scalar @result;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @result 0 0 0
151 0 ▶ say "$tracker: $who visited: @result" if scalar @result;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @result 0 0 0
152 },
153  
154 MSG_WATCH => sub {
155 0 ▶ my %args = @args;
Subroutine __ANON__: not called CC=3 SCAR=24.8
156 0 my ($watcher, $who, $result) = @args{'source', 'target', 'result'};
157 0 my @result = @{$result};
158 0 local $, = ', ';
159 0 ▶ say "$watcher: $who was not visited by anyone" unless scalar @result;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @result 0 0 0
160 0 ▶ say "$watcher: $who was visited by: @result" if scalar @result;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @result 0 0 0
161 },
162  
163 MSG_ROLECOP => sub {
164 0 ▶ my %args = @args;
Subroutine __ANON__: not called CC=1 SCAR=6.9
165 0 my ($rolecop, $who, $role) = @args{'source', 'target', 'result'};
166 0 say "$rolecop: $who\'s role is: $role"
167 },
168  
169 MSG_COP => sub {
170 6 ▶ my %args = @args;
Subroutine __ANON__: called CC=3 SCAR=11.4
171 6 my ($cop, $who, $ismafia) = @args{'source', 'target', 'result'};
172 6 ▶ say "$cop: $who is mafia" if $ismafia;
Branch: 1 branch
BranchTrueFalseTotal
if $ismafia 0 6 6
173 6 ▶ say "$cop: $who is not mafia" unless $ismafia;
Branch: 1 branch
BranchTrueFalseTotal
unless $ismafia 6 0 6
174 },
175 67 );
176  
177 67 $msg_lut{$type}->();
178 }
179  
180 sub putaction {
181 24 ▶ my ($delay, $type, %args) = @_;
Subroutine putaction: called CC=6 SCAR=20.5
Pod undocumented
182 24 ▶ $actions[$delay]->{$type} //= [];
Condition50%1/2
$actions[$delay]{$type} //= []
l!l
024
MC/DC0%0/1
$actions[$delay]{$type} //= []
$actions[$delay]{$type}
Truth table50%1/2
A
A= $actions[$delay]{$type}
Aresult
11
00
183 24 ▶ if (exists $args{target} && exists $args{source} && $players{$args{target}}{faction} eq mafia && $players{$args{source}}{weak}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"target"} and exists $args{"source"} and $players{$args{"target"}}{"faction"} eq "mafia" and $players{$args{"source"}}{"weak"}) 0 24 24
Condition55%5/9
exists $args{"target"} and exists $args{"source"} and $players{$args{"target"}}{"faction"} eq "mafia" and $players{$args{"source"}}{"weak"}
!ll&&!rl&&r
2400
exists $args{"target"} and exists $args{"source"} and $players{$args{"target"}}{"faction"} eq "mafia"
!ll&&!rl&&r
11130
exists $args{"target"} and exists $args{"source"}
!ll&&!rl&&r
01113
MC/DC0%0/4
exists $args{"target"} and exists $args{"source"} and $players{$args{"target"}}{"faction"} eq "mafia" and $players{$args{"source"}}{"weak"}
exists $args{"target"} exists $args{"source"} $players{$args{"target"}}{"faction"} eq "mafia" $players{$args{"source"}}{"weak"}
Truth table40%2/5
A and B and C and D
A= exists $args{"target"}B= exists $args{"source"}C= $players{$args{"target"}}{"faction"} eq "mafia"D= $players{$args{"source"}}{"weak"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
184 0 putaction($delay, ACT_KILL, target => $args{source}, reason => 'targeted scum');
185 }
186 24 push @{$actions[$delay]->{$type}}, \%args
187 }
188  
189 sub doaction { ## no critic (ProhibitExcessComplexity)
190 24 ▶ my ($type, $args) = @_;
Subroutine doaction: called CC=14 SCAR=39.7
Pod undocumented
191 24 my %args = %$args;
192 24 my $source = $args{source};
193 24 my $target = $args{target};
194 24 ▶ if (defined $source && defined $target) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source and defined $target) 13 11 24
Condition66%2/3
defined $source and defined $target
!ll&&!rl&&r
11013
MC/DC50%1/2
defined $source and defined $target
defined $source defined $target
Truth table66%2/3
A and B
A= defined $sourceB= defined $target
ABresult
0X0
100
111
195 # Watcher and tracker variables
196 13 ▶ $tplayers{$source}{targets} //= [];
Condition50%1/2
$tplayers{$source}{"targets"} //= []
l!l
013
MC/DC0%0/1
$tplayers{$source}{"targets"} //= []
$tplayers{$source}{"targets"}
Truth table50%1/2
A
A= $tplayers{$source}{"targets"}
Aresult
11
00
197 13 push @{$tplayers{$source}{targets}}, $target;
198 13 ▶ $tplayers{$target}{sources} //= [];
Condition100%2/2
$tplayers{$target}{"sources"} //= []
l!l
211
MC/DC100%1/1
$tplayers{$target}{"sources"} //= []
$tplayers{$target}{"sources"}
Truth table100%2/2
A
A= $tplayers{$target}{"sources"}
Aresult
11
00
199 13 push @{$tplayers{$target}{sources}}, $source;
200  
201 # Copy this action to everybody hiding behind $target
202 13 ▶ if (exists $tplayers{$target}{hiders}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $tplayers{$target}{"hiders"}) 0 13 13
203 0 for my $target (@{$tplayers{$target}{hiders}}) {
204 0 my %new_args = %args;
205 0 $new_args{target} = $target;
206 0 $new_args{hidepierce} = 1;
207 0 doaction($type, \%new_args);
208 }
209 }
210  
211 # Check if the action should be blocked
212 13 ▶ my $strongkill = $type eq ACT_KILL && $args{strong};
Condition66%2/3
$type eq 'ACT_KILL' && $args{'strong'}
!ll&&!rl&&r
760
MC/DC0%0/2
$type eq 'ACT_KILL' && $args{'strong'}
$type eq 'ACT_KILL' $args{'strong'}
Truth table66%2/3
A && B
A= $type eq 'ACT_KILL'B= $args{'strong'}
ABresult
0X0
100
111
213 13 my $roleblocked = $tplayers{$source}{roleblocked};
214 13 my $hidden = $tplayers{$target}{hidden};
215 13 my $hidepierce = $args{hidepierce};
216 13 ▶ if ($source && (( $roleblocked && !$strongkill ) || ($hidden && !$hidepierce) )) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source and $roleblocked && !$strongkill || $hidden && !$hidepierce) 0 13 13
Condition33%4/12
$source and $roleblocked && !$strongkill || $hidden && !$hidepierce
!ll&&!rl&&r
0130
$roleblocked and not $strongkill or $hidden and not $hidepierce
l!l&&r!l&&!r
0013
$roleblocked and not $strongkill
!ll&&!rl&&r
1300
$hidden and not $hidepierce
!ll&&!rl&&r
1300
MC/DC0%0/5
$source and $roleblocked && !$strongkill || $hidden && !$hidepierce
$source $roleblocked not $strongkill $hidden not $hidepierce
Truth table0%0/8
A and B and not(C) or D and not(E)
A= $sourceB= $roleblockedC= not $strongkillD= $hiddenE= not $hidepierce
ABCDEresult
0XXXX0
10X0X0
10X100
1100X0
110100
111XX1
10X111
110111
217 0 ▶ msg MSG_NORESULT, %args if $INVESTIGATIVE_ACTIONS_HASH{$type};
Branch: 1 branch
BranchTrueFalseTotal
if $INVESTIGATIVE_ACTIONS_HASH{$type} 0 0 0
218 return
219 0 }
220 }
221  
222 my %act_lut = (
223 ACT_KILL => sub {
224 6 ▶ break if $tplayers{$target}{bulletproof} && defined $source;
Subroutine __ANON__: called CC=7 SCAR=28.4
Branch: 1 branch
BranchTrueFalseTotal
if $tplayers{$target}{"bulletproof"} and defined $source 0 6 6
Condition33%1/3
$tplayers{$target}{"bulletproof"} and defined $source
!ll&&!rl&&r
600
MC/DC0%0/2
$tplayers{$target}{"bulletproof"} and defined $source
$tplayers{$target}{"bulletproof"} defined $source
Truth table33%1/3
A and B
A= $tplayers{$target}{"bulletproof"}B= defined $source
ABresult
0X0
100
111
225 6 ▶ if ($tplayers{$target}{guard_count} && defined $source) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tplayers{$target}{"guard_count"} and defined $source) 0 6 6
Condition33%1/3
$tplayers{$target}{"guard_count"} and defined $source
!ll&&!rl&&r
600
MC/DC0%0/2
$tplayers{$target}{"guard_count"} and defined $source
$tplayers{$target}{"guard_count"} defined $source
Truth table33%1/3
A and B
A= $tplayers{$target}{"guard_count"}B= defined $source
ABresult
0X0
100
111
226 0 $tplayers{$target}{guard_count}--;
227 # Copy this action to the first guard
228 0 $args{target} = shift @{$tplayers{$target}{guards}};
229 0 @_ = ($type, %args);
230 0 goto &doaction;
231 }
232 6 ▶ if ($tplayers{$target}{protection} && !$args{strong}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tplayers{$target}{"protection"} and not $args{"strong"}) 0 6 6
Condition33%1/3
$tplayers{$target}{"protection"} and not $args{"strong"}
!ll&&!rl&&r
600
MC/DC0%0/2
$tplayers{$target}{"protection"} and not $args{"strong"}
$tplayers{$target}{"protection"} not $args{"strong"}
Truth table33%1/3
A and not(B)
A= $tplayers{$target}{"protection"}B= not $args{"strong"}
ABresult
0X0
100
111
233 0 $tplayers{$target}{protection}--;
234 break
235 0 }
236 6 msg MSG_DEATH, %args;
237 6 delete $players{$target}
238 },
239  
240 ACT_LYNCH => sub {
241 11 ▶ if ($tplayers{$target}{guard_count}) {
Subroutine __ANON__: called CC=3 SCAR=15.4
Branch: 1 branch
BranchTrueFalseTotal
if ($tplayers{$target}{"guard_count"}) 0 11 11
242 0 $tplayers{$target}{guard_count}--;
243 0 $args{target} = shift @{$tplayers{$target}{guards}};
244 0 $target=$args{target};
245 }
246 11 ▶ if ($tplayers{$target}{protection}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tplayers{$target}{"protection"}) 0 11 11
247 0 $tplayers{$target}{protection}--;
248 break
249 0 }
250 11 msg MSG_DEATH, %args, reason => 'lynched';
251 11 delete $players{$target}
252 },
253  
254 ACT_PROTECT => sub {
255 1 ▶ my $count = $args{count} // 1;
Subroutine __ANON__: called CC=3 SCAR=12.0
Condition50%1/2
$args{"count"} // 1
l!l
01
MC/DC0%0/1
$args{"count"} // 1
$args{"count"}
Truth table50%1/2
A
A= $args{"count"}
Aresult
11
00
256 $tplayers{$target}{protection} += $count unless $tplayers{$target}{macho}
257 1 ▶ },
Branch: 1 branch
BranchTrueFalseTotal
unless $tplayers{$target}{"macho"} 1 0 1
258  
259 ACT_ROLEBLOCK => sub {
260 0 ▶ $tplayers{$target}{roleblocked} = 1
Subroutine __ANON__: not called CC=1 SCAR=6.9
261 },
262  
263 ACT_GUNCHECK => sub {
264 0 ▶ my $role = $players{$target}{role};
Subroutine __ANON__: not called CC=3 SCAR=24.8
265 0 ▶ my $hasgun = $GUNROLES_HASH{$role} || ($players{$target}{faction} eq mafia && $role ne doctor);
Condition0%0/6
$GUNROLES_HASH{$role} || $players{$target}{'faction'} eq 'mafia' && $role ne 'doctor'
l!l&&r!l&&!r
000
$players{$target}{"faction"} eq "mafia" and $role ne "doctor"
!ll&&!rl&&r
000
MC/DC0%0/3
$GUNROLES_HASH{$role} || $players{$target}{'faction'} eq 'mafia' && $role ne 'doctor'
$GUNROLES_HASH{$role} $players{$target}{"faction"} eq "mafia" $role ne "doctor"
Truth table0%0/4
A || B and C
A= $GUNROLES_HASH{$role}B= $players{$target}{"faction"} eq "mafia"C= $role ne "doctor"
ABCresult
1XX1
0111
00X0
0100
266 0 msg MSG_GUNCHECK, %args, result => $hasgun
267 },
268  
269 ACT_TRACK_RESULT => sub {
270 0 ▶ msg MSG_TRACK, %args, result => [ uniq @{$tplayers{$target}{targets} // []} ];
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$tplayers{$target}{"targets"} // []
l!l
00
MC/DC0%0/1
$tplayers{$target}{"targets"} // []
$tplayers{$target}{"targets"}
Truth table0%0/2
A
A= $tplayers{$target}{"targets"}
Aresult
11
00
271 },
272  
273 ACT_WATCH_RESULT => sub {
274 0 ▶ msg MSG_WATCH, %args, result => [ uniq @{$tplayers{$target}{sources} // []} ];
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$tplayers{$target}{"sources"} // []
l!l
00
MC/DC0%0/1
$tplayers{$target}{"sources"} // []
$tplayers{$target}{"sources"}
Truth table0%0/2
A
A= $tplayers{$target}{"sources"}
Aresult
11
00
275 },
276  
277 ACT_GUARD => sub {
278 0 ▶ $tplayers{$target}{guard_count}++;
Subroutine __ANON__: not called CC=2 SCAR=17.9
279 0 ▶ $tplayers{$target}{guards} //= [];
Condition0%0/2
$tplayers{$target}{"guards"} //= []
l!l
00
MC/DC0%0/1
$tplayers{$target}{"guards"} //= []
$tplayers{$target}{"guards"}
Truth table0%0/2
A
A= $tplayers{$target}{"guards"}
Aresult
11
00
280 0 push @{$tplayers{$target}{guards}}, $source;
281 },
282  
283 ACT_ROLECOP => sub {
284 0 ▶ my $result = $players{$target}{role};
Subroutine __ANON__: not called CC=2 SCAR=17.9
285 0 ▶ $result = vanilla if $result eq goon;
Branch: 1 branch
BranchTrueFalseTotal
if $result eq "goon" 0 0 0
286 0 msg MSG_ROLECOP, %args, result => ucfirst $result
287 },
288  
289 ACT_COP => sub {
290 6 ▶ my $result = $players{$target}{faction} eq mafia;
Subroutine __ANON__: called CC=3 SCAR=11.4
291 6 ▶ $result = 1 if $players{$target}{miller};
Branch: 1 branch
BranchTrueFalseTotal
if $players{$target}{"miller"} 0 6 6
292 6 ▶ $result = 0 if $players{$target}{godfather};
Branch: 1 branch
BranchTrueFalseTotal
if $players{$target}{"godfather"} 0 6 6
293 6 msg MSG_COP, %args, result => $result
294 },
295  
296 ACT_HIDE => sub {
297 0 ▶ $tplayers{$source}{hidden} = 1;
Subroutine __ANON__: not called CC=2 SCAR=17.9
298 0 ▶ $tplayers{$target}{hiders} //= [];
Condition0%0/2
$tplayers{$target}{"hiders"} //= []
l!l
00
MC/DC0%0/1
$tplayers{$target}{"hiders"} //= []
$tplayers{$target}{"hiders"}
Truth table0%0/2
A
A= $tplayers{$target}{"hiders"}
Aresult
11
00
299 0 push @{$tplayers{$target}{hiders}}, $source
300 },
301 24 );
302  
303 24 $act_lut{$type}->();
304 }
305  
306 sub process_phase_change {
307 22 ▶ %tplayers = %{dclone \%players};
Subroutine process_phase_change: called CC=3 SCAR=11.0
Pod undocumented
308 22 my $actions = shift @actions;
309 22 for my $type (@{ACTION_ORDER()}) {
310 286 doaction $type, $_ for @{$actions->{$type}}
311 }
312 }
313  
314 ################################################## User subs
315  
316 sub player {
317 35 ▶ my ($name, @args) = @_;
Subroutine player: called CC=5 SCAR=16.1
Pod documented
318 35 my %player;
319 35 for my $trait (@args) {
320 70 ▶ $player{role} = $trait if $ROLE_HASH{$trait};
Branch: 1 branch
BranchTrueFalseTotal
if $ROLE_HASH{$trait} 35 35 70
321 70 ▶ $player{faction} = $trait if $FACTION_HASH{$trait};
Branch: 1 branch
BranchTrueFalseTotal
if $FACTION_HASH{$trait} 35 35 70
322 70 ▶ $player{$trait} = 1 if $FLAG_HASH{$trait};
Branch: 1 branch
BranchTrueFalseTotal
if $FLAG_HASH{$trait} 0 70 70
323 }
324  
325 35 $players{$name} = \%player;
326 }
327  
328 sub day {
329 11 ▶ process_phase_change;
Subroutine day: called CC=1 SCAR=0.0
Pod documented
330 11 $isday = 1;
331 11 msg MSG_DAY, ++$daycnt;
332 11 msg MSG_PLAYERS_ALIVE, keys %players;
333 }
334  
335 sub night {
336 11 ▶ process_phase_change;
Subroutine night: called CC=1 SCAR=0.0
Pod documented
337 11 $isday = 0;
338 11 msg MSG_NIGHT, ++$nightcnt;
339 11 msg MSG_PLAYERS_ALIVE, keys %players;
340 }
341  
342 sub lynch {
343 11 ▶ my ($who) = @_;
Subroutine lynch: called CC=1 SCAR=0.0
Pod documented
344 11 putaction 0, ACT_LYNCH, target => $who;
345 }
346  
347 sub factionkill {
348 6 ▶ my ($killer, $who, $reason, @args) = @_;
Subroutine factionkill: called CC=1 SCAR=0.0
Pod documented
349 6 putaction 0, ACT_KILL, target => $who, source => $killer, reason => $reason, @args;
350 }
351  
352 sub protect {
353 1 ▶ my ($doctor, $who) = @_;
Subroutine protect: called CC=1 SCAR=0.0
Pod documented
354 1 putaction 0, ACT_PROTECT, target => $who, source => $doctor;
355 }
356  
357 sub vig {
358 0 ▶ my ($vig, $who, $reason, @args) = @_;
Subroutine vig: not called CC=1 SCAR=6.9
Pod documented
359 0 putaction 0, ACT_KILL, target => $who, source => $vig, reason => $reason, @args;
360 }
361  
362 sub roleblock {
363 0 ▶ my ($roleblocker, $who) = @_;
Subroutine roleblock: not called CC=1 SCAR=6.9
Pod documented
364 0 putaction 0, ACT_ROLEBLOCK, target => $who, source => $roleblocker;
365 }
366  
367 sub jailkeep {
368 0 ▶ my ($jailkeeper, $who) = @_;
Subroutine jailkeep: not called CC=1 SCAR=6.9
Pod documented
369 0 putaction 0, ACT_ROLEBLOCK, target => $who, source => $jailkeeper;
370 0 putaction 0, ACT_PROTECT, target => $who, source => $jailkeeper, count => 1000;
371 }
372  
373 sub guncheck {
374 0 ▶ my ($gunsmith, $who) = @_;
Subroutine guncheck: not called CC=1 SCAR=6.9
Pod documented
375 0 putaction 0, ACT_GUNCHECK, target => $who, source => $gunsmith;
376 }
377  
378 sub track {
379 0 ▶ my ($tracker, $who) = @_;
Subroutine track: not called CC=1 SCAR=6.9
Pod documented
380 0 putaction 0, ACT_TRACK, target => $who, source => $tracker;
381 0 putaction 0, ACT_TRACK_RESULT, target => $who, source => $tracker;
382 }
383  
384 sub watch {
385 0 ▶ my ($watcher, $who) = @_;
Subroutine watch: not called CC=1 SCAR=6.9
Pod documented
386 0 putaction 0, ACT_WATCH, target => $who, source => $watcher;
387 0 putaction 0, ACT_WATCH_RESULT, target => $who, source => $watcher;
388 }
389  
390 sub guard {
391 0 ▶ my ($guard, $who) = @_;
Subroutine guard: not called CC=1 SCAR=6.9
Pod documented
392 0 putaction 0, ACT_GUARD, target => $who, source => $guard;
393 }
394  
395 sub rolecopcheck {
396 0 ▶ my ($rolecop, $who) = @_;
Subroutine rolecopcheck: not called CC=1 SCAR=6.9
Pod documented
397 0 putaction 0, ACT_ROLECOP, target => $who, source => $rolecop;
398 }
399  
400 sub copcheck {
401 6 ▶ my ($cop, $who) = @_;
Subroutine copcheck: called CC=1 SCAR=0.0
Pod documented
402 6 putaction 0, ACT_COP, target => $who, source => $cop;
403 }
404  
405 sub skill {
406 0 ▶ my ($sk, $who, $reason, @args) = @_;
Subroutine skill: not called CC=1 SCAR=6.9
Pod documented
407 0 putaction 0, ACT_KILL, target => $who, source => $sk, reason => $reason, @args;
408 }
409  
410 sub hide {
411 0 ▶ my ($hider, $who) = @_;
Subroutine hide: not called CC=1 SCAR=6.9
Pod documented
412 0 putaction 0, ACT_HIDE, target => $who, source => $hider;
413 }
414  
415 1 1;
416 __END__
↑ Summary