… | |
… | |
20 | |
20 | |
21 | =cut |
21 | =cut |
22 | |
22 | |
23 | our $CFG; |
23 | our $CFG; |
24 | |
24 | |
25 | sub read_config { |
25 | sub load_config { |
26 | my ($filename) = @_; |
26 | cf::trace "loading jeweler config from $cf::DATADIR/jeweler\n"; |
27 | |
27 | |
28 | if (my $meta = $cf::RESOURCE{$filename}) { |
28 | 0 < Coro::AIO::aio_load "$cf::DATADIR/jeweler", my $data |
|
|
29 | or die "$cf::DATADIR/jeweler: $!"; |
|
|
30 | |
29 | $CFG = cf::decode_json $meta->{data}; |
31 | $CFG = cf::decode_json $data; |
30 | } else { |
|
|
31 | warn "$filename doesn't exist! no config for jeweler skill loaded!\n"; |
|
|
32 | $CFG = {}; |
|
|
33 | } |
|
|
34 | } |
32 | } |
35 | |
33 | |
36 | sub getcfg { |
34 | sub getcfg { |
37 | my ($sect, $key) = @_; |
35 | my ($sect, $key) = @_; |
38 | return $CFG->{$sect} unless defined $key; |
36 | return $CFG->{$sect} unless defined $key; |
… | |
… | |
251 | } |
249 | } |
252 | |
250 | |
253 | |
251 | |
254 | package Jeweler::CauldronHandler; |
252 | package Jeweler::CauldronHandler; |
255 | |
253 | |
256 | use strict; |
254 | use common::sense; |
257 | |
255 | |
258 | =head2 CauldronHandler |
256 | =head2 CauldronHandler |
259 | |
257 | |
260 | The Jeweler::CauldronHandler package, that helps you with handling the |
258 | The Jeweler::CauldronHandler package, that helps you with handling the |
261 | cauldron stuff. Can also be used for other skills. |
259 | cauldron stuff. Can also be used for other skills. |
… | |
… | |
369 | =back |
367 | =back |
370 | |
368 | |
371 | =cut |
369 | =cut |
372 | |
370 | |
373 | package Jeweler::Ingredients; |
371 | package Jeweler::Ingredients; |
|
|
372 | |
|
|
373 | use common::sense; |
|
|
374 | |
374 | use Storable qw/dclone/; |
375 | use Storable qw/dclone/; |
375 | use strict; |
|
|
376 | |
376 | |
377 | =head2 Ingredients |
377 | =head2 Ingredients |
378 | |
378 | |
379 | This class handles the ingredients. |
379 | This class handles the ingredients. |
380 | |
380 | |
… | |
… | |
591 | } |
591 | } |
592 | |
592 | |
593 | if ($do_remove) { |
593 | if ($do_remove) { |
594 | my $rem = $costs->{$key}; |
594 | my $rem = $costs->{$key}; |
595 | $self->do_grep (sub { |
595 | $self->do_grep (sub { |
|
|
596 | if ($rem) { |
596 | if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } |
597 | $rem = Jeweler::Util::remove ($_[0], $rem); |
|
|
598 | } |
597 | 1 |
599 | 1 |
598 | }, @grepar); |
600 | }, @grepar); |
599 | if ($rem > 0) { |
601 | if ($rem > 0) { |
600 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
602 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
601 | } |
603 | } |
… | |
… | |
626 | } |
628 | } |
627 | } |
629 | } |
628 | } |
630 | } |
629 | |
631 | |
630 | package Jeweler::Object; |
632 | package Jeweler::Object; |
631 | use strict; |
633 | |
|
|
634 | use common::sense; |
632 | use POSIX; |
635 | use POSIX; |
633 | use List::Util qw/max min sum/; |
636 | use List::Util qw/max min sum/; |
634 | |
637 | |
635 | sub new { |
638 | sub new { |
636 | my ($class, %arg) = @_; |
639 | my ($class, %arg) = @_; |
… | |
… | |
651 | return 1 if $self->{hash}->{resist}->{$resnum}; |
654 | return 1 if $self->{hash}->{resist}->{$resnum}; |
652 | } |
655 | } |
653 | return undef; |
656 | return undef; |
654 | } |
657 | } |
655 | |
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 | |
656 | sub projected_exp { |
666 | sub projected_exp { |
657 | my ($self, $input_level) = @_; |
667 | my ($self, $input_level) = @_; |
658 | |
668 | |
659 | my $lvl = max ($self->power_to_level, 1); |
669 | my $lvl = max ($self->power_to_level, 1); |
660 | my $exp = |
670 | my $exp = lvl2exp ($lvl); |
661 | (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) |
|
|
662 | / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring |
|
|
663 | # should get you to the rings level at least. |
|
|
664 | |
671 | |
665 | if (defined $input_level) { |
672 | if (defined $input_level) { # in case we merge rings: |
666 | my $subexp = |
673 | my $subexp = lvl2exp ($input_level); |
667 | (cf::level_to_min_exp ($input_level) |
|
|
668 | - cf::level_to_min_exp ($input_level - 1)) |
|
|
669 | / (10 + max ($input_level - 1, 0)); # see above for comment |
|
|
670 | |
|
|
671 | $exp -= $subexp; |
674 | $exp -= $subexp; |
672 | $exp = max ($exp, 0); |
675 | $exp = max ($exp, 0); |
673 | |
676 | |
674 | } else { |
677 | } else { |
675 | # 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 |
… | |
… | |
855 | sub to_object { |
858 | sub to_object { |
856 | my ($self) = @_; |
859 | my ($self) = @_; |
857 | |
860 | |
858 | my $obj = cf::object::new $self->{hash}->{arch}; |
861 | my $obj = cf::object::new $self->{hash}->{arch}; |
859 | |
862 | |
860 | $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! |
861 | |
864 | |
862 | $obj->face ($self->{hash}{face}); |
865 | $obj->face ($self->{hash}{face}); |
863 | |
866 | |
864 | my $stats = $obj->stats; |
867 | my $stats = $obj->stats; |
865 | |
868 | |
… | |
… | |
1108 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1111 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1109 | } |
1112 | } |
1110 | |
1113 | |
1111 | package Jeweler::Util; |
1114 | package Jeweler::Util; |
1112 | |
1115 | |
1113 | use strict; |
1116 | use common::sense; |
1114 | |
1117 | |
1115 | =head2 Util |
1118 | =head2 Util |
1116 | |
1119 | |
1117 | Some utility functions for the Jeweler skill. |
1120 | Some utility functions for the Jeweler skill. |
1118 | |
1121 | |
… | |
… | |
1125 | |
1128 | |
1126 | =cut |
1129 | =cut |
1127 | |
1130 | |
1128 | sub remove { |
1131 | sub remove { |
1129 | my ($obj, $nrof) = @_; |
1132 | my ($obj, $nrof) = @_; |
1130 | |
1133 | |
1131 | my $c = $obj->nrof || 1; |
1134 | my $c = $obj->number_of; |
1132 | my $r = $c > $nrof ? 0 : $nrof - $c; |
1135 | my $r = $c > $nrof ? 0 : $nrof - $c; |
1133 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1136 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1134 | |
1137 | |
1135 | $r |
1138 | $r |
1136 | } |
1139 | } |