| 1 | package BalanceOfPower::Role::GameMaster; | ||||||||||
| 2 | 11 | $BalanceOfPower::Role::GameMaster::VERSION = '0.300010'; | |||||||||
| 3 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 11 | ▶ | use v5.10; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 11 | ▶ | use Moo::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 11 | ▶ | use BalanceOfPower::Player; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 11 | ▶ | use BalanceOfPower::Constants ':all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | has players => ( | ||||||||||
| 13 | is => 'rw', | ||||||||||
| 14 | 0 | ▶ | default => sub { [] } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 15 | 11 | ); | |||||||||
| 16 | |||||||||||
| 17 | sub get_player | ||||||||||
| 18 | { | ||||||||||
| 19 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_player: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 20 | 0 | my $name = shift; | |||||||||
| 21 | 0 | my @good = grep { $_->name eq $name} @{$self->players}; | |||||||||
| 22 | 0 | ▶ | if(@good) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | { | ||||||||||
| 24 | 0 | return $good[0]; | |||||||||
| 25 | } | ||||||||||
| 26 | else | ||||||||||
| 27 | { | ||||||||||
| 28 | 0 | return undef; | |||||||||
| 29 | } | ||||||||||
| 30 | } | ||||||||||
| 31 | sub create_player | ||||||||||
| 32 | { | ||||||||||
| 33 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
create_player: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 34 | 0 | my $username = shift; | |||||||||
| 35 | 0 | my $already = $self->get_player($username); | |||||||||
| 36 | 0 | ▶ | return 0 if($already); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | my $log_name = $username . ".log"; | |||||||||
| 38 | 0 | $log_name =~ s/ /_/g; | |||||||||
| 39 | 0 | my $pl = BalanceOfPower::Player->new(name => $username, money => START_PLAYER_MONEY, log_name => $log_name, log_dir => $self->log_dir, current_year => $self->current_year); | |||||||||
| 40 | 0 | $pl->delete_log(); | |||||||||
| 41 | 0 | $pl->register_event("ENTERING THE GAME"); | |||||||||
| 42 | 0 | $self->register_event("$username IS ENTERING THE GAME"); | |||||||||
| 43 | 0 | $self->add_player($pl); | |||||||||
| 44 | 0 | return 1; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | |||||||||||
| 48 | sub add_player | ||||||||||
| 49 | { | ||||||||||
| 50 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
add_player: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 51 | 0 | my $player = shift; | |||||||||
| 52 | 0 | ▶ | if($self->get_player($player->name)) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | { | ||||||||||
| 54 | 0 | return 0; | |||||||||
| 55 | } | ||||||||||
| 56 | else | ||||||||||
| 57 | { | ||||||||||
| 58 | 0 | push @{$self->players}, $player; | |||||||||
| 59 | 0 | return 1; | |||||||||
| 60 | } | ||||||||||
| 61 | } | ||||||||||
| 62 | sub delete_player | ||||||||||
| 63 | { | ||||||||||
| 64 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
delete_player: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 65 | 0 | my $player = shift; | |||||||||
| 66 | 0 | my @players = grep { $_->name ne $player} @{$self->players}; | |||||||||
| 67 | 0 | $self->players(\@players); | |||||||||
| 68 | } | ||||||||||
| 69 | sub player_current_year | ||||||||||
| 70 | { | ||||||||||
| 71 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
player_current_year: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 72 | 0 | for(@{$self->players}) | |||||||||
| 73 | { | ||||||||||
| 74 | 0 | $_->current_year($self->current_year); | |||||||||
| 75 | } | ||||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 11 | 1; | |||||||||