1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | use Data::Dumper; |
3 | use strict; |
|
|
4 | |
4 | use Jeweler; |
5 | use Jeweler; |
5 | use List::Util qw/max min sum/; |
6 | use List::Util qw/max min sum/; |
6 | use strict; |
|
|
7 | |
7 | |
8 | sub ingred_alias { |
8 | sub ingred_alias { |
9 | my ($ing) = @_; |
9 | my ($ing) = @_; |
10 | |
10 | |
11 | my %aliases = ( |
11 | my %aliases = ( |
… | |
… | |
48 | |
48 | |
49 | my @ring = $ingred->get_ring; |
49 | my @ring = $ingred->get_ring; |
50 | my @rings = map { Jeweler::Object->new (object => $_) } @ring; |
50 | my @rings = map { Jeweler::Object->new (object => $_) } @ring; |
51 | |
51 | |
52 | @rings >= 2 |
52 | @rings >= 2 |
53 | or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); |
53 | or return $pl->message ("You slap yourself, you forgot to put at least 2 jewels in!"); |
54 | |
54 | |
55 | my $input_level; |
55 | my $input_level = 0; |
56 | my $value; |
56 | my $value; |
57 | for (@rings) { |
57 | for (@rings) { |
58 | $input_level = max ($_->power_to_level, $input_level); |
58 | $input_level = max ($_->power_to_level, $input_level); |
59 | $value += $_->{hash}->{value}; |
59 | $value += $_->{hash}->{value}; |
60 | } |
60 | } |
61 | |
61 | |
62 | my $ring = shift @rings; |
62 | my $ring = shift @rings; |
63 | $ring->improve_by_ring (@rings); |
63 | $ring->improve_by_ring (@rings); |
64 | |
64 | |
65 | if ($do_analyze) { |
65 | if ($do_analyze) { |
66 | $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl)); |
66 | $pl->message ("You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl, $input_level)); |
67 | $ring->wiz_analyze ($pl) |
67 | $ring->wiz_analyze ($pl) |
68 | if $pl->flag (cf::FLAG_WIZ); |
68 | if $pl->flag (cf::FLAG_WIZ); |
69 | return; |
69 | return; |
70 | } |
70 | } |
71 | |
71 | |
… | |
… | |
86 | |
86 | |
87 | my $make_status; |
87 | my $make_status; |
88 | my $exp; |
88 | my $exp; |
89 | |
89 | |
90 | if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { |
90 | if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { |
91 | my $lvl = max ($ring->power_to_level, 1); |
91 | $exp = $ring->projected_exp ($input_level); |
92 | $exp = |
|
|
93 | (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) |
|
|
94 | / (10 + max ($lvl - 1, 0)); |
|
|
95 | # divided by 10 + level |
|
|
96 | |
|
|
97 | if (defined $input_level) { |
|
|
98 | my $subexp = |
|
|
99 | (cf::level_to_min_exp ($input_level) |
|
|
100 | - cf::level_to_min_exp ($input_level - 1)) |
|
|
101 | / (10 + max ($input_level - 1, 0)); |
|
|
102 | $exp -= $subexp; |
|
|
103 | $exp = max ($exp, 0); |
|
|
104 | } |
|
|
105 | |
92 | |
106 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
93 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
107 | $pl->message ("You succeed and get $exp experience points."); |
94 | $pl->message ("You succeed and get $exp experience points."); |
108 | $make_status = "succeeded"; |
95 | $make_status = "succeeded"; |
109 | |
96 | |
… | |
… | |
125 | "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s", |
112 | "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s", |
126 | $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl, |
113 | $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl, |
127 | $ring->power_to_level, $exp, $make_status; |
114 | $ring->power_to_level, $exp, $make_status; |
128 | |
115 | |
129 | warn "$make_info\n" if $make_status eq 'succeeded'; |
116 | warn "$make_info\n" if $make_status eq 'succeeded'; |
130 | |
|
|
131 | $ring_ob->set_ob_key_value (ext_jeweler_made_by => $pl->name); |
|
|
132 | $ring_ob->set_ob_key_value (ext_jeweler_make_info => $make_info); |
|
|
133 | } |
117 | } |
134 | |
118 | |
135 | $chdl->put ($ring_ob); |
119 | $chdl->put ($ring_ob); |
136 | } |
120 | } |
137 | |
121 | |
… | |
… | |
225 | my $plan = $ingred->get_plan; |
209 | my $plan = $ingred->get_plan; |
226 | |
210 | |
227 | if ($plan) { |
211 | if ($plan) { |
228 | my @ring = $ingred->get_ring; |
212 | my @ring = $ingred->get_ring; |
229 | |
213 | |
|
|
214 | if (!@ring) { |
|
|
215 | # actually the algorithm cant |
|
|
216 | $pl->message ("You slap yourself, you forgot the jewelery!"); |
|
|
217 | return; |
|
|
218 | |
230 | if ((@ring > 1) || ($ring[0]->nrof > 1)) { |
219 | } elsif ((@ring > 1) || (grep { $_->nrof > 1 } @ring)) { |
231 | # actually the algorithm cant handle more than one improvement at a time |
220 | # actually the algorithm cant handle more than one improvement at a time |
232 | $pl->message ("You can't manage to improve more than one thing at a time!"); |
221 | $pl->message ("You can't manage to improve more than one thing at a time!"); |
233 | return; |
222 | return; |
234 | |
|
|
235 | } elsif (@ring < 1) { |
|
|
236 | # actually the algorithm cant |
|
|
237 | $pl->message ("You slap yourself, you forgot the jewelery!"); |
|
|
238 | return; |
|
|
239 | |
|
|
240 | } else { |
223 | } else { |
241 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
224 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
242 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
225 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
243 | my $c1 = $ringo->calc_costs; |
226 | my $c1 = $ringo->calc_costs; |
244 | my $c2 = $iring->calc_costs; |
227 | my $c2 = $iring->calc_costs; |
245 | my $value = $iring->calc_value_from_cost ($c2); |
228 | my $value = $iring->calc_value_from_cost ($c2); |
|
|
229 | |
|
|
230 | if ((not defined $c1) || (not defined $c2)) { |
|
|
231 | $pl->message ("The jewel has or will become a resistancy above 99%,\n" |
|
|
232 | ."that is completly impossible to make!"); |
|
|
233 | return; |
|
|
234 | } |
246 | |
235 | |
247 | my %keys; |
236 | my %keys; |
248 | my %cdiff; |
237 | my %cdiff; |
249 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
238 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
250 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } |
239 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } |
… | |
… | |
280 | }; |
269 | }; |
281 | $@ and warn "ERROR: $@\n"; |
270 | $@ and warn "ERROR: $@\n"; |
282 | } |
271 | } |
283 | ); |
272 | ); |
284 | |
273 | |
285 | Jeweler::read_config (cf::datadir . '/jeweler.yaml'); |
274 | Jeweler::read_config "res/jeweler.yaml"; |
|
|
275 | |