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