… | |
… | |
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) || []} }; |
… | |
… | |
584 | @grepar = ('gems', undef, undef, $key); |
586 | @grepar = ('gems', undef, undef, $key); |
585 | } |
587 | } |
586 | |
588 | |
587 | if ($do_remove) { |
589 | if ($do_remove) { |
588 | my $rem = $costs->{$key}; |
590 | my $rem = $costs->{$key}; |
|
|
591 | $self->do_grep (sub { |
589 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
592 | if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } |
|
|
593 | 1 |
|
|
594 | }, @grepar); |
590 | if ($rem > 0) { |
595 | if ($rem > 0) { |
591 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
596 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
592 | } |
597 | } |
|
|
598 | |
593 | } else { |
599 | } else { |
594 | my $nr; |
600 | my $nr; |
595 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
601 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
596 | $costs->{$key} -= $nr; |
602 | $costs->{$key} -= $nr; |
597 | } |
603 | } |
… | |
… | |
661 | $exp -= $subexp; |
667 | $exp -= $subexp; |
662 | $exp = max ($exp, 0); |
668 | $exp = max ($exp, 0); |
663 | |
669 | |
664 | } else { |
670 | } else { |
665 | # the experience bonus here is to make level 1 rings give you at least |
671 | # the experience bonus here is to make level 1 rings give you at least |
666 | # 100 exp points when making them. This also makes leveling in the |
672 | # 200 exp points when making them. This also makes leveling in the |
667 | # first few levels a bit easier. (probably until around level 5-6). |
673 | # first few levels a bit easier. (probably until around level 5-6). |
668 | my $expbonus = cf::level_to_min_exp (2) / 10; |
674 | my $expbonus = cf::level_to_min_exp (2) / 5; |
669 | # this bonus should also only be given for _new_ rings and not for merged |
675 | # this bonus should also only be given for _new_ rings and not for merged |
670 | # ones - to prevent infinite exp making. |
676 | # ones - to prevent infinite exp making. |
671 | $exp += $expbonus; |
677 | $exp += $expbonus; |
672 | } |
678 | } |
673 | |
679 | |
… | |
… | |
717 | if (defined $costs) { |
723 | if (defined $costs) { |
718 | my $desc = ""; |
724 | my $desc = ""; |
719 | my $lvl = $self->power_to_level (\$desc); |
725 | my $lvl = $self->power_to_level (\$desc); |
720 | my $scosts = $self->calc_value_from_cost ($costs); |
726 | my $scosts = $self->calc_value_from_cost ($costs); |
721 | |
727 | |
722 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
728 | $pl->message ("costs: " |
|
|
729 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
|
|
730 | . " (" |
|
|
731 | . ($scosts / "platinacoin"->cf::arch::find->value) |
|
|
732 | . " platinum)"); |
723 | $pl->message ("level: " . $desc); |
733 | $pl->message ("level: $desc"); |
724 | } else { |
734 | } else { |
725 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
735 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
726 | } |
736 | } |
727 | } |
737 | } |
728 | |
738 | |
… | |
… | |
1094 | =over 4 |
1104 | =over 4 |
1095 | |
1105 | |
1096 | =item remove ($object[, $nrof]) |
1106 | =item remove ($object[, $nrof]) |
1097 | |
1107 | |
1098 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1108 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1099 | The returnvalue is the number of 'single' objects that couldn't be removed. |
1109 | The return value is the number of 'single' objects that couldn't be removed. |
1100 | |
1110 | |
1101 | =cut |
1111 | =cut |
1102 | |
1112 | |
1103 | sub remove { |
1113 | sub remove { |
1104 | my ($obj, $nrof) = @_; |
1114 | my ($obj, $nrof) = @_; |
|
|
1115 | |
|
|
1116 | my $c = $obj->nrof || 1; |
|
|
1117 | my $r = $c > $nrof ? 0 : $nrof - $c; |
|
|
1118 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1105 | |
1119 | |
1106 | my $cnt; |
1120 | $r |
1107 | |
|
|
1108 | if (defined $nrof) { |
|
|
1109 | # TODO: Check tihis line: |
|
|
1110 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
|
|
1111 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
|
|
1112 | |
|
|
1113 | if ($cnt > 0) { |
|
|
1114 | $obj->nrof ($cnt); |
|
|
1115 | return 0; |
|
|
1116 | } |
|
|
1117 | } |
|
|
1118 | |
|
|
1119 | remove ($_) for $obj->inv; |
|
|
1120 | $obj->destroy; |
|
|
1121 | return $cnt; |
|
|
1122 | } |
1121 | } |
1123 | |
1122 | |
1124 | sub check_for_match { |
1123 | sub check_for_match { |
1125 | my ($thing, @matchar) = @_; |
1124 | my ($thing, @matchar) = @_; |
1126 | |
1125 | |