… | |
… | |
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; |
… | |
… | |
164 | |
161 | |
165 | sub analyze { |
162 | sub analyze { |
166 | my ($sk, $chdl, $pl, $input_level) = @_; |
163 | my ($sk, $chdl, $pl, $input_level) = @_; |
167 | |
164 | |
168 | my $hadunid = 0; |
165 | my $hadunid = 0; |
|
|
166 | my $found = 0; |
169 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
167 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
170 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
168 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
171 | $hadunid = 1; |
169 | $hadunid = 1; |
172 | next; |
170 | next; |
173 | } |
171 | } |
|
|
172 | $found = 1; |
174 | my $r = Jeweler::Object->new (object => $_); |
173 | my $r = Jeweler::Object->new (object => $_); |
175 | my $msg = $r->analyze ($sk, $pl, $input_level); |
174 | my $msg = $r->analyze ($sk, $pl, $input_level); |
176 | $pl->message ($r->to_string . ": " . $msg); |
175 | $pl->message ($r->to_string . ": " . $msg); |
177 | if ($pl->flag (cf::FLAG_WIZ)) { |
176 | if ($pl->flag (cf::FLAG_WIZ)) { |
178 | $r->wiz_analyze ($pl); |
177 | $r->wiz_analyze ($pl); |
179 | } |
178 | } |
180 | } |
179 | } |
181 | $pl->message ("You couldn't identify the other rings and not analyze them!") |
180 | $pl->message ("You couldn't identify the other rings and not analyze them!") |
182 | if $hadunid; |
181 | if $hadunid; |
|
|
182 | $pl->message ("You couldn't find anything in the bench to analyse!") |
|
|
183 | unless $found; |
183 | } |
184 | } |
184 | |
185 | |
185 | # this function converts metals/minerals into a raw ring (of adornment) |
186 | # this function converts metals/minerals into a raw ring (of adornment) |
186 | sub simple_converter { |
187 | sub simple_converter { |
187 | my ($pl, $ingred, $chdl, $conv) = @_; |
188 | my ($pl, $ingred, $chdl, $conv, $sk_lvl, $low_skill_cb) = @_; |
188 | |
189 | |
189 | $conv = lc $conv; |
190 | $conv = lc $conv; |
190 | my $cnvs = $CFG->{conversions}; |
191 | my $cnvs = $CFG->{conversions}; |
191 | |
192 | |
192 | return unless $cnvs->{$conv}; |
193 | return unless $cnvs->{$conv}; |
… | |
… | |
214 | |
215 | |
215 | unless ($outarchvalfact >= 1) { |
216 | unless ($outarchvalfact >= 1) { |
216 | 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"; |
217 | } |
218 | } |
218 | |
219 | |
219 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
220 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
220 | $ingred->remove ($ingr_grp, $srcarchname); |
|
|
221 | |
|
|
222 | my $outarchval = cf::arch::find ($outarch)->value; |
221 | my $outarchval = cf::arch::find ($outarch)->value; |
223 | |
|
|
224 | 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 | |
225 | if ($nrof) { |
230 | if ($nrof) { |
226 | # 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); |
227 | for (1 .. $nrof) { |
233 | for (1 .. $nrof) { |
228 | $chdl->put (my $ob = cf::object::new $outarch); |
234 | $chdl->put (my $ob = cf::object::new $outarch); |
229 | $ob->set_animation (cf::rndm $ob->num_animations) |
235 | $ob->set_animation (cf::rndm $ob->num_animations) |
230 | if ($ob->type == cf::RING); |
236 | if ($ob->type == cf::RING); |
231 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
237 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
… | |
… | |
475 | } |
481 | } |
476 | |
482 | |
477 | sub improve_ring_by_plan { |
483 | sub improve_ring_by_plan { |
478 | my ($self, $plan, $ring) = @_; |
484 | my ($self, $plan, $ring) = @_; |
479 | |
485 | |
480 | $ring = do { my $guard = Coro::Storable::guard; dclone $ring }; |
486 | $ring = dclone $ring; |
481 | |
487 | |
482 | my $ingred = $self->{ingredients}; |
488 | my $ingred = $self->{ingredients}; |
483 | my $impr = {}; |
489 | my $impr = {}; |
484 | |
490 | |
485 | if ($plan =~ m/^stat_(\S+)$/) { |
491 | if ($plan =~ m/^stat_(\S+)$/) { |
… | |
… | |
569 | } |
575 | } |
570 | |
576 | |
571 | sub check_costs { |
577 | sub check_costs { |
572 | my ($self, $costs, $do_remove) = @_; |
578 | my ($self, $costs, $do_remove) = @_; |
573 | |
579 | |
574 | my $costs = do { my $guard = Coro::Storable::guard; dclone $costs }; |
580 | my $costs = dclone $costs; |
575 | |
581 | |
576 | for my $key (keys %$costs) { |
582 | for my $key (keys %$costs) { |
577 | my @grepar; |
583 | my @grepar; |
578 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
584 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
579 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
585 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
… | |
… | |
582 | @grepar = ('gems', undef, undef, $key); |
588 | @grepar = ('gems', undef, undef, $key); |
583 | } |
589 | } |
584 | |
590 | |
585 | if ($do_remove) { |
591 | if ($do_remove) { |
586 | my $rem = $costs->{$key}; |
592 | my $rem = $costs->{$key}; |
|
|
593 | $self->do_grep (sub { |
587 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
594 | if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } |
|
|
595 | 1 |
|
|
596 | }, @grepar); |
588 | if ($rem > 0) { |
597 | if ($rem > 0) { |
589 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
598 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
590 | } |
599 | } |
|
|
600 | |
591 | } else { |
601 | } else { |
592 | my $nr; |
602 | my $nr; |
593 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
603 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
594 | $costs->{$key} -= $nr; |
604 | $costs->{$key} -= $nr; |
595 | } |
605 | } |
… | |
… | |
659 | $exp -= $subexp; |
669 | $exp -= $subexp; |
660 | $exp = max ($exp, 0); |
670 | $exp = max ($exp, 0); |
661 | |
671 | |
662 | } else { |
672 | } else { |
663 | # the experience bonus here is to make level 1 rings give you at least |
673 | # 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 |
674 | # 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). |
675 | # first few levels a bit easier. (probably until around level 5-6). |
666 | my $expbonus = cf::level_to_min_exp (2) / 10; |
676 | my $expbonus = cf::level_to_min_exp (2) / 5; |
667 | # this bonus should also only be given for _new_ rings and not for merged |
677 | # this bonus should also only be given for _new_ rings and not for merged |
668 | # ones - to prevent infinite exp making. |
678 | # ones - to prevent infinite exp making. |
669 | $exp += $expbonus; |
679 | $exp += $expbonus; |
670 | } |
680 | } |
671 | |
681 | |
… | |
… | |
715 | if (defined $costs) { |
725 | if (defined $costs) { |
716 | my $desc = ""; |
726 | my $desc = ""; |
717 | my $lvl = $self->power_to_level (\$desc); |
727 | my $lvl = $self->power_to_level (\$desc); |
718 | my $scosts = $self->calc_value_from_cost ($costs); |
728 | my $scosts = $self->calc_value_from_cost ($costs); |
719 | |
729 | |
720 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
730 | $pl->message ("costs: " |
|
|
731 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
|
|
732 | . " (" |
|
|
733 | . ($scosts / "platinacoin"->cf::arch::find->value) |
|
|
734 | . " platinum)"); |
721 | $pl->message ("level: " . $desc); |
735 | $pl->message ("level: $desc"); |
722 | } else { |
736 | } else { |
723 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
737 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
724 | } |
738 | } |
725 | } |
739 | } |
726 | |
740 | |
… | |
… | |
829 | $obj->{arch} = $thing->arch->archname; |
843 | $obj->{arch} = $thing->arch->archname; |
830 | $obj->{face} = $thing->face; |
844 | $obj->{face} = $thing->face; |
831 | |
845 | |
832 | $obj->{value} = $thing->value; |
846 | $obj->{value} = $thing->value; |
833 | |
847 | |
|
|
848 | $obj->{is_ring} = ($thing->type == cf::RING); |
|
|
849 | |
834 | $self->{hash} = $obj |
850 | $self->{hash} = $obj |
835 | } |
851 | } |
836 | |
852 | |
837 | sub to_object { |
853 | sub to_object { |
838 | my ($self) = @_; |
854 | my ($self) = @_; |
… | |
… | |
900 | sub resist_level { |
916 | sub resist_level { |
901 | my ($self) = @_; |
917 | my ($self) = @_; |
902 | |
918 | |
903 | my $resists = $self->{hash}->{resist} || {}; |
919 | my $resists = $self->{hash}->{resist} || {}; |
904 | |
920 | |
905 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
921 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
906 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
922 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
907 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
923 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
908 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
924 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
909 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
925 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
910 | |
926 | |
911 | my $ressum = 0; |
927 | my $ressum = 0; |
… | |
… | |
971 | sub power_to_level { |
987 | sub power_to_level { |
972 | my ($self, $lvldescr) = @_; |
988 | my ($self, $lvldescr) = @_; |
973 | |
989 | |
974 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
990 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
975 | my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); |
991 | my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); |
|
|
992 | my $ring_offs = Jeweler::getcfg (maxlevels => 'ring_offset'); |
976 | |
993 | |
977 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
994 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
978 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
995 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
979 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
996 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
980 | |
997 | |
981 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
998 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
982 | |
999 | |
983 | my $impr_lvl = ceil (($max_impr_lvl / ($max_imprs + 1)) * ($impr_sum - 1)); # 1 improvemnt bonus |
1000 | my $impr_lvl = |
|
|
1001 | ceil (($max_impr_lvl / ($max_imprs + 1)) |
|
|
1002 | * ($impr_sum - 1)); # 1 improvemnt bonus |
984 | |
1003 | |
985 | my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); |
1004 | my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); |
|
|
1005 | |
|
|
1006 | if ($self->{hash}->{is_ring}) { |
|
|
1007 | $levl += $ring_offs; |
|
|
1008 | } |
|
|
1009 | |
|
|
1010 | $levl = min ($levl, cf::settings->max_level); |
986 | |
1011 | |
987 | if ($lvldescr) { |
1012 | if ($lvldescr) { |
988 | $$lvldescr = |
1013 | $$lvldescr = |
989 | sprintf "%3d: %s\n", $levl, |
1014 | sprintf "%3d: %s\n", $levl, |
990 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
1015 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
… | |
… | |
1092 | =over 4 |
1117 | =over 4 |
1093 | |
1118 | |
1094 | =item remove ($object[, $nrof]) |
1119 | =item remove ($object[, $nrof]) |
1095 | |
1120 | |
1096 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1121 | 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. |
1122 | The return value is the number of 'single' objects that couldn't be removed. |
1098 | |
1123 | |
1099 | =cut |
1124 | =cut |
1100 | |
1125 | |
1101 | sub remove { |
1126 | sub remove { |
1102 | my ($obj, $nrof) = @_; |
1127 | my ($obj, $nrof) = @_; |
|
|
1128 | |
|
|
1129 | my $c = $obj->nrof || 1; |
|
|
1130 | my $r = $c > $nrof ? 0 : $nrof - $c; |
|
|
1131 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1103 | |
1132 | |
1104 | my $cnt; |
1133 | $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 | } |
1134 | } |
1121 | |
1135 | |
1122 | sub check_for_match { |
1136 | sub check_for_match { |
1123 | my ($thing, @matchar) = @_; |
1137 | my ($thing, @matchar) = @_; |
1124 | |
1138 | |