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.2 by elmex, Tue Dec 19 15:43:22 2006 UTC vs.
Revision 1.10 by elmex, Sun Feb 4 11:44:43 2007 UTC

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
122our %REV_RESMAP = map { $RESMAP{$_} => $_ } keys %RESMAP;
123
122our %LVL_DIFF_CHANCES = ( 124our %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, propably you used not enough source material?");
235 } 244 }
236} 245}
237 246
238 247
239package Jeweler::CauldronHandler; 248package 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}
427sub get_plan { 443sub 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
451sub get_ring { 463sub get_ring {
454 @{$self->{ingredients}->{ammys} || []}, 466 @{$self->{ingredients}->{ammys} || []},
455 @{$self->{ingredients}->{rings} || []} 467 @{$self->{ingredients}->{rings} || []}
456 ); 468 );
457} 469}
458 470
471sub improve_max {
472 my ($stat, $impro) = @_;
473 if ($stat >= 0) {
474 $stat = $impro > $stat ? $impro : $stat;
475 }
476 $stat
477}
478
459sub improve_ring_by_plan { 479sub 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
501sub do_grep { 555sub 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
522sub check_costs { 573sub 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 @grepar = @{Jeweler::getcfg (plans => $key) || []};
531 } else { 582 } else { # check the gems
532 @grepar = (undef, undef, $key); 583 @grepar = ('gems', undef, undef, $key);
533 } 584 }
534 585
535 if ($do_remove) { 586 if ($do_remove) {
536 my $rem = $costs->{$key}; 587 my $rem = $costs->{$key};
537 $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); 588 $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar);
538 if ($rem > 0) { 589 if ($rem > 0) {
539 warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; 590 warn "JEWELER BUG: removed ingredients $rem > 0 after removing!";
540 } 591 }
541 } else { 592 } else {
542 my $nr; 593 my $nr;
543 $self->do_grep (sub { $nr += $_[0]->nrof; 0 }, @grepar); 594 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar);
544 $costs->{$key} -= $nr; 595 $costs->{$key} -= $nr;
545 } 596 }
597
546 } 598 }
547 599
548 return $costs; 600 return $costs;
549} 601}
550 602
575 my $self = bless { }, $class; 627 my $self = bless { }, $class;
576 628
577 $self->ring_or_ammy_to_hash ($arg{object}); 629 $self->ring_or_ammy_to_hash ($arg{object});
578 630
579 $self; 631 $self;
632}
633
634sub 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;
580} 643}
581 644
582sub analyze { 645sub analyze {
583 my ($self, $sk, $pl) = @_; 646 my ($self, $sk, $pl) = @_;
584 647
593 } 656 }
594 my $msg = sprintf "Projected success rate: %s", $tmpl; 657 my $msg = sprintf "Projected success rate: %s", $tmpl;
595 return $msg; 658 return $msg;
596} 659}
597 660
661sub 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
598sub wiz_analyze { 677sub wiz_analyze {
599 my ($self, $pl) = @_; 678 my ($self, $pl) = @_;
600 my $costs = $self->calc_costs; 679 my $costs = $self->calc_costs;
601 my $desc = ""; 680 my $desc = "";
602 my $lvl = $self->power_to_level (\$desc); 681 my $lvl = $self->power_to_level (\$desc);
682 my $scosts = $self->calc_value_from_cost ($costs);
683
603 $pl->message ("costs: " . join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)); 684 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)");
604 $pl->message ("level: " . $desc); 685 $pl->message ("level: " . $desc);
605} 686}
606
607 687
608sub get_chance_perc { 688sub get_chance_perc {
609 my ($self, $sk) = @_; 689 my ($self, $sk) = @_;
610 my $sklvl = cf::exp_to_level ($sk->stats->exp); 690 my $sklvl = cf::exp_to_level ($sk->stats->exp);
611 my $ringlvl = $self->power_to_level; 691 my $ringlvl = $self->power_to_level;
614 694
615sub fx { 695sub fx {
616 my ($res, $cfg) = @_; 696 my ($res, $cfg) = @_;
617 my $or = $res; 697 my $or = $res;
618 my $ar = $Jeweler::CFG->{functions}->{$cfg}; 698 my $ar = $Jeweler::CFG->{functions}->{$cfg};
699
619 if (ref $ar->[0] eq 'ARRAY') { 700 if (ref $ar->[0] eq 'ARRAY') {
620 $res = $res - 1; 701 $res = $res - 1;
702 return $ar->[max (min ($res, @$ar - 1), 0)];
703
621 } else { 704 } else {
705 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3...
622 $res = ceil ($res / 5) - 1; 706 my $idx = ceil (($res / 5) + 0.1) - 1;
623 }
624 $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 }
625} 713}
626 714
627sub improve_by_ring { 715sub improve_by_ring {
628 my ($self, @rings) = @_; 716 my ($self, @rings) = @_;
629 my $ring = $self; 717 my $ring = $self;
645 if ($self->{hash}->{$cat}->{$k} > 0) { 733 if ($self->{hash}->{$cat}->{$k} > 0) {
646 $self->{hash}->{$cat}->{$k} *= -1; 734 $self->{hash}->{$cat}->{$k} *= -1;
647 } 735 }
648 } 736 }
649 } 737 }
738 $self->{hash}{value} = 0;
650} 739}
651 740
652sub to_string { 741sub to_string {
653 my ($self) = @_; 742 my ($self) = @_;
654 my $r = $self->{hash}; 743 my $r = $self->{hash};
675 my ($self, $thing) = @_; 764 my ($self, $thing) = @_;
676 765
677 my $obj = {}; 766 my $obj = {};
678 767
679 for (@Jeweler::RESISTS) { 768 for (@Jeweler::RESISTS) {
680 $obj->{resist}->{$_} = $thing->resistance ($_); 769 $obj->{resist}->{$_} = $thing->resist ($_);
681 } 770 }
682 771
683 my $stats = $thing->stats; 772 my $stats = $thing->stats;
684 773
685 for (qw/Str Dex Con Wis Cha Int Pow/) { 774 for (qw/Str Dex Con Wis Cha Int Pow/) {
696 785
697 $obj->{name} = $thing->name; 786 $obj->{name} = $thing->name;
698 $obj->{arch} = $thing->arch->name; 787 $obj->{arch} = $thing->arch->name;
699 $obj->{face} = $thing->face; 788 $obj->{face} = $thing->face;
700 789
790 $obj->{value} = $thing->value;
791
701 $self->{hash} = $obj 792 $self->{hash} = $obj
702} 793}
703 794
704sub to_object { 795sub to_object {
705 my ($self) = @_; 796 my ($self) = @_;
706 797
707 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!
708 801
709 $obj->face ($self->{hash}{face}); 802 $obj->face ($self->{hash}{face});
710 803
711 my $stats = $obj->stats; 804 my $stats = $obj->stats;
712 805
720 813
721 $stats->$_ ($self->{hash}{stat}{lc $_}) 814 $stats->$_ ($self->{hash}{stat}{lc $_})
722 for qw/Str Dex Con Wis Cha Int Pow/; 815 for qw/Str Dex Con Wis Cha Int Pow/;
723 816
724 for (@Jeweler::RESISTS) { 817 for (@Jeweler::RESISTS) {
725 $obj->resistance ($_, $self->{hash}->{resist}->{$_}); 818 $obj->resist ($_, $self->{hash}->{resist}->{$_});
726 } 819 }
727 820
728 $obj->flag (cf::FLAG_IDENTIFIED, 1); 821 $obj->flag (cf::FLAG_IDENTIFIED, 1);
729 822
823 $obj->value ($self->{hash}{value});
824
730 return $obj; 825 return $obj;
826}
827
828sub set_value { $_[0]->{hash}{value} = $_[1] }
829
830sub is_better_than {
831 my ($self, $other) = @_;
832
833 for my $type (qw/spec stat resist/) {
834 for my $stat (keys %{$self->{hash}->{$type}}) {
835 if ($self->{hash}->{$type}->{$stat} > $other->{hash}->{$type}->{$stat}) {
836 return 1;
837 }
838 }
839 }
840
841 return 0;
731} 842}
732 843
733sub stat_level { 844sub stat_level {
734 my ($self) = @_; 845 my ($self) = @_;
735 my $stats = $self->{hash}->{stat} || {}; 846 my $stats = $self->{hash}->{stat} || {};
849 for my $stat (keys %$stats) { 960 for my $stat (keys %$stats) {
850 my $sum = $stats->{$stat}; 961 my $sum = $stats->{$stat};
851 962
852 next unless $sum > 0; 963 next unless $sum > 0;
853 964
854 my $statfx = fx ($sum, 'stat_potions'); 965 my $statfx = fx ($sum, 'stat_items');
855 $cost->{"stat_$stat"} += $statfx->[0]; 966 $cost->{"stat_$stat"} += $statfx->[0];
856 split_diamonds ($cost, $statfx->[1], 'stat_' . $stat); 967 split_diamonds ($cost, $statfx->[1], 'stat_' . $stat);
857 } 968 }
858} 969}
859 970
865 for my $spec (keys %$specials) { 976 for my $spec (keys %$specials) {
866 my $sum = $specials->{$spec}; 977 my $sum = $specials->{$spec};
867 978
868 next unless $sum > 0; 979 next unless $sum > 0;
869 980
870 my $specfx = fx ($sum, 'spec_potions'); 981 my $specfx = fx ($sum, 'spec_items');
871 $cost->{"spec_$spec"} += $specfx->[0]; 982 $cost->{"spec_$spec"} += $specfx->[0];
872 split_diamonds ($cost, $specfx->[1], 'spec_' . $spec); 983 split_diamonds ($cost, $specfx->[1], 'spec_' . $spec);
873 } 984 }
874} 985}
875 986
878 989
879 my $costs = {}; 990 my $costs = {};
880 991
881 my $ring = $self->{hash}; 992 my $ring = $self->{hash};
882 993
883 for my $resnam (keys %{$ring->{resist} || {}}) { 994 for my $resnum (keys %{$ring->{resist} || {}}) {
884 995
885 my $res = $ring->{resist}->{$resnam}; 996 my $res = $ring->{resist}->{$resnum};
886 997
887 next unless $res > 0; 998 next unless $res > 0;
888 999
889 $costs->{"resist_" . $Jeweler::RESMAP{$resnam} . "_item"} += $res; 1000 $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res;
890 1001
891 my $diamonds; 1002 my $diamonds;
892 if (grep { $resnam eq $_ } @Jeweler::EFFECT_RESISTS) { 1003 if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) {
893 $diamonds += fx ($res, 'effect_resist_diamonds'); 1004 $diamonds += fx ($res, 'effect_resist_diamonds');
894 } else { 1005 } else {
895 $diamonds += fx ($res, 'attack_resist_diamonds'); 1006 $diamonds += fx ($res, 'attack_resist_diamonds');
896 } 1007 }
897 1008
898 split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnam}); 1009 split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum});
899 } 1010 }
900 1011
901 $self->add_stat_costs ($costs); 1012 $self->add_stat_costs ($costs);
902 $self->add_special_costs ($costs); 1013 $self->add_special_costs ($costs);
903 1014
950 my ($obj, $nrof) = @_; 1061 my ($obj, $nrof) = @_;
951 1062
952 my $cnt; 1063 my $cnt;
953 1064
954 if (defined $nrof) { 1065 if (defined $nrof) {
1066 # TODO: Check tihis line:
955 return 0 if ($nrof * 1) == 0; 1067 return 0 if ($nrof * 1) == 0; #XXX: ???
956 $cnt = int (($obj->nrof || 1) - (1 * $nrof)); 1068 $cnt = int (($obj->nrof || 1) - (1 * $nrof));
957 1069
958 if ($cnt > 0) { 1070 if ($cnt > 0) {
959 $obj->nrof ($cnt); 1071 $obj->nrof ($cnt);
960 return 0; 1072 return 0;
964 remove ($_) for $obj->inv; 1076 remove ($_) for $obj->inv;
965 $obj->destroy; 1077 $obj->destroy;
966 return $cnt; 1078 return $cnt;
967} 1079}
968 1080
969sub grep_for_match { 1081sub check_for_match {
970 my ($thing, @matchar) = @_; 1082 my ($thing, @matchar) = @_;
971 1083
972 my $i = 0; 1084 my $i = 0;
1085 my $check_cnts = 0;
1086 my $check_true = 0;
973 for my $match (@matchar) { 1087 for my $match (@matchar) {
1088 $check_cnts = 0 if $i % 3 == 0;
1089
974 if ($match =~ m/^\s*$/) { 1090 if ($match =~ m/^\s*$/) {
975 $i++; 1091 $i++;
976 next; 1092 next;
977 } 1093 }
978 1094
1095 $check_cnts++;
979 if ($i % 3 == 0) { 1096 if ($i % 3 == 0) {
980 $thing->name eq $match 1097 $thing->name eq $match
981 and return 1; 1098 and $check_true++;
982 } elsif ($i % 3 == 1) { 1099 } elsif ($i % 3 == 1) {
983 $thing->title eq $match 1100 $thing->title eq $match
984 and return 1; 1101 and $check_true++;
985 } else { # $i % 3 == 2 1102 } else { # $i % 3 == 2
986 $thing->arch->name eq $match 1103 $thing->arch->name eq $match
987 and return 1; 1104 and $check_true++;
988 } 1105 }
989 $i++; 1106 $i++;
990 } 1107 }
1108 if ($check_true && $check_cnts == $check_true) {
1109 return 1;
1110 }
991 return 0; 1111 return 0;
992} 1112}
993 1113
1114sub grep_for_match {
1115 my ($ingred, $group, @matchar) = @_;
1116
1117 for my $thing (@{$ingred->{$group} || []}) {
1118 #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d#
1119 if (check_for_match ($thing, @matchar)) {
1120 return $thing;
1121 }
1122 }
1123 return undef;
1124}
1125
994=back 1126=back
995 1127
9961 11281

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines