… | |
… | |
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 | |
… | |
… | |
186 | unless $found; |
185 | unless $found; |
187 | } |
186 | } |
188 | |
187 | |
189 | # this function converts metals/minerals into a raw ring (of adornment) |
188 | # this function converts metals/minerals into a raw ring (of adornment) |
190 | sub simple_converter { |
189 | sub simple_converter { |
191 | my ($pl, $ingred, $chdl, $conv) = @_; |
190 | my ($pl, $ingred, $chdl, $conv, $sk_lvl, $low_skill_cb) = @_; |
192 | |
191 | |
193 | $conv = lc $conv; |
192 | $conv = lc $conv; |
194 | my $cnvs = $CFG->{conversions}; |
193 | my $cnvs = $CFG->{conversions}; |
195 | |
194 | |
196 | return unless $cnvs->{$conv}; |
195 | return unless $cnvs->{$conv}; |
… | |
… | |
218 | |
217 | |
219 | unless ($outarchvalfact >= 1) { |
218 | unless ($outarchvalfact >= 1) { |
220 | 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"; |
221 | } |
220 | } |
222 | |
221 | |
223 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
222 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
224 | $ingred->remove ($ingr_grp, $srcarchname); |
|
|
225 | |
|
|
226 | my $outarchval = cf::arch::find ($outarch)->value; |
223 | my $outarchval = cf::arch::find ($outarch)->value; |
227 | |
|
|
228 | 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 | |
229 | if ($nrof) { |
232 | 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) |
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); |
231 | for (1 .. $nrof) { |
235 | for (1 .. $nrof) { |
232 | $chdl->put (my $ob = cf::object::new $outarch); |
236 | $chdl->put (my $ob = cf::object::new $outarch); |
233 | $ob->set_animation (cf::rndm $ob->num_animations) |
237 | $ob->set_animation (cf::rndm $ob->num_animations) |
234 | if ($ob->type == cf::RING); |
238 | if ($ob->type == cf::RING); |
235 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
239 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
… | |
… | |
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 | } |
… | |
… | |
663 | $exp -= $subexp; |
671 | $exp -= $subexp; |
664 | $exp = max ($exp, 0); |
672 | $exp = max ($exp, 0); |
665 | |
673 | |
666 | } else { |
674 | } else { |
667 | # 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 |
668 | # 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 |
669 | # 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). |
670 | my $expbonus = cf::level_to_min_exp (2) / 10; |
678 | my $expbonus = cf::level_to_min_exp (2) / 5; |
671 | # 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 |
672 | # ones - to prevent infinite exp making. |
680 | # ones - to prevent infinite exp making. |
673 | $exp += $expbonus; |
681 | $exp += $expbonus; |
674 | } |
682 | } |
675 | |
683 | |
… | |
… | |
722 | my $scosts = $self->calc_value_from_cost ($costs); |
730 | my $scosts = $self->calc_value_from_cost ($costs); |
723 | |
731 | |
724 | $pl->message ("costs: " |
732 | $pl->message ("costs: " |
725 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
733 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
726 | . " (" |
734 | . " (" |
727 | . ($scosts / "royalty"->cf::arch::find->value) |
735 | . ($scosts / "platinacoin"->cf::arch::find->value) |
728 | . " royalties)"); |
736 | . " platinum)"); |
729 | $pl->message ("level: $desc"); |
737 | $pl->message ("level: $desc"); |
730 | } else { |
738 | } else { |
731 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
739 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
732 | } |
740 | } |
733 | } |
741 | } |
… | |
… | |
908 | sub resist_level { |
916 | sub resist_level { |
909 | my ($self) = @_; |
917 | my ($self) = @_; |
910 | |
918 | |
911 | my $resists = $self->{hash}->{resist} || {}; |
919 | my $resists = $self->{hash}->{resist} || {}; |
912 | |
920 | |
913 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
921 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
914 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
922 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
915 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
923 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
916 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
924 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
917 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
925 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
918 | |
926 | |
919 | my $ressum = 0; |
927 | my $ressum = 0; |
… | |
… | |
1100 | =over 4 |
1108 | =over 4 |
1101 | |
1109 | |
1102 | =item remove ($object[, $nrof]) |
1110 | =item remove ($object[, $nrof]) |
1103 | |
1111 | |
1104 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1112 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1105 | The returnvalue is the number of 'single' objects that couldn't be removed. |
1113 | The return value is the number of 'single' objects that couldn't be removed. |
1106 | |
1114 | |
1107 | =cut |
1115 | =cut |
1108 | |
1116 | |
1109 | sub remove { |
1117 | sub remove { |
1110 | my ($obj, $nrof) = @_; |
1118 | my ($obj, $nrof) = @_; |
|
|
1119 | |
|
|
1120 | my $c = $obj->nrof || 1; |
|
|
1121 | my $r = $c > $nrof ? 0 : $nrof - $c; |
|
|
1122 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1111 | |
1123 | |
1112 | my $cnt; |
1124 | $r |
1113 | |
|
|
1114 | if (defined $nrof) { |
|
|
1115 | # TODO: Check tihis line: |
|
|
1116 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
|
|
1117 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
|
|
1118 | |
|
|
1119 | if ($cnt > 0) { |
|
|
1120 | $obj->nrof ($cnt); |
|
|
1121 | return 0; |
|
|
1122 | } |
|
|
1123 | } |
|
|
1124 | |
|
|
1125 | remove ($_) for $obj->inv; |
|
|
1126 | $obj->destroy; |
|
|
1127 | return $cnt; |
|
|
1128 | } |
1125 | } |
1129 | |
1126 | |
1130 | sub check_for_match { |
1127 | sub check_for_match { |
1131 | my ($thing, @matchar) = @_; |
1128 | my ($thing, @matchar) = @_; |
1132 | |
1129 | |