… | |
… | |
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 | |
|
|
122 | our %REV_RESMAP = map { $RESMAP{$_} => $_ } keys %RESMAP; |
|
|
123 | |
122 | our %LVL_DIFF_CHANCES = ( |
124 | our %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 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
|
|
233 | } |
228 | |
234 | |
229 | my $xp_sum = ($xp_gain * $nrof); |
235 | my $xp_sum = ($xp_gain * $nrof); |
230 | |
236 | |
231 | if ($xp_sum) { |
237 | if ($xp_sum) { |
232 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
238 | $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); |
239 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
234 | } |
240 | } |
|
|
241 | } else { |
|
|
242 | $pl->ob->message ("You fail to make something, propably you used not enough source material?"); |
235 | } |
243 | } |
236 | } |
244 | } |
237 | |
245 | |
238 | |
246 | |
239 | package Jeweler::CauldronHandler; |
247 | package Jeweler::CauldronHandler; |
… | |
… | |
323 | |
331 | |
324 | for ($self->{cauldron}->inv) { |
332 | for ($self->{cauldron}->inv) { |
325 | |
333 | |
326 | if (my $k = $type_to_key{$_->type}) { |
334 | if (my $k = $type_to_key{$_->type}) { |
327 | push @{$ingreds->{$k}}, $_; |
335 | push @{$ingreds->{$k}}, $_; |
|
|
336 | } else { |
|
|
337 | push @{$ingreds->{other}}, $_; |
328 | } |
338 | } |
329 | } |
339 | } |
330 | |
340 | |
331 | return Jeweler::Ingredients->new (ingredients => $ingreds, cauldron_helper => $self) |
341 | return Jeweler::Ingredients->new (ingredients => $ingreds, cauldron_helper => $self) |
332 | } |
342 | } |
… | |
… | |
427 | sub get_plan { |
437 | sub get_plan { |
428 | my ($self) = @_; |
438 | my ($self) = @_; |
429 | |
439 | |
430 | my $ingred = $self->{ingredients}; |
440 | my $ingred = $self->{ingredients}; |
431 | |
441 | |
432 | for my $grp (keys %$ingred) { |
|
|
433 | for my $pot (@{$ingred->{$grp}}) { |
|
|
434 | for my $plan (keys %{$Jeweler::CFG->{plans}}) { |
442 | for my $plan (keys %{$Jeweler::CFG->{plans}}) { |
435 | my $plg = $Jeweler::CFG->{plans}->{$plan}; |
443 | my $plg = $Jeweler::CFG->{plans}->{$plan}; |
436 | my @plga = (); |
444 | my @plga = (); |
437 | unless (ref $plg eq 'ARRAY') { |
445 | unless (ref $plg eq 'ARRAY') { |
438 | push @plga, $plg; |
446 | push @plga, $plg; |
439 | } else { |
447 | } else { |
440 | @plga = @$plg; |
448 | @plga = @$plg; |
441 | } |
449 | } |
442 | next unless @plga > 0; |
450 | next unless @plga > 0; |
443 | if (Jeweler::Util::grep_for_match ($pot, @plga)) { |
451 | if (Jeweler::Util::grep_for_match ($ingred, @plga)) { |
444 | return $plan; |
452 | return $plan; |
445 | } |
|
|
446 | } |
|
|
447 | } |
453 | } |
448 | } |
454 | } |
449 | } |
455 | } |
450 | |
456 | |
451 | sub get_ring { |
457 | sub get_ring { |
… | |
… | |
454 | @{$self->{ingredients}->{ammys} || []}, |
460 | @{$self->{ingredients}->{ammys} || []}, |
455 | @{$self->{ingredients}->{rings} || []} |
461 | @{$self->{ingredients}->{rings} || []} |
456 | ); |
462 | ); |
457 | } |
463 | } |
458 | |
464 | |
|
|
465 | sub improve_max { |
|
|
466 | my ($stat, $impro) = @_; |
|
|
467 | if ($stat >= 0) { |
|
|
468 | $stat = $impro > $stat ? $impro : $stat; |
|
|
469 | } |
|
|
470 | $stat |
|
|
471 | } |
|
|
472 | |
459 | sub improve_ring_by_plan { |
473 | sub improve_ring_by_plan { |
460 | my ($self, $plan, $ring) = @_; |
474 | my ($self, $plan, $ring) = @_; |
461 | |
475 | |
462 | $ring = dclone ($ring); |
476 | $ring = dclone ($ring); |
463 | |
477 | |
… | |
… | |
468 | my $statname = $1; |
482 | my $statname = $1; |
469 | my $plingred = Jeweler::getcfg (plans => $plan) |
483 | my $plingred = Jeweler::getcfg (plans => $plan) |
470 | or die "ingredients for plan '$plan' not defined!"; |
484 | or die "ingredients for plan '$plan' not defined!"; |
471 | |
485 | |
472 | my $cnt = 0; |
486 | my $cnt = 0; |
473 | for my $pot (@{$ingred->{potions}}) { |
|
|
474 | if (Jeweler::Util::grep_for_match ($pot, @$plingred)) { |
487 | if (my $pot = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { |
475 | $cnt += $pot->nrof; |
488 | $cnt += $pot->nrof; |
476 | } |
|
|
477 | } |
489 | } |
478 | |
490 | |
479 | my $maxstat = Jeweler::getcfg (maximprovements => 'stats'); |
491 | my $maxstat = Jeweler::getcfg (maximprovements => 'stats'); |
480 | my $did_impr = 0; |
|
|
481 | for my $x (1..$maxstat) { |
492 | for my $x (1..$maxstat) { |
482 | my $y = Jeweler::Object::fx ($x, 'stat_potions'); |
493 | my $y = Jeweler::Object::fx ($x, 'stat_items'); |
483 | |
494 | |
484 | if ($cnt <= $y->[0]) { |
495 | if ($cnt <= $y->[0]) { |
485 | $ring->{hash}->{stat}->{$statname} += $x; |
496 | $ring->{hash}->{stat}->{$statname} = |
486 | $did_impr = 1; |
497 | improve_max $ring->{hash}->{stat}->{$statname}, $x; |
487 | last; |
498 | last; |
488 | } |
499 | } |
489 | } |
500 | } |
490 | |
501 | |
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+)$/) { |
502 | } elsif ($plan =~ m/^spec_(\S+)$/) { |
|
|
503 | my $specname = $1; |
|
|
504 | my $plingred = Jeweler::getcfg (plans => $plan) |
|
|
505 | or die "ingredients for plan '$plan' not defined!"; |
|
|
506 | |
|
|
507 | my $cnt = 0; |
|
|
508 | if (my $pot = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { |
|
|
509 | $cnt += $pot->nrof; |
|
|
510 | } |
|
|
511 | |
|
|
512 | my $maxspec = Jeweler::getcfg (maximprovements => 'specials'); |
|
|
513 | for my $x (1..$maxspec) { |
|
|
514 | my $y = Jeweler::Object::fx ($x, 'spec_items'); |
|
|
515 | |
|
|
516 | if ($cnt <= $y->[0]) { |
|
|
517 | $ring->{hash}->{spec}->{$specname} = |
|
|
518 | improve_max $ring->{hash}->{spec}->{$specname}, $x; |
|
|
519 | last; |
|
|
520 | } |
|
|
521 | } |
|
|
522 | |
495 | } elsif ($plan =~ m/^resist_(\S+)$/) { |
523 | } elsif ($plan =~ m/^resist_(\S+)$/) { |
|
|
524 | my $resname = $1; |
|
|
525 | my $resnum = $REV_RESMAP{$resname}; |
|
|
526 | my $plingred = Jeweler::getcfg (plans => $plan) |
|
|
527 | or die "ingredients for plan '$plan' not defined!"; |
|
|
528 | |
|
|
529 | my $cnt = 0; |
|
|
530 | if (my $it = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { |
|
|
531 | $cnt += $it->nrof; |
|
|
532 | } |
|
|
533 | my $resist_item_nr = 0; |
|
|
534 | $self->do_grep (sub { $resist_item_nr += ($_[0]->nrof || 1); 0 }, @$plingred); |
|
|
535 | |
|
|
536 | my $maximprovname = (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) |
|
|
537 | ? 'effect_resistances' |
|
|
538 | : 'attack_resistances'; |
|
|
539 | |
|
|
540 | my $maxres = Jeweler::getcfg (maximprovements => $maximprovname); |
|
|
541 | $resist_item_nr = $maxres if ($resist_item_nr > $maxres); |
|
|
542 | $ring->{hash}->{resist}->{$resnum} = |
|
|
543 | improve_max $ring->{hash}->{resist}->{$resnum}, $resist_item_nr; |
496 | } |
544 | } |
497 | |
545 | |
498 | return $ring; |
546 | return $ring; |
499 | } |
547 | } |
500 | |
548 | |
501 | sub do_grep { |
549 | sub do_grep { |
502 | my ($self, $cb, @grepar) = @_; |
550 | my ($self, $cb, $cat, @grepar) = @_; |
503 | |
551 | |
504 | my $ingred = $self->{ingredients}; |
552 | my $ingred = $self->{ingredients}; |
505 | |
553 | |
506 | |
|
|
507 | for my $cat (keys %$ingred) { |
|
|
508 | my @rem; |
554 | my @rem; |
509 | for my $ing (@{$ingred->{$cat}}) { |
555 | for my $ing (@{$ingred->{$cat}}) { |
510 | if (Jeweler::Util::grep_for_match ($ing, @grepar)) { |
556 | if (Jeweler::Util::check_for_match ($ing, @grepar)) { |
511 | unless ($cb->($ing)) { |
557 | unless ($cb->($ing)) { |
512 | push @rem, $ing; |
|
|
513 | } |
|
|
514 | } else { |
|
|
515 | push @rem, $ing; |
558 | push @rem, $ing; |
516 | } |
559 | } |
|
|
560 | } else { |
|
|
561 | push @rem, $ing; |
517 | } |
562 | } |
|
|
563 | } |
518 | @{$ingred->{$cat}} = @rem; |
564 | @{$ingred->{$cat}} = @rem; |
519 | } |
|
|
520 | } |
565 | } |
521 | |
566 | |
522 | sub check_costs { |
567 | sub check_costs { |
523 | my ($self, $costs, $do_remove) = @_; |
568 | my ($self, $costs, $do_remove) = @_; |
524 | |
569 | |
525 | my $costs = dclone ($costs); |
570 | my $costs = dclone ($costs); |
526 | |
571 | |
527 | for my $key (keys %$costs) { |
572 | for my $key (keys %$costs) { |
528 | my @grepar; |
573 | my @grepar; |
529 | if ($key =~ m/^stat_(\S+)$/) { |
574 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
530 | @grepar = @{Jeweler::getcfg (plans => $key) || []}; |
575 | @grepar = @{Jeweler::getcfg (plans => $key) || []}; |
531 | } else { |
576 | } else { # check the gems |
532 | @grepar = (undef, undef, $key); |
577 | @grepar = ('gems', undef, undef, $key); |
533 | } |
578 | } |
534 | |
579 | |
535 | if ($do_remove) { |
580 | if ($do_remove) { |
536 | my $rem = $costs->{$key}; |
581 | my $rem = $costs->{$key}; |
537 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
582 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
538 | if ($rem > 0) { |
583 | if ($rem > 0) { |
539 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
584 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
540 | } |
585 | } |
541 | } else { |
586 | } else { |
542 | my $nr; |
587 | my $nr; |
543 | $self->do_grep (sub { $nr += $_[0]->nrof; 0 }, @grepar); |
588 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
544 | $costs->{$key} -= $nr; |
589 | $costs->{$key} -= $nr; |
|
|
590 | warn "CHECKCOST $key <-> $nr -> $costs->{$key}\n"; |
545 | } |
591 | } |
|
|
592 | |
546 | } |
593 | } |
547 | |
594 | |
548 | return $costs; |
595 | return $costs; |
549 | } |
596 | } |
550 | |
597 | |
… | |
… | |
728 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
775 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
729 | |
776 | |
730 | return $obj; |
777 | return $obj; |
731 | } |
778 | } |
732 | |
779 | |
|
|
780 | sub is_better_than { |
|
|
781 | my ($self, $other) = @_; |
|
|
782 | |
|
|
783 | for my $type (qw/spec stat resist/) { |
|
|
784 | for my $stat (keys %{$self->{hash}->{$type}}) { |
|
|
785 | if ($self->{hash}->{$type}->{$stat} > $other->{hash}->{$type}->{$stat}) { |
|
|
786 | return 1; |
|
|
787 | } |
|
|
788 | } |
|
|
789 | } |
|
|
790 | |
|
|
791 | return 0; |
|
|
792 | } |
|
|
793 | |
733 | sub stat_level { |
794 | sub stat_level { |
734 | my ($self) = @_; |
795 | my ($self) = @_; |
735 | my $stats = $self->{hash}->{stat} || {}; |
796 | my $stats = $self->{hash}->{stat} || {}; |
736 | |
797 | |
737 | my $maxlevel = Jeweler::getcfg (maxlevels => 'stat_level'); |
798 | my $maxlevel = Jeweler::getcfg (maxlevels => 'stat_level'); |
… | |
… | |
849 | for my $stat (keys %$stats) { |
910 | for my $stat (keys %$stats) { |
850 | my $sum = $stats->{$stat}; |
911 | my $sum = $stats->{$stat}; |
851 | |
912 | |
852 | next unless $sum > 0; |
913 | next unless $sum > 0; |
853 | |
914 | |
854 | my $statfx = fx ($sum, 'stat_potions'); |
915 | my $statfx = fx ($sum, 'stat_items'); |
855 | $cost->{"stat_$stat"} += $statfx->[0]; |
916 | $cost->{"stat_$stat"} += $statfx->[0]; |
856 | split_diamonds ($cost, $statfx->[1], 'stat_' . $stat); |
917 | split_diamonds ($cost, $statfx->[1], 'stat_' . $stat); |
857 | } |
918 | } |
858 | } |
919 | } |
859 | |
920 | |
… | |
… | |
865 | for my $spec (keys %$specials) { |
926 | for my $spec (keys %$specials) { |
866 | my $sum = $specials->{$spec}; |
927 | my $sum = $specials->{$spec}; |
867 | |
928 | |
868 | next unless $sum > 0; |
929 | next unless $sum > 0; |
869 | |
930 | |
870 | my $specfx = fx ($sum, 'spec_potions'); |
931 | my $specfx = fx ($sum, 'spec_items'); |
871 | $cost->{"spec_$spec"} += $specfx->[0]; |
932 | $cost->{"spec_$spec"} += $specfx->[0]; |
872 | split_diamonds ($cost, $specfx->[1], 'spec_' . $spec); |
933 | split_diamonds ($cost, $specfx->[1], 'spec_' . $spec); |
873 | } |
934 | } |
874 | } |
935 | } |
875 | |
936 | |
… | |
… | |
878 | |
939 | |
879 | my $costs = {}; |
940 | my $costs = {}; |
880 | |
941 | |
881 | my $ring = $self->{hash}; |
942 | my $ring = $self->{hash}; |
882 | |
943 | |
883 | for my $resnam (keys %{$ring->{resist} || {}}) { |
944 | for my $resnum (keys %{$ring->{resist} || {}}) { |
884 | |
945 | |
885 | my $res = $ring->{resist}->{$resnam}; |
946 | my $res = $ring->{resist}->{$resnum}; |
886 | |
947 | |
887 | next unless $res > 0; |
948 | next unless $res > 0; |
888 | |
949 | |
889 | $costs->{"resist_" . $Jeweler::RESMAP{$resnam} . "_item"} += $res; |
950 | $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; |
890 | |
951 | |
891 | my $diamonds; |
952 | my $diamonds; |
892 | if (grep { $resnam eq $_ } @Jeweler::EFFECT_RESISTS) { |
953 | if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { |
893 | $diamonds += fx ($res, 'effect_resist_diamonds'); |
954 | $diamonds += fx ($res, 'effect_resist_diamonds'); |
894 | } else { |
955 | } else { |
895 | $diamonds += fx ($res, 'attack_resist_diamonds'); |
956 | $diamonds += fx ($res, 'attack_resist_diamonds'); |
896 | } |
957 | } |
897 | |
958 | |
898 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnam}); |
959 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); |
899 | } |
960 | } |
900 | |
961 | |
901 | $self->add_stat_costs ($costs); |
962 | $self->add_stat_costs ($costs); |
902 | $self->add_special_costs ($costs); |
963 | $self->add_special_costs ($costs); |
903 | |
964 | |
… | |
… | |
950 | my ($obj, $nrof) = @_; |
1011 | my ($obj, $nrof) = @_; |
951 | |
1012 | |
952 | my $cnt; |
1013 | my $cnt; |
953 | |
1014 | |
954 | if (defined $nrof) { |
1015 | if (defined $nrof) { |
|
|
1016 | # TODO: Check tihis line: |
955 | return 0 if ($nrof * 1) == 0; |
1017 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
956 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
1018 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
957 | |
1019 | |
958 | if ($cnt > 0) { |
1020 | if ($cnt > 0) { |
959 | $obj->nrof ($cnt); |
1021 | $obj->nrof ($cnt); |
960 | return 0; |
1022 | return 0; |
… | |
… | |
964 | remove ($_) for $obj->inv; |
1026 | remove ($_) for $obj->inv; |
965 | $obj->destroy; |
1027 | $obj->destroy; |
966 | return $cnt; |
1028 | return $cnt; |
967 | } |
1029 | } |
968 | |
1030 | |
969 | sub grep_for_match { |
1031 | sub check_for_match { |
970 | my ($thing, @matchar) = @_; |
1032 | my ($thing, @matchar) = @_; |
971 | |
1033 | |
972 | my $i = 0; |
1034 | my $i = 0; |
973 | for my $match (@matchar) { |
1035 | for my $match (@matchar) { |
974 | if ($match =~ m/^\s*$/) { |
1036 | if ($match =~ m/^\s*$/) { |
… | |
… | |
989 | $i++; |
1051 | $i++; |
990 | } |
1052 | } |
991 | return 0; |
1053 | return 0; |
992 | } |
1054 | } |
993 | |
1055 | |
|
|
1056 | sub grep_for_match { |
|
|
1057 | my ($ingred, $group, @matchar) = @_; |
|
|
1058 | |
|
|
1059 | for my $thing (@{$ingred->{$group} || []}) { |
|
|
1060 | warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# |
|
|
1061 | if (check_for_match ($thing, @matchar)) { |
|
|
1062 | return $thing; |
|
|
1063 | } |
|
|
1064 | } |
|
|
1065 | return undef; |
|
|
1066 | } |
|
|
1067 | |
994 | =back |
1068 | =back |
995 | |
1069 | |
996 | 1 |
1070 | 1 |