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 = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100; |
|
|
93 | |
|
|
94 | if (defined $input_level) { |
|
|
95 | my $subexp = |
|
|
96 | (cf::level_to_min_exp ($input_level) |
|
|
97 | - cf::level_to_min_exp ($input_level - 1)) |
|
|
98 | / 100; |
|
|
99 | $exp -= $subexp; |
|
|
100 | $exp = max ($exp, 0); |
|
|
101 | } |
|
|
102 | |
92 | |
103 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
93 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
|
|
94 | $pl->message ( |
104 | $pl->message ("You succeed and get $exp experience points."); |
95 | "You succeed and get " . int ($exp) . " experience points."); |
105 | $make_status = "succeeded"; |
96 | $make_status = "succeeded"; |
106 | |
97 | |
107 | $ring->set_value ($value * 0.8); # 20% of the input values will vanish |
98 | $ring->set_value ($value * 0.8); # 20% of the input values will vanish |
108 | |
99 | |
109 | } else { |
100 | } else { |
… | |
… | |
122 | "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s", |
113 | "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s", |
123 | $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl, |
114 | $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl, |
124 | $ring->power_to_level, $exp, $make_status; |
115 | $ring->power_to_level, $exp, $make_status; |
125 | |
116 | |
126 | warn "$make_info\n" if $make_status eq 'succeeded'; |
117 | warn "$make_info\n" if $make_status eq 'succeeded'; |
127 | |
|
|
128 | $ring_ob->set_ob_key_value (ext_jeweler_made_by => $pl->name); |
|
|
129 | $ring_ob->set_ob_key_value (ext_jeweler_make_info => $make_info); |
|
|
130 | } |
118 | } |
131 | |
119 | |
132 | $chdl->put ($ring_ob); |
120 | $chdl->put ($ring_ob); |
133 | } |
121 | } |
134 | |
122 | |
… | |
… | |
162 | if ($ringo->has_resist ($1)) { |
150 | if ($ringo->has_resist ($1)) { |
163 | $self->map->trigger ( |
151 | $self->map->trigger ( |
164 | $cfg->{connection}, |
152 | $cfg->{connection}, |
165 | $cfg->{state} |
153 | $cfg->{state} |
166 | ); |
154 | ); |
|
|
155 | $obj->decrease (1); |
167 | cf::override; |
156 | cf::override; |
168 | } |
157 | } |
169 | } |
158 | } |
170 | } |
159 | } |
171 | } |
160 | } |
… | |
… | |
222 | my $plan = $ingred->get_plan; |
211 | my $plan = $ingred->get_plan; |
223 | |
212 | |
224 | if ($plan) { |
213 | if ($plan) { |
225 | my @ring = $ingred->get_ring; |
214 | my @ring = $ingred->get_ring; |
226 | |
215 | |
|
|
216 | if (!@ring) { |
|
|
217 | # actually the algorithm cant |
|
|
218 | $pl->message ("You slap yourself, you forgot the jewelery!"); |
|
|
219 | return; |
|
|
220 | |
227 | if ((@ring > 1) || ($ring[0]->nrof > 1)) { |
221 | } elsif ((@ring > 1) || (grep { $_->nrof > 1 } @ring)) { |
228 | # actually the algorithm cant handle more than one improvement at a time |
222 | # actually the algorithm cant handle more than one improvement at a time |
229 | $pl->message ("You can't manage to improve more than one thing at a time!"); |
223 | $pl->message ("You can't manage to improve more than one thing at a time!"); |
230 | return; |
224 | return; |
231 | |
|
|
232 | } elsif (@ring < 1) { |
|
|
233 | # actually the algorithm cant |
|
|
234 | $pl->message ("You slap yourself, you forgot the jewelery!"); |
|
|
235 | return; |
|
|
236 | |
|
|
237 | } else { |
225 | } else { |
238 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
226 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
239 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
227 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
240 | my $c1 = $ringo->calc_costs; |
228 | my $c1 = $ringo->calc_costs; |
241 | my $c2 = $iring->calc_costs; |
229 | my $c2 = $iring->calc_costs; |
242 | my $value = $iring->calc_value_from_cost ($c2); |
230 | my $value = $iring->calc_value_from_cost ($c2); |
|
|
231 | |
|
|
232 | if ((not defined $c1) || (not defined $c2)) { |
|
|
233 | $pl->message ("The jewel has or will become a resistancy above 99%,\n" |
|
|
234 | ."that is completly impossible to make!"); |
|
|
235 | return; |
|
|
236 | } |
243 | |
237 | |
244 | my %keys; |
238 | my %keys; |
245 | my %cdiff; |
239 | my %cdiff; |
246 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
240 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
247 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } |
241 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } |
… | |
… | |
277 | }; |
271 | }; |
278 | $@ and warn "ERROR: $@\n"; |
272 | $@ and warn "ERROR: $@\n"; |
279 | } |
273 | } |
280 | ); |
274 | ); |
281 | |
275 | |
282 | Jeweler::read_config (cf::datadir . '/jeweler.yaml'); |
276 | Jeweler::read_config "res/jeweler.yaml"; |
|
|
277 | |