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