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.23 by root, Mon Dec 17 08:03:22 2007 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;
170 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { 169 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) {
171 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { 170 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) {
172 $hadunid = 1; 171 $hadunid = 1;
173 next; 172 next;
174 } 173 }
175 my $r = Jeweler::Object->new (object => $_); 174 my $r = Jeweler::Object->new (object => $_);
176 my $msg = $r->analyze ($sk, $pl); 175 my $msg = $r->analyze ($sk, $pl, $input_level);
177 $pl->message ($r->to_string . ": " . $msg); 176 $pl->message ($r->to_string . ": " . $msg);
178 if ($pl->flag (cf::FLAG_WIZ)) { 177 if ($pl->flag (cf::FLAG_WIZ)) {
179 $r->wiz_analyze ($pl); 178 $r->wiz_analyze ($pl);
180 } 179 }
181 } 180 }
182 if ($hadunid) {
183 $pl->message ("You couldn't identify the other rings and not analyze them!"); 181 $pl->message ("You couldn't identify the other rings and not analyze them!")
184 } 182 if $hadunid;
185} 183}
186 184
187# this function converts metals/minerals into a raw ring (of adornment) 185# this function converts metals/minerals into a raw ring (of adornment)
188sub simple_converter { 186sub simple_converter {
189 my ($pl, $ingred, $chdl, $conv) = @_; 187 my ($pl, $ingred, $chdl, $conv) = @_;
203 warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; 201 warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!";
204 return; 202 return;
205 } 203 }
206 204
207 unless ($xp_gain > 0) { 205 unless ($xp_gain > 0) {
208 warn "WARNING: xp gain isn't > 0 in convesion '$outarch'\n"; 206 warn "WARNING: xp gain isn't > 0 in conversion '$outarch'\n";
209 return; 207 return;
210 } 208 }
211 209
212 unless ($outarchvalfact) { 210 unless ($outarchvalfact) {
213 warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; 211 warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n";
219 } 217 }
220 218
221 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); 219 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname);
222 $ingred->remove ($ingr_grp, $srcarchname); 220 $ingred->remove ($ingr_grp, $srcarchname);
223 221
224 my $outarchval = cf::arch::find ($outarch)->clone->value; 222 my $outarchval = cf::arch::find ($outarch)->value;
225 223
226 my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); 224 my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact);
227 if ($nrof) { 225 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) 226 # 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) { 227 for (1 .. $nrof) {
230 $chdl->put (my $ob = cf::object::new $outarch); 228 $chdl->put (my $ob = cf::object::new $outarch);
231 $ob->set_animation (cf::rndm $ob->num_animations); 229 $ob->set_animation (cf::rndm $ob->num_animations)
230 if ($ob->type == cf::RING);
232 $ob->flag (cf::FLAG_IDENTIFIED, 1); 231 $ob->flag (cf::FLAG_IDENTIFIED, 1);
233 } 232 }
234 233
235 my $xp_sum = ($xp_gain * $nrof); 234 my $xp_sum = $xp_gain * $nrof;
236 235
237 if ($xp_sum) { 236 if ($xp_sum) {
238 $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); 237 $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); 238 $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY);
240 } 239 }
241 } else { 240 } else {
242 $pl->ob->message ("You fail to make something, propably you used not enough source material?"); 241 $pl->ob->message ("You fail to make something, probably you used not enough source material?");
243 } 242 }
244} 243}
245 244
246 245
247package Jeweler::CauldronHandler; 246package Jeweler::CauldronHandler;
279 my ($self, $arch_name, @map_stack) = @_; 278 my ($self, $arch_name, @map_stack) = @_;
280 279
281 my @c = 280 my @c =
282 grep { 281 grep {
283 $_->flag (cf::FLAG_IS_CAULDRON) 282 $_->flag (cf::FLAG_IS_CAULDRON)
284 and $_->arch->name eq $arch_name 283 and $_->arch->archname eq $arch_name
285 } @map_stack; 284 } @map_stack;
286 285
287 $self->{cauldron} = $c[0]; 286 $self->{cauldron} = $c[0];
288} 287}
289 288
328 cf::POTION => 'potions', 327 cf::POTION => 'potions',
329 cf::SCROLL => 'scrolls', 328 cf::SCROLL => 'scrolls',
330 ); 329 );
331 330
332 for ($self->{cauldron}->inv) { 331 for ($self->{cauldron}->inv) {
332 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) {
333 die "unidentified";
333 if ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { 334 } elsif ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) {
334 die "cursed"; 335 die "cursed";
335 } 336 }
336 337
337 if (my $k = $type_to_key{$_->type}) { 338 if (my $k = $type_to_key{$_->type}) {
338 push @{$ingreds->{$k}}, $_; 339 push @{$ingreds->{$k}}, $_;
352 353
353sub put { 354sub put {
354 my ($self, $obj) = @_; 355 my ($self, $obj) = @_;
355 356
356 return undef unless $self->{cauldron}; 357 return undef unless $self->{cauldron};
357 $obj->insert_ob_in_ob ($self->{cauldron}); 358 $self->{cauldron}->insert ($obj);
358} 359}
359 360
360=back 361=back
361 362
362=cut 363=cut
395 396
396sub value { 397sub value {
397 my ($self, $group, $archname) = @_; 398 my ($self, $group, $archname) = @_;
398 399
399 my @objs = grep { 400 my @objs = grep {
400 $_->arch->name eq $archname 401 $_->arch->archname eq $archname
401 } @{$self->{ingredients}->{$group} || []}; 402 } @{$self->{ingredients}->{$group} || []};
402 403
403 my $sum = 0; 404 my $sum = 0;
404 for (@objs) { 405 for (@objs) {
405 $sum += ($_->nrof || 1) * $_->value; 406 $sum += ($_->nrof || 1) * $_->value;
422 423
423 my @out; 424 my @out;
424 425
425 for (@{$ingred->{$group}}) { 426 for (@{$ingred->{$group}}) {
426 if (defined $archname) { 427 if (defined $archname) {
427 if ($_->arch->name eq $archname) { 428 if ($_->arch->archname eq $archname) {
428 Jeweler::Util::remove ($_); 429 Jeweler::Util::remove ($_);
429 } else { 430 } else {
430 push @out, $_; 431 push @out, $_;
431 } 432 }
432 } else { 433 } else {
474} 475}
475 476
476sub improve_ring_by_plan { 477sub improve_ring_by_plan {
477 my ($self, $plan, $ring) = @_; 478 my ($self, $plan, $ring) = @_;
478 479
479 $ring = dclone ($ring); 480 $ring = do { my $guard = Coro::Storable::guard; dclone $ring };
480 481
481 my $ingred = $self->{ingredients}; 482 my $ingred = $self->{ingredients};
482 my $impr = {}; 483 my $impr = {};
483 484
484 if ($plan =~ m/^stat_(\S+)$/) { 485 if ($plan =~ m/^stat_(\S+)$/) {
568} 569}
569 570
570sub check_costs { 571sub check_costs {
571 my ($self, $costs, $do_remove) = @_; 572 my ($self, $costs, $do_remove) = @_;
572 573
573 my $costs = dclone ($costs); 574 my $costs = do { my $guard = Coro::Storable::guard; dclone $costs };
574 575
575 for my $key (keys %$costs) { 576 for my $key (keys %$costs) {
576 my @grepar; 577 my @grepar;
577 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 578 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
578 @grepar = @{Jeweler::getcfg (plans => $key) || []}; 579 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
580 next if $@;
579 } else { # check the gems 581 } else { # check the gems
580 @grepar = ('gems', undef, undef, $key); 582 @grepar = ('gems', undef, undef, $key);
581 } 583 }
582 584
583 if ($do_remove) { 585 if ($do_remove) {
626 $self->ring_or_ammy_to_hash ($arg{object}); 628 $self->ring_or_ammy_to_hash ($arg{object});
627 629
628 $self; 630 $self;
629} 631}
630 632
633sub has_resist {
634 my ($self, $resistnam, $resistval) = @_;
635 my $resnum = $REV_RESMAP{uc $resistnam};
636 if (defined ($resistval)) {
637 return 1 if $self->{hash}->{resist}->{$resnum} == $resistval;
638 } else {
639 return 1 if $self->{hash}->{resist}->{$resnum};
640 }
641 return undef;
642}
643
644sub projected_exp {
645 my ($self, $input_level) = @_;
646
647 my $lvl = max ($self->power_to_level, 1);
648 my $exp =
649 (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1))
650 / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring
651 # should get you to the rings level at least.
652
653 if (defined $input_level) {
654 my $subexp =
655 (cf::level_to_min_exp ($input_level)
656 - cf::level_to_min_exp ($input_level - 1))
657 / (10 + max ($input_level - 1, 0)); # see above for comment
658
659 $exp -= $subexp;
660 $exp = max ($exp, 0);
661
662 } else {
663 # the experience bonus here is to make level 1 rings give you at least
664 # 100 exp points when making them. This also makes leveling in the
665 # first few levels a bit easier. (probably until around level 5-6).
666 my $expbonus = cf::level_to_min_exp (2) / 10;
667 # this bonus should also only be given for _new_ rings and not for merged
668 # ones - to prevent infinite exp making.
669 $exp += $expbonus;
670 }
671
672 $exp
673}
674
631sub analyze { 675sub analyze {
632 my ($self, $sk, $pl) = @_; 676 my ($self, $sk, $pl, $input_level) = @_;
677 my $costs = $self->calc_costs;
678
679 unless (defined $costs) {
680 return "This ring has a resistancy above 99%, you can't make that.";
681 }
633 682
634 my $sklvl = cf::exp_to_level ($sk->stats->exp); 683 my $sklvl = cf::exp_to_level ($sk->stats->exp);
635 my $ringlvl = $self->power_to_level; 684 my $ringlvl = $self->power_to_level;
636 685
637 my $tmpl; 686 my $tmpl;
638 if ($pl->flag (cf::FLAG_WIZ)) { 687 if ($pl->flag (cf::FLAG_WIZ)) {
639 $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); 688 $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl);
640 } else { 689 } else {
641 $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); 690 $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl);
642 } 691 }
643 my $msg = sprintf "Projected success rate: %s", $tmpl; 692 my $msg = sprintf "Projected success rate: %s, you would get %d exp for this.", $tmpl, $self->projected_exp ($input_level);
644 return $msg; 693 return $msg;
645} 694}
646 695
647sub wiz_analyze { 696sub calc_value_from_cost {
648 my ($self, $pl) = @_; 697 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'; 698 my $emarch = cf::arch::find 'emerald';
653 my $saarch = cf::arch::find 'sapphire'; 699 my $saarch = cf::arch::find 'sapphire';
654 my $pearch = cf::arch::find 'pearl'; 700 my $pearch = cf::arch::find 'pearl';
655 my $ruarch = cf::arch::find 'ruby'; 701 my $ruarch = cf::arch::find 'ruby';
656 my $diarch = cf::arch::find 'gem'; 702 my $diarch = cf::arch::find 'gem';
657 my $scosts = $emarch->clone->value * $costs->{emerald} 703 my $value = $emarch->value * $costs->{emerald}
658 + $saarch->clone->value * $costs->{sapphire} 704 + $saarch->value * $costs->{sapphire}
659 + $pearch->clone->value * $costs->{pearl} 705 + $pearch->value * $costs->{pearl}
660 + $ruarch->clone->value * $costs->{ruby} 706 + $ruarch->value * $costs->{ruby}
661 + $diarch->clone->value * $costs->{gem}; 707 + $diarch->value * $costs->{gem};
662 708
709 $value
710}
711
712sub wiz_analyze {
713 my ($self, $pl) = @_;
714 my $costs = $self->calc_costs;
715 if (defined $costs) {
716 my $desc = "";
717 my $lvl = $self->power_to_level (\$desc);
718 my $scosts = $self->calc_value_from_cost ($costs);
719
663 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); 720 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)");
664 $pl->message ("level: " . $desc); 721 $pl->message ("level: " . $desc);
722 } else {
723 $pl->message ("level: impossible to make, due to impossible resistancy configuration");
724 }
665} 725}
666
667 726
668sub get_chance_perc { 727sub get_chance_perc {
669 my ($self, $sk) = @_; 728 my ($self, $sk) = @_;
670 my $sklvl = cf::exp_to_level ($sk->stats->exp); 729 my $sklvl = cf::exp_to_level ($sk->stats->exp);
671 my $ringlvl = $self->power_to_level; 730 my $ringlvl = $self->power_to_level;
674 733
675sub fx { 734sub fx {
676 my ($res, $cfg) = @_; 735 my ($res, $cfg) = @_;
677 my $or = $res; 736 my $or = $res;
678 my $ar = $Jeweler::CFG->{functions}->{$cfg}; 737 my $ar = $Jeweler::CFG->{functions}->{$cfg};
738
679 if (ref $ar->[0] eq 'ARRAY') { 739 if (ref $ar && ref $ar->[0] eq 'ARRAY') {
680 $res = $res - 1; 740 $res = $res - 1;
741 return $ar->[max (min ($res, @$ar - 1), 0)];
742
681 } else { 743 } else {
682 $res = ceil ($res / 5) - 1; 744 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3...
683 } 745 # old code:
746 #my $idx = ceil (($res / 5) + 0.1) - 1;
684 $ar->[max (min ($res, @$ar - 1), 0)]; 747 #my $a = $ar->[max (min ($idx, @$ar - 1), 0)];
748 #my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)];
749 #my $diff = $b - $a; # use the difference of the cost to the next cost
750 #my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation
751 #return $o_cost;
752 return 0 if $res <= 0;
753 return ($ar / (1 - ($res * 0.01)) - $ar)
754 }
685} 755}
686 756
687sub improve_by_ring { 757sub improve_by_ring {
688 my ($self, @rings) = @_; 758 my ($self, @rings) = @_;
689 my $ring = $self; 759 my $ring = $self;
705 if ($self->{hash}->{$cat}->{$k} > 0) { 775 if ($self->{hash}->{$cat}->{$k} > 0) {
706 $self->{hash}->{$cat}->{$k} *= -1; 776 $self->{hash}->{$cat}->{$k} *= -1;
707 } 777 }
708 } 778 }
709 } 779 }
780 $self->{hash}{value} = 0;
710} 781}
711 782
712sub to_string { 783sub to_string {
713 my ($self) = @_; 784 my ($self) = @_;
714 my $r = $self->{hash}; 785 my $r = $self->{hash};
753 $obj->{spec}{ac} = $stats->ac; 824 $obj->{spec}{ac} = $stats->ac;
754 $obj->{spec}{speed} = $stats->exp; 825 $obj->{spec}{speed} = $stats->exp;
755 $obj->{spec}{food} = $stats->food; 826 $obj->{spec}{food} = $stats->food;
756 827
757 $obj->{name} = $thing->name; 828 $obj->{name} = $thing->name;
758 $obj->{arch} = $thing->arch->name; 829 $obj->{arch} = $thing->arch->archname;
759 $obj->{face} = $thing->face; 830 $obj->{face} = $thing->face;
831
832 $obj->{value} = $thing->value;
760 833
761 $self->{hash} = $obj 834 $self->{hash} = $obj
762} 835}
763 836
764sub to_object { 837sub to_object {
765 my ($self) = @_; 838 my ($self) = @_;
766 839
767 my $obj = cf::object::new $self->{hash}->{arch}; 840 my $obj = cf::object::new $self->{hash}->{arch};
841
842 $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached!
768 843
769 $obj->face ($self->{hash}{face}); 844 $obj->face ($self->{hash}{face});
770 845
771 my $stats = $obj->stats; 846 my $stats = $obj->stats;
772 847
785 $obj->resist ($_, $self->{hash}->{resist}->{$_}); 860 $obj->resist ($_, $self->{hash}->{resist}->{$_});
786 } 861 }
787 862
788 $obj->flag (cf::FLAG_IDENTIFIED, 1); 863 $obj->flag (cf::FLAG_IDENTIFIED, 1);
789 864
865 $obj->value ($self->{hash}{value});
866
790 return $obj; 867 return $obj;
791} 868}
869
870sub set_value { $_[0]->{hash}{value} = $_[1] }
792 871
793sub is_better_than { 872sub is_better_than {
794 my ($self, $other) = @_; 873 my ($self, $other) = @_;
795 874
796 for my $type (qw/spec stat resist/) { 875 for my $type (qw/spec stat resist/) {
958 1037
959 my $res = $ring->{resist}->{$resnum}; 1038 my $res = $ring->{resist}->{$resnum};
960 1039
961 next unless $res > 0; 1040 next unless $res > 0;
962 1041
1042 return undef if $res == 100;
1043
963 $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; 1044 $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res;
964 1045
965 my $diamonds; 1046 my $diamonds;
966 if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { 1047 if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) {
967 $diamonds += fx ($res, 'effect_resist_diamonds'); 1048 $diamonds += fx ($res, 'effect_resist_diamonds_x');
968 } else { 1049 } else {
969 $diamonds += fx ($res, 'attack_resist_diamonds'); 1050 $diamonds += fx ($res, 'attack_resist_diamonds_x');
970 } 1051 }
971 1052
972 split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); 1053 split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum});
973 } 1054 }
974 1055
982 my ($cost, $diamonds, $category) = @_; 1063 my ($cost, $diamonds, $category) = @_;
983 1064
984 my $stat_split = Jeweler::getcfg (diamond_split => $category); 1065 my $stat_split = Jeweler::getcfg (diamond_split => $category);
985 1066
986 my $sum = sum (@$stat_split); 1067 my $sum = sum (@$stat_split);
987 if ($sum < (1 - 0.0001)) {
988 warn "JEWELER BUG: sum (@$stat_split) = $sum < 1 for $category!";
989 }
990 1068
991 my $emarch = cf::arch::find 'emerald'; 1069 my $emarch = cf::arch::find 'emerald';
992 my $saarch = cf::arch::find 'sapphire'; 1070 my $saarch = cf::arch::find 'sapphire';
993 my $pearch = cf::arch::find 'pearl'; 1071 my $pearch = cf::arch::find 'pearl';
994 my $ruarch = cf::arch::find 'ruby'; 1072 my $ruarch = cf::arch::find 'ruby';
995 my $diarch = cf::arch::find 'gem'; 1073 my $diarch = cf::arch::find 'gem';
996 1074
997 my $sumvalue = $diarch->clone->value * $diamonds; 1075 my $sumvalue = $diarch->value * $diamonds;
998 1076
999 $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->clone->value; 1077 $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->value;
1000 $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->clone->value; 1078 $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->value;
1001 $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->clone->value; 1079 $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->value;
1002 $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->clone->value; 1080 $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->value;
1003 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->clone->value; 1081 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value;
1004} 1082}
1005 1083
1006package Jeweler::Util; 1084package Jeweler::Util;
1007 1085
1008use strict; 1086use strict;
1043 1121
1044sub check_for_match { 1122sub check_for_match {
1045 my ($thing, @matchar) = @_; 1123 my ($thing, @matchar) = @_;
1046 1124
1047 my $i = 0; 1125 my $i = 0;
1126 my $check_cnts = 0;
1127 my $check_true = 0;
1048 for my $match (@matchar) { 1128 for my $match (@matchar) {
1129 if ($i % 3 == 0) {
1130 return 1 if $check_true && $check_cnts == $check_true;
1131 $check_cnts = 0;
1132 $check_true = 0;
1133 }
1134
1049 if ($match =~ m/^\s*$/) { 1135 if ($match =~ m/^\s*$/) {
1050 $i++; 1136 $i++;
1051 next; 1137 next;
1052 } 1138 }
1053 1139
1140 $check_cnts++;
1054 if ($i % 3 == 0) { 1141 if ($i % 3 == 0) {
1055 $thing->name eq $match 1142 $thing->name eq $match
1056 and return 1; 1143 and $check_true++;
1057 } elsif ($i % 3 == 1) { 1144 } elsif ($i % 3 == 1) {
1058 $thing->title eq $match 1145 $thing->title eq $match
1059 and return 1; 1146 and $check_true++;
1060 } else { # $i % 3 == 2 1147 } else { # $i % 3 == 2
1061 $thing->arch->name eq $match 1148 $thing->arch->archname eq $match
1062 and return 1; 1149 and $check_true++;
1063 } 1150 }
1064 $i++; 1151 $i++;
1065 } 1152 }
1153 #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->archname))."\n";
1154 return 1 if $check_true && $check_cnts == $check_true;
1066 return 0; 1155 return 0;
1067} 1156}
1068 1157
1069sub grep_for_match { 1158sub grep_for_match {
1070 my ($ingred, $group, @matchar) = @_; 1159 my ($ingred, $group, @matchar) = @_;
1071 1160
1072 for my $thing (@{$ingred->{$group} || []}) { 1161 for my $thing (@{$ingred->{$group} || []}) {
1073 warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# 1162 #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)) { 1163 if (check_for_match ($thing, @matchar)) {
1075 return $thing; 1164 return $thing;
1076 } 1165 }
1077 } 1166 }
1078 return undef; 1167 return undef;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines