… | |
… | |
117 | cf::ATNR_LIFE_STEALING => "LIFE_STEALING", |
117 | cf::ATNR_LIFE_STEALING => "LIFE_STEALING", |
118 | cf::ATNR_BLIND => "BLIND", |
118 | cf::ATNR_BLIND => "BLIND", |
119 | cf::ATNR_DISEASE => "DISEASE", |
119 | cf::ATNR_DISEASE => "DISEASE", |
120 | ); |
120 | ); |
121 | |
121 | |
|
|
122 | our %REV_RESMAP = map { $RESMAP{$_} => $_ } keys %RESMAP; |
|
|
123 | |
122 | our %LVL_DIFF_CHANCES = ( |
124 | our %LVL_DIFF_CHANCES = ( |
123 | +5 => 100, |
125 | +5 => 100, |
124 | +4 => 95, |
126 | +4 => 95, |
125 | +3 => 85, |
127 | +3 => 85, |
126 | +2 => 75, |
128 | +2 => 75, |
… | |
… | |
222 | my $outarchval = cf::arch::find ($outarch)->clone->value; |
224 | my $outarchval = cf::arch::find ($outarch)->clone->value; |
223 | |
225 | |
224 | my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); |
226 | my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); |
225 | if ($nrof) { |
227 | if ($nrof) { |
226 | # 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) { |
227 | $chdl->put (cf::object::new $outarch) for 1..$nrof; |
230 | $chdl->put (my $ob = cf::object::new $outarch); |
|
|
231 | $ob->set_animation (cf::rndm $ob->num_animations) |
|
|
232 | if ($ob->type == cf::RING); |
|
|
233 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
|
|
234 | } |
228 | |
235 | |
229 | my $xp_sum = ($xp_gain * $nrof); |
236 | my $xp_sum = ($xp_gain * $nrof); |
230 | |
237 | |
231 | if ($xp_sum) { |
238 | if ($xp_sum) { |
232 | $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"); |
233 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_ADD_SKILL); |
240 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
234 | } |
241 | } |
|
|
242 | } else { |
|
|
243 | $pl->ob->message ("You fail to make something, probably you used not enough source material?"); |
235 | } |
244 | } |
236 | } |
245 | } |
237 | |
246 | |
238 | |
247 | |
239 | package Jeweler::CauldronHandler; |
248 | package Jeweler::CauldronHandler; |
… | |
… | |
320 | cf::POTION => 'potions', |
329 | cf::POTION => 'potions', |
321 | cf::SCROLL => 'scrolls', |
330 | cf::SCROLL => 'scrolls', |
322 | ); |
331 | ); |
323 | |
332 | |
324 | 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 | } |
325 | |
339 | |
326 | if (my $k = $type_to_key{$_->type}) { |
340 | if (my $k = $type_to_key{$_->type}) { |
327 | push @{$ingreds->{$k}}, $_; |
341 | push @{$ingreds->{$k}}, $_; |
|
|
342 | } else { |
|
|
343 | push @{$ingreds->{other}}, $_; |
328 | } |
344 | } |
329 | } |
345 | } |
330 | |
346 | |
331 | return Jeweler::Ingredients->new (ingredients => $ingreds, cauldron_helper => $self) |
347 | return Jeweler::Ingredients->new (ingredients => $ingreds, cauldron_helper => $self) |
332 | } |
348 | } |
… | |
… | |
427 | sub get_plan { |
443 | sub get_plan { |
428 | my ($self) = @_; |
444 | my ($self) = @_; |
429 | |
445 | |
430 | my $ingred = $self->{ingredients}; |
446 | my $ingred = $self->{ingredients}; |
431 | |
447 | |
432 | for my $grp (keys %$ingred) { |
|
|
433 | for my $pot (@{$ingred->{$grp}}) { |
|
|
434 | for my $plan (keys %{$Jeweler::CFG->{plans}}) { |
448 | for my $plan (keys %{$Jeweler::CFG->{plans}}) { |
435 | my $plg = $Jeweler::CFG->{plans}->{$plan}; |
449 | my $plg = $Jeweler::CFG->{plans}->{$plan}; |
436 | my @plga = (); |
450 | my @plga = (); |
437 | unless (ref $plg eq 'ARRAY') { |
451 | unless (ref $plg eq 'ARRAY') { |
438 | push @plga, $plg; |
452 | push @plga, $plg; |
439 | } else { |
453 | } else { |
440 | @plga = @$plg; |
454 | @plga = @$plg; |
441 | } |
455 | } |
442 | next unless @plga > 0; |
456 | next unless @plga > 0; |
443 | if (Jeweler::Util::grep_for_match ($pot, @plga)) { |
457 | if (Jeweler::Util::grep_for_match ($ingred, @plga)) { |
444 | return $plan; |
458 | return $plan; |
445 | } |
|
|
446 | } |
|
|
447 | } |
459 | } |
448 | } |
460 | } |
449 | } |
461 | } |
450 | |
462 | |
451 | sub get_ring { |
463 | sub get_ring { |
… | |
… | |
454 | @{$self->{ingredients}->{ammys} || []}, |
466 | @{$self->{ingredients}->{ammys} || []}, |
455 | @{$self->{ingredients}->{rings} || []} |
467 | @{$self->{ingredients}->{rings} || []} |
456 | ); |
468 | ); |
457 | } |
469 | } |
458 | |
470 | |
|
|
471 | sub improve_max { |
|
|
472 | my ($stat, $impro) = @_; |
|
|
473 | if ($stat >= 0) { |
|
|
474 | $stat = $impro > $stat ? $impro : $stat; |
|
|
475 | } |
|
|
476 | $stat |
|
|
477 | } |
|
|
478 | |
459 | sub improve_ring_by_plan { |
479 | sub improve_ring_by_plan { |
460 | my ($self, $plan, $ring) = @_; |
480 | my ($self, $plan, $ring) = @_; |
461 | |
481 | |
462 | $ring = dclone ($ring); |
482 | $ring = dclone ($ring); |
463 | |
483 | |
… | |
… | |
468 | my $statname = $1; |
488 | my $statname = $1; |
469 | my $plingred = Jeweler::getcfg (plans => $plan) |
489 | my $plingred = Jeweler::getcfg (plans => $plan) |
470 | or die "ingredients for plan '$plan' not defined!"; |
490 | or die "ingredients for plan '$plan' not defined!"; |
471 | |
491 | |
472 | my $cnt = 0; |
492 | my $cnt = 0; |
473 | for my $pot (@{$ingred->{potions}}) { |
|
|
474 | if (Jeweler::Util::grep_for_match ($pot, @$plingred)) { |
493 | if (my $pot = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { |
475 | $cnt += $pot->nrof; |
494 | $cnt += $pot->nrof; |
476 | } |
|
|
477 | } |
495 | } |
478 | |
496 | |
479 | my $maxstat = Jeweler::getcfg (maximprovements => 'stats'); |
497 | my $maxstat = Jeweler::getcfg (maximprovements => 'stats'); |
480 | my $did_impr = 0; |
|
|
481 | for my $x (1..$maxstat) { |
498 | for my $x (1..$maxstat) { |
482 | my $y = Jeweler::Object::fx ($x, 'stat_potions'); |
499 | my $y = Jeweler::Object::fx ($x, 'stat_items'); |
483 | |
500 | |
484 | if ($cnt <= $y->[0]) { |
501 | if ($cnt <= $y->[0]) { |
485 | $ring->{hash}->{stat}->{$statname} += $x; |
502 | $ring->{hash}->{stat}->{$statname} = |
486 | $did_impr = 1; |
503 | improve_max $ring->{hash}->{stat}->{$statname}, $x; |
487 | last; |
504 | last; |
488 | } |
505 | } |
489 | } |
506 | } |
490 | |
507 | |
491 | # we want at least this improvement if we have a plan... |
|
|
492 | $ring->{hash}->{stat}->{$statname} += 1 unless $did_impr; |
|
|
493 | |
|
|
494 | } elsif ($plan =~ m/^spec_(\S+)$/) { |
508 | } elsif ($plan =~ m/^spec_(\S+)$/) { |
|
|
509 | my $specname = $1; |
|
|
510 | my $plingred = Jeweler::getcfg (plans => $plan) |
|
|
511 | or die "ingredients for plan '$plan' not defined!"; |
|
|
512 | |
|
|
513 | my $cnt = 0; |
|
|
514 | if (my $pot = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { |
|
|
515 | $cnt += $pot->nrof; |
|
|
516 | } |
|
|
517 | |
|
|
518 | my $maxspec = Jeweler::getcfg (maximprovements => 'specials'); |
|
|
519 | for my $x (1..$maxspec) { |
|
|
520 | my $y = Jeweler::Object::fx ($x, 'spec_items'); |
|
|
521 | |
|
|
522 | if ($cnt <= $y->[0]) { |
|
|
523 | $ring->{hash}->{spec}->{$specname} = |
|
|
524 | improve_max $ring->{hash}->{spec}->{$specname}, $x; |
|
|
525 | last; |
|
|
526 | } |
|
|
527 | } |
|
|
528 | |
495 | } elsif ($plan =~ m/^resist_(\S+)$/) { |
529 | } elsif ($plan =~ m/^resist_(\S+)$/) { |
|
|
530 | my $resname = $1; |
|
|
531 | my $resnum = $REV_RESMAP{$resname}; |
|
|
532 | my $plingred = Jeweler::getcfg (plans => $plan) |
|
|
533 | or die "ingredients for plan '$plan' not defined!"; |
|
|
534 | |
|
|
535 | my $cnt = 0; |
|
|
536 | if (my $it = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { |
|
|
537 | $cnt += $it->nrof; |
|
|
538 | } |
|
|
539 | my $resist_item_nr = 0; |
|
|
540 | $self->do_grep (sub { $resist_item_nr += ($_[0]->nrof || 1); 0 }, @$plingred); |
|
|
541 | |
|
|
542 | my $maximprovname = (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) |
|
|
543 | ? 'effect_resistances' |
|
|
544 | : 'attack_resistances'; |
|
|
545 | |
|
|
546 | my $maxres = Jeweler::getcfg (maximprovements => $maximprovname); |
|
|
547 | $resist_item_nr = $maxres if ($resist_item_nr > $maxres); |
|
|
548 | $ring->{hash}->{resist}->{$resnum} = |
|
|
549 | improve_max $ring->{hash}->{resist}->{$resnum}, $resist_item_nr; |
496 | } |
550 | } |
497 | |
551 | |
498 | return $ring; |
552 | return $ring; |
499 | } |
553 | } |
500 | |
554 | |
501 | sub do_grep { |
555 | sub do_grep { |
502 | my ($self, $cb, @grepar) = @_; |
556 | my ($self, $cb, $cat, @grepar) = @_; |
503 | |
557 | |
504 | my $ingred = $self->{ingredients}; |
558 | my $ingred = $self->{ingredients}; |
505 | |
559 | |
506 | |
|
|
507 | for my $cat (keys %$ingred) { |
|
|
508 | my @rem; |
560 | my @rem; |
509 | for my $ing (@{$ingred->{$cat}}) { |
561 | for my $ing (@{$ingred->{$cat}}) { |
510 | if (Jeweler::Util::grep_for_match ($ing, @grepar)) { |
562 | if (Jeweler::Util::check_for_match ($ing, @grepar)) { |
511 | unless ($cb->($ing)) { |
563 | unless ($cb->($ing)) { |
512 | push @rem, $ing; |
|
|
513 | } |
|
|
514 | } else { |
|
|
515 | push @rem, $ing; |
564 | push @rem, $ing; |
516 | } |
565 | } |
|
|
566 | } else { |
|
|
567 | push @rem, $ing; |
517 | } |
568 | } |
|
|
569 | } |
518 | @{$ingred->{$cat}} = @rem; |
570 | @{$ingred->{$cat}} = @rem; |
519 | } |
|
|
520 | } |
571 | } |
521 | |
572 | |
522 | sub check_costs { |
573 | sub check_costs { |
523 | my ($self, $costs, $do_remove) = @_; |
574 | my ($self, $costs, $do_remove) = @_; |
524 | |
575 | |
525 | my $costs = dclone ($costs); |
576 | my $costs = dclone ($costs); |
526 | |
577 | |
527 | for my $key (keys %$costs) { |
578 | for my $key (keys %$costs) { |
528 | my @grepar; |
579 | my @grepar; |
529 | if ($key =~ m/^stat_(\S+)$/) { |
580 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
530 | @grepar = @{Jeweler::getcfg (plans => $key) || []}; |
581 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
531 | } else { |
582 | next if $@; |
|
|
583 | } else { # check the gems |
532 | @grepar = (undef, undef, $key); |
584 | @grepar = ('gems', undef, undef, $key); |
533 | } |
585 | } |
534 | |
586 | |
535 | if ($do_remove) { |
587 | if ($do_remove) { |
536 | my $rem = $costs->{$key}; |
588 | my $rem = $costs->{$key}; |
537 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
589 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
538 | if ($rem > 0) { |
590 | if ($rem > 0) { |
539 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
591 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
540 | } |
592 | } |
541 | } else { |
593 | } else { |
542 | my $nr; |
594 | my $nr; |
543 | $self->do_grep (sub { $nr += $_[0]->nrof; 0 }, @grepar); |
595 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
544 | $costs->{$key} -= $nr; |
596 | $costs->{$key} -= $nr; |
545 | } |
597 | } |
|
|
598 | |
546 | } |
599 | } |
547 | |
600 | |
548 | return $costs; |
601 | return $costs; |
549 | } |
602 | } |
550 | |
603 | |
… | |
… | |
575 | my $self = bless { }, $class; |
628 | my $self = bless { }, $class; |
576 | |
629 | |
577 | $self->ring_or_ammy_to_hash ($arg{object}); |
630 | $self->ring_or_ammy_to_hash ($arg{object}); |
578 | |
631 | |
579 | $self; |
632 | $self; |
|
|
633 | } |
|
|
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; |
580 | } |
644 | } |
581 | |
645 | |
582 | sub analyze { |
646 | sub analyze { |
583 | my ($self, $sk, $pl) = @_; |
647 | my ($self, $sk, $pl) = @_; |
584 | |
648 | |
… | |
… | |
593 | } |
657 | } |
594 | my $msg = sprintf "Projected success rate: %s", $tmpl; |
658 | my $msg = sprintf "Projected success rate: %s", $tmpl; |
595 | return $msg; |
659 | return $msg; |
596 | } |
660 | } |
597 | |
661 | |
|
|
662 | sub calc_value_from_cost { |
|
|
663 | my ($self, $costs) = @_; |
|
|
664 | my $emarch = cf::arch::find 'emerald'; |
|
|
665 | my $saarch = cf::arch::find 'sapphire'; |
|
|
666 | my $pearch = cf::arch::find 'pearl'; |
|
|
667 | my $ruarch = cf::arch::find 'ruby'; |
|
|
668 | my $diarch = cf::arch::find 'gem'; |
|
|
669 | my $value = $emarch->clone->value * $costs->{emerald} |
|
|
670 | + $saarch->clone->value * $costs->{sapphire} |
|
|
671 | + $pearch->clone->value * $costs->{pearl} |
|
|
672 | + $ruarch->clone->value * $costs->{ruby} |
|
|
673 | + $diarch->clone->value * $costs->{gem}; |
|
|
674 | |
|
|
675 | $value |
|
|
676 | } |
|
|
677 | |
598 | sub wiz_analyze { |
678 | sub wiz_analyze { |
599 | my ($self, $pl) = @_; |
679 | my ($self, $pl) = @_; |
600 | my $costs = $self->calc_costs; |
680 | my $costs = $self->calc_costs; |
601 | my $desc = ""; |
681 | my $desc = ""; |
602 | my $lvl = $self->power_to_level (\$desc); |
682 | my $lvl = $self->power_to_level (\$desc); |
|
|
683 | my $scosts = $self->calc_value_from_cost ($costs); |
|
|
684 | |
603 | $pl->message ("costs: " . join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)); |
685 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
604 | $pl->message ("level: " . $desc); |
686 | $pl->message ("level: " . $desc); |
605 | } |
687 | } |
606 | |
|
|
607 | |
688 | |
608 | sub get_chance_perc { |
689 | sub get_chance_perc { |
609 | my ($self, $sk) = @_; |
690 | my ($self, $sk) = @_; |
610 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
691 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
611 | my $ringlvl = $self->power_to_level; |
692 | my $ringlvl = $self->power_to_level; |
… | |
… | |
614 | |
695 | |
615 | sub fx { |
696 | sub fx { |
616 | my ($res, $cfg) = @_; |
697 | my ($res, $cfg) = @_; |
617 | my $or = $res; |
698 | my $or = $res; |
618 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
699 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
|
|
700 | |
619 | if (ref $ar->[0] eq 'ARRAY') { |
701 | if (ref $ar->[0] eq 'ARRAY') { |
620 | $res = $res - 1; |
702 | $res = $res - 1; |
|
|
703 | return $ar->[max (min ($res, @$ar - 1), 0)]; |
|
|
704 | |
621 | } else { |
705 | } else { |
|
|
706 | # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3... |
622 | $res = ceil ($res / 5) - 1; |
707 | my $idx = ceil (($res / 5) + 0.1) - 1; |
623 | } |
|
|
624 | $ar->[max (min ($res, @$ar - 1), 0)]; |
708 | my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; |
|
|
709 | my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; |
|
|
710 | my $diff = $b - $a; # use the difference of the cost to the next cost |
|
|
711 | my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation |
|
|
712 | return $o_cost; |
|
|
713 | } |
625 | } |
714 | } |
626 | |
715 | |
627 | sub improve_by_ring { |
716 | sub improve_by_ring { |
628 | my ($self, @rings) = @_; |
717 | my ($self, @rings) = @_; |
629 | my $ring = $self; |
718 | my $ring = $self; |
… | |
… | |
645 | if ($self->{hash}->{$cat}->{$k} > 0) { |
734 | if ($self->{hash}->{$cat}->{$k} > 0) { |
646 | $self->{hash}->{$cat}->{$k} *= -1; |
735 | $self->{hash}->{$cat}->{$k} *= -1; |
647 | } |
736 | } |
648 | } |
737 | } |
649 | } |
738 | } |
|
|
739 | $self->{hash}{value} = 0; |
650 | } |
740 | } |
651 | |
741 | |
652 | sub to_string { |
742 | sub to_string { |
653 | my ($self) = @_; |
743 | my ($self) = @_; |
654 | my $r = $self->{hash}; |
744 | my $r = $self->{hash}; |
… | |
… | |
675 | my ($self, $thing) = @_; |
765 | my ($self, $thing) = @_; |
676 | |
766 | |
677 | my $obj = {}; |
767 | my $obj = {}; |
678 | |
768 | |
679 | for (@Jeweler::RESISTS) { |
769 | for (@Jeweler::RESISTS) { |
680 | $obj->{resist}->{$_} = $thing->resistance ($_); |
770 | $obj->{resist}->{$_} = $thing->resist ($_); |
681 | } |
771 | } |
682 | |
772 | |
683 | my $stats = $thing->stats; |
773 | my $stats = $thing->stats; |
684 | |
774 | |
685 | for (qw/Str Dex Con Wis Cha Int Pow/) { |
775 | for (qw/Str Dex Con Wis Cha Int Pow/) { |
… | |
… | |
696 | |
786 | |
697 | $obj->{name} = $thing->name; |
787 | $obj->{name} = $thing->name; |
698 | $obj->{arch} = $thing->arch->name; |
788 | $obj->{arch} = $thing->arch->name; |
699 | $obj->{face} = $thing->face; |
789 | $obj->{face} = $thing->face; |
700 | |
790 | |
|
|
791 | $obj->{value} = $thing->value; |
|
|
792 | |
701 | $self->{hash} = $obj |
793 | $self->{hash} = $obj |
702 | } |
794 | } |
703 | |
795 | |
704 | sub to_object { |
796 | sub to_object { |
705 | my ($self) = @_; |
797 | my ($self) = @_; |
706 | |
798 | |
707 | my $obj = cf::object::new $self->{hash}->{arch}; |
799 | my $obj = cf::object::new $self->{hash}->{arch}; |
|
|
800 | |
|
|
801 | $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached! |
708 | |
802 | |
709 | $obj->face ($self->{hash}{face}); |
803 | $obj->face ($self->{hash}{face}); |
710 | |
804 | |
711 | my $stats = $obj->stats; |
805 | my $stats = $obj->stats; |
712 | |
806 | |
… | |
… | |
720 | |
814 | |
721 | $stats->$_ ($self->{hash}{stat}{lc $_}) |
815 | $stats->$_ ($self->{hash}{stat}{lc $_}) |
722 | for qw/Str Dex Con Wis Cha Int Pow/; |
816 | for qw/Str Dex Con Wis Cha Int Pow/; |
723 | |
817 | |
724 | for (@Jeweler::RESISTS) { |
818 | for (@Jeweler::RESISTS) { |
725 | $obj->resistance ($_, $self->{hash}->{resist}->{$_}); |
819 | $obj->resist ($_, $self->{hash}->{resist}->{$_}); |
726 | } |
820 | } |
727 | |
821 | |
728 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
822 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
729 | |
823 | |
|
|
824 | $obj->value ($self->{hash}{value}); |
|
|
825 | |
730 | return $obj; |
826 | return $obj; |
|
|
827 | } |
|
|
828 | |
|
|
829 | sub set_value { $_[0]->{hash}{value} = $_[1] } |
|
|
830 | |
|
|
831 | sub is_better_than { |
|
|
832 | my ($self, $other) = @_; |
|
|
833 | |
|
|
834 | for my $type (qw/spec stat resist/) { |
|
|
835 | for my $stat (keys %{$self->{hash}->{$type}}) { |
|
|
836 | if ($self->{hash}->{$type}->{$stat} > $other->{hash}->{$type}->{$stat}) { |
|
|
837 | return 1; |
|
|
838 | } |
|
|
839 | } |
|
|
840 | } |
|
|
841 | |
|
|
842 | return 0; |
731 | } |
843 | } |
732 | |
844 | |
733 | sub stat_level { |
845 | sub stat_level { |
734 | my ($self) = @_; |
846 | my ($self) = @_; |
735 | my $stats = $self->{hash}->{stat} || {}; |
847 | my $stats = $self->{hash}->{stat} || {}; |
… | |
… | |
849 | for my $stat (keys %$stats) { |
961 | for my $stat (keys %$stats) { |
850 | my $sum = $stats->{$stat}; |
962 | my $sum = $stats->{$stat}; |
851 | |
963 | |
852 | next unless $sum > 0; |
964 | next unless $sum > 0; |
853 | |
965 | |
854 | my $statfx = fx ($sum, 'stat_potions'); |
966 | my $statfx = fx ($sum, 'stat_items'); |
855 | $cost->{"stat_$stat"} += $statfx->[0]; |
967 | $cost->{"stat_$stat"} += $statfx->[0]; |
856 | split_diamonds ($cost, $statfx->[1], 'stat_' . $stat); |
968 | split_diamonds ($cost, $statfx->[1], 'stat_' . $stat); |
857 | } |
969 | } |
858 | } |
970 | } |
859 | |
971 | |
… | |
… | |
865 | for my $spec (keys %$specials) { |
977 | for my $spec (keys %$specials) { |
866 | my $sum = $specials->{$spec}; |
978 | my $sum = $specials->{$spec}; |
867 | |
979 | |
868 | next unless $sum > 0; |
980 | next unless $sum > 0; |
869 | |
981 | |
870 | my $specfx = fx ($sum, 'spec_potions'); |
982 | my $specfx = fx ($sum, 'spec_items'); |
871 | $cost->{"spec_$spec"} += $specfx->[0]; |
983 | $cost->{"spec_$spec"} += $specfx->[0]; |
872 | split_diamonds ($cost, $specfx->[1], 'spec_' . $spec); |
984 | split_diamonds ($cost, $specfx->[1], 'spec_' . $spec); |
873 | } |
985 | } |
874 | } |
986 | } |
875 | |
987 | |
… | |
… | |
878 | |
990 | |
879 | my $costs = {}; |
991 | my $costs = {}; |
880 | |
992 | |
881 | my $ring = $self->{hash}; |
993 | my $ring = $self->{hash}; |
882 | |
994 | |
883 | for my $resnam (keys %{$ring->{resist} || {}}) { |
995 | for my $resnum (keys %{$ring->{resist} || {}}) { |
884 | |
996 | |
885 | my $res = $ring->{resist}->{$resnam}; |
997 | my $res = $ring->{resist}->{$resnum}; |
886 | |
998 | |
887 | next unless $res > 0; |
999 | next unless $res > 0; |
888 | |
1000 | |
889 | $costs->{"resist_" . $Jeweler::RESMAP{$resnam} . "_item"} += $res; |
1001 | $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; |
890 | |
1002 | |
891 | my $diamonds; |
1003 | my $diamonds; |
892 | if (grep { $resnam eq $_ } @Jeweler::EFFECT_RESISTS) { |
1004 | if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { |
893 | $diamonds += fx ($res, 'effect_resist_diamonds'); |
1005 | $diamonds += fx ($res, 'effect_resist_diamonds'); |
894 | } else { |
1006 | } else { |
895 | $diamonds += fx ($res, 'attack_resist_diamonds'); |
1007 | $diamonds += fx ($res, 'attack_resist_diamonds'); |
896 | } |
1008 | } |
897 | |
1009 | |
898 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnam}); |
1010 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); |
899 | } |
1011 | } |
900 | |
1012 | |
901 | $self->add_stat_costs ($costs); |
1013 | $self->add_stat_costs ($costs); |
902 | $self->add_special_costs ($costs); |
1014 | $self->add_special_costs ($costs); |
903 | |
1015 | |
… | |
… | |
950 | my ($obj, $nrof) = @_; |
1062 | my ($obj, $nrof) = @_; |
951 | |
1063 | |
952 | my $cnt; |
1064 | my $cnt; |
953 | |
1065 | |
954 | if (defined $nrof) { |
1066 | if (defined $nrof) { |
|
|
1067 | # TODO: Check tihis line: |
955 | return 0 if ($nrof * 1) == 0; |
1068 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
956 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
1069 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
957 | |
1070 | |
958 | if ($cnt > 0) { |
1071 | if ($cnt > 0) { |
959 | $obj->nrof ($cnt); |
1072 | $obj->nrof ($cnt); |
960 | return 0; |
1073 | return 0; |
… | |
… | |
964 | remove ($_) for $obj->inv; |
1077 | remove ($_) for $obj->inv; |
965 | $obj->destroy; |
1078 | $obj->destroy; |
966 | return $cnt; |
1079 | return $cnt; |
967 | } |
1080 | } |
968 | |
1081 | |
969 | sub grep_for_match { |
1082 | sub check_for_match { |
970 | my ($thing, @matchar) = @_; |
1083 | my ($thing, @matchar) = @_; |
971 | |
1084 | |
972 | my $i = 0; |
1085 | my $i = 0; |
|
|
1086 | my $check_cnts = 0; |
|
|
1087 | my $check_true = 0; |
973 | for my $match (@matchar) { |
1088 | for my $match (@matchar) { |
|
|
1089 | if ($i % 3 == 0) { |
|
|
1090 | return 1 if $check_true && $check_cnts == $check_true; |
|
|
1091 | $check_cnts = 0; |
|
|
1092 | $check_true = 0; |
|
|
1093 | } |
|
|
1094 | |
974 | if ($match =~ m/^\s*$/) { |
1095 | if ($match =~ m/^\s*$/) { |
975 | $i++; |
1096 | $i++; |
976 | next; |
1097 | next; |
977 | } |
1098 | } |
978 | |
1099 | |
|
|
1100 | $check_cnts++; |
979 | if ($i % 3 == 0) { |
1101 | if ($i % 3 == 0) { |
980 | $thing->name eq $match |
1102 | $thing->name eq $match |
981 | and return 1; |
1103 | and $check_true++; |
982 | } elsif ($i % 3 == 1) { |
1104 | } elsif ($i % 3 == 1) { |
983 | $thing->title eq $match |
1105 | $thing->title eq $match |
984 | and return 1; |
1106 | and $check_true++; |
985 | } else { # $i % 3 == 2 |
1107 | } else { # $i % 3 == 2 |
986 | $thing->arch->name eq $match |
1108 | $thing->arch->name eq $match |
987 | and return 1; |
1109 | and $check_true++; |
988 | } |
1110 | } |
989 | $i++; |
1111 | $i++; |
990 | } |
1112 | } |
|
|
1113 | #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->name))."\n"; |
|
|
1114 | return 1 if $check_true && $check_cnts == $check_true; |
991 | return 0; |
1115 | return 0; |
992 | } |
1116 | } |
993 | |
1117 | |
|
|
1118 | sub grep_for_match { |
|
|
1119 | my ($ingred, $group, @matchar) = @_; |
|
|
1120 | |
|
|
1121 | for my $thing (@{$ingred->{$group} || []}) { |
|
|
1122 | #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# |
|
|
1123 | if (check_for_match ($thing, @matchar)) { |
|
|
1124 | return $thing; |
|
|
1125 | } |
|
|
1126 | } |
|
|
1127 | return undef; |
|
|
1128 | } |
|
|
1129 | |
994 | =back |
1130 | =back |
995 | |
1131 | |
996 | =back |
|
|
997 | |
|
|
998 | 1 |
1132 | 1 |