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