… | |
… | |
162 | $delta = 5 if $delta > 5; |
162 | $delta = 5 if $delta > 5; |
163 | return $LVL_DIFF_CHANCES{$delta} |
163 | return $LVL_DIFF_CHANCES{$delta} |
164 | } |
164 | } |
165 | |
165 | |
166 | sub analyze { |
166 | sub analyze { |
167 | my ($sk, $chdl, $pl) = @_; |
167 | my ($sk, $chdl, $pl, $input_level) = @_; |
168 | |
168 | |
169 | my $hadunid = 0; |
169 | my $hadunid = 0; |
170 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
170 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
171 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
171 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
172 | $hadunid = 1; |
172 | $hadunid = 1; |
173 | next; |
173 | next; |
174 | } |
174 | } |
175 | my $r = Jeweler::Object->new (object => $_); |
175 | my $r = Jeweler::Object->new (object => $_); |
176 | my $msg = $r->analyze ($sk, $pl); |
176 | my $msg = $r->analyze ($sk, $pl, $input_level); |
177 | $pl->message ($r->to_string . ": " . $msg); |
177 | $pl->message ($r->to_string . ": " . $msg); |
178 | if ($pl->flag (cf::FLAG_WIZ)) { |
178 | if ($pl->flag (cf::FLAG_WIZ)) { |
179 | $r->wiz_analyze ($pl); |
179 | $r->wiz_analyze ($pl); |
180 | } |
180 | } |
181 | } |
181 | } |
… | |
… | |
219 | } |
219 | } |
220 | |
220 | |
221 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
221 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
222 | $ingred->remove ($ingr_grp, $srcarchname); |
222 | $ingred->remove ($ingr_grp, $srcarchname); |
223 | |
223 | |
224 | my $outarchval = cf::arch::find ($outarch)->clone->value; |
224 | my $outarchval = cf::arch::find ($outarch)->value; |
225 | |
225 | |
226 | my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); |
226 | my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); |
227 | if ($nrof) { |
227 | if ($nrof) { |
228 | # XXX: yes, i know what i'm doing here, i don't set nrof, but it didn't work somehow (pls. chek sometimes) |
228 | # XXX: yes, i know what i'm doing here, i don't set nrof, but it didn't work somehow (pls. chek sometimes) |
229 | for (1..$nrof) { |
229 | for (1..$nrof) { |
230 | $chdl->put (my $ob = cf::object::new $outarch); |
230 | $chdl->put (my $ob = cf::object::new $outarch); |
231 | $ob->set_animation (cf::rndm $ob->num_animations); |
231 | $ob->set_animation (cf::rndm $ob->num_animations) |
|
|
232 | if ($ob->type == cf::RING); |
232 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
233 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
233 | } |
234 | } |
234 | |
235 | |
235 | my $xp_sum = ($xp_gain * $nrof); |
236 | my $xp_sum = ($xp_gain * $nrof); |
236 | |
237 | |
237 | if ($xp_sum) { |
238 | if ($xp_sum) { |
238 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
239 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
239 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
240 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
240 | } |
241 | } |
241 | } else { |
242 | } else { |
242 | $pl->ob->message ("You fail to make something, propably you used not enough source material?"); |
243 | $pl->ob->message ("You fail to make something, probably you used not enough source material?"); |
243 | } |
244 | } |
244 | } |
245 | } |
245 | |
246 | |
246 | |
247 | |
247 | package Jeweler::CauldronHandler; |
248 | package Jeweler::CauldronHandler; |
… | |
… | |
279 | my ($self, $arch_name, @map_stack) = @_; |
280 | my ($self, $arch_name, @map_stack) = @_; |
280 | |
281 | |
281 | my @c = |
282 | my @c = |
282 | grep { |
283 | grep { |
283 | $_->flag (cf::FLAG_IS_CAULDRON) |
284 | $_->flag (cf::FLAG_IS_CAULDRON) |
284 | and $_->arch->name eq $arch_name |
285 | and $_->arch->archname eq $arch_name |
285 | } @map_stack; |
286 | } @map_stack; |
286 | |
287 | |
287 | $self->{cauldron} = $c[0]; |
288 | $self->{cauldron} = $c[0]; |
288 | } |
289 | } |
289 | |
290 | |
… | |
… | |
328 | cf::POTION => 'potions', |
329 | cf::POTION => 'potions', |
329 | cf::SCROLL => 'scrolls', |
330 | cf::SCROLL => 'scrolls', |
330 | ); |
331 | ); |
331 | |
332 | |
332 | for ($self->{cauldron}->inv) { |
333 | for ($self->{cauldron}->inv) { |
|
|
334 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
|
|
335 | die "unidentified"; |
|
|
336 | } elsif ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { |
|
|
337 | die "cursed"; |
|
|
338 | } |
333 | |
339 | |
334 | if (my $k = $type_to_key{$_->type}) { |
340 | if (my $k = $type_to_key{$_->type}) { |
335 | push @{$ingreds->{$k}}, $_; |
341 | push @{$ingreds->{$k}}, $_; |
336 | } else { |
342 | } else { |
337 | push @{$ingreds->{other}}, $_; |
343 | push @{$ingreds->{other}}, $_; |
… | |
… | |
349 | |
355 | |
350 | sub put { |
356 | sub put { |
351 | my ($self, $obj) = @_; |
357 | my ($self, $obj) = @_; |
352 | |
358 | |
353 | return undef unless $self->{cauldron}; |
359 | return undef unless $self->{cauldron}; |
354 | $obj->insert_ob_in_ob ($self->{cauldron}); |
360 | $self->{cauldron}->insert ($obj); |
355 | } |
361 | } |
356 | |
362 | |
357 | =back |
363 | =back |
358 | |
364 | |
359 | =cut |
365 | =cut |
… | |
… | |
392 | |
398 | |
393 | sub value { |
399 | sub value { |
394 | my ($self, $group, $archname) = @_; |
400 | my ($self, $group, $archname) = @_; |
395 | |
401 | |
396 | my @objs = grep { |
402 | my @objs = grep { |
397 | $_->arch->name eq $archname |
403 | $_->arch->archname eq $archname |
398 | } @{$self->{ingredients}->{$group} || []}; |
404 | } @{$self->{ingredients}->{$group} || []}; |
399 | |
405 | |
400 | my $sum = 0; |
406 | my $sum = 0; |
401 | for (@objs) { |
407 | for (@objs) { |
402 | $sum += ($_->nrof || 1) * $_->value; |
408 | $sum += ($_->nrof || 1) * $_->value; |
… | |
… | |
419 | |
425 | |
420 | my @out; |
426 | my @out; |
421 | |
427 | |
422 | for (@{$ingred->{$group}}) { |
428 | for (@{$ingred->{$group}}) { |
423 | if (defined $archname) { |
429 | if (defined $archname) { |
424 | if ($_->arch->name eq $archname) { |
430 | if ($_->arch->archname eq $archname) { |
425 | Jeweler::Util::remove ($_); |
431 | Jeweler::Util::remove ($_); |
426 | } else { |
432 | } else { |
427 | push @out, $_; |
433 | push @out, $_; |
428 | } |
434 | } |
429 | } else { |
435 | } else { |
… | |
… | |
570 | my $costs = dclone ($costs); |
576 | my $costs = dclone ($costs); |
571 | |
577 | |
572 | for my $key (keys %$costs) { |
578 | for my $key (keys %$costs) { |
573 | my @grepar; |
579 | my @grepar; |
574 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
580 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
575 | @grepar = @{Jeweler::getcfg (plans => $key) || []}; |
581 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
|
|
582 | next if $@; |
576 | } else { # check the gems |
583 | } else { # check the gems |
577 | @grepar = ('gems', undef, undef, $key); |
584 | @grepar = ('gems', undef, undef, $key); |
578 | } |
585 | } |
579 | |
586 | |
580 | if ($do_remove) { |
587 | if ($do_remove) { |
… | |
… | |
585 | } |
592 | } |
586 | } else { |
593 | } else { |
587 | my $nr; |
594 | my $nr; |
588 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
595 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
589 | $costs->{$key} -= $nr; |
596 | $costs->{$key} -= $nr; |
590 | warn "CHECKCOST $key <-> $nr -> $costs->{$key}\n"; |
|
|
591 | } |
597 | } |
592 | |
598 | |
593 | } |
599 | } |
594 | |
600 | |
595 | return $costs; |
601 | return $costs; |
… | |
… | |
624 | $self->ring_or_ammy_to_hash ($arg{object}); |
630 | $self->ring_or_ammy_to_hash ($arg{object}); |
625 | |
631 | |
626 | $self; |
632 | $self; |
627 | } |
633 | } |
628 | |
634 | |
|
|
635 | sub has_resist { |
|
|
636 | my ($self, $resistnam, $resistval) = @_; |
|
|
637 | my $resnum = $REV_RESMAP{uc $resistnam}; |
|
|
638 | if (defined ($resistval)) { |
|
|
639 | return 1 if $self->{hash}->{resist}->{$resnum} == $resistval; |
|
|
640 | } else { |
|
|
641 | return 1 if $self->{hash}->{resist}->{$resnum}; |
|
|
642 | } |
|
|
643 | return undef; |
|
|
644 | } |
|
|
645 | |
|
|
646 | sub projected_exp { |
|
|
647 | my ($self, $input_level) = @_; |
|
|
648 | |
|
|
649 | my $lvl = max ($self->power_to_level, 1); |
|
|
650 | my $exp = |
|
|
651 | (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) |
|
|
652 | / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring |
|
|
653 | # should get you to the rings level at least. |
|
|
654 | |
|
|
655 | if (defined $input_level) { |
|
|
656 | my $subexp = |
|
|
657 | (cf::level_to_min_exp ($input_level) |
|
|
658 | - cf::level_to_min_exp ($input_level - 1)) |
|
|
659 | / (10 + max ($input_level - 1, 0)); # see above for comment |
|
|
660 | |
|
|
661 | $exp -= $subexp; |
|
|
662 | $exp = max ($exp, 0); |
|
|
663 | |
|
|
664 | } else { |
|
|
665 | # the experience bonus here is to make level 1 rings give you at least |
|
|
666 | # 100 exp points when making them. This also makes leveling in the |
|
|
667 | # first few levels a bit easier. (probably until around level 5-6). |
|
|
668 | my $expbonus = cf::level_to_min_exp (2) / 10; |
|
|
669 | # this bonus should also only be given for _new_ rings and not for merged |
|
|
670 | # ones - to prevent infinite exp making. |
|
|
671 | $exp += $expbonus; |
|
|
672 | } |
|
|
673 | |
|
|
674 | $exp |
|
|
675 | } |
|
|
676 | |
629 | sub analyze { |
677 | sub analyze { |
630 | my ($self, $sk, $pl) = @_; |
678 | my ($self, $sk, $pl, $input_level) = @_; |
|
|
679 | my $costs = $self->calc_costs; |
|
|
680 | |
|
|
681 | unless (defined $costs) { |
|
|
682 | return "This ring has a resistancy above 99%, you can't make that."; |
|
|
683 | } |
631 | |
684 | |
632 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
685 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
633 | my $ringlvl = $self->power_to_level; |
686 | my $ringlvl = $self->power_to_level; |
634 | |
687 | |
635 | my $tmpl; |
688 | my $tmpl; |
636 | if ($pl->flag (cf::FLAG_WIZ)) { |
689 | if ($pl->flag (cf::FLAG_WIZ)) { |
637 | $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); |
690 | $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); |
638 | } else { |
691 | } else { |
639 | $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); |
692 | $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); |
640 | } |
693 | } |
641 | my $msg = sprintf "Projected success rate: %s", $tmpl; |
694 | my $msg = sprintf "Projected success rate: %s, you would get %d exp for this.", $tmpl, $self->projected_exp ($input_level); |
642 | return $msg; |
695 | return $msg; |
|
|
696 | } |
|
|
697 | |
|
|
698 | sub calc_value_from_cost { |
|
|
699 | my ($self, $costs) = @_; |
|
|
700 | my $emarch = cf::arch::find 'emerald'; |
|
|
701 | my $saarch = cf::arch::find 'sapphire'; |
|
|
702 | my $pearch = cf::arch::find 'pearl'; |
|
|
703 | my $ruarch = cf::arch::find 'ruby'; |
|
|
704 | my $diarch = cf::arch::find 'gem'; |
|
|
705 | my $value = $emarch->value * $costs->{emerald} |
|
|
706 | + $saarch->value * $costs->{sapphire} |
|
|
707 | + $pearch->value * $costs->{pearl} |
|
|
708 | + $ruarch->value * $costs->{ruby} |
|
|
709 | + $diarch->value * $costs->{gem}; |
|
|
710 | |
|
|
711 | $value |
643 | } |
712 | } |
644 | |
713 | |
645 | sub wiz_analyze { |
714 | sub wiz_analyze { |
646 | my ($self, $pl) = @_; |
715 | my ($self, $pl) = @_; |
647 | my $costs = $self->calc_costs; |
716 | my $costs = $self->calc_costs; |
|
|
717 | if (defined $costs) { |
648 | my $desc = ""; |
718 | my $desc = ""; |
649 | my $lvl = $self->power_to_level (\$desc); |
719 | my $lvl = $self->power_to_level (\$desc); |
|
|
720 | my $scosts = $self->calc_value_from_cost ($costs); |
|
|
721 | |
650 | $pl->message ("costs: " . join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)); |
722 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
651 | $pl->message ("level: " . $desc); |
723 | $pl->message ("level: " . $desc); |
|
|
724 | } else { |
|
|
725 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
|
|
726 | } |
652 | } |
727 | } |
653 | |
|
|
654 | |
728 | |
655 | sub get_chance_perc { |
729 | sub get_chance_perc { |
656 | my ($self, $sk) = @_; |
730 | my ($self, $sk) = @_; |
657 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
731 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
658 | my $ringlvl = $self->power_to_level; |
732 | my $ringlvl = $self->power_to_level; |
… | |
… | |
661 | |
735 | |
662 | sub fx { |
736 | sub fx { |
663 | my ($res, $cfg) = @_; |
737 | my ($res, $cfg) = @_; |
664 | my $or = $res; |
738 | my $or = $res; |
665 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
739 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
|
|
740 | |
666 | if (ref $ar->[0] eq 'ARRAY') { |
741 | if (ref $ar && ref $ar->[0] eq 'ARRAY') { |
667 | $res = $res - 1; |
742 | $res = $res - 1; |
|
|
743 | return $ar->[max (min ($res, @$ar - 1), 0)]; |
|
|
744 | |
668 | } else { |
745 | } else { |
669 | $res = ceil ($res / 5) - 1; |
746 | # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3... |
670 | } |
747 | # old code: |
|
|
748 | #my $idx = ceil (($res / 5) + 0.1) - 1; |
671 | $ar->[max (min ($res, @$ar - 1), 0)]; |
749 | #my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; |
|
|
750 | #my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; |
|
|
751 | #my $diff = $b - $a; # use the difference of the cost to the next cost |
|
|
752 | #my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation |
|
|
753 | #return $o_cost; |
|
|
754 | return 0 if $res <= 0; |
|
|
755 | return ($ar / (1 - ($res * 0.01)) - $ar) |
|
|
756 | } |
672 | } |
757 | } |
673 | |
758 | |
674 | sub improve_by_ring { |
759 | sub improve_by_ring { |
675 | my ($self, @rings) = @_; |
760 | my ($self, @rings) = @_; |
676 | my $ring = $self; |
761 | my $ring = $self; |
… | |
… | |
692 | if ($self->{hash}->{$cat}->{$k} > 0) { |
777 | if ($self->{hash}->{$cat}->{$k} > 0) { |
693 | $self->{hash}->{$cat}->{$k} *= -1; |
778 | $self->{hash}->{$cat}->{$k} *= -1; |
694 | } |
779 | } |
695 | } |
780 | } |
696 | } |
781 | } |
|
|
782 | $self->{hash}{value} = 0; |
697 | } |
783 | } |
698 | |
784 | |
699 | sub to_string { |
785 | sub to_string { |
700 | my ($self) = @_; |
786 | my ($self) = @_; |
701 | my $r = $self->{hash}; |
787 | my $r = $self->{hash}; |
… | |
… | |
740 | $obj->{spec}{ac} = $stats->ac; |
826 | $obj->{spec}{ac} = $stats->ac; |
741 | $obj->{spec}{speed} = $stats->exp; |
827 | $obj->{spec}{speed} = $stats->exp; |
742 | $obj->{spec}{food} = $stats->food; |
828 | $obj->{spec}{food} = $stats->food; |
743 | |
829 | |
744 | $obj->{name} = $thing->name; |
830 | $obj->{name} = $thing->name; |
745 | $obj->{arch} = $thing->arch->name; |
831 | $obj->{arch} = $thing->arch->archname; |
746 | $obj->{face} = $thing->face; |
832 | $obj->{face} = $thing->face; |
|
|
833 | |
|
|
834 | $obj->{value} = $thing->value; |
747 | |
835 | |
748 | $self->{hash} = $obj |
836 | $self->{hash} = $obj |
749 | } |
837 | } |
750 | |
838 | |
751 | sub to_object { |
839 | sub to_object { |
752 | my ($self) = @_; |
840 | my ($self) = @_; |
753 | |
841 | |
754 | my $obj = cf::object::new $self->{hash}->{arch}; |
842 | my $obj = cf::object::new $self->{hash}->{arch}; |
|
|
843 | |
|
|
844 | $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached! |
755 | |
845 | |
756 | $obj->face ($self->{hash}{face}); |
846 | $obj->face ($self->{hash}{face}); |
757 | |
847 | |
758 | my $stats = $obj->stats; |
848 | my $stats = $obj->stats; |
759 | |
849 | |
… | |
… | |
772 | $obj->resist ($_, $self->{hash}->{resist}->{$_}); |
862 | $obj->resist ($_, $self->{hash}->{resist}->{$_}); |
773 | } |
863 | } |
774 | |
864 | |
775 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
865 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
776 | |
866 | |
|
|
867 | $obj->value ($self->{hash}{value}); |
|
|
868 | |
777 | return $obj; |
869 | return $obj; |
778 | } |
870 | } |
|
|
871 | |
|
|
872 | sub set_value { $_[0]->{hash}{value} = $_[1] } |
779 | |
873 | |
780 | sub is_better_than { |
874 | sub is_better_than { |
781 | my ($self, $other) = @_; |
875 | my ($self, $other) = @_; |
782 | |
876 | |
783 | for my $type (qw/spec stat resist/) { |
877 | for my $type (qw/spec stat resist/) { |
… | |
… | |
945 | |
1039 | |
946 | my $res = $ring->{resist}->{$resnum}; |
1040 | my $res = $ring->{resist}->{$resnum}; |
947 | |
1041 | |
948 | next unless $res > 0; |
1042 | next unless $res > 0; |
949 | |
1043 | |
|
|
1044 | return undef if $res == 100; |
|
|
1045 | |
950 | $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; |
1046 | $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; |
951 | |
1047 | |
952 | my $diamonds; |
1048 | my $diamonds; |
953 | if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { |
1049 | if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { |
954 | $diamonds += fx ($res, 'effect_resist_diamonds'); |
1050 | $diamonds += fx ($res, 'effect_resist_diamonds_x'); |
955 | } else { |
1051 | } else { |
956 | $diamonds += fx ($res, 'attack_resist_diamonds'); |
1052 | $diamonds += fx ($res, 'attack_resist_diamonds_x'); |
957 | } |
1053 | } |
958 | |
1054 | |
959 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); |
1055 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); |
960 | } |
1056 | } |
961 | |
1057 | |
… | |
… | |
969 | my ($cost, $diamonds, $category) = @_; |
1065 | my ($cost, $diamonds, $category) = @_; |
970 | |
1066 | |
971 | my $stat_split = Jeweler::getcfg (diamond_split => $category); |
1067 | my $stat_split = Jeweler::getcfg (diamond_split => $category); |
972 | |
1068 | |
973 | my $sum = sum (@$stat_split); |
1069 | my $sum = sum (@$stat_split); |
974 | if ($sum < (1 - 0.0001)) { |
|
|
975 | warn "JEWELER BUG: sum (@$stat_split) = $sum < 1 for $category!"; |
|
|
976 | } |
|
|
977 | |
1070 | |
978 | my $emarch = cf::arch::find 'emerald'; |
1071 | my $emarch = cf::arch::find 'emerald'; |
979 | my $saarch = cf::arch::find 'sapphire'; |
1072 | my $saarch = cf::arch::find 'sapphire'; |
980 | my $pearch = cf::arch::find 'pearl'; |
1073 | my $pearch = cf::arch::find 'pearl'; |
981 | my $ruarch = cf::arch::find 'ruby'; |
1074 | my $ruarch = cf::arch::find 'ruby'; |
982 | my $diarch = cf::arch::find 'gem'; |
1075 | my $diarch = cf::arch::find 'gem'; |
983 | |
1076 | |
984 | my $sumvalue = $diarch->clone->value * $diamonds; |
1077 | my $sumvalue = $diarch->value * $diamonds; |
985 | |
1078 | |
986 | $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->clone->value; |
1079 | $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->value; |
987 | $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->clone->value; |
1080 | $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->value; |
988 | $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->clone->value; |
1081 | $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->value; |
989 | $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->clone->value; |
1082 | $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->value; |
990 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->clone->value; |
1083 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
991 | } |
1084 | } |
992 | |
1085 | |
993 | package Jeweler::Util; |
1086 | package Jeweler::Util; |
994 | |
1087 | |
995 | use strict; |
1088 | use strict; |
… | |
… | |
1030 | |
1123 | |
1031 | sub check_for_match { |
1124 | sub check_for_match { |
1032 | my ($thing, @matchar) = @_; |
1125 | my ($thing, @matchar) = @_; |
1033 | |
1126 | |
1034 | my $i = 0; |
1127 | my $i = 0; |
|
|
1128 | my $check_cnts = 0; |
|
|
1129 | my $check_true = 0; |
1035 | for my $match (@matchar) { |
1130 | for my $match (@matchar) { |
|
|
1131 | if ($i % 3 == 0) { |
|
|
1132 | return 1 if $check_true && $check_cnts == $check_true; |
|
|
1133 | $check_cnts = 0; |
|
|
1134 | $check_true = 0; |
|
|
1135 | } |
|
|
1136 | |
1036 | if ($match =~ m/^\s*$/) { |
1137 | if ($match =~ m/^\s*$/) { |
1037 | $i++; |
1138 | $i++; |
1038 | next; |
1139 | next; |
1039 | } |
1140 | } |
1040 | |
1141 | |
|
|
1142 | $check_cnts++; |
1041 | if ($i % 3 == 0) { |
1143 | if ($i % 3 == 0) { |
1042 | $thing->name eq $match |
1144 | $thing->name eq $match |
1043 | and return 1; |
1145 | and $check_true++; |
1044 | } elsif ($i % 3 == 1) { |
1146 | } elsif ($i % 3 == 1) { |
1045 | $thing->title eq $match |
1147 | $thing->title eq $match |
1046 | and return 1; |
1148 | and $check_true++; |
1047 | } else { # $i % 3 == 2 |
1149 | } else { # $i % 3 == 2 |
1048 | $thing->arch->name eq $match |
1150 | $thing->arch->archname eq $match |
1049 | and return 1; |
1151 | and $check_true++; |
1050 | } |
1152 | } |
1051 | $i++; |
1153 | $i++; |
1052 | } |
1154 | } |
|
|
1155 | #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->archname))."\n"; |
|
|
1156 | return 1 if $check_true && $check_cnts == $check_true; |
1053 | return 0; |
1157 | return 0; |
1054 | } |
1158 | } |
1055 | |
1159 | |
1056 | sub grep_for_match { |
1160 | sub grep_for_match { |
1057 | my ($ingred, $group, @matchar) = @_; |
1161 | my ($ingred, $group, @matchar) = @_; |
1058 | |
1162 | |
1059 | for my $thing (@{$ingred->{$group} || []}) { |
1163 | for my $thing (@{$ingred->{$group} || []}) { |
1060 | warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# |
1164 | #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->archname, "@matchar"; #d# |
1061 | if (check_for_match ($thing, @matchar)) { |
1165 | if (check_for_match ($thing, @matchar)) { |
1062 | return $thing; |
1166 | return $thing; |
1063 | } |
1167 | } |
1064 | } |
1168 | } |
1065 | return undef; |
1169 | return undef; |