… | |
… | |
249 | } |
249 | } |
250 | |
250 | |
251 | |
251 | |
252 | package Jeweler::CauldronHandler; |
252 | package Jeweler::CauldronHandler; |
253 | |
253 | |
254 | use strict; |
254 | use common::sense; |
255 | |
255 | |
256 | =head2 CauldronHandler |
256 | =head2 CauldronHandler |
257 | |
257 | |
258 | The Jeweler::CauldronHandler package, that helps you with handling the |
258 | The Jeweler::CauldronHandler package, that helps you with handling the |
259 | cauldron stuff. Can also be used for other skills. |
259 | cauldron stuff. Can also be used for other skills. |
… | |
… | |
367 | =back |
367 | =back |
368 | |
368 | |
369 | =cut |
369 | =cut |
370 | |
370 | |
371 | package Jeweler::Ingredients; |
371 | package Jeweler::Ingredients; |
|
|
372 | |
|
|
373 | use common::sense; |
|
|
374 | |
372 | use Storable qw/dclone/; |
375 | use Storable qw/dclone/; |
373 | use strict; |
|
|
374 | |
376 | |
375 | =head2 Ingredients |
377 | =head2 Ingredients |
376 | |
378 | |
377 | This class handles the ingredients. |
379 | This class handles the ingredients. |
378 | |
380 | |
… | |
… | |
589 | } |
591 | } |
590 | |
592 | |
591 | if ($do_remove) { |
593 | if ($do_remove) { |
592 | my $rem = $costs->{$key}; |
594 | my $rem = $costs->{$key}; |
593 | $self->do_grep (sub { |
595 | $self->do_grep (sub { |
|
|
596 | if ($rem) { |
594 | if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } |
597 | $rem = Jeweler::Util::remove ($_[0], $rem); |
|
|
598 | } |
595 | 1 |
599 | 1 |
596 | }, @grepar); |
600 | }, @grepar); |
597 | if ($rem > 0) { |
601 | if ($rem > 0) { |
598 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
602 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
599 | } |
603 | } |
… | |
… | |
624 | } |
628 | } |
625 | } |
629 | } |
626 | } |
630 | } |
627 | |
631 | |
628 | package Jeweler::Object; |
632 | package Jeweler::Object; |
629 | use strict; |
633 | |
|
|
634 | use common::sense; |
630 | use POSIX; |
635 | use POSIX; |
631 | use List::Util qw/max min sum/; |
636 | use List::Util qw/max min sum/; |
632 | |
637 | |
633 | sub new { |
638 | sub new { |
634 | my ($class, %arg) = @_; |
639 | my ($class, %arg) = @_; |
… | |
… | |
649 | return 1 if $self->{hash}->{resist}->{$resnum}; |
654 | return 1 if $self->{hash}->{resist}->{$resnum}; |
650 | } |
655 | } |
651 | return undef; |
656 | return undef; |
652 | } |
657 | } |
653 | |
658 | |
|
|
659 | sub lvl2exp { |
|
|
660 | my $lvl = shift; |
|
|
661 | (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) |
|
|
662 | / (20 + max ($lvl - 1, 0)) # 20 + level times making such a ring |
|
|
663 | # should get you to the rings level at least. |
|
|
664 | } |
|
|
665 | |
654 | sub projected_exp { |
666 | sub projected_exp { |
655 | my ($self, $input_level) = @_; |
667 | my ($self, $input_level) = @_; |
656 | |
668 | |
657 | my $lvl = max ($self->power_to_level, 1); |
669 | my $lvl = max ($self->power_to_level, 1); |
658 | my $exp = |
670 | my $exp = lvl2exp ($lvl); |
659 | (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) |
|
|
660 | / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring |
|
|
661 | # should get you to the rings level at least. |
|
|
662 | |
671 | |
663 | if (defined $input_level) { |
672 | if (defined $input_level) { # in case we merge rings: |
664 | my $subexp = |
673 | my $subexp = lvl2exp ($input_level); |
665 | (cf::level_to_min_exp ($input_level) |
|
|
666 | - cf::level_to_min_exp ($input_level - 1)) |
|
|
667 | / (10 + max ($input_level - 1, 0)); # see above for comment |
|
|
668 | |
|
|
669 | $exp -= $subexp; |
674 | $exp -= $subexp; |
670 | $exp = max ($exp, 0); |
675 | $exp = max ($exp, 0); |
671 | |
676 | |
672 | } else { |
677 | } else { |
673 | # the experience bonus here is to make level 1 rings give you at least |
678 | # the experience bonus here is to make level 1 rings give you at least |
… | |
… | |
853 | sub to_object { |
858 | sub to_object { |
854 | my ($self) = @_; |
859 | my ($self) = @_; |
855 | |
860 | |
856 | my $obj = cf::object::new $self->{hash}->{arch}; |
861 | my $obj = cf::object::new $self->{hash}->{arch}; |
857 | |
862 | |
858 | $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached! |
863 | $obj->item_power (floor ($self->power_to_level / 5)); # there have to be strings attached! |
859 | |
864 | |
860 | $obj->face ($self->{hash}{face}); |
865 | $obj->face ($self->{hash}{face}); |
861 | |
866 | |
862 | my $stats = $obj->stats; |
867 | my $stats = $obj->stats; |
863 | |
868 | |
… | |
… | |
1106 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1111 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1107 | } |
1112 | } |
1108 | |
1113 | |
1109 | package Jeweler::Util; |
1114 | package Jeweler::Util; |
1110 | |
1115 | |
1111 | use strict; |
1116 | use common::sense; |
1112 | |
1117 | |
1113 | =head2 Util |
1118 | =head2 Util |
1114 | |
1119 | |
1115 | Some utility functions for the Jeweler skill. |
1120 | Some utility functions for the Jeweler skill. |
1116 | |
1121 | |
… | |
… | |
1123 | |
1128 | |
1124 | =cut |
1129 | =cut |
1125 | |
1130 | |
1126 | sub remove { |
1131 | sub remove { |
1127 | my ($obj, $nrof) = @_; |
1132 | my ($obj, $nrof) = @_; |
1128 | |
1133 | |
1129 | my $c = $obj->nrof || 1; |
1134 | my $c = $obj->number_of; |
1130 | my $r = $c > $nrof ? 0 : $nrof - $c; |
1135 | my $r = $c > $nrof ? 0 : $nrof - $c; |
1131 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1136 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1132 | |
1137 | |
1133 | $r |
1138 | $r |
1134 | } |
1139 | } |