… | |
… | |
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 | |
… | |
… | |
479 | } |
478 | } |
480 | |
479 | |
481 | sub improve_ring_by_plan { |
480 | sub improve_ring_by_plan { |
482 | my ($self, $plan, $ring) = @_; |
481 | my ($self, $plan, $ring) = @_; |
483 | |
482 | |
484 | $ring = do { my $guard = Coro::Storable::guard; dclone $ring }; |
483 | $ring = dclone $ring; |
485 | |
484 | |
486 | my $ingred = $self->{ingredients}; |
485 | my $ingred = $self->{ingredients}; |
487 | my $impr = {}; |
486 | my $impr = {}; |
488 | |
487 | |
489 | if ($plan =~ m/^stat_(\S+)$/) { |
488 | if ($plan =~ m/^stat_(\S+)$/) { |
… | |
… | |
573 | } |
572 | } |
574 | |
573 | |
575 | sub check_costs { |
574 | sub check_costs { |
576 | my ($self, $costs, $do_remove) = @_; |
575 | my ($self, $costs, $do_remove) = @_; |
577 | |
576 | |
578 | my $costs = do { my $guard = Coro::Storable::guard; dclone $costs }; |
577 | my $costs = dclone $costs; |
579 | |
578 | |
580 | for my $key (keys %$costs) { |
579 | for my $key (keys %$costs) { |
581 | my @grepar; |
580 | my @grepar; |
582 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
581 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
583 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
582 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
… | |
… | |
586 | @grepar = ('gems', undef, undef, $key); |
585 | @grepar = ('gems', undef, undef, $key); |
587 | } |
586 | } |
588 | |
587 | |
589 | if ($do_remove) { |
588 | if ($do_remove) { |
590 | my $rem = $costs->{$key}; |
589 | my $rem = $costs->{$key}; |
|
|
590 | $self->do_grep (sub { |
591 | $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); |
592 | if ($rem > 0) { |
594 | if ($rem > 0) { |
593 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
595 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
594 | } |
596 | } |
|
|
597 | |
595 | } else { |
598 | } else { |
596 | my $nr; |
599 | my $nr; |
597 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
600 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
598 | $costs->{$key} -= $nr; |
601 | $costs->{$key} -= $nr; |
599 | } |
602 | } |
… | |
… | |
663 | $exp -= $subexp; |
666 | $exp -= $subexp; |
664 | $exp = max ($exp, 0); |
667 | $exp = max ($exp, 0); |
665 | |
668 | |
666 | } else { |
669 | } else { |
667 | # 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 |
668 | # 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 |
669 | # 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). |
670 | my $expbonus = cf::level_to_min_exp (2) / 10; |
673 | my $expbonus = cf::level_to_min_exp (2) / 5; |
671 | # 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 |
672 | # ones - to prevent infinite exp making. |
675 | # ones - to prevent infinite exp making. |
673 | $exp += $expbonus; |
676 | $exp += $expbonus; |
674 | } |
677 | } |
675 | |
678 | |
… | |
… | |
719 | if (defined $costs) { |
722 | if (defined $costs) { |
720 | my $desc = ""; |
723 | my $desc = ""; |
721 | my $lvl = $self->power_to_level (\$desc); |
724 | my $lvl = $self->power_to_level (\$desc); |
722 | my $scosts = $self->calc_value_from_cost ($costs); |
725 | my $scosts = $self->calc_value_from_cost ($costs); |
723 | |
726 | |
724 | $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)"); |
725 | $pl->message ("level: " . $desc); |
732 | $pl->message ("level: $desc"); |
726 | } else { |
733 | } else { |
727 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
734 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
728 | } |
735 | } |
729 | } |
736 | } |
730 | |
737 | |
… | |
… | |
1096 | =over 4 |
1103 | =over 4 |
1097 | |
1104 | |
1098 | =item remove ($object[, $nrof]) |
1105 | =item remove ($object[, $nrof]) |
1099 | |
1106 | |
1100 | 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. |
1101 | 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. |
1102 | |
1109 | |
1103 | =cut |
1110 | =cut |
1104 | |
1111 | |
1105 | sub remove { |
1112 | sub remove { |
1106 | 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)); |
1107 | |
1118 | |
1108 | my $cnt; |
1119 | $r |
1109 | |
|
|
1110 | if (defined $nrof) { |
|
|
1111 | # TODO: Check tihis line: |
|
|
1112 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
|
|
1113 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
|
|
1114 | |
|
|
1115 | if ($cnt > 0) { |
|
|
1116 | $obj->nrof ($cnt); |
|
|
1117 | return 0; |
|
|
1118 | } |
|
|
1119 | } |
|
|
1120 | |
|
|
1121 | remove ($_) for $obj->inv; |
|
|
1122 | $obj->destroy; |
|
|
1123 | return $cnt; |
|
|
1124 | } |
1120 | } |
1125 | |
1121 | |
1126 | sub check_for_match { |
1122 | sub check_for_match { |
1127 | my ($thing, @matchar) = @_; |
1123 | my ($thing, @matchar) = @_; |
1128 | |
1124 | |