… | |
… | |
8 | |
8 | |
9 | =cut |
9 | =cut |
10 | |
10 | |
11 | package Jeweler; |
11 | package Jeweler; |
12 | |
12 | |
13 | use strict; |
13 | use common::sense; |
14 | use YAML; |
|
|
15 | |
14 | |
16 | =over 4 |
15 | =over 4 |
17 | |
16 | |
18 | =item @RESISTS |
17 | =item @RESISTS |
19 | |
18 | |
… | |
… | |
24 | our $CFG; |
23 | our $CFG; |
25 | |
24 | |
26 | sub read_config { |
25 | sub read_config { |
27 | my ($filename) = @_; |
26 | my ($filename) = @_; |
28 | |
27 | |
29 | unless (-e $filename) { |
28 | if (my $meta = $cf::RESOURCE{$filename}) { |
|
|
29 | $CFG = cf::decode_json $meta->{data}; |
|
|
30 | } else { |
30 | warn "$filename doesn't exists! no config for jeweler skill loaded!\n"; |
31 | warn "$filename doesn't exist! no config for jeweler skill loaded!\n"; |
31 | $CFG = {}; |
32 | $CFG = {}; |
32 | return |
|
|
33 | } |
33 | } |
34 | |
|
|
35 | $CFG = YAML::LoadFile $filename; |
|
|
36 | } |
34 | } |
37 | |
35 | |
38 | sub getcfg { |
36 | sub getcfg { |
39 | my ($sect, $key) = @_; |
37 | my ($sect, $key) = @_; |
40 | return $CFG->{$sect} unless defined $key; |
38 | return $CFG->{$sect} unless defined $key; |
… | |
… | |
165 | |
163 | |
166 | sub analyze { |
164 | sub analyze { |
167 | my ($sk, $chdl, $pl, $input_level) = @_; |
165 | my ($sk, $chdl, $pl, $input_level) = @_; |
168 | |
166 | |
169 | my $hadunid = 0; |
167 | my $hadunid = 0; |
|
|
168 | my $found = 0; |
170 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
169 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
171 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
170 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
172 | $hadunid = 1; |
171 | $hadunid = 1; |
173 | next; |
172 | next; |
174 | } |
173 | } |
|
|
174 | $found = 1; |
175 | my $r = Jeweler::Object->new (object => $_); |
175 | my $r = Jeweler::Object->new (object => $_); |
176 | my $msg = $r->analyze ($sk, $pl, $input_level); |
176 | my $msg = $r->analyze ($sk, $pl, $input_level); |
177 | $pl->message ($r->to_string . ": " . $msg); |
177 | $pl->message ($r->to_string . ": " . $msg); |
178 | if ($pl->flag (cf::FLAG_WIZ)) { |
178 | if ($pl->flag (cf::FLAG_WIZ)) { |
179 | $r->wiz_analyze ($pl); |
179 | $r->wiz_analyze ($pl); |
180 | } |
180 | } |
181 | } |
181 | } |
182 | if ($hadunid) { |
|
|
183 | $pl->message ("You couldn't identify the other rings and not analyze them!"); |
182 | $pl->message ("You couldn't identify the other rings and not analyze them!") |
184 | } |
183 | if $hadunid; |
|
|
184 | $pl->message ("You couldn't find anything in the bench to analyse!") |
|
|
185 | unless $found; |
185 | } |
186 | } |
186 | |
187 | |
187 | # this function converts metals/minerals into a raw ring (of adornment) |
188 | # this function converts metals/minerals into a raw ring (of adornment) |
188 | sub simple_converter { |
189 | sub simple_converter { |
189 | my ($pl, $ingred, $chdl, $conv) = @_; |
190 | my ($pl, $ingred, $chdl, $conv) = @_; |
… | |
… | |
203 | warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; |
204 | warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; |
204 | return; |
205 | return; |
205 | } |
206 | } |
206 | |
207 | |
207 | unless ($xp_gain > 0) { |
208 | unless ($xp_gain > 0) { |
208 | warn "WARNING: xp gain isn't > 0 in convesion '$outarch'\n"; |
209 | warn "WARNING: xp gain isn't > 0 in conversion '$outarch'\n"; |
209 | return; |
210 | return; |
210 | } |
211 | } |
211 | |
212 | |
212 | unless ($outarchvalfact) { |
213 | unless ($outarchvalfact) { |
213 | warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; |
214 | warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; |
… | |
… | |
221 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
222 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
222 | $ingred->remove ($ingr_grp, $srcarchname); |
223 | $ingred->remove ($ingr_grp, $srcarchname); |
223 | |
224 | |
224 | my $outarchval = cf::arch::find ($outarch)->value; |
225 | my $outarchval = cf::arch::find ($outarch)->value; |
225 | |
226 | |
226 | my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); |
227 | my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact); |
227 | if ($nrof) { |
228 | 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) |
229 | # 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) { |
230 | for (1 .. $nrof) { |
230 | $chdl->put (my $ob = cf::object::new $outarch); |
231 | $chdl->put (my $ob = cf::object::new $outarch); |
231 | $ob->set_animation (cf::rndm $ob->num_animations) |
232 | $ob->set_animation (cf::rndm $ob->num_animations) |
232 | if ($ob->type == cf::RING); |
233 | if ($ob->type == cf::RING); |
233 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
234 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
234 | } |
235 | } |
235 | |
236 | |
236 | my $xp_sum = ($xp_gain * $nrof); |
237 | my $xp_sum = $xp_gain * $nrof; |
237 | |
238 | |
238 | if ($xp_sum) { |
239 | if ($xp_sum) { |
239 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
240 | $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); |
241 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
241 | } |
242 | } |
… | |
… | |
355 | |
356 | |
356 | sub put { |
357 | sub put { |
357 | my ($self, $obj) = @_; |
358 | my ($self, $obj) = @_; |
358 | |
359 | |
359 | return undef unless $self->{cauldron}; |
360 | return undef unless $self->{cauldron}; |
360 | $obj->insert_ob_in_ob ($self->{cauldron}); |
361 | $self->{cauldron}->insert ($obj); |
361 | } |
362 | } |
362 | |
363 | |
363 | =back |
364 | =back |
364 | |
365 | |
365 | =cut |
366 | =cut |
… | |
… | |
477 | } |
478 | } |
478 | |
479 | |
479 | sub improve_ring_by_plan { |
480 | sub improve_ring_by_plan { |
480 | my ($self, $plan, $ring) = @_; |
481 | my ($self, $plan, $ring) = @_; |
481 | |
482 | |
482 | $ring = dclone ($ring); |
483 | $ring = dclone $ring; |
483 | |
484 | |
484 | my $ingred = $self->{ingredients}; |
485 | my $ingred = $self->{ingredients}; |
485 | my $impr = {}; |
486 | my $impr = {}; |
486 | |
487 | |
487 | if ($plan =~ m/^stat_(\S+)$/) { |
488 | if ($plan =~ m/^stat_(\S+)$/) { |
… | |
… | |
571 | } |
572 | } |
572 | |
573 | |
573 | sub check_costs { |
574 | sub check_costs { |
574 | my ($self, $costs, $do_remove) = @_; |
575 | my ($self, $costs, $do_remove) = @_; |
575 | |
576 | |
576 | my $costs = dclone ($costs); |
577 | my $costs = dclone $costs; |
577 | |
578 | |
578 | for my $key (keys %$costs) { |
579 | for my $key (keys %$costs) { |
579 | my @grepar; |
580 | my @grepar; |
580 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
581 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
581 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
582 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
… | |
… | |
584 | @grepar = ('gems', undef, undef, $key); |
585 | @grepar = ('gems', undef, undef, $key); |
585 | } |
586 | } |
586 | |
587 | |
587 | if ($do_remove) { |
588 | if ($do_remove) { |
588 | my $rem = $costs->{$key}; |
589 | my $rem = $costs->{$key}; |
|
|
590 | $self->do_grep (sub { |
589 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
591 | if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } |
|
|
592 | 1 |
|
|
593 | }, @grepar); |
590 | if ($rem > 0) { |
594 | if ($rem > 0) { |
591 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
595 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
592 | } |
596 | } |
|
|
597 | |
593 | } else { |
598 | } else { |
594 | my $nr; |
599 | my $nr; |
595 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
600 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
596 | $costs->{$key} -= $nr; |
601 | $costs->{$key} -= $nr; |
597 | } |
602 | } |
… | |
… | |
661 | $exp -= $subexp; |
666 | $exp -= $subexp; |
662 | $exp = max ($exp, 0); |
667 | $exp = max ($exp, 0); |
663 | |
668 | |
664 | } else { |
669 | } else { |
665 | # the experience bonus here is to make level 1 rings give you at least |
670 | # 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 |
671 | # 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). |
672 | # first few levels a bit easier. (probably until around level 5-6). |
668 | my $expbonus = cf::level_to_min_exp (2) / 10; |
673 | my $expbonus = cf::level_to_min_exp (2) / 5; |
669 | # this bonus should also only be given for _new_ rings and not for merged |
674 | # this bonus should also only be given for _new_ rings and not for merged |
670 | # ones - to prevent infinite exp making. |
675 | # ones - to prevent infinite exp making. |
671 | $exp += $expbonus; |
676 | $exp += $expbonus; |
672 | } |
677 | } |
673 | |
678 | |
… | |
… | |
717 | if (defined $costs) { |
722 | if (defined $costs) { |
718 | my $desc = ""; |
723 | my $desc = ""; |
719 | my $lvl = $self->power_to_level (\$desc); |
724 | my $lvl = $self->power_to_level (\$desc); |
720 | my $scosts = $self->calc_value_from_cost ($costs); |
725 | my $scosts = $self->calc_value_from_cost ($costs); |
721 | |
726 | |
722 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
727 | $pl->message ("costs: " |
|
|
728 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
|
|
729 | . " (" |
|
|
730 | . ($scosts / "platinacoin"->cf::arch::find->value) |
|
|
731 | . " platinum)"); |
723 | $pl->message ("level: " . $desc); |
732 | $pl->message ("level: $desc"); |
724 | } else { |
733 | } else { |
725 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
734 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
726 | } |
735 | } |
727 | } |
736 | } |
728 | |
737 | |
… | |
… | |
1065 | my ($cost, $diamonds, $category) = @_; |
1074 | my ($cost, $diamonds, $category) = @_; |
1066 | |
1075 | |
1067 | my $stat_split = Jeweler::getcfg (diamond_split => $category); |
1076 | my $stat_split = Jeweler::getcfg (diamond_split => $category); |
1068 | |
1077 | |
1069 | my $sum = sum (@$stat_split); |
1078 | my $sum = sum (@$stat_split); |
1070 | if ($sum < (1 - 0.0001)) { |
|
|
1071 | warn "JEWELER BUG: sum (@$stat_split) = $sum < 1 for $category!"; |
|
|
1072 | } |
|
|
1073 | |
1079 | |
1074 | my $emarch = cf::arch::find 'emerald'; |
1080 | my $emarch = cf::arch::find 'emerald'; |
1075 | my $saarch = cf::arch::find 'sapphire'; |
1081 | my $saarch = cf::arch::find 'sapphire'; |
1076 | my $pearch = cf::arch::find 'pearl'; |
1082 | my $pearch = cf::arch::find 'pearl'; |
1077 | my $ruarch = cf::arch::find 'ruby'; |
1083 | my $ruarch = cf::arch::find 'ruby'; |
… | |
… | |
1097 | =over 4 |
1103 | =over 4 |
1098 | |
1104 | |
1099 | =item remove ($object[, $nrof]) |
1105 | =item remove ($object[, $nrof]) |
1100 | |
1106 | |
1101 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1107 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1102 | The returnvalue is the number of 'single' objects that couldn't be removed. |
1108 | The return value is the number of 'single' objects that couldn't be removed. |
1103 | |
1109 | |
1104 | =cut |
1110 | =cut |
1105 | |
1111 | |
1106 | sub remove { |
1112 | sub remove { |
1107 | my ($obj, $nrof) = @_; |
1113 | my ($obj, $nrof) = @_; |
|
|
1114 | |
|
|
1115 | my $c = $obj->nrof || 1; |
|
|
1116 | my $r = $c > $nrof ? 0 : $nrof - $c; |
|
|
1117 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1108 | |
1118 | |
1109 | my $cnt; |
1119 | $r |
1110 | |
|
|
1111 | if (defined $nrof) { |
|
|
1112 | # TODO: Check tihis line: |
|
|
1113 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
|
|
1114 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
|
|
1115 | |
|
|
1116 | if ($cnt > 0) { |
|
|
1117 | $obj->nrof ($cnt); |
|
|
1118 | return 0; |
|
|
1119 | } |
|
|
1120 | } |
|
|
1121 | |
|
|
1122 | remove ($_) for $obj->inv; |
|
|
1123 | $obj->destroy; |
|
|
1124 | return $cnt; |
|
|
1125 | } |
1120 | } |
1126 | |
1121 | |
1127 | sub check_for_match { |
1122 | sub check_for_match { |
1128 | my ($thing, @matchar) = @_; |
1123 | my ($thing, @matchar) = @_; |
1129 | |
1124 | |