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