… | |
… | |
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 | |
… | |
… | |
164 | |
163 | |
165 | sub analyze { |
164 | sub analyze { |
166 | my ($sk, $chdl, $pl, $input_level) = @_; |
165 | my ($sk, $chdl, $pl, $input_level) = @_; |
167 | |
166 | |
168 | my $hadunid = 0; |
167 | my $hadunid = 0; |
|
|
168 | my $found = 0; |
169 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
169 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
170 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
170 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
171 | $hadunid = 1; |
171 | $hadunid = 1; |
172 | next; |
172 | next; |
173 | } |
173 | } |
|
|
174 | $found = 1; |
174 | my $r = Jeweler::Object->new (object => $_); |
175 | my $r = Jeweler::Object->new (object => $_); |
175 | my $msg = $r->analyze ($sk, $pl, $input_level); |
176 | my $msg = $r->analyze ($sk, $pl, $input_level); |
176 | $pl->message ($r->to_string . ": " . $msg); |
177 | $pl->message ($r->to_string . ": " . $msg); |
177 | if ($pl->flag (cf::FLAG_WIZ)) { |
178 | if ($pl->flag (cf::FLAG_WIZ)) { |
178 | $r->wiz_analyze ($pl); |
179 | $r->wiz_analyze ($pl); |
179 | } |
180 | } |
180 | } |
181 | } |
181 | $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!") |
182 | if $hadunid; |
183 | if $hadunid; |
|
|
184 | $pl->message ("You couldn't find anything in the bench to analyse!") |
|
|
185 | unless $found; |
183 | } |
186 | } |
184 | |
187 | |
185 | # this function converts metals/minerals into a raw ring (of adornment) |
188 | # this function converts metals/minerals into a raw ring (of adornment) |
186 | sub simple_converter { |
189 | sub simple_converter { |
187 | my ($pl, $ingred, $chdl, $conv) = @_; |
190 | my ($pl, $ingred, $chdl, $conv) = @_; |
… | |
… | |
475 | } |
478 | } |
476 | |
479 | |
477 | sub improve_ring_by_plan { |
480 | sub improve_ring_by_plan { |
478 | my ($self, $plan, $ring) = @_; |
481 | my ($self, $plan, $ring) = @_; |
479 | |
482 | |
480 | $ring = do { my $guard = Coro::Storable::guard; dclone $ring }; |
483 | $ring = dclone $ring; |
481 | |
484 | |
482 | my $ingred = $self->{ingredients}; |
485 | my $ingred = $self->{ingredients}; |
483 | my $impr = {}; |
486 | my $impr = {}; |
484 | |
487 | |
485 | if ($plan =~ m/^stat_(\S+)$/) { |
488 | if ($plan =~ m/^stat_(\S+)$/) { |
… | |
… | |
569 | } |
572 | } |
570 | |
573 | |
571 | sub check_costs { |
574 | sub check_costs { |
572 | my ($self, $costs, $do_remove) = @_; |
575 | my ($self, $costs, $do_remove) = @_; |
573 | |
576 | |
574 | my $costs = do { my $guard = Coro::Storable::guard; dclone $costs }; |
577 | my $costs = dclone $costs; |
575 | |
578 | |
576 | for my $key (keys %$costs) { |
579 | for my $key (keys %$costs) { |
577 | my @grepar; |
580 | my @grepar; |
578 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
581 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
579 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
582 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
… | |
… | |
582 | @grepar = ('gems', undef, undef, $key); |
585 | @grepar = ('gems', undef, undef, $key); |
583 | } |
586 | } |
584 | |
587 | |
585 | if ($do_remove) { |
588 | if ($do_remove) { |
586 | my $rem = $costs->{$key}; |
589 | my $rem = $costs->{$key}; |
|
|
590 | $self->do_grep (sub { |
587 | $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); |
588 | if ($rem > 0) { |
594 | if ($rem > 0) { |
589 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
595 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
590 | } |
596 | } |
|
|
597 | |
591 | } else { |
598 | } else { |
592 | my $nr; |
599 | my $nr; |
593 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
600 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
594 | $costs->{$key} -= $nr; |
601 | $costs->{$key} -= $nr; |
595 | } |
602 | } |
… | |
… | |
659 | $exp -= $subexp; |
666 | $exp -= $subexp; |
660 | $exp = max ($exp, 0); |
667 | $exp = max ($exp, 0); |
661 | |
668 | |
662 | } else { |
669 | } else { |
663 | # 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 |
664 | # 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 |
665 | # 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). |
666 | my $expbonus = cf::level_to_min_exp (2) / 10; |
673 | my $expbonus = cf::level_to_min_exp (2) / 5; |
667 | # 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 |
668 | # ones - to prevent infinite exp making. |
675 | # ones - to prevent infinite exp making. |
669 | $exp += $expbonus; |
676 | $exp += $expbonus; |
670 | } |
677 | } |
671 | |
678 | |
… | |
… | |
715 | if (defined $costs) { |
722 | if (defined $costs) { |
716 | my $desc = ""; |
723 | my $desc = ""; |
717 | my $lvl = $self->power_to_level (\$desc); |
724 | my $lvl = $self->power_to_level (\$desc); |
718 | my $scosts = $self->calc_value_from_cost ($costs); |
725 | my $scosts = $self->calc_value_from_cost ($costs); |
719 | |
726 | |
720 | $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)"); |
721 | $pl->message ("level: " . $desc); |
732 | $pl->message ("level: $desc"); |
722 | } else { |
733 | } else { |
723 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
734 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
724 | } |
735 | } |
725 | } |
736 | } |
726 | |
737 | |
… | |
… | |
1092 | =over 4 |
1103 | =over 4 |
1093 | |
1104 | |
1094 | =item remove ($object[, $nrof]) |
1105 | =item remove ($object[, $nrof]) |
1095 | |
1106 | |
1096 | 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. |
1097 | 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. |
1098 | |
1109 | |
1099 | =cut |
1110 | =cut |
1100 | |
1111 | |
1101 | sub remove { |
1112 | sub remove { |
1102 | 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)); |
1103 | |
1118 | |
1104 | my $cnt; |
1119 | $r |
1105 | |
|
|
1106 | if (defined $nrof) { |
|
|
1107 | # TODO: Check tihis line: |
|
|
1108 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
|
|
1109 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
|
|
1110 | |
|
|
1111 | if ($cnt > 0) { |
|
|
1112 | $obj->nrof ($cnt); |
|
|
1113 | return 0; |
|
|
1114 | } |
|
|
1115 | } |
|
|
1116 | |
|
|
1117 | remove ($_) for $obj->inv; |
|
|
1118 | $obj->destroy; |
|
|
1119 | return $cnt; |
|
|
1120 | } |
1120 | } |
1121 | |
1121 | |
1122 | sub check_for_match { |
1122 | sub check_for_match { |
1123 | my ($thing, @matchar) = @_; |
1123 | my ($thing, @matchar) = @_; |
1124 | |
1124 | |