line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BalanceOfPower::Relations::Friendship; |
2
|
|
|
|
|
|
|
$BalanceOfPower::Relations::Friendship::VERSION = '0.400115'; |
3
|
13
|
|
|
13
|
|
64
|
use strict; |
|
13
|
|
|
|
|
19
|
|
|
13
|
|
|
|
|
326
|
|
4
|
13
|
|
|
13
|
|
120
|
use v5.10; |
|
13
|
|
|
|
|
44
|
|
5
|
|
|
|
|
|
|
|
6
|
13
|
|
|
13
|
|
63
|
use Moo; |
|
13
|
|
|
|
|
16
|
|
|
13
|
|
|
|
|
77
|
|
7
|
13
|
|
|
13
|
|
3323
|
use BalanceOfPower::Constants ':all'; |
|
13
|
|
|
|
|
23
|
|
|
13
|
|
|
|
|
7033
|
|
8
|
13
|
|
|
13
|
|
76
|
use BalanceOfPower::Utils qw( as_html_dangerous ); |
|
13
|
|
|
|
|
20
|
|
|
13
|
|
|
|
|
696
|
|
9
|
|
|
|
|
|
|
|
10
|
13
|
|
|
13
|
|
92
|
use Term::ANSIColor; |
|
13
|
|
|
|
|
25
|
|
|
13
|
|
|
|
|
660
|
|
11
|
13
|
|
|
13
|
|
80
|
use HTML::Entities; |
|
13
|
|
|
|
|
23
|
|
|
13
|
|
|
|
|
14726
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has factor => ( |
14
|
|
|
|
|
|
|
is => 'rw' |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
has crisis_level => ( |
17
|
|
|
|
|
|
|
is => 'rw', |
18
|
|
|
|
|
|
|
default => 0 |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
with 'BalanceOfPower::Relations::Role::Relation'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub get_crisis_level |
23
|
|
|
|
|
|
|
{ |
24
|
1074
|
|
|
1074
|
0
|
972
|
my $self = shift; |
25
|
1074
|
100
|
|
|
|
1997
|
if($self->factor > PERMANENT_CRISIS_HATE_LIMIT) |
26
|
|
|
|
|
|
|
{ |
27
|
913
|
|
|
|
|
2741
|
return $self->crisis_level; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
else |
30
|
|
|
|
|
|
|
{ |
31
|
161
|
50
|
|
|
|
339
|
if($self->crisis_level < CRISIS_MAX_FACTOR) |
32
|
|
|
|
|
|
|
{ |
33
|
161
|
|
|
|
|
546
|
return $self->crisis_level + 1; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else |
36
|
|
|
|
|
|
|
{ |
37
|
0
|
|
|
|
|
0
|
return $self->crisis_level; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
sub status |
42
|
|
|
|
|
|
|
{ |
43
|
744
|
|
|
744
|
0
|
634
|
my $self = shift; |
44
|
744
|
100
|
|
|
|
1887
|
if($self->factor == ALLIANCE_FRIENDSHIP_FACTOR) |
|
|
100
|
|
|
|
|
|
45
|
|
|
|
|
|
|
{ |
46
|
16
|
|
|
|
|
38
|
return 'ALLIANCE'; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif($self->factor == DOMINION_DIPLOMACY) |
49
|
|
|
|
|
|
|
{ |
50
|
3
|
|
|
|
|
11
|
return 'INFLUENCE PRESENT'; |
51
|
|
|
|
|
|
|
} |
52
|
725
|
100
|
|
|
|
1402
|
if($self->factor <= HATE_LIMIT) |
|
|
100
|
|
|
|
|
|
53
|
|
|
|
|
|
|
{ |
54
|
233
|
|
|
|
|
650
|
return 'HATE'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
elsif($self->factor >= LOVE_LIMIT) |
57
|
|
|
|
|
|
|
{ |
58
|
204
|
|
|
|
|
638
|
return 'FRIENDSHIP'; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
else |
61
|
|
|
|
|
|
|
{ |
62
|
288
|
|
|
|
|
821
|
return 'NEUTRAL'; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
sub status_html_class |
66
|
|
|
|
|
|
|
{ |
67
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
68
|
0
|
0
|
|
|
|
0
|
if($self->factor == ALLIANCE_FRIENDSHIP_FACTOR) |
|
|
0
|
|
|
|
|
|
69
|
|
|
|
|
|
|
{ |
70
|
0
|
|
|
|
|
0
|
return 'rel-alliance'; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
elsif($self->factor == DOMINION_DIPLOMACY) |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
|
|
0
|
return 'rel-influence'; |
75
|
|
|
|
|
|
|
} |
76
|
0
|
0
|
|
|
|
0
|
if($self->factor <= HATE_LIMIT) |
|
|
0
|
|
|
|
|
|
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
|
|
0
|
return 'rel-hate'; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
elsif($self->factor >= LOVE_LIMIT) |
81
|
|
|
|
|
|
|
{ |
82
|
0
|
|
|
|
|
0
|
return 'rel-friendship'; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
else |
85
|
|
|
|
|
|
|
{ |
86
|
0
|
|
|
|
|
0
|
return 'rel-neutral'; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub colored_status |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
94
|
0
|
|
|
|
|
0
|
return $self->status_color . $self->status . color("reset"); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub status_color |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
100
|
0
|
0
|
0
|
|
|
0
|
if($self->status eq 'ALLIANCE' || $self->status eq 'INFLUENCE PRESENT') |
101
|
|
|
|
|
|
|
{ |
102
|
0
|
|
|
|
|
0
|
return color("cyan bold"); |
103
|
|
|
|
|
|
|
} |
104
|
0
|
0
|
|
|
|
0
|
if($self->status eq 'HATE') |
|
|
0
|
|
|
|
|
|
105
|
|
|
|
|
|
|
{ |
106
|
0
|
|
|
|
|
0
|
return color("red bold"); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
elsif($self->status eq 'FRIENDSHIP') |
109
|
|
|
|
|
|
|
{ |
110
|
0
|
|
|
|
|
0
|
return color("green bold"); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
else |
113
|
|
|
|
|
|
|
{ |
114
|
0
|
|
|
|
|
0
|
return ""; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub html |
120
|
|
|
|
|
|
|
{ |
121
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
122
|
0
|
|
|
|
|
0
|
my $from = shift; |
123
|
0
|
|
|
|
|
0
|
my $link = encode_entities($self->print($from, 0)); |
124
|
0
|
0
|
|
|
|
0
|
if($self->status eq 'HATE') |
125
|
|
|
|
|
|
|
{ |
126
|
0
|
|
|
|
|
0
|
$link = as_html_dangerous($link); |
127
|
|
|
|
|
|
|
} |
128
|
0
|
|
|
|
|
0
|
return $link; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub print |
132
|
|
|
|
|
|
|
{ |
133
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
134
|
0
|
|
|
|
|
0
|
my $from = shift; |
135
|
0
|
|
|
|
|
0
|
my $color = shift; |
136
|
0
|
0
|
|
|
|
0
|
$color = 1 if(! defined $color); |
137
|
0
|
|
|
|
|
0
|
my $second_node; |
138
|
|
|
|
|
|
|
my $out; |
139
|
0
|
0
|
|
|
|
0
|
if($from) |
140
|
|
|
|
|
|
|
{ |
141
|
0
|
0
|
|
|
|
0
|
if($from eq $self->node1) |
|
|
0
|
|
|
|
|
|
142
|
|
|
|
|
|
|
{ |
143
|
0
|
|
|
|
|
0
|
$second_node = $self->node2; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
elsif($from eq $self->node2) |
146
|
|
|
|
|
|
|
{ |
147
|
0
|
|
|
|
|
0
|
$second_node = $self->node1; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
else |
151
|
|
|
|
|
|
|
{ |
152
|
0
|
|
|
|
|
0
|
$from = $self->node1; |
153
|
0
|
|
|
|
|
0
|
$second_node = $self->node2; |
154
|
|
|
|
|
|
|
} |
155
|
0
|
0
|
|
|
|
0
|
$out = $self->status_color if $color; |
156
|
0
|
|
|
|
|
0
|
$out .= $from . " <--> " . $second_node . " [" . $self->factor . " " . $self->status . "]"; |
157
|
0
|
0
|
|
|
|
0
|
if($self->get_crisis_level > 0) |
158
|
|
|
|
|
|
|
{ |
159
|
0
|
0
|
|
|
|
0
|
if($color) |
160
|
|
|
|
|
|
|
{ |
161
|
0
|
|
|
|
|
0
|
$out .= " " . $self->print_crisis_bar(); |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
else |
164
|
|
|
|
|
|
|
{ |
165
|
0
|
|
|
|
|
0
|
$out .= " " . $self->print_grey_crisis_bar(); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
} |
168
|
0
|
0
|
|
|
|
0
|
$out .= color("reset") if $color; |
169
|
0
|
|
|
|
|
0
|
return $out; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
sub print_status |
172
|
|
|
|
|
|
|
{ |
173
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
174
|
0
|
|
|
|
|
0
|
return $self->status_color . $self->status . color("reset"); |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
sub print_crisis |
177
|
|
|
|
|
|
|
{ |
178
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
179
|
0
|
|
|
|
|
0
|
my $color = shift; |
180
|
0
|
0
|
|
|
|
0
|
$color = 1 if(! defined $color); |
181
|
0
|
0
|
|
|
|
0
|
if($self->get_crisis_level > 0) |
182
|
|
|
|
|
|
|
{ |
183
|
0
|
|
|
|
|
0
|
my $out = $self->node1 . " <-> " . $self->node2; |
184
|
0
|
0
|
|
|
|
0
|
if($color) |
185
|
|
|
|
|
|
|
{ |
186
|
0
|
|
|
|
|
0
|
return $out . " " . $self->print_crisis_bar(); |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
else |
189
|
|
|
|
|
|
|
{ |
190
|
0
|
|
|
|
|
0
|
return $out . " " . $self->print_grey_crisis_bar(); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
else |
194
|
|
|
|
|
|
|
{ |
195
|
0
|
|
|
|
|
0
|
return ""; |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
sub html_crisis |
199
|
|
|
|
|
|
|
{ |
200
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
201
|
0
|
|
|
|
|
0
|
return encode_entities($self->print_crisis(0)); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
sub print_grey_crisis_bar |
204
|
|
|
|
|
|
|
{ |
205
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
206
|
0
|
|
|
|
|
0
|
my $out = ""; |
207
|
0
|
0
|
|
|
|
0
|
if($self->get_crisis_level > 0) |
208
|
|
|
|
|
|
|
{ |
209
|
0
|
|
|
|
|
0
|
$out .= "["; |
210
|
0
|
|
|
|
|
0
|
for(my $i = 0; $i < CRISIS_MAX_FACTOR; $i++) |
211
|
|
|
|
|
|
|
{ |
212
|
0
|
0
|
|
|
|
0
|
if($i < $self->get_crisis_level) |
213
|
|
|
|
|
|
|
{ |
214
|
0
|
|
|
|
|
0
|
$out .= "*"; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
else |
217
|
|
|
|
|
|
|
{ |
218
|
0
|
|
|
|
|
0
|
$out .= " "; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
} |
221
|
0
|
|
|
|
|
0
|
$out .= "]"; |
222
|
|
|
|
|
|
|
} |
223
|
0
|
|
|
|
|
0
|
return $out; |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
sub print_crisis_bar |
226
|
|
|
|
|
|
|
{ |
227
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
228
|
0
|
|
|
|
|
0
|
return $self->status_color . $self->print_grey_crisis_bar . color("reset"); |
229
|
|
|
|
|
|
|
} |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
sub change_factor |
232
|
|
|
|
|
|
|
{ |
233
|
42
|
|
|
42
|
0
|
55
|
my $self = shift; |
234
|
42
|
|
|
|
|
60
|
my $delta = shift; |
235
|
42
|
|
|
|
|
91
|
my $new_factor = $self->factor + $delta; |
236
|
42
|
100
|
|
|
|
130
|
$new_factor = $new_factor < 0 ? 0 : $new_factor > 100 ? 100 : $new_factor; |
|
|
100
|
|
|
|
|
|
237
|
42
|
|
|
|
|
102
|
$self->factor($new_factor); |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub escalate_crisis |
241
|
|
|
|
|
|
|
{ |
242
|
27
|
|
|
27
|
0
|
47
|
my $self = shift; |
243
|
27
|
50
|
|
|
|
117
|
if($self->crisis_level < CRISIS_MAX_FACTOR) |
244
|
|
|
|
|
|
|
{ |
245
|
27
|
|
|
|
|
144
|
$self->crisis_level($self->crisis_level() + 1); |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
sub cooldown_crisis |
249
|
|
|
|
|
|
|
{ |
250
|
5
|
|
|
5
|
0
|
11
|
my $self = shift; |
251
|
5
|
100
|
|
|
|
27
|
if($self->crisis_level > 0) |
252
|
|
|
|
|
|
|
{ |
253
|
2
|
|
|
|
|
13
|
$self->crisis_level($self->crisis_level() - 1); |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
sub is_crisis |
257
|
|
|
|
|
|
|
{ |
258
|
684
|
|
|
684
|
0
|
588
|
my $self = shift; |
259
|
684
|
|
|
|
|
891
|
return $self->get_crisis_level() > 0; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
sub is_max_crisis |
262
|
|
|
|
|
|
|
{ |
263
|
10
|
|
|
10
|
0
|
18
|
my $self = shift; |
264
|
10
|
|
|
|
|
28
|
return $self->get_crisis_level() == CRISIS_MAX_FACTOR; |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
sub dump |
267
|
|
|
|
|
|
|
{ |
268
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
269
|
0
|
|
|
|
|
|
my $io = shift; |
270
|
0
|
|
0
|
|
|
|
my $indent = shift || ""; |
271
|
0
|
|
|
|
|
|
print {$io} $indent . join(";", $self->node1, $self->node2, $self->factor, $self->crisis_level) . "\n"; |
|
0
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
sub load |
274
|
|
|
|
|
|
|
{ |
275
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
276
|
0
|
|
|
|
|
|
my $data = shift; |
277
|
0
|
|
|
|
|
|
$data =~ s/^\s+//; |
278
|
0
|
|
|
|
|
|
chomp $data; |
279
|
0
|
|
|
|
|
|
my ($node1, $node2, $factor, $crisis_level) = split ";", $data; |
280
|
0
|
|
|
|
|
|
return $self->new(node1 => $node1, node2 => $node2, factor => $factor, crisis_level => $crisis_level); |
281
|
|
|
|
|
|
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
1; |