« lib/BalanceOfPower/Commands/RebelMilitarySupport.pm
↑ Summary
lib/BalanceOfPower/Player/Role/Traveler.pm »
| 1 | package BalanceOfPower::Player::Role::Friend; | ||
| 2 | $BalanceOfPower::Player::Role::Friend::VERSION = '0.400115'; | ||
| 3 | use strict; | ||
| 4 | use v5.10; | ||
| 5 | use Moo::Role; | ||
| 6 | |||
| 7 | use BalanceOfPower::Constants ':all'; | ||
| 8 | |||
| 9 | has friendship => ( | ||
| 10 | is => 'ro', | ||
| 11 | default => sub { {} }, | ||
| 12 | ); | ||
| 13 | |||
| 14 | sub get_friendship | ||
| 15 | { | ||
| 16 | my $self = shift; | ||
| 17 | my $nation = shift; | ||
| 18 | if(exists $self->friendship->{$nation}) | ||
| 19 | { | ||
| 20 | return 50 + $self->friendship->{$nation}; | ||
| 21 | } | ||
| 22 | else | ||
| 23 | { | ||
| 24 | return 50; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | sub add_friendship | ||
| 29 | { | ||
| 30 | my $self = shift; | ||
| 31 | my $nation = shift; | ||
| 32 | my $value = shift; | ||
| 33 | if(exists $self->friendship->{$nation}) | ||
| 34 | { | ||
| 35 | $self->friendship->{$nation} = $self->friendship->{$nation} + $value; | ||
| 36 | $self->friendship->{$nation} = 50 if $self->friendship->{$nation} > 50; | ||
| 37 | $self->friendship->{$nation} = -50 if $self->friendship->{$nation} < -50; | ||
| 38 | delete $self->friendship->{$nation} if $self->friendship->{$nation} == 0; | ||
| 39 | } | ||
| 40 | else | ||
| 41 | { | ||
| 42 | $self->friendship->{$nation} = $value; | ||
| 43 | } | ||
| 44 | return $self->get_friendship($nation); | ||
| 45 | } | ||
| 46 | sub print_friendship | ||
| 47 | { | ||
| 48 | my $self = shift; | ||
| 49 | my $nation = shift; | ||
| 50 | my $mode = shift || 'print'; | ||
| 51 | if(! $nation) | ||
| 52 | { | ||
| 53 | my $data = { player => $self->name, | ||
| 54 | friendship => $self->friendship, | ||
| 55 | others => 1 }; | ||
| 56 | return BalanceOfPower::Printer::print($mode, $self, 'print_player_friendship', $data); | ||
| 57 | } | ||
| 58 | else | ||
| 59 | { | ||
| 60 | my $data = { player => $self->name, | ||
| 61 | friendship => { $nation => $self->get_friendship($nation) }, | ||
| 62 | others => 0 }; | ||
| 63 | return BalanceOfPower::Printer::print($mode, $self, 'print_player_friendship', $data); | ||
| 64 | } | ||
| 65 | |||
| 66 | } | ||
| 67 | |||
| 68 | 1; |