… | |
… | |
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 | $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!") |
183 | if $hadunid; |
184 | if $hadunid; |
|
|
185 | $pl->message ("You couldn't find anything in the bench to analyse!") |
|
|
186 | unless $found; |
184 | } |
187 | } |
185 | |
188 | |
186 | # this function converts metals/minerals into a raw ring (of adornment) |
189 | # this function converts metals/minerals into a raw ring (of adornment) |
187 | sub simple_converter { |
190 | sub simple_converter { |
188 | my ($pl, $ingred, $chdl, $conv) = @_; |
191 | my ($pl, $ingred, $chdl, $conv) = @_; |
… | |
… | |
583 | @grepar = ('gems', undef, undef, $key); |
586 | @grepar = ('gems', undef, undef, $key); |
584 | } |
587 | } |
585 | |
588 | |
586 | if ($do_remove) { |
589 | if ($do_remove) { |
587 | my $rem = $costs->{$key}; |
590 | my $rem = $costs->{$key}; |
|
|
591 | $self->do_grep (sub { |
588 | $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); |
589 | if ($rem > 0) { |
595 | if ($rem > 0) { |
590 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
596 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
591 | } |
597 | } |
|
|
598 | |
592 | } else { |
599 | } else { |
593 | my $nr; |
600 | my $nr; |
594 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
601 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
595 | $costs->{$key} -= $nr; |
602 | $costs->{$key} -= $nr; |
596 | } |
603 | } |
… | |
… | |
660 | $exp -= $subexp; |
667 | $exp -= $subexp; |
661 | $exp = max ($exp, 0); |
668 | $exp = max ($exp, 0); |
662 | |
669 | |
663 | } else { |
670 | } else { |
664 | # 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 |
665 | # 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 |
666 | # 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). |
667 | my $expbonus = cf::level_to_min_exp (2) / 10; |
674 | my $expbonus = cf::level_to_min_exp (2) / 5; |
668 | # 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 |
669 | # ones - to prevent infinite exp making. |
676 | # ones - to prevent infinite exp making. |
670 | $exp += $expbonus; |
677 | $exp += $expbonus; |
671 | } |
678 | } |
672 | |
679 | |
… | |
… | |
716 | if (defined $costs) { |
723 | if (defined $costs) { |
717 | my $desc = ""; |
724 | my $desc = ""; |
718 | my $lvl = $self->power_to_level (\$desc); |
725 | my $lvl = $self->power_to_level (\$desc); |
719 | my $scosts = $self->calc_value_from_cost ($costs); |
726 | my $scosts = $self->calc_value_from_cost ($costs); |
720 | |
727 | |
721 | $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)"); |
722 | $pl->message ("level: " . $desc); |
733 | $pl->message ("level: $desc"); |
723 | } else { |
734 | } else { |
724 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
735 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
725 | } |
736 | } |
726 | } |
737 | } |
727 | |
738 | |
… | |
… | |
1093 | =over 4 |
1104 | =over 4 |
1094 | |
1105 | |
1095 | =item remove ($object[, $nrof]) |
1106 | =item remove ($object[, $nrof]) |
1096 | |
1107 | |
1097 | 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. |
1098 | 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. |
1099 | |
1110 | |
1100 | =cut |
1111 | =cut |
1101 | |
1112 | |
1102 | sub remove { |
1113 | sub remove { |
1103 | 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)); |
1104 | |
1119 | |
1105 | my $cnt; |
1120 | $r |
1106 | |
|
|
1107 | if (defined $nrof) { |
|
|
1108 | # TODO: Check tihis line: |
|
|
1109 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
|
|
1110 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
|
|
1111 | |
|
|
1112 | if ($cnt > 0) { |
|
|
1113 | $obj->nrof ($cnt); |
|
|
1114 | return 0; |
|
|
1115 | } |
|
|
1116 | } |
|
|
1117 | |
|
|
1118 | remove ($_) for $obj->inv; |
|
|
1119 | $obj->destroy; |
|
|
1120 | return $cnt; |
|
|
1121 | } |
1121 | } |
1122 | |
1122 | |
1123 | sub check_for_match { |
1123 | sub check_for_match { |
1124 | my ($thing, @matchar) = @_; |
1124 | my ($thing, @matchar) = @_; |
1125 | |
1125 | |