… | |
… | |
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 | |
… | |
… | |
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"; |
333 | if ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { |
336 | } elsif ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { |
334 | die "cursed"; |
337 | die "cursed"; |
335 | } |
338 | } |
336 | |
339 | |
337 | if (my $k = $type_to_key{$_->type}) { |
340 | if (my $k = $type_to_key{$_->type}) { |
338 | push @{$ingreds->{$k}}, $_; |
341 | push @{$ingreds->{$k}}, $_; |
… | |
… | |
626 | $self->ring_or_ammy_to_hash ($arg{object}); |
629 | $self->ring_or_ammy_to_hash ($arg{object}); |
627 | |
630 | |
628 | $self; |
631 | $self; |
629 | } |
632 | } |
630 | |
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 | |
631 | sub analyze { |
645 | sub analyze { |
632 | my ($self, $sk, $pl) = @_; |
646 | my ($self, $sk, $pl) = @_; |
633 | |
647 | |
634 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
648 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
635 | my $ringlvl = $self->power_to_level; |
649 | my $ringlvl = $self->power_to_level; |
… | |
… | |
642 | } |
656 | } |
643 | my $msg = sprintf "Projected success rate: %s", $tmpl; |
657 | my $msg = sprintf "Projected success rate: %s", $tmpl; |
644 | return $msg; |
658 | return $msg; |
645 | } |
659 | } |
646 | |
660 | |
|
|
661 | sub calc_value_from_cost { |
|
|
662 | my ($self, $costs) = @_; |
|
|
663 | my $emarch = cf::arch::find 'emerald'; |
|
|
664 | my $saarch = cf::arch::find 'sapphire'; |
|
|
665 | my $pearch = cf::arch::find 'pearl'; |
|
|
666 | my $ruarch = cf::arch::find 'ruby'; |
|
|
667 | my $diarch = cf::arch::find 'gem'; |
|
|
668 | my $value = $emarch->clone->value * $costs->{emerald} |
|
|
669 | + $saarch->clone->value * $costs->{sapphire} |
|
|
670 | + $pearch->clone->value * $costs->{pearl} |
|
|
671 | + $ruarch->clone->value * $costs->{ruby} |
|
|
672 | + $diarch->clone->value * $costs->{gem}; |
|
|
673 | |
|
|
674 | $value |
|
|
675 | } |
|
|
676 | |
647 | sub wiz_analyze { |
677 | sub wiz_analyze { |
648 | my ($self, $pl) = @_; |
678 | my ($self, $pl) = @_; |
649 | my $costs = $self->calc_costs; |
679 | my $costs = $self->calc_costs; |
650 | my $desc = ""; |
680 | my $desc = ""; |
651 | my $lvl = $self->power_to_level (\$desc); |
681 | my $lvl = $self->power_to_level (\$desc); |
652 | my $emarch = cf::arch::find 'emerald'; |
682 | my $scosts = $self->calc_value_from_cost ($costs); |
653 | my $saarch = cf::arch::find 'sapphire'; |
|
|
654 | my $pearch = cf::arch::find 'pearl'; |
|
|
655 | my $ruarch = cf::arch::find 'ruby'; |
|
|
656 | my $diarch = cf::arch::find 'gem'; |
|
|
657 | my $scosts = $emarch->clone->value * $costs->{emerald} |
|
|
658 | + $saarch->clone->value * $costs->{sapphire} |
|
|
659 | + $pearch->clone->value * $costs->{pearl} |
|
|
660 | + $ruarch->clone->value * $costs->{ruby} |
|
|
661 | + $diarch->clone->value * $costs->{gem}; |
|
|
662 | |
683 | |
663 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
684 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
664 | $pl->message ("level: " . $desc); |
685 | $pl->message ("level: " . $desc); |
665 | } |
686 | } |
666 | |
|
|
667 | |
687 | |
668 | sub get_chance_perc { |
688 | sub get_chance_perc { |
669 | my ($self, $sk) = @_; |
689 | my ($self, $sk) = @_; |
670 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
690 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
671 | my $ringlvl = $self->power_to_level; |
691 | my $ringlvl = $self->power_to_level; |
… | |
… | |
674 | |
694 | |
675 | sub fx { |
695 | sub fx { |
676 | my ($res, $cfg) = @_; |
696 | my ($res, $cfg) = @_; |
677 | my $or = $res; |
697 | my $or = $res; |
678 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
698 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
|
|
699 | |
679 | if (ref $ar->[0] eq 'ARRAY') { |
700 | if (ref $ar->[0] eq 'ARRAY') { |
680 | $res = $res - 1; |
701 | $res = $res - 1; |
|
|
702 | return $ar->[max (min ($res, @$ar - 1), 0)]; |
|
|
703 | |
681 | } else { |
704 | } else { |
|
|
705 | # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3... |
682 | $res = ceil ($res / 5) - 1; |
706 | my $idx = ceil (($res / 5) + 0.1) - 1; |
683 | } |
|
|
684 | $ar->[max (min ($res, @$ar - 1), 0)]; |
707 | my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; |
|
|
708 | my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; |
|
|
709 | my $diff = $b - $a; # use the difference of the cost to the next cost |
|
|
710 | my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation |
|
|
711 | return $o_cost; |
|
|
712 | } |
685 | } |
713 | } |
686 | |
714 | |
687 | sub improve_by_ring { |
715 | sub improve_by_ring { |
688 | my ($self, @rings) = @_; |
716 | my ($self, @rings) = @_; |
689 | my $ring = $self; |
717 | my $ring = $self; |
… | |
… | |
705 | if ($self->{hash}->{$cat}->{$k} > 0) { |
733 | if ($self->{hash}->{$cat}->{$k} > 0) { |
706 | $self->{hash}->{$cat}->{$k} *= -1; |
734 | $self->{hash}->{$cat}->{$k} *= -1; |
707 | } |
735 | } |
708 | } |
736 | } |
709 | } |
737 | } |
|
|
738 | $self->{hash}{value} = 0; |
710 | } |
739 | } |
711 | |
740 | |
712 | sub to_string { |
741 | sub to_string { |
713 | my ($self) = @_; |
742 | my ($self) = @_; |
714 | my $r = $self->{hash}; |
743 | my $r = $self->{hash}; |
… | |
… | |
756 | |
785 | |
757 | $obj->{name} = $thing->name; |
786 | $obj->{name} = $thing->name; |
758 | $obj->{arch} = $thing->arch->name; |
787 | $obj->{arch} = $thing->arch->name; |
759 | $obj->{face} = $thing->face; |
788 | $obj->{face} = $thing->face; |
760 | |
789 | |
|
|
790 | $obj->{value} = $thing->value; |
|
|
791 | |
761 | $self->{hash} = $obj |
792 | $self->{hash} = $obj |
762 | } |
793 | } |
763 | |
794 | |
764 | sub to_object { |
795 | sub to_object { |
765 | my ($self) = @_; |
796 | my ($self) = @_; |
766 | |
797 | |
767 | my $obj = cf::object::new $self->{hash}->{arch}; |
798 | my $obj = cf::object::new $self->{hash}->{arch}; |
|
|
799 | |
|
|
800 | $obj->item_power ($self->power_to_level); # there have to be strings attached! |
768 | |
801 | |
769 | $obj->face ($self->{hash}{face}); |
802 | $obj->face ($self->{hash}{face}); |
770 | |
803 | |
771 | my $stats = $obj->stats; |
804 | my $stats = $obj->stats; |
772 | |
805 | |
… | |
… | |
785 | $obj->resist ($_, $self->{hash}->{resist}->{$_}); |
818 | $obj->resist ($_, $self->{hash}->{resist}->{$_}); |
786 | } |
819 | } |
787 | |
820 | |
788 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
821 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
789 | |
822 | |
|
|
823 | $obj->value ($self->{hash}{value}); |
|
|
824 | |
790 | return $obj; |
825 | return $obj; |
791 | } |
826 | } |
|
|
827 | |
|
|
828 | sub set_value { $_[0]->{hash}{value} = $_[1] } |
792 | |
829 | |
793 | sub is_better_than { |
830 | sub is_better_than { |
794 | my ($self, $other) = @_; |
831 | my ($self, $other) = @_; |
795 | |
832 | |
796 | for my $type (qw/spec stat resist/) { |
833 | for my $type (qw/spec stat resist/) { |
… | |
… | |
1043 | |
1080 | |
1044 | sub check_for_match { |
1081 | sub check_for_match { |
1045 | my ($thing, @matchar) = @_; |
1082 | my ($thing, @matchar) = @_; |
1046 | |
1083 | |
1047 | my $i = 0; |
1084 | my $i = 0; |
|
|
1085 | my $check_cnts = 0; |
|
|
1086 | my $check_true = 0; |
1048 | for my $match (@matchar) { |
1087 | for my $match (@matchar) { |
1049 | if ($match =~ m/^\s*$/) { |
1088 | if ($match =~ m/^\s*$/) { |
1050 | $i++; |
1089 | $i++; |
1051 | next; |
1090 | next; |
1052 | } |
1091 | } |
1053 | |
1092 | |
|
|
1093 | $check_cnts++; |
1054 | if ($i % 3 == 0) { |
1094 | if ($i % 3 == 0) { |
1055 | $thing->name eq $match |
1095 | $thing->name eq $match |
1056 | and return 1; |
1096 | and $check_true++; |
1057 | } elsif ($i % 3 == 1) { |
1097 | } elsif ($i % 3 == 1) { |
1058 | $thing->title eq $match |
1098 | $thing->title eq $match |
1059 | and return 1; |
1099 | and $check_true++; |
1060 | } else { # $i % 3 == 2 |
1100 | } else { # $i % 3 == 2 |
1061 | $thing->arch->name eq $match |
1101 | $thing->arch->name eq $match |
1062 | and return 1; |
1102 | and $check_true++; |
1063 | } |
1103 | } |
1064 | $i++; |
1104 | $i++; |
|
|
1105 | } |
|
|
1106 | if ($check_true && $check_cnts == $check_true) { |
|
|
1107 | return 1; |
1065 | } |
1108 | } |
1066 | return 0; |
1109 | return 0; |
1067 | } |
1110 | } |
1068 | |
1111 | |
1069 | sub grep_for_match { |
1112 | sub grep_for_match { |
1070 | my ($ingred, $group, @matchar) = @_; |
1113 | my ($ingred, $group, @matchar) = @_; |
1071 | |
1114 | |
1072 | for my $thing (@{$ingred->{$group} || []}) { |
1115 | for my $thing (@{$ingred->{$group} || []}) { |
1073 | warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# |
1116 | #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# |
1074 | if (check_for_match ($thing, @matchar)) { |
1117 | if (check_for_match ($thing, @matchar)) { |
1075 | return $thing; |
1118 | return $thing; |
1076 | } |
1119 | } |
1077 | } |
1120 | } |
1078 | return undef; |
1121 | return undef; |