a7f68beeb96e0753ab2bbfda19c851a0916ab2fb
6 use parent qw
/Exporter/;
9 use Storable qw
/dclone/;
11 our $VERSION = '0.001';
13 sub defconst
{ constant
->import($_ => $_) for @_ }
17 defconst qw
/vanilla goon doctor vigilante roleblocker jailkeeper gunsmith tracker watcher bodyguard rolecop cop sk hider/;
20 defconst qw
/mafia town/;
23 defconst qw
/miller godfather weak macho bulletproof/;
26 defconst qw
/MSG_NIGHT MSG_DAY MSG_PLAYERS_ALIVE MSG_DEATH MSG_GUNCHECK MSG_NORESULT MSG_TRACK MSG_WATCH MSG_COP MSG_ROLECOP/;
29 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/;
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
],
44 grep { $_ !~ [qw
/import/] and exists &$_ } keys %{__PACKAGE__
. '::'};
47 ################################################## Helper subs
51 goto &Exporter
::import
;
54 my (%players, %tplayers, @actions);
71 my %hash = map { $_ => 1 } @_;
76 return "Day $daycnt" if $isday;
77 return "Night $nightcnt" unless $isday;
81 my %player = %{$players{$_[0]}};
82 my ($faction, $role) = ($player{faction
}, $player{role
});
83 if (defined $faction && $faction eq town
&& $role eq vanilla
){
85 $role = 'Vanilla Townie';
88 push @tokens, ucfirst $faction if $faction;
89 for my $flag (@
{FLAG
()}) {
90 push @tokens, ucfirst $flag if $player{$flag}
92 push @tokens, ucfirst $role unless $role eq goon
&& $player{godfather
};
97 my ($type, @args) = @_;
101 say '' unless $first;
103 say "It is Night $night";
108 say '' unless $first;
110 say "It is Day $day";
113 when (MSG_PLAYERS_ALIVE
) {
115 say "Players alive: ", join ', ', @args
120 my ($who, $reason) = @args{'target', 'reason'};
122 my $rolename = rolename
$who;
123 say "$who ($rolename) — $reason $phase";
126 when (MSG_GUNCHECK
) {
128 my ($gunsmith, $who, $hasgun) = @args{'source', 'target', 'result'};
129 say "$gunsmith: $who has a gun" if $hasgun;
130 say "$gunsmith: $who does not have a gun" unless $hasgun;
133 when (MSG_NORESULT
) {
135 my ($who) = $args{'source'};
136 say "$who: No result"
141 my ($tracker, $who, $result) = @args{'source', 'target', 'result'};
142 my @result = @
{$result};
144 say "$tracker: $who did not visit anyone" unless scalar @result;
145 say "$tracker: $who visited: @result" if scalar @result;
150 my ($watcher, $who, $result) = @args{'source', 'target', 'result'};
151 my @result = @
{$result};
153 say "$watcher: $who was not visited by anyone" unless scalar @result;
154 say "$watcher: $who was visited by: @result" if scalar @result;
159 my ($rolecop, $who, $role) = @args{'source', 'target', 'result'};
160 say "$rolecop: $who\'s role is: $role"
165 my ($cop, $who, $ismafia) = @args{'source', 'target', 'result'};
166 say "$cop: $who is mafia" if $ismafia;
167 say "$cop: $who is not mafia" unless $ismafia;
173 my ($delay, $type, %args) = @_;
174 $actions[$delay]->{$type} //= [];
175 if (exists $args{target
} && exists $args{source
} && $players{$args{target
}}{faction
} eq mafia
&& $players{$args{source
}}{weak
}) {
176 putaction
($delay, ACT_KILL
, target
=> $args{source
}, reason
=> 'targeted scum');
178 push $actions[$delay]->{$type}, \
%args
182 my ($type, $args) = @_;
184 my $source = $args{source
};
185 my $target = $args{target
};
186 if (defined $source && defined $target) {
187 # Watcher and tracker variables
188 $tplayers{$source}{targets
} //= [];
189 push $tplayers{$source}{targets
}, $target;
190 $tplayers{$target}{sources
} //= [];
191 push $tplayers{$target}{sources
}, $source;
193 # Copy this action to everybody hiding behind $target
194 if (exists $tplayers{$target}{hiders
}) {
195 for my $target (@
{$tplayers{$target}{hiders
}}) {
197 $args{target
} = $target;
198 $args{hidepierce
} = 1;
199 doaction
($type, \
%args);
203 # Check if the action should be blocked
204 my $strongkill = $type eq ACT_KILL
&& $args{strong
};
205 my $roleblocked = $tplayers{$source}{roleblocked
};
206 my $hidden = $tplayers{$target}{hidden
};
207 my $hidepierce = $args{hidepierce
};
208 if ($source && (( $roleblocked && !$strongkill ) || ($hidden && !$hidepierce) )) {
209 msg MSG_NORESULT
, %args if $type ~~ INVESTIGATIVE_ACTIONS
;
217 break if $tplayers{$target}{bulletproof
} && defined $source;
218 if ($tplayers{$target}{guard_count
} && defined $source) {
219 $tplayers{$target}{guard_count
}--;
220 # Copy this action to the first guard
221 $args{target
} = shift $tplayers{$target}{guards
};
225 if ($tplayers{$target}{protection
} && !$args{strong
}) {
226 $tplayers{$target}{protection
}--;
229 msg MSG_DEATH
, %args;
230 delete $players{$target}
234 if ($tplayers{$target}{guard_count
}) {
235 $tplayers{$target}{guard_count
}--;
236 $args{target
} = shift $tplayers{$target}{guards
};
237 $target=$args{target
};
239 if ($tplayers{$target}{protection
}) {
240 $tplayers{$target}{protection
}--;
243 msg MSG_DEATH
, %args, reason
=> 'lynched';
244 delete $players{$target}
248 my $count = $args{count
} // 1;
249 $tplayers{$target}{protection
} += $count unless $tplayers{$target}{macho
}
253 $tplayers{$target}{roleblocked
} = 1
257 my $role = $players{$target}{role
};
258 my $hasgun = $role ~~ GUNROLES
|| ($players{$target}{faction
} eq mafia
&& $role ne doctor
);
259 msg MSG_GUNCHECK
, %args, result
=> $hasgun
262 when(ACT_TRACK_RESULT
){
263 msg MSG_TRACK
, %args, result
=> [ uniq @
{$tplayers{$target}{targets
} // []} ];
266 when(ACT_WATCH_RESULT
){
267 msg MSG_WATCH
, %args, result
=> [ uniq @
{$tplayers{$target}{sources
} // []} ];
271 $tplayers{$target}{guard_count
}++;
272 $tplayers{$target}{guards
} //= [];
273 push $tplayers{$target}{guards
}, $source;
277 my $result = $players{$target}{role
};
278 $result = vanilla
if $result eq goon
;
279 msg MSG_ROLECOP
, %args, result
=> ucfirst $result
283 my $result = $players{$target}{faction
} eq mafia
;
284 $result = 1 if $players{$target}{miller
};
285 $result = 0 if $players{$target}{godfather
};
286 msg MSG_COP
, %args, result
=> $result
290 $tplayers{$source}{hidden
} = 1;
291 $tplayers{$target}{hiders
} //= [];
292 push $tplayers{$target}{hiders
}, $source
297 sub process_phase_change
{
298 %tplayers = %{dclone \
%players};
299 my $actions = shift @actions;
300 for my $type(@
{ACTION_ORDER
()}) {
301 doaction
$type, $_ for @
{$actions->{$type}}
305 ################################################## User subs
308 my ($name, @args) = @_;
310 for my $trait (@args) {
312 $player{role
} = $trait when ROLE
;
313 $player{faction
} = $trait when FACTION
;
314 $player{$trait} = 1 when FLAG
;
318 $players{$name} = \
%player;
322 process_phase_change
;
324 msg MSG_DAY
, ++$daycnt;
325 msg MSG_PLAYERS_ALIVE
, keys %players;
329 process_phase_change
;
331 msg MSG_NIGHT
, ++$nightcnt;
332 msg MSG_PLAYERS_ALIVE
, keys %players;
337 putaction
0, ACT_LYNCH
, target
=> $who;
341 my ($killer, $who, $reason, @args) = @_;
342 putaction
0, ACT_KILL
, target
=> $who, source
=> $killer, reason
=> $reason, @args;
346 my ($doctor, $who) = @_;
347 putaction
0, ACT_PROTECT
, target
=> $who, source
=> $doctor;
351 my ($vig, $who, $reason, @args) = @_;
352 putaction
0, ACT_KILL
, target
=> $who, source
=> $vig, reason
=> $reason, @args;
356 my ($roleblocker, $who) = @_;
357 putaction
0, ACT_ROLEBLOCK
, target
=> $who, source
=> $roleblocker;
361 my ($jailkeeper, $who) = @_;
362 putaction
0, ACT_ROLEBLOCK
, target
=> $who, source
=> $jailkeeper;
363 putaction
0, ACT_PROTECT
, target
=> $who, source
=> $jailkeeper, count
=> 1000;
367 my ($gunsmith, $who) = @_;
368 putaction
0, ACT_GUNCHECK
, target
=> $who, source
=> $gunsmith;
372 my ($tracker, $who) = @_;
373 putaction
0, ACT_TRACK
, target
=> $who, source
=> $tracker;
374 putaction
0, ACT_TRACK_RESULT
, target
=> $who, source
=> $tracker;
378 my ($watcher, $who) = @_;
379 putaction
0, ACT_WATCH
, target
=> $who, source
=> $watcher;
380 putaction
0, ACT_WATCH_RESULT
, target
=> $who, source
=> $watcher;
384 my ($guard, $who) = @_;
385 putaction
0, ACT_GUARD
, target
=> $who, source
=> $guard;
389 my ($rolecop, $who) = @_;
390 putaction
0, ACT_ROLECOP
, target
=> $who, source
=> $rolecop;
394 my ($cop, $who) = @_;
395 putaction
0, ACT_COP
, target
=> $who, source
=> $cop;
399 my ($sk, $who, $reason, @args) = @_;
400 putaction
0, ACT_KILL
, target
=> $who, source
=> $sk, reason
=> $reason, @args;
404 my ($hider, $who) = @_;
405 putaction
0, ACT_HIDE
, target
=> $who, source
=> $hider;
415 Mafia - easily moderate Mafia games
422 player 'Banana Bob', cop, town;
423 player 'Dragon Phoenix', vanilla, townie;
424 player 'Gammie', mafia, goon;
425 player 'gslamm', vanilla, townie;
426 player 'Untrod Tripod', mafia, goon;
427 player 'Werebear', vanilla, townie;
428 player 'willows_weep', town, doctor;
431 lynch 'Untrod Tripod';
434 factionkill 'Gammie', 'willows_weep', 'shot';
435 copcheck 'Banana Bob', 'gslamm';
444 Mafia.pm is a Perl extension for easily moderating Mafia games. You don't even need to know Perl to use it (see L<"WHAT YOU NEED TO KNOW"> for details).
446 =head1 WHAT YOU NEED TO KNOW
448 A typical script starts with the following two lines
453 The rest of the script is a series of function calls that describe the players and their actions.
455 A function call looks like this:
457 function_name first_argument, second_argument, ...
459 Each argument is either a number, a string (which is a sequence of characters between single or double quotes, such as C<'badguy'>, C<'qwrf'>) or a constant (such as C<mafia>, C<vanilla>, C<bulletproof>).
463 player 'Somebody', mafia, goon; # player is the function, 'Somebody' is a string, mafia and goon are constants.
464 lynch 'Nobody'; # lynch is the function, 'Nobody' is a string.
465 day; # day is the function. There are no arguments.
471 =item B<player> I<name>, I<trait>, ...
473 Defines a new player named I<name> and its traits (role, faction, role modifiers).
475 Roles: C<vanilla, goon, doctor, vigilante, roleblocker, jailkeeper, gunsmith, tracker, watcher, bodyguard, rolecop, cop, sk, hider>.
477 Factions: C<mafia, town>. C<townie> is a synonim for C<town>.
479 Other attributes: C<miller, godfather, weak, macho, bulletproof>
481 These traits may be specified in any order.
485 player 'alice', town, bulletproof, miller, vigilante; # Alice is a NK-Immune Miller Vig
486 player 'bob', town, weak, doctor; # Bob is a Town Weak Doctor
487 player 'eve', mafia, godfather, goon; # Eve is a Mafia Godfather
491 Defines the start of a new Day. All actions in the previous Night are now resolved.
495 Defines the start of a new Night. All actions in the previous Day are now resolved.
497 =item B<lynch> I<player>
499 Notes that I<player> was lynched.
501 =item B<factionkill> I<killer>, I<player>, I<flavour>, [ strong => 1 ]
503 Notes that I<killer> killed I<player> with flavour I<flavour>. Append C<< strong => 1 >> if the kill should ignore roleblocks and doctor/jailkeeper protections. Use this for mafia kills.
507 factionkill 'eve', 'alice', 'strangled to death';
508 factionkill 'eve', 'bob', 'brutally murdered', strong => 1; # This is a strongman kill
510 =item B<protect> I<doctor>, I<player>
512 Notes that I<doctor> protected I<player>.
514 =item B<vig> I<vigilante>, I<player>, I<flavour>, [ strong => 1 ]
516 Notes that I<killer> killed I<player> with flavour I<flavour>. Append C<< strong => 1 >> if the kill should ignore roleblocks and doctor/jailkeeper protections. Use this for Vigilante/Juggernaut kills.
520 vig 'chuck', 'bob', 'shot';
521 vig 'chuck', 'bob', 'shot seven times', strong => 1; # This is a Juggernaut (Strongman Vigilante) kill
523 =item B<roleblock> I<roleblocker>, I<player>
525 Notes that I<roleblocker> roleblocked I<player>.
527 =item B<jailkeep> I<jailkeeper>, I<player>
529 Notes that I<jailkeeper> roleblocked and protected I<player>.
531 =item B<guncheck> I<gunsmith>, I<player>
533 Notes that I<gunsmith> checked if I<player> has a gun.
535 =item B<track> I<tracker>, I<player>
537 Notes that I<tracker> tracked I<player>.
539 =item B<watch> I<watcher>, I<player>
541 Notes that I<watcher> watched I<player>.
543 =item B<guard> I<bodyguard>, I<player>
545 Notes that I<bodyguard> guarded I<player>
547 =item B<rolecopcheck> I<rolecop>, I<player>
549 Notes that I<rolecop> checked the role of I<player>
551 =item B<copcheck> I<cop>, I<player>
553 Notes that I<cop> checked whether I<player> is mafia.
555 =item B<skill> I<SK>, I<player>, I<flavour>, [ strong => 1 ]
557 Notes that I<SK> killed player with flavour I<flavour>. Append C<< strong => 1 >>> if the kill should ignore roleblocks and doctor/jailkeeper protections. Use this for Serial Killer kills.
559 =item B<hide> I<hider>, I<player>
561 Notes that I<hider> hid behind I<player>.
567 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
569 =head1 COPYRIGHT AND LICENSE
571 Copyright (C) 2013 by Marius Gavrilescu
573 This library is free software; you can redistribute it and/or modify
574 it under the same terms as Perl itself, either Perl version 5.14.2 or,
575 at your option, any later version of Perl 5 you may have available.
This page took 0.053015 seconds and 3 git commands to generate.