| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package BalanceOfPower::Role::Shopper; |
|
2
|
|
|
|
|
|
|
$BalanceOfPower::Role::Shopper::VERSION = '0.400115'; |
|
3
|
13
|
|
|
13
|
|
5609
|
use strict; |
|
|
13
|
|
|
|
|
28
|
|
|
|
13
|
|
|
|
|
390
|
|
|
4
|
13
|
|
|
13
|
|
130
|
use v5.10; |
|
|
13
|
|
|
|
|
43
|
|
|
5
|
13
|
|
|
13
|
|
49
|
use Moo::Role; |
|
|
13
|
|
|
|
|
33
|
|
|
|
13
|
|
|
|
|
80
|
|
|
6
|
13
|
|
|
13
|
|
3285
|
use BalanceOfPower::Constants ':all'; |
|
|
13
|
|
|
|
|
33
|
|
|
|
13
|
|
|
|
|
7599
|
|
|
7
|
13
|
|
|
13
|
|
90
|
use BalanceOfPower::Utils qw( prev_turn ); |
|
|
13
|
|
|
|
|
21
|
|
|
|
13
|
|
|
|
|
662
|
|
|
8
|
13
|
|
|
13
|
|
64
|
use BalanceOfPower::Printer; |
|
|
13
|
|
|
|
|
20
|
|
|
|
13
|
|
|
|
|
280
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
13
|
|
|
13
|
|
53
|
use Data::Dumper; |
|
|
13
|
|
|
|
|
20
|
|
|
|
13
|
|
|
|
|
10932
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
requires 'order_statistics'; |
|
13
|
|
|
|
|
|
|
requires 'get_statistics_value'; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my @products = ( 'goods', 'luxury', 'arms', 'tech', 'culture' ); |
|
17
|
|
|
|
|
|
|
my %dependencies = ( 'goods' => 'p/d', |
|
18
|
|
|
|
|
|
|
'luxury' => 'w/d', |
|
19
|
|
|
|
|
|
|
'arms' => 'army', |
|
20
|
|
|
|
|
|
|
'tech' => 'progress', |
|
21
|
|
|
|
|
|
|
'culture' => 'prestige' ); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get_stat_for_price |
|
24
|
|
|
|
|
|
|
{ |
|
25
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
26
|
0
|
|
|
|
|
|
my $y = shift; |
|
27
|
0
|
|
|
|
|
|
my $type = shift; |
|
28
|
0
|
|
|
|
|
|
my $nation = shift; #Max value if null |
|
29
|
0
|
0
|
0
|
|
|
|
my $turn = $type eq 'goods' || $type eq 'prestige' ? $y : prev_turn($y); |
|
30
|
0
|
0
|
|
|
|
|
if(! $nation) |
|
31
|
|
|
|
|
|
|
{ |
|
32
|
0
|
|
|
|
|
|
my @stat_values = $self->order_statistics($turn, $dependencies{$type}); |
|
33
|
0
|
0
|
|
|
|
|
if(@stat_values == 0) |
|
34
|
|
|
|
|
|
|
{ |
|
35
|
0
|
|
|
|
|
|
return 0; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
else |
|
38
|
|
|
|
|
|
|
{ |
|
39
|
0
|
|
|
|
|
|
return $stat_values[0]->{'value'}; |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
else |
|
43
|
|
|
|
|
|
|
{ |
|
44
|
0
|
|
|
|
|
|
return $self->get_statistics_value($turn, $nation, $dependencies{$type}); |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub calculate_price |
|
49
|
|
|
|
|
|
|
{ |
|
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
51
|
0
|
|
|
|
|
|
my $y = shift; |
|
52
|
0
|
|
|
|
|
|
my $type = shift; |
|
53
|
0
|
|
|
|
|
|
my $nation = shift; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#Price formula is MaxPrice - (( MaxPrice - MinPrice) / MaxValue) * Value |
|
56
|
|
|
|
|
|
|
#MaxPrice and MinPrice are constant |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $min_price = PRICE_RANGES->{$type}->[0]; |
|
59
|
0
|
|
|
|
|
|
my $max_price = PRICE_RANGES->{$type}->[1]; |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $max_value = $self->get_stat_for_price($y, $type); |
|
62
|
0
|
0
|
|
|
|
|
return SHOP_PRICE_FACTOR if($max_value == 0); |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
my $value = $self->get_stat_for_price($y, $type, $nation); |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return int(((($max_price - (($max_price - $min_price) / $max_value) * $value))* SHOP_PRICE_FACTOR)*100)/100; |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub get_all_nation_prices |
|
70
|
|
|
|
|
|
|
{ |
|
71
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
72
|
0
|
|
|
|
|
|
my $nation = shift; |
|
73
|
0
|
|
|
|
|
|
my $year = shift; |
|
74
|
0
|
|
|
|
|
|
my %data = (); |
|
75
|
0
|
|
|
|
|
|
foreach my $p (@products) |
|
76
|
|
|
|
|
|
|
{ |
|
77
|
0
|
|
|
|
|
|
my $price = $self->calculate_price($year, $p, $nation); |
|
78
|
0
|
|
|
|
|
|
my $stat = $self->get_stat_for_price($year, $p, $nation); |
|
79
|
0
|
|
|
|
|
|
$data{$p} = { price => $price, stat => $stat }; |
|
80
|
|
|
|
|
|
|
} |
|
81
|
0
|
|
|
|
|
|
return %data; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub print_nation_shop_prices |
|
85
|
|
|
|
|
|
|
{ |
|
86
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
87
|
0
|
|
|
|
|
|
my $y = shift; |
|
88
|
0
|
|
|
|
|
|
my $nation = shift; |
|
89
|
0
|
|
0
|
|
|
|
my $mode = shift || 'print'; |
|
90
|
0
|
|
|
|
|
|
my %data = $self->get_all_nation_prices($nation, $y); |
|
91
|
0
|
|
|
|
|
|
$data{nation} = $nation; |
|
92
|
0
|
|
|
|
|
|
return BalanceOfPower::Printer::print($mode, $self, 'print_shop_prices', \%data); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub print_all_nations_prices |
|
96
|
|
|
|
|
|
|
{ |
|
97
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
98
|
0
|
|
|
|
|
|
my $y = shift; |
|
99
|
0
|
|
0
|
|
|
|
my $mode = shift || 'print'; |
|
100
|
0
|
|
|
|
|
|
my @nations = @{$self->nation_names}; |
|
|
0
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
my %data = (); |
|
102
|
0
|
|
|
|
|
|
foreach my $n (@nations) |
|
103
|
|
|
|
|
|
|
{ |
|
104
|
0
|
|
|
|
|
|
my %prices = $self->get_all_nation_prices($n, $y); |
|
105
|
0
|
|
|
|
|
|
$data{$n} = \%prices; |
|
106
|
|
|
|
|
|
|
} |
|
107
|
0
|
|
|
|
|
|
return BalanceOfPower::Printer::print($mode, $self, 'print_all_shop_prices', |
|
108
|
|
|
|
|
|
|
{ prices => \%data, |
|
109
|
|
|
|
|
|
|
names => \@nations }); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub do_transaction |
|
115
|
|
|
|
|
|
|
{ |
|
116
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
117
|
0
|
|
|
|
|
|
my $player = shift; |
|
118
|
0
|
|
|
|
|
|
my $action = shift; |
|
119
|
0
|
|
|
|
|
|
my $q = shift; |
|
120
|
0
|
|
|
|
|
|
my $what = shift; |
|
121
|
0
|
|
|
|
|
|
my $flags = shift; |
|
122
|
0
|
0
|
|
|
|
|
if(! grep {$_ eq $what} @products) |
|
|
0
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
{ |
|
124
|
0
|
|
|
|
|
|
return -10; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
0
|
0
|
|
|
|
|
if($player->get_friendship($player->position) < FRIENDSHIP_LIMIT_TO_SHOP) |
|
127
|
|
|
|
|
|
|
{ |
|
128
|
0
|
|
|
|
|
|
return -14; |
|
129
|
|
|
|
|
|
|
} |
|
130
|
0
|
|
|
|
|
|
my $price = $self->calculate_price($self->current_year, $what, $player->position); |
|
131
|
0
|
|
|
|
|
|
my $stat = $self->get_stat_for_price($self->current_year, $what, $player->position); |
|
132
|
0
|
|
|
|
|
|
my $cost = $price * $q; |
|
133
|
0
|
0
|
|
|
|
|
if($action eq 'buy') |
|
|
|
0
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
{ |
|
135
|
0
|
0
|
|
|
|
|
if($cost > $player->money) |
|
136
|
|
|
|
|
|
|
{ |
|
137
|
0
|
|
|
|
|
|
return -11; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
0
|
0
|
|
|
|
|
if($q > $player->cargo_free_space) |
|
140
|
|
|
|
|
|
|
{ |
|
141
|
0
|
|
|
|
|
|
return -12; |
|
142
|
|
|
|
|
|
|
} |
|
143
|
0
|
|
|
|
|
|
$player->add_money(-1 * $cost); |
|
144
|
0
|
|
|
|
|
|
$player->add_cargo($what, $q, $cost, $stat); |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
elsif($action eq 'sell') |
|
147
|
|
|
|
|
|
|
{ |
|
148
|
0
|
|
|
|
|
|
my $have = $player->get_cargo($what); |
|
149
|
0
|
0
|
|
|
|
|
if($have < $q) |
|
150
|
|
|
|
|
|
|
{ |
|
151
|
0
|
|
|
|
|
|
return -13; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
0
|
0
|
|
|
|
|
if(exists $flags->{'bm'}) |
|
154
|
|
|
|
|
|
|
{ |
|
155
|
0
|
|
|
|
|
|
$cost = $cost + (BLACK_MARKET_PERCENT_SELLING_BONUS * $cost) / 100; |
|
156
|
0
|
|
|
|
|
|
$player->add_money($cost); |
|
157
|
0
|
|
|
|
|
|
$player->add_cargo($what, -1 * $q, $cost, $stat); |
|
158
|
0
|
|
|
|
|
|
$player->add_friendship($player->position, BLACK_MARKET_FRIENDSHIP_MALUS); |
|
159
|
|
|
|
|
|
|
} |
|
160
|
|
|
|
|
|
|
else |
|
161
|
|
|
|
|
|
|
{ |
|
162
|
0
|
|
|
|
|
|
$player->add_money($cost); |
|
163
|
0
|
|
|
|
|
|
$player->add_cargo($what, -1 * $q, $cost, $stat); |
|
164
|
|
|
|
|
|
|
} |
|
165
|
|
|
|
|
|
|
} |
|
166
|
0
|
|
|
|
|
|
return (1, $cost); |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|