… | |
… | |
24 | our $CFG; |
24 | our $CFG; |
25 | |
25 | |
26 | sub read_config { |
26 | sub read_config { |
27 | my ($filename) = @_; |
27 | my ($filename) = @_; |
28 | |
28 | |
29 | unless (-e $filename) { |
29 | if (my $meta = $cf::RESOURCE{$filename}) { |
|
|
30 | $CFG = cf::decode_json $meta->{data}; |
|
|
31 | } else { |
30 | warn "$filename doesn't exists! no config for jeweler skill loaded!\n"; |
32 | warn "$filename doesn't exist! no config for jeweler skill loaded!\n"; |
31 | $CFG = {}; |
33 | $CFG = {}; |
32 | return |
|
|
33 | } |
34 | } |
34 | |
|
|
35 | $CFG = YAML::LoadFile $filename; |
|
|
36 | } |
35 | } |
37 | |
36 | |
38 | sub getcfg { |
37 | sub getcfg { |
39 | my ($sect, $key) = @_; |
38 | my ($sect, $key) = @_; |
40 | return $CFG->{$sect} unless defined $key; |
39 | return $CFG->{$sect} unless defined $key; |
… | |
… | |
165 | |
164 | |
166 | sub analyze { |
165 | sub analyze { |
167 | my ($sk, $chdl, $pl, $input_level) = @_; |
166 | my ($sk, $chdl, $pl, $input_level) = @_; |
168 | |
167 | |
169 | my $hadunid = 0; |
168 | my $hadunid = 0; |
|
|
169 | my $found = 0; |
170 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
170 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
171 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
171 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
172 | $hadunid = 1; |
172 | $hadunid = 1; |
173 | next; |
173 | next; |
174 | } |
174 | } |
|
|
175 | $found = 1; |
175 | my $r = Jeweler::Object->new (object => $_); |
176 | my $r = Jeweler::Object->new (object => $_); |
176 | my $msg = $r->analyze ($sk, $pl, $input_level); |
177 | my $msg = $r->analyze ($sk, $pl, $input_level); |
177 | $pl->message ($r->to_string . ": " . $msg); |
178 | $pl->message ($r->to_string . ": " . $msg); |
178 | if ($pl->flag (cf::FLAG_WIZ)) { |
179 | if ($pl->flag (cf::FLAG_WIZ)) { |
179 | $r->wiz_analyze ($pl); |
180 | $r->wiz_analyze ($pl); |
180 | } |
181 | } |
181 | } |
182 | } |
182 | if ($hadunid) { |
|
|
183 | $pl->message ("You couldn't identify the other rings and not analyze them!"); |
183 | $pl->message ("You couldn't identify the other rings and not analyze them!") |
184 | } |
184 | if $hadunid; |
|
|
185 | $pl->message ("You couldn't find anything in the bench to analyse!") |
|
|
186 | unless $found; |
185 | } |
187 | } |
186 | |
188 | |
187 | # this function converts metals/minerals into a raw ring (of adornment) |
189 | # this function converts metals/minerals into a raw ring (of adornment) |
188 | sub simple_converter { |
190 | sub simple_converter { |
189 | my ($pl, $ingred, $chdl, $conv) = @_; |
191 | my ($pl, $ingred, $chdl, $conv) = @_; |
… | |
… | |
203 | warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; |
205 | warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; |
204 | return; |
206 | return; |
205 | } |
207 | } |
206 | |
208 | |
207 | unless ($xp_gain > 0) { |
209 | unless ($xp_gain > 0) { |
208 | warn "WARNING: xp gain isn't > 0 in convesion '$outarch'\n"; |
210 | warn "WARNING: xp gain isn't > 0 in conversion '$outarch'\n"; |
209 | return; |
211 | return; |
210 | } |
212 | } |
211 | |
213 | |
212 | unless ($outarchvalfact) { |
214 | unless ($outarchvalfact) { |
213 | warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; |
215 | warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; |
… | |
… | |
221 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
223 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
222 | $ingred->remove ($ingr_grp, $srcarchname); |
224 | $ingred->remove ($ingr_grp, $srcarchname); |
223 | |
225 | |
224 | my $outarchval = cf::arch::find ($outarch)->value; |
226 | my $outarchval = cf::arch::find ($outarch)->value; |
225 | |
227 | |
226 | my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); |
228 | my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact); |
227 | if ($nrof) { |
229 | if ($nrof) { |
228 | # XXX: yes, i know what i'm doing here, i don't set nrof, but it didn't work somehow (pls. chek sometimes) |
230 | # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes) |
229 | for (1..$nrof) { |
231 | for (1 .. $nrof) { |
230 | $chdl->put (my $ob = cf::object::new $outarch); |
232 | $chdl->put (my $ob = cf::object::new $outarch); |
231 | $ob->set_animation (cf::rndm $ob->num_animations) |
233 | $ob->set_animation (cf::rndm $ob->num_animations) |
232 | if ($ob->type == cf::RING); |
234 | if ($ob->type == cf::RING); |
233 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
235 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
234 | } |
236 | } |
235 | |
237 | |
236 | my $xp_sum = ($xp_gain * $nrof); |
238 | my $xp_sum = $xp_gain * $nrof; |
237 | |
239 | |
238 | if ($xp_sum) { |
240 | if ($xp_sum) { |
239 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
241 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
240 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
242 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
241 | } |
243 | } |
… | |
… | |
477 | } |
479 | } |
478 | |
480 | |
479 | sub improve_ring_by_plan { |
481 | sub improve_ring_by_plan { |
480 | my ($self, $plan, $ring) = @_; |
482 | my ($self, $plan, $ring) = @_; |
481 | |
483 | |
482 | $ring = dclone ($ring); |
484 | $ring = do { my $guard = Coro::Storable::guard; dclone $ring }; |
483 | |
485 | |
484 | my $ingred = $self->{ingredients}; |
486 | my $ingred = $self->{ingredients}; |
485 | my $impr = {}; |
487 | my $impr = {}; |
486 | |
488 | |
487 | if ($plan =~ m/^stat_(\S+)$/) { |
489 | if ($plan =~ m/^stat_(\S+)$/) { |
… | |
… | |
571 | } |
573 | } |
572 | |
574 | |
573 | sub check_costs { |
575 | sub check_costs { |
574 | my ($self, $costs, $do_remove) = @_; |
576 | my ($self, $costs, $do_remove) = @_; |
575 | |
577 | |
576 | my $costs = dclone ($costs); |
578 | my $costs = do { my $guard = Coro::Storable::guard; dclone $costs }; |
577 | |
579 | |
578 | for my $key (keys %$costs) { |
580 | for my $key (keys %$costs) { |
579 | my @grepar; |
581 | my @grepar; |
580 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
582 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
581 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
583 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
… | |
… | |
717 | if (defined $costs) { |
719 | if (defined $costs) { |
718 | my $desc = ""; |
720 | my $desc = ""; |
719 | my $lvl = $self->power_to_level (\$desc); |
721 | my $lvl = $self->power_to_level (\$desc); |
720 | my $scosts = $self->calc_value_from_cost ($costs); |
722 | my $scosts = $self->calc_value_from_cost ($costs); |
721 | |
723 | |
722 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
724 | $pl->message ("costs: " |
|
|
725 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
|
|
726 | . " (" |
|
|
727 | . ($scosts / "royalty"->cf::arch::find->value) |
|
|
728 | . " royalties)"); |
723 | $pl->message ("level: " . $desc); |
729 | $pl->message ("level: $desc"); |
724 | } else { |
730 | } else { |
725 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
731 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
726 | } |
732 | } |
727 | } |
733 | } |
728 | |
734 | |