… | |
… | |
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 | |
… | |
… | |
21 | |
20 | |
22 | =cut |
21 | =cut |
23 | |
22 | |
24 | our $CFG; |
23 | our $CFG; |
25 | |
24 | |
26 | sub read_config { |
25 | sub load_config { |
27 | my ($filename) = @_; |
26 | cf::trace "loading jeweler config from $cf::DATADIR/jeweler\n"; |
28 | |
27 | |
29 | if (my $meta = $cf::RESOURCE{$filename}) { |
28 | 0 < Coro::AIO::aio_load "$cf::DATADIR/jeweler", my $data |
|
|
29 | or die "$cf::DATADIR/jeweler: $!"; |
|
|
30 | |
30 | $CFG = cf::decode_json $meta->{data}; |
31 | $CFG = cf::decode_json $data; |
31 | } else { |
|
|
32 | warn "$filename doesn't exist! no config for jeweler skill loaded!\n"; |
|
|
33 | $CFG = {}; |
|
|
34 | } |
|
|
35 | } |
32 | } |
36 | |
33 | |
37 | sub getcfg { |
34 | sub getcfg { |
38 | my ($sect, $key) = @_; |
35 | my ($sect, $key) = @_; |
39 | return $CFG->{$sect} unless defined $key; |
36 | return $CFG->{$sect} unless defined $key; |
… | |
… | |
186 | unless $found; |
183 | unless $found; |
187 | } |
184 | } |
188 | |
185 | |
189 | # this function converts metals/minerals into a raw ring (of adornment) |
186 | # this function converts metals/minerals into a raw ring (of adornment) |
190 | sub simple_converter { |
187 | sub simple_converter { |
191 | my ($pl, $ingred, $chdl, $conv) = @_; |
188 | my ($pl, $ingred, $chdl, $conv, $sk_lvl, $low_skill_cb) = @_; |
192 | |
189 | |
193 | $conv = lc $conv; |
190 | $conv = lc $conv; |
194 | my $cnvs = $CFG->{conversions}; |
191 | my $cnvs = $CFG->{conversions}; |
195 | |
192 | |
196 | return unless $cnvs->{$conv}; |
193 | return unless $cnvs->{$conv}; |
… | |
… | |
218 | |
215 | |
219 | unless ($outarchvalfact >= 1) { |
216 | unless ($outarchvalfact >= 1) { |
220 | warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n"; |
217 | warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n"; |
221 | } |
218 | } |
222 | |
219 | |
223 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
220 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
224 | $ingred->remove ($ingr_grp, $srcarchname); |
|
|
225 | |
|
|
226 | my $outarchval = cf::arch::find ($outarch)->value; |
221 | my $outarchval = cf::arch::find ($outarch)->value; |
227 | |
|
|
228 | my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact); |
222 | my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact); |
|
|
223 | my $can_make_nr = int (($sk_lvl / 2) + 10); |
|
|
224 | |
|
|
225 | if ($nrof > $can_make_nr) { |
|
|
226 | $pl->ob->message ("Your jeweler level is too low to make $nrof rings, you can only make $can_make_nr at your current level."); |
|
|
227 | return; |
|
|
228 | } |
|
|
229 | |
229 | if ($nrof) { |
230 | if ($nrof) { |
230 | # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes) |
231 | # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes) |
|
|
232 | $ingred->remove ($ingr_grp, $srcarchname); |
231 | for (1 .. $nrof) { |
233 | for (1 .. $nrof) { |
232 | $chdl->put (my $ob = cf::object::new $outarch); |
234 | $chdl->put (my $ob = cf::object::new $outarch); |
233 | $ob->set_animation (cf::rndm $ob->num_animations) |
235 | $ob->set_animation (cf::rndm $ob->num_animations) |
234 | if ($ob->type == cf::RING); |
236 | if ($ob->type == cf::RING); |
235 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
237 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
… | |
… | |
247 | } |
249 | } |
248 | |
250 | |
249 | |
251 | |
250 | package Jeweler::CauldronHandler; |
252 | package Jeweler::CauldronHandler; |
251 | |
253 | |
252 | use strict; |
254 | use common::sense; |
253 | |
255 | |
254 | =head2 CauldronHandler |
256 | =head2 CauldronHandler |
255 | |
257 | |
256 | The Jeweler::CauldronHandler package, that helps you with handling the |
258 | The Jeweler::CauldronHandler package, that helps you with handling the |
257 | cauldron stuff. Can also be used for other skills. |
259 | cauldron stuff. Can also be used for other skills. |
… | |
… | |
365 | =back |
367 | =back |
366 | |
368 | |
367 | =cut |
369 | =cut |
368 | |
370 | |
369 | package Jeweler::Ingredients; |
371 | package Jeweler::Ingredients; |
|
|
372 | |
|
|
373 | use common::sense; |
|
|
374 | |
370 | use Storable qw/dclone/; |
375 | use Storable qw/dclone/; |
371 | use strict; |
|
|
372 | |
376 | |
373 | =head2 Ingredients |
377 | =head2 Ingredients |
374 | |
378 | |
375 | This class handles the ingredients. |
379 | This class handles the ingredients. |
376 | |
380 | |
… | |
… | |
479 | } |
483 | } |
480 | |
484 | |
481 | sub improve_ring_by_plan { |
485 | sub improve_ring_by_plan { |
482 | my ($self, $plan, $ring) = @_; |
486 | my ($self, $plan, $ring) = @_; |
483 | |
487 | |
484 | $ring = do { my $guard = Coro::Storable::guard; dclone $ring }; |
488 | $ring = dclone $ring; |
485 | |
489 | |
486 | my $ingred = $self->{ingredients}; |
490 | my $ingred = $self->{ingredients}; |
487 | my $impr = {}; |
491 | my $impr = {}; |
488 | |
492 | |
489 | if ($plan =~ m/^stat_(\S+)$/) { |
493 | if ($plan =~ m/^stat_(\S+)$/) { |
… | |
… | |
573 | } |
577 | } |
574 | |
578 | |
575 | sub check_costs { |
579 | sub check_costs { |
576 | my ($self, $costs, $do_remove) = @_; |
580 | my ($self, $costs, $do_remove) = @_; |
577 | |
581 | |
578 | my $costs = do { my $guard = Coro::Storable::guard; dclone $costs }; |
582 | my $costs = dclone $costs; |
579 | |
583 | |
580 | for my $key (keys %$costs) { |
584 | for my $key (keys %$costs) { |
581 | my @grepar; |
585 | my @grepar; |
582 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
586 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
583 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
587 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
… | |
… | |
586 | @grepar = ('gems', undef, undef, $key); |
590 | @grepar = ('gems', undef, undef, $key); |
587 | } |
591 | } |
588 | |
592 | |
589 | if ($do_remove) { |
593 | if ($do_remove) { |
590 | my $rem = $costs->{$key}; |
594 | my $rem = $costs->{$key}; |
|
|
595 | $self->do_grep (sub { |
591 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
596 | if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } |
|
|
597 | 1 |
|
|
598 | }, @grepar); |
592 | if ($rem > 0) { |
599 | if ($rem > 0) { |
593 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
600 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
594 | } |
601 | } |
|
|
602 | |
595 | } else { |
603 | } else { |
596 | my $nr; |
604 | my $nr; |
597 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
605 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
598 | $costs->{$key} -= $nr; |
606 | $costs->{$key} -= $nr; |
599 | } |
607 | } |
… | |
… | |
618 | } |
626 | } |
619 | } |
627 | } |
620 | } |
628 | } |
621 | |
629 | |
622 | package Jeweler::Object; |
630 | package Jeweler::Object; |
623 | use strict; |
631 | |
|
|
632 | use common::sense; |
624 | use POSIX; |
633 | use POSIX; |
625 | use List::Util qw/max min sum/; |
634 | use List::Util qw/max min sum/; |
626 | |
635 | |
627 | sub new { |
636 | sub new { |
628 | my ($class, %arg) = @_; |
637 | my ($class, %arg) = @_; |
… | |
… | |
663 | $exp -= $subexp; |
672 | $exp -= $subexp; |
664 | $exp = max ($exp, 0); |
673 | $exp = max ($exp, 0); |
665 | |
674 | |
666 | } else { |
675 | } else { |
667 | # the experience bonus here is to make level 1 rings give you at least |
676 | # 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 |
677 | # 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). |
678 | # first few levels a bit easier. (probably until around level 5-6). |
670 | my $expbonus = cf::level_to_min_exp (2) / 10; |
679 | my $expbonus = cf::level_to_min_exp (2) / 5; |
671 | # this bonus should also only be given for _new_ rings and not for merged |
680 | # this bonus should also only be given for _new_ rings and not for merged |
672 | # ones - to prevent infinite exp making. |
681 | # ones - to prevent infinite exp making. |
673 | $exp += $expbonus; |
682 | $exp += $expbonus; |
674 | } |
683 | } |
675 | |
684 | |
… | |
… | |
719 | if (defined $costs) { |
728 | if (defined $costs) { |
720 | my $desc = ""; |
729 | my $desc = ""; |
721 | my $lvl = $self->power_to_level (\$desc); |
730 | my $lvl = $self->power_to_level (\$desc); |
722 | my $scosts = $self->calc_value_from_cost ($costs); |
731 | my $scosts = $self->calc_value_from_cost ($costs); |
723 | |
732 | |
724 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
733 | $pl->message ("costs: " |
|
|
734 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
|
|
735 | . " (" |
|
|
736 | . ($scosts / "platinacoin"->cf::arch::find->value) |
|
|
737 | . " platinum)"); |
725 | $pl->message ("level: " . $desc); |
738 | $pl->message ("level: $desc"); |
726 | } else { |
739 | } else { |
727 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
740 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
728 | } |
741 | } |
729 | } |
742 | } |
730 | |
743 | |
… | |
… | |
833 | $obj->{arch} = $thing->arch->archname; |
846 | $obj->{arch} = $thing->arch->archname; |
834 | $obj->{face} = $thing->face; |
847 | $obj->{face} = $thing->face; |
835 | |
848 | |
836 | $obj->{value} = $thing->value; |
849 | $obj->{value} = $thing->value; |
837 | |
850 | |
|
|
851 | $obj->{is_ring} = ($thing->type == cf::RING); |
|
|
852 | |
838 | $self->{hash} = $obj |
853 | $self->{hash} = $obj |
839 | } |
854 | } |
840 | |
855 | |
841 | sub to_object { |
856 | sub to_object { |
842 | my ($self) = @_; |
857 | my ($self) = @_; |
… | |
… | |
904 | sub resist_level { |
919 | sub resist_level { |
905 | my ($self) = @_; |
920 | my ($self) = @_; |
906 | |
921 | |
907 | my $resists = $self->{hash}->{resist} || {}; |
922 | my $resists = $self->{hash}->{resist} || {}; |
908 | |
923 | |
909 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
924 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
910 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
925 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
911 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
926 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
912 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
927 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
913 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
928 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
914 | |
929 | |
915 | my $ressum = 0; |
930 | my $ressum = 0; |
… | |
… | |
975 | sub power_to_level { |
990 | sub power_to_level { |
976 | my ($self, $lvldescr) = @_; |
991 | my ($self, $lvldescr) = @_; |
977 | |
992 | |
978 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
993 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
979 | my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); |
994 | my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); |
|
|
995 | my $ring_offs = Jeweler::getcfg (maxlevels => 'ring_offset'); |
980 | |
996 | |
981 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
997 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
982 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
998 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
983 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
999 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
984 | |
1000 | |
985 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
1001 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
986 | |
1002 | |
987 | my $impr_lvl = ceil (($max_impr_lvl / ($max_imprs + 1)) * ($impr_sum - 1)); # 1 improvemnt bonus |
1003 | my $impr_lvl = |
|
|
1004 | ceil (($max_impr_lvl / ($max_imprs + 1)) |
|
|
1005 | * ($impr_sum - 1)); # 1 improvemnt bonus |
988 | |
1006 | |
989 | my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); |
1007 | my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); |
|
|
1008 | |
|
|
1009 | if ($self->{hash}->{is_ring}) { |
|
|
1010 | $levl += $ring_offs; |
|
|
1011 | } |
|
|
1012 | |
|
|
1013 | $levl = min ($levl, cf::settings->max_level); |
990 | |
1014 | |
991 | if ($lvldescr) { |
1015 | if ($lvldescr) { |
992 | $$lvldescr = |
1016 | $$lvldescr = |
993 | sprintf "%3d: %s\n", $levl, |
1017 | sprintf "%3d: %s\n", $levl, |
994 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
1018 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
… | |
… | |
1085 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1109 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1086 | } |
1110 | } |
1087 | |
1111 | |
1088 | package Jeweler::Util; |
1112 | package Jeweler::Util; |
1089 | |
1113 | |
1090 | use strict; |
1114 | use common::sense; |
1091 | |
1115 | |
1092 | =head2 Util |
1116 | =head2 Util |
1093 | |
1117 | |
1094 | Some utility functions for the Jeweler skill. |
1118 | Some utility functions for the Jeweler skill. |
1095 | |
1119 | |
1096 | =over 4 |
1120 | =over 4 |
1097 | |
1121 | |
1098 | =item remove ($object[, $nrof]) |
1122 | =item remove ($object[, $nrof]) |
1099 | |
1123 | |
1100 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1124 | 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. |
1125 | The return value is the number of 'single' objects that couldn't be removed. |
1102 | |
1126 | |
1103 | =cut |
1127 | =cut |
1104 | |
1128 | |
1105 | sub remove { |
1129 | sub remove { |
1106 | my ($obj, $nrof) = @_; |
1130 | my ($obj, $nrof) = @_; |
|
|
1131 | |
|
|
1132 | my $c = $obj->nrof || 1; |
|
|
1133 | my $r = $c > $nrof ? 0 : $nrof - $c; |
|
|
1134 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1107 | |
1135 | |
1108 | my $cnt; |
1136 | $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 | } |
1137 | } |
1125 | |
1138 | |
1126 | sub check_for_match { |
1139 | sub check_for_match { |
1127 | my ($thing, @matchar) = @_; |
1140 | my ($thing, @matchar) = @_; |
1128 | |
1141 | |