ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/Jeweler.pm
(Generate patch)

Comparing deliantra/server/ext/Jeweler.pm (file contents):
Revision 1.5 by elmex, Wed Jan 31 15:53:17 2007 UTC vs.
Revision 1.24 by elmex, Sun Feb 17 22:37:34 2008 UTC

24our $CFG; 24our $CFG;
25 25
26sub read_config { 26sub 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
38sub getcfg { 37sub 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
166sub analyze { 165sub 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)
188sub simple_converter { 190sub 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
247package Jeweler::CauldronHandler; 250package 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";
333 if ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { 338 } elsif ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) {
334 die "cursed"; 339 die "cursed";
335 } 340 }
336 341
337 if (my $k = $type_to_key{$_->type}) { 342 if (my $k = $type_to_key{$_->type}) {
338 push @{$ingreds->{$k}}, $_; 343 push @{$ingreds->{$k}}, $_;
352 357
353sub put { 358sub put {
354 my ($self, $obj) = @_; 359 my ($self, $obj) = @_;
355 360
356 return undef unless $self->{cauldron}; 361 return undef unless $self->{cauldron};
357 $obj->insert_ob_in_ob ($self->{cauldron}); 362 $self->{cauldron}->insert ($obj);
358} 363}
359 364
360=back 365=back
361 366
362=cut 367=cut
395 400
396sub value { 401sub value {
397 my ($self, $group, $archname) = @_; 402 my ($self, $group, $archname) = @_;
398 403
399 my @objs = grep { 404 my @objs = grep {
400 $_->arch->name eq $archname 405 $_->arch->archname eq $archname
401 } @{$self->{ingredients}->{$group} || []}; 406 } @{$self->{ingredients}->{$group} || []};
402 407
403 my $sum = 0; 408 my $sum = 0;
404 for (@objs) { 409 for (@objs) {
405 $sum += ($_->nrof || 1) * $_->value; 410 $sum += ($_->nrof || 1) * $_->value;
422 427
423 my @out; 428 my @out;
424 429
425 for (@{$ingred->{$group}}) { 430 for (@{$ingred->{$group}}) {
426 if (defined $archname) { 431 if (defined $archname) {
427 if ($_->arch->name eq $archname) { 432 if ($_->arch->archname eq $archname) {
428 Jeweler::Util::remove ($_); 433 Jeweler::Util::remove ($_);
429 } else { 434 } else {
430 push @out, $_; 435 push @out, $_;
431 } 436 }
432 } else { 437 } else {
474} 479}
475 480
476sub improve_ring_by_plan { 481sub improve_ring_by_plan {
477 my ($self, $plan, $ring) = @_; 482 my ($self, $plan, $ring) = @_;
478 483
479 $ring = dclone ($ring); 484 $ring = do { my $guard = Coro::Storable::guard; dclone $ring };
480 485
481 my $ingred = $self->{ingredients}; 486 my $ingred = $self->{ingredients};
482 my $impr = {}; 487 my $impr = {};
483 488
484 if ($plan =~ m/^stat_(\S+)$/) { 489 if ($plan =~ m/^stat_(\S+)$/) {
568} 573}
569 574
570sub check_costs { 575sub check_costs {
571 my ($self, $costs, $do_remove) = @_; 576 my ($self, $costs, $do_remove) = @_;
572 577
573 my $costs = dclone ($costs); 578 my $costs = do { my $guard = Coro::Storable::guard; dclone $costs };
574 579
575 for my $key (keys %$costs) { 580 for my $key (keys %$costs) {
576 my @grepar; 581 my @grepar;
577 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 582 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
578 @grepar = @{Jeweler::getcfg (plans => $key) || []}; 583 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
584 next if $@;
579 } else { # check the gems 585 } else { # check the gems
580 @grepar = ('gems', undef, undef, $key); 586 @grepar = ('gems', undef, undef, $key);
581 } 587 }
582 588
583 if ($do_remove) { 589 if ($do_remove) {
626 $self->ring_or_ammy_to_hash ($arg{object}); 632 $self->ring_or_ammy_to_hash ($arg{object});
627 633
628 $self; 634 $self;
629} 635}
630 636
637sub 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
648sub 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 # 100 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) / 10;
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
631sub analyze { 679sub analyze {
632 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 }
633 686
634 my $sklvl = cf::exp_to_level ($sk->stats->exp); 687 my $sklvl = cf::exp_to_level ($sk->stats->exp);
635 my $ringlvl = $self->power_to_level; 688 my $ringlvl = $self->power_to_level;
636 689
637 my $tmpl; 690 my $tmpl;
638 if ($pl->flag (cf::FLAG_WIZ)) { 691 if ($pl->flag (cf::FLAG_WIZ)) {
639 $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); 692 $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl);
640 } else { 693 } else {
641 $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); 694 $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl);
642 } 695 }
643 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);
644 return $msg; 697 return $msg;
645} 698}
646 699
647sub wiz_analyze { 700sub calc_value_from_cost {
648 my ($self, $pl) = @_; 701 my ($self, $costs) = @_;
649 my $costs = $self->calc_costs;
650 my $desc = "";
651 my $lvl = $self->power_to_level (\$desc);
652 my $emarch = cf::arch::find 'emerald'; 702 my $emarch = cf::arch::find 'emerald';
653 my $saarch = cf::arch::find 'sapphire'; 703 my $saarch = cf::arch::find 'sapphire';
654 my $pearch = cf::arch::find 'pearl'; 704 my $pearch = cf::arch::find 'pearl';
655 my $ruarch = cf::arch::find 'ruby'; 705 my $ruarch = cf::arch::find 'ruby';
656 my $diarch = cf::arch::find 'gem'; 706 my $diarch = cf::arch::find 'gem';
657 my $scosts = $emarch->clone->value * $costs->{emerald} 707 my $value = $emarch->value * $costs->{emerald}
658 + $saarch->clone->value * $costs->{sapphire} 708 + $saarch->value * $costs->{sapphire}
659 + $pearch->clone->value * $costs->{pearl} 709 + $pearch->value * $costs->{pearl}
660 + $ruarch->clone->value * $costs->{ruby} 710 + $ruarch->value * $costs->{ruby}
661 + $diarch->clone->value * $costs->{gem}; 711 + $diarch->value * $costs->{gem};
662 712
713 $value
714}
715
716sub wiz_analyze {
717 my ($self, $pl) = @_;
718 my $costs = $self->calc_costs;
719 if (defined $costs) {
720 my $desc = "";
721 my $lvl = $self->power_to_level (\$desc);
722 my $scosts = $self->calc_value_from_cost ($costs);
723
663 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); 724 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)");
664 $pl->message ("level: " . $desc); 725 $pl->message ("level: " . $desc);
726 } else {
727 $pl->message ("level: impossible to make, due to impossible resistancy configuration");
728 }
665} 729}
666
667 730
668sub get_chance_perc { 731sub get_chance_perc {
669 my ($self, $sk) = @_; 732 my ($self, $sk) = @_;
670 my $sklvl = cf::exp_to_level ($sk->stats->exp); 733 my $sklvl = cf::exp_to_level ($sk->stats->exp);
671 my $ringlvl = $self->power_to_level; 734 my $ringlvl = $self->power_to_level;
674 737
675sub fx { 738sub fx {
676 my ($res, $cfg) = @_; 739 my ($res, $cfg) = @_;
677 my $or = $res; 740 my $or = $res;
678 my $ar = $Jeweler::CFG->{functions}->{$cfg}; 741 my $ar = $Jeweler::CFG->{functions}->{$cfg};
742
679 if (ref $ar->[0] eq 'ARRAY') { 743 if (ref $ar && ref $ar->[0] eq 'ARRAY') {
680 $res = $res - 1; 744 $res = $res - 1;
745 return $ar->[max (min ($res, @$ar - 1), 0)];
746
681 } else { 747 } else {
682 $res = ceil ($res / 5) - 1; 748 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3...
683 } 749 # old code:
750 #my $idx = ceil (($res / 5) + 0.1) - 1;
684 $ar->[max (min ($res, @$ar - 1), 0)]; 751 #my $a = $ar->[max (min ($idx, @$ar - 1), 0)];
752 #my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)];
753 #my $diff = $b - $a; # use the difference of the cost to the next cost
754 #my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation
755 #return $o_cost;
756 return 0 if $res <= 0;
757 return ($ar / (1 - ($res * 0.01)) - $ar)
758 }
685} 759}
686 760
687sub improve_by_ring { 761sub improve_by_ring {
688 my ($self, @rings) = @_; 762 my ($self, @rings) = @_;
689 my $ring = $self; 763 my $ring = $self;
705 if ($self->{hash}->{$cat}->{$k} > 0) { 779 if ($self->{hash}->{$cat}->{$k} > 0) {
706 $self->{hash}->{$cat}->{$k} *= -1; 780 $self->{hash}->{$cat}->{$k} *= -1;
707 } 781 }
708 } 782 }
709 } 783 }
784 $self->{hash}{value} = 0;
710} 785}
711 786
712sub to_string { 787sub to_string {
713 my ($self) = @_; 788 my ($self) = @_;
714 my $r = $self->{hash}; 789 my $r = $self->{hash};
753 $obj->{spec}{ac} = $stats->ac; 828 $obj->{spec}{ac} = $stats->ac;
754 $obj->{spec}{speed} = $stats->exp; 829 $obj->{spec}{speed} = $stats->exp;
755 $obj->{spec}{food} = $stats->food; 830 $obj->{spec}{food} = $stats->food;
756 831
757 $obj->{name} = $thing->name; 832 $obj->{name} = $thing->name;
758 $obj->{arch} = $thing->arch->name; 833 $obj->{arch} = $thing->arch->archname;
759 $obj->{face} = $thing->face; 834 $obj->{face} = $thing->face;
835
836 $obj->{value} = $thing->value;
760 837
761 $self->{hash} = $obj 838 $self->{hash} = $obj
762} 839}
763 840
764sub to_object { 841sub to_object {
765 my ($self) = @_; 842 my ($self) = @_;
766 843
767 my $obj = cf::object::new $self->{hash}->{arch}; 844 my $obj = cf::object::new $self->{hash}->{arch};
845
846 $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached!
768 847
769 $obj->face ($self->{hash}{face}); 848 $obj->face ($self->{hash}{face});
770 849
771 my $stats = $obj->stats; 850 my $stats = $obj->stats;
772 851
785 $obj->resist ($_, $self->{hash}->{resist}->{$_}); 864 $obj->resist ($_, $self->{hash}->{resist}->{$_});
786 } 865 }
787 866
788 $obj->flag (cf::FLAG_IDENTIFIED, 1); 867 $obj->flag (cf::FLAG_IDENTIFIED, 1);
789 868
869 $obj->value ($self->{hash}{value});
870
790 return $obj; 871 return $obj;
791} 872}
873
874sub set_value { $_[0]->{hash}{value} = $_[1] }
792 875
793sub is_better_than { 876sub is_better_than {
794 my ($self, $other) = @_; 877 my ($self, $other) = @_;
795 878
796 for my $type (qw/spec stat resist/) { 879 for my $type (qw/spec stat resist/) {
958 1041
959 my $res = $ring->{resist}->{$resnum}; 1042 my $res = $ring->{resist}->{$resnum};
960 1043
961 next unless $res > 0; 1044 next unless $res > 0;
962 1045
1046 return undef if $res == 100;
1047
963 $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; 1048 $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res;
964 1049
965 my $diamonds; 1050 my $diamonds;
966 if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { 1051 if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) {
967 $diamonds += fx ($res, 'effect_resist_diamonds'); 1052 $diamonds += fx ($res, 'effect_resist_diamonds_x');
968 } else { 1053 } else {
969 $diamonds += fx ($res, 'attack_resist_diamonds'); 1054 $diamonds += fx ($res, 'attack_resist_diamonds_x');
970 } 1055 }
971 1056
972 split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); 1057 split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum});
973 } 1058 }
974 1059
982 my ($cost, $diamonds, $category) = @_; 1067 my ($cost, $diamonds, $category) = @_;
983 1068
984 my $stat_split = Jeweler::getcfg (diamond_split => $category); 1069 my $stat_split = Jeweler::getcfg (diamond_split => $category);
985 1070
986 my $sum = sum (@$stat_split); 1071 my $sum = sum (@$stat_split);
987 if ($sum < (1 - 0.0001)) {
988 warn "JEWELER BUG: sum (@$stat_split) = $sum < 1 for $category!";
989 }
990 1072
991 my $emarch = cf::arch::find 'emerald'; 1073 my $emarch = cf::arch::find 'emerald';
992 my $saarch = cf::arch::find 'sapphire'; 1074 my $saarch = cf::arch::find 'sapphire';
993 my $pearch = cf::arch::find 'pearl'; 1075 my $pearch = cf::arch::find 'pearl';
994 my $ruarch = cf::arch::find 'ruby'; 1076 my $ruarch = cf::arch::find 'ruby';
995 my $diarch = cf::arch::find 'gem'; 1077 my $diarch = cf::arch::find 'gem';
996 1078
997 my $sumvalue = $diarch->clone->value * $diamonds; 1079 my $sumvalue = $diarch->value * $diamonds;
998 1080
999 $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->clone->value; 1081 $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->value;
1000 $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->clone->value; 1082 $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->value;
1001 $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->clone->value; 1083 $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->value;
1002 $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->clone->value; 1084 $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->value;
1003 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->clone->value; 1085 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value;
1004} 1086}
1005 1087
1006package Jeweler::Util; 1088package Jeweler::Util;
1007 1089
1008use strict; 1090use strict;
1043 1125
1044sub check_for_match { 1126sub check_for_match {
1045 my ($thing, @matchar) = @_; 1127 my ($thing, @matchar) = @_;
1046 1128
1047 my $i = 0; 1129 my $i = 0;
1130 my $check_cnts = 0;
1131 my $check_true = 0;
1048 for my $match (@matchar) { 1132 for my $match (@matchar) {
1133 if ($i % 3 == 0) {
1134 return 1 if $check_true && $check_cnts == $check_true;
1135 $check_cnts = 0;
1136 $check_true = 0;
1137 }
1138
1049 if ($match =~ m/^\s*$/) { 1139 if ($match =~ m/^\s*$/) {
1050 $i++; 1140 $i++;
1051 next; 1141 next;
1052 } 1142 }
1053 1143
1144 $check_cnts++;
1054 if ($i % 3 == 0) { 1145 if ($i % 3 == 0) {
1055 $thing->name eq $match 1146 $thing->name eq $match
1056 and return 1; 1147 and $check_true++;
1057 } elsif ($i % 3 == 1) { 1148 } elsif ($i % 3 == 1) {
1058 $thing->title eq $match 1149 $thing->title eq $match
1059 and return 1; 1150 and $check_true++;
1060 } else { # $i % 3 == 2 1151 } else { # $i % 3 == 2
1061 $thing->arch->name eq $match 1152 $thing->arch->archname eq $match
1062 and return 1; 1153 and $check_true++;
1063 } 1154 }
1064 $i++; 1155 $i++;
1065 } 1156 }
1157 #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->archname))."\n";
1158 return 1 if $check_true && $check_cnts == $check_true;
1066 return 0; 1159 return 0;
1067} 1160}
1068 1161
1069sub grep_for_match { 1162sub grep_for_match {
1070 my ($ingred, $group, @matchar) = @_; 1163 my ($ingred, $group, @matchar) = @_;
1071 1164
1072 for my $thing (@{$ingred->{$group} || []}) { 1165 for my $thing (@{$ingred->{$group} || []}) {
1073 warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# 1166 #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->archname, "@matchar"; #d#
1074 if (check_for_match ($thing, @matchar)) { 1167 if (check_for_match ($thing, @matchar)) {
1075 return $thing; 1168 return $thing;
1076 } 1169 }
1077 } 1170 }
1078 return undef; 1171 return undef;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines