line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BalanceOfPower::Commands::Role::Command; |
2
|
|
|
|
|
|
|
$BalanceOfPower::Commands::Role::Command::VERSION = '0.400110'; |
3
|
13
|
|
|
13
|
|
4148
|
use strict; |
|
13
|
|
|
|
|
17
|
|
|
13
|
|
|
|
|
262
|
|
4
|
13
|
|
|
13
|
|
92
|
use v5.10; |
|
13
|
|
|
|
|
28
|
|
5
|
13
|
|
|
13
|
|
36
|
use Moo::Role; |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
60
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
has name => ( |
8
|
|
|
|
|
|
|
is => 'ro', |
9
|
|
|
|
|
|
|
default => 'DO NOTHING' |
10
|
|
|
|
|
|
|
); |
11
|
|
|
|
|
|
|
has actor => ( |
12
|
|
|
|
|
|
|
is => 'rw', |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has world => ( |
16
|
|
|
|
|
|
|
is => 'ro' |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
has synonyms => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
default => sub { [] } |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
has export_cost => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
default => 0 |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
has domestic_cost => ( |
27
|
|
|
|
|
|
|
is => 'ro', |
28
|
|
|
|
|
|
|
default => 0 |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
has prestige_cost => ( |
31
|
|
|
|
|
|
|
is => 'ro', |
32
|
|
|
|
|
|
|
default => 0 |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has allowed_at_war => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
default => 0 |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
has production_limit => ( |
40
|
|
|
|
|
|
|
is => 'ro', |
41
|
|
|
|
|
|
|
default => sub { {} } |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
has army_limit => ( |
44
|
|
|
|
|
|
|
is => 'ro', |
45
|
|
|
|
|
|
|
default => sub { {} } |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
has treaty_limit => ( |
48
|
|
|
|
|
|
|
is => 'ro', |
49
|
|
|
|
|
|
|
default => 0 |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub has_argument |
53
|
|
|
|
|
|
|
{ |
54
|
0
|
|
|
0
|
0
|
0
|
return 1; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub get_nation |
58
|
|
|
|
|
|
|
{ |
59
|
417
|
|
|
417
|
0
|
315
|
my $self = shift; |
60
|
417
|
|
|
|
|
1040
|
return $self->world->get_nation($self->actor); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub allowed |
64
|
|
|
|
|
|
|
{ |
65
|
252
|
|
|
252
|
0
|
216
|
my $self = shift; |
66
|
252
|
|
|
|
|
364
|
my $nation = $self->get_nation(); |
67
|
252
|
100
|
|
|
|
505
|
return 0 |
68
|
|
|
|
|
|
|
if($nation->internal_disorder_status() eq 'Civil war'); |
69
|
237
|
100
|
|
|
|
554
|
if(! $self->allowed_at_war) |
70
|
|
|
|
|
|
|
{ |
71
|
198
|
100
|
|
|
|
447
|
if($self->world->at_war($self->actor)) |
72
|
|
|
|
|
|
|
{ |
73
|
8
|
|
|
|
|
18
|
return 0; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
229
|
50
|
|
|
|
708
|
if(exists $self->production_limit->{'<'}) |
|
|
50
|
|
|
|
|
|
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
0
|
return $nation->production() <= $self->production_limit->{'<'}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif(exists $self->production_limit->{'>'}) |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
|
|
0
|
return $nation->production() >= $self->production_limit->{'>'}; |
83
|
|
|
|
|
|
|
} |
84
|
229
|
50
|
|
|
|
557
|
if(exists $self->army_limit->{'<'}) |
|
|
100
|
|
|
|
|
|
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
|
|
0
|
return $nation->army() <= $self->army_limit->{'<'}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
elsif(exists $self->army_limit->{'>'}) |
89
|
|
|
|
|
|
|
{ |
90
|
37
|
|
|
|
|
123
|
return $nation->army() >= $self->army_limit->{'>'}; |
91
|
|
|
|
|
|
|
} |
92
|
192
|
100
|
|
|
|
525
|
if($nation->production_for_domestic < $self->domestic_cost) |
93
|
|
|
|
|
|
|
{ |
94
|
9
|
|
|
|
|
15
|
return 0; |
95
|
|
|
|
|
|
|
} |
96
|
183
|
100
|
|
|
|
427
|
if($nation->production_for_export < $self->export_cost) |
97
|
|
|
|
|
|
|
{ |
98
|
4
|
|
|
|
|
9
|
return 0; |
99
|
|
|
|
|
|
|
} |
100
|
179
|
100
|
|
|
|
430
|
if($nation->prestige < $self->prestige_cost) |
101
|
|
|
|
|
|
|
{ |
102
|
17
|
|
|
|
|
35
|
return 0; |
103
|
|
|
|
|
|
|
} |
104
|
162
|
100
|
|
|
|
330
|
if($self->treaty_limit == 1) |
105
|
|
|
|
|
|
|
{ |
106
|
15
|
50
|
|
|
|
54
|
if($self->world->get_treaties_for_nation($nation->name) >= $nation->treaty_limit) |
107
|
|
|
|
|
|
|
{ |
108
|
0
|
|
|
|
|
0
|
return 0; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
} |
111
|
162
|
|
|
|
|
287
|
return 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub extract_argument |
115
|
|
|
|
|
|
|
{ |
116
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
117
|
0
|
|
|
|
|
|
my $query = shift; |
118
|
0
|
|
|
|
|
|
my $extract = shift; |
119
|
0
|
|
|
|
|
|
$query = uc $query; #Commands are always all caps |
120
|
0
|
0
|
|
|
|
|
$extract = 1 if(! defined $extract); |
121
|
0
|
|
|
|
|
|
my $name = $self->name; |
122
|
0
|
0
|
|
|
|
|
if($query =~ /^$name( (.*))?$/) |
123
|
|
|
|
|
|
|
{ |
124
|
0
|
0
|
|
|
|
|
if($extract) |
125
|
|
|
|
|
|
|
{ |
126
|
0
|
|
|
|
|
|
return $2; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
else |
129
|
|
|
|
|
|
|
{ |
130
|
0
|
|
|
|
|
|
return 1; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
} |
133
|
0
|
|
|
|
|
|
foreach my $syn (@{$self->synonyms}) |
|
0
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
{ |
135
|
0
|
0
|
|
|
|
|
if($query =~ /^$syn( (.*))?/) |
136
|
|
|
|
|
|
|
{ |
137
|
0
|
0
|
|
|
|
|
if($extract) |
138
|
|
|
|
|
|
|
{ |
139
|
0
|
|
|
|
|
|
return $2; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
else |
142
|
|
|
|
|
|
|
{ |
143
|
0
|
|
|
|
|
|
return 1; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
return undef; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub recognize |
151
|
|
|
|
|
|
|
{ |
152
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
153
|
0
|
|
|
|
|
|
my $query = shift; |
154
|
0
|
0
|
|
|
|
|
if($self->extract_argument($query, 0)) |
155
|
|
|
|
|
|
|
{ |
156
|
0
|
|
|
|
|
|
return 1; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
else |
159
|
|
|
|
|
|
|
{ |
160
|
0
|
|
|
|
|
|
return 0; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub execute |
165
|
|
|
|
|
|
|
{ |
166
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
167
|
0
|
|
|
|
|
|
my $query = shift; |
168
|
0
|
|
|
|
|
|
return { status => 1, command => uc $query }; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub print |
172
|
|
|
|
|
|
|
{ |
173
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
174
|
0
|
|
|
|
|
|
return $self->name; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub IA |
178
|
|
|
|
|
|
|
{ |
179
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
180
|
0
|
|
|
|
|
|
return $self->name; |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |