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

Comparing deliantra/maps/perl/Jeweler.pm (file contents):
Revision 1.4 by elmex, Fri Sep 1 13:40:05 2006 UTC vs.
Revision 1.8 by elmex, Tue Sep 12 17:03:02 2006 UTC

163sub analyze { 163sub analyze {
164 my ($sk, $chdl, $pl) = @_; 164 my ($sk, $chdl, $pl) = @_;
165 165
166 my $hadunid = 0; 166 my $hadunid = 0;
167 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { 167 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) {
168 if (!$_->get_flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { 168 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) {
169 $hadunid = 1; 169 $hadunid = 1;
170 next; 170 next;
171 } 171 }
172 my $r = Jeweler::Object->new (object => $_); 172 my $r = Jeweler::Object->new (object => $_);
173 my $msg = $r->analyze ($sk, $pl); 173 my $msg = $r->analyze ($sk, $pl);
174 $pl->message ($r->to_string . ": " . $msg); 174 $pl->message ($r->to_string . ": " . $msg);
175 if ($pl->get_flag (cf::FLAG_WIZ)) { 175 if ($pl->flag (cf::FLAG_WIZ)) {
176 $r->wiz_analyze ($pl); 176 $r->wiz_analyze ($pl);
177 } 177 }
178 } 178 }
179 if ($hadunid) { 179 if ($hadunid) {
180 $pl->message ("You couldn't identify the other rings and not analyze them!"); 180 $pl->message ("You couldn't identify the other rings and not analyze them!");
269 my ($self, $arch_name, @map_stack) = @_; 269 my ($self, $arch_name, @map_stack) = @_;
270 270
271 my @c = 271 my @c =
272 grep { 272 grep {
273 $_->flag (cf::FLAG_IS_CAULDRON) 273 $_->flag (cf::FLAG_IS_CAULDRON)
274 and $_->archetype->name eq $arch_name 274 and $_->arch->name eq $arch_name
275 } @map_stack; 275 } @map_stack;
276 276
277 $self->{cauldron} = $c[0]; 277 $self->{cauldron} = $c[0];
278} 278}
279 279
380 380
381sub value { 381sub value {
382 my ($self, $group, $archname) = @_; 382 my ($self, $group, $archname) = @_;
383 383
384 my @objs = grep { 384 my @objs = grep {
385 $_->archetype->name eq $archname 385 $_->arch->name eq $archname
386 } @{$self->{ingredients}->{$group} || []}; 386 } @{$self->{ingredients}->{$group} || []};
387 387
388 my $sum = 0; 388 my $sum = 0;
389 for (@objs) { 389 for (@objs) {
390 $sum += ($_->nrof || 1) * $_->value; 390 $sum += ($_->nrof || 1) * $_->value;
407 407
408 my @out; 408 my @out;
409 409
410 for (@{$ingred->{$group}}) { 410 for (@{$ingred->{$group}}) {
411 if (defined $archname) { 411 if (defined $archname) {
412 if ($_->archetype->name eq $archname) { 412 if ($_->arch->name eq $archname) {
413 Jeweler::Util::remove ($_); 413 Jeweler::Util::remove ($_);
414 } else { 414 } else {
415 push @out, $_; 415 push @out, $_;
416 } 416 }
417 } else { 417 } else {
582 582
583 my $sklvl = cf::exp_to_level ($sk->stats->exp); 583 my $sklvl = cf::exp_to_level ($sk->stats->exp);
584 my $ringlvl = $self->power_to_level; 584 my $ringlvl = $self->power_to_level;
585 585
586 my $tmpl; 586 my $tmpl;
587 if ($pl->get_flag (cf::FLAG_WIZ)) { 587 if ($pl->flag (cf::FLAG_WIZ)) {
588 $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); 588 $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl);
589 } else { 589 } else {
590 $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); 590 $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl);
591 } 591 }
592 my $msg = sprintf "Projected success rate: %s", $tmpl; 592 my $msg = sprintf "Projected success rate: %s", $tmpl;
659 my $rv = $r->{resist}->{$_}; 659 my $rv = $r->{resist}->{$_};
660 "(resist " . (lc $Jeweler::RESMAP{$_}) . " " . ($rv > 0 ? '+' : '') . $rv . ")" 660 "(resist " . (lc $Jeweler::RESMAP{$_}) . " " . ($rv > 0 ? '+' : '') . $rv . ")"
661 } grep { $r->{resist}->{$_} } @Jeweler::RESISTS), 661 } grep { $r->{resist}->{$_} } @Jeweler::RESISTS),
662 (map { 662 (map {
663 my $rv = $r->{stat}->{$_}; 663 my $rv = $r->{stat}->{$_};
664 "(" . (lc $_) . ($rv > 0 ? '+' : '') . $rv . ")" 664 "(" . (ucfirst lc $_) . ($rv > 0 ? '+' : '') . $rv . ")"
665 } grep { $r->{stat}->{$_} } keys %{$r->{stat}}), 665 } grep { $r->{stat}->{$_} } keys %{$r->{stat}}),
666 (map { 666 (map {
667 my $rv = $r->{spec}->{$_}; 667 my $rv = $r->{spec}->{$_};
668 "(" . (lc $_) . ($rv > 0 ? '+' : '') . $rv . ")" 668 "(" . (lc $_) . ($rv > 0 ? '+' : '') . $rv . ")"
669 } grep { $r->{spec}->{$_} } keys %{$r->{spec}}))) 669 } grep { $r->{spec}->{$_} } keys %{$r->{spec}})))
673 my ($self, $thing) = @_; 673 my ($self, $thing) = @_;
674 674
675 my $obj = {}; 675 my $obj = {};
676 676
677 for (@Jeweler::RESISTS) { 677 for (@Jeweler::RESISTS) {
678 $obj->{resist}->{$_} = $thing->get_resistance ($_); 678 $obj->{resist}->{$_} = $thing->resistance ($_);
679 } 679 }
680 680
681 my $stats = $thing->stats; 681 my $stats = $thing->stats;
682 682
683 for (qw/Str Dex Con Wis Cha Int Pow/) { 683 for (qw/Str Dex Con Wis Cha Int Pow/) {
684 $obj->{stat}->{lc $_} = $stats->$_; 684 $obj->{stat}->{lc $_} = $stats->$_;
685 } 685 }
686 686
687 $obj->{spec}->{regen} = $thing->hp; 687 $obj->{spec}{regen} = $stats->hp;
688 $obj->{spec}->{magic} = $thing->sp; 688 $obj->{spec}{magic} = $stats->sp;
689 $obj->{spec}->{wc} = $thing->wc; 689 $obj->{spec}{wc} = $stats->wc;
690 $obj->{spec}->{dam} = $thing->dam; 690 $obj->{spec}{dam} = $stats->dam;
691 $obj->{spec}->{ac} = $thing->ac; 691 $obj->{spec}{ac} = $stats->ac;
692 $obj->{spec}->{speed} = $thing->stats->exp; 692 $obj->{spec}{speed} = $stats->exp;
693 $obj->{spec}->{suste} = $thing->food; 693 $obj->{spec}{food} = $stats->food;
694 694
695 $obj->{name} = $thing->name; 695 $obj->{name} = $thing->name;
696 $obj->{arch} = $thing->archetype->name; 696 $obj->{arch} = $thing->arch->name;
697 $obj->{face} = $thing->face; 697 $obj->{face} = $thing->face;
698 698
699 $self->{hash} = $obj 699 $self->{hash} = $obj
700} 700}
701 701
702sub to_object { 702sub to_object {
703 my ($self) = @_; 703 my ($self) = @_;
704
704 my $obj = cf::object::new $self->{hash}->{arch}; 705 my $obj = cf::object::new $self->{hash}->{arch};
706
705 $obj->set_face ($self->{hash}->{face}); 707 $obj->face ($self->{hash}{face});
706 708
709 my $stats = $obj->stats;
710
707 $obj->set_hp ($self->{hash}->{spec}->{regen} * 1); 711 $stats->hp ($self->{hash}{spec}{regen});
708 $obj->set_sp ($self->{hash}->{spec}->{magic} * 1); 712 $stats->sp ($self->{hash}{spec}{magic});
709 $obj->set_wc ($self->{hash}->{spec}->{wc} * 1); 713 $stats->wc ($self->{hash}{spec}{wc});
710 $obj->set_dam ($self->{hash}->{spec}->{dam} * 1); 714 $stats->dam ($self->{hash}{spec}{dam});
711 $obj->set_ac ($self->{hash}->{spec}->{ac} * 1); 715 $stats->ac ($self->{hash}{spec}{ac});
712 $obj->stats->exp ($self->{hash}->{spec}->{speed} * 1); 716 $stats->exp ($self->{hash}{spec}{speed});
713 $obj->set_food ($self->{hash}->{spec}->{suste} * 1); 717 $stats->food ($self->{hash}{spec}{food});
714 718
719 $stats->$_ ($self->{hash}{stat}{lc $_})
715 for (qw/Str Dex Con Wis Cha Int Pow/) { 720 for qw/Str Dex Con Wis Cha Int Pow/;
716 $obj->stats->$_ ($self->{hash}->{stat}->{lc $_} * 1);
717 }
718 721
719 for (@Jeweler::RESISTS) { 722 for (@Jeweler::RESISTS) {
720 $obj->set_resistance ($_, $self->{hash}->{resist}->{$_} * 1); 723 $obj->set_resistance ($_, $self->{hash}->{resist}->{$_});
721 } 724 }
722 725
723 $obj->set_flag (cf::FLAG_IDENTIFIED, 1); 726 $obj->flag (cf::FLAG_IDENTIFIED, 1);
724 727
725 return $obj; 728 return $obj;
726} 729}
727 730
728sub stat_level { 731sub stat_level {
731 734
732 my $maxlevel = Jeweler::getcfg (maxlevels => 'stat_level'); 735 my $maxlevel = Jeweler::getcfg (maxlevels => 'stat_level');
733 my $maxstat = Jeweler::getcfg (maximprovements => 'stats'); 736 my $maxstat = Jeweler::getcfg (maximprovements => 'stats');
734 737
735 my $stat_cnt = scalar (grep { $_ > 0 } values %$stats); 738 my $stat_cnt = scalar (grep { $_ > 0 } values %$stats);
736 my $stat_sum = sum (values %$stats); 739 my $stat_sum = sum (values %$stats); # also count the negative stats!
737 my $level = int (($maxlevel / $maxstat) * $stat_sum); 740 my $level = int (($maxlevel / $maxstat) * $stat_sum);
738 741
739 ($level, $stat_cnt) 742 ($level, $stat_cnt)
740} 743}
741 744
907 my $sum = sum (@$stat_split); 910 my $sum = sum (@$stat_split);
908 if ($sum < (1 - 0.0001)) { 911 if ($sum < (1 - 0.0001)) {
909 warn "JEWELER BUG: sum (@$stat_split) = $sum < 1 for $category!"; 912 warn "JEWELER BUG: sum (@$stat_split) = $sum < 1 for $category!";
910 } 913 }
911 914
912 my $emarch = cf::arch::find ('emerald'); 915 my $emarch = cf::arch::find 'emerald';
913 my $saarch = cf::arch::find ('sapphire'); 916 my $saarch = cf::arch::find 'sapphire';
914 my $pearch = cf::arch::find ('pearl'); 917 my $pearch = cf::arch::find 'pearl';
915 my $ruarch = cf::arch::find ('ruby'); 918 my $ruarch = cf::arch::find 'ruby';
916 my $diarch = cf::arch::find ('gem'); 919 my $diarch = cf::arch::find 'gem';
917 920
918 my $sumvalue = $diarch->clone->value * $diamonds; 921 my $sumvalue = $diarch->clone->value * $diamonds;
919 922
920 $cost->{emerald} += ceil (($sumvalue * $stat_split->[0]) / max (1, $emarch->clone->value)); 923 $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->clone->value;
921 $cost->{sapphire} += ceil (($sumvalue * $stat_split->[1]) / max (1, $saarch->clone->value)); 924 $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->clone->value;
922 $cost->{pearl} += ceil (($sumvalue * $stat_split->[2]) / max (1, $pearch->clone->value)); 925 $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->clone->value;
923 $cost->{ruby} += ceil (($sumvalue * $stat_split->[3]) / max (1, $ruarch->clone->value)); 926 $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->clone->value;
924 $cost->{gem} += ceil (($sumvalue * $stat_split->[4]) / max (1, $diarch->clone->value)); 927 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->clone->value;
925} 928}
926 929
927 930
928 931
929package Jeweler::Util; 932package Jeweler::Util;
950 if (defined $nrof) { 953 if (defined $nrof) {
951 return 0 if ($nrof * 1) == 0; 954 return 0 if ($nrof * 1) == 0;
952 $cnt = int (($obj->nrof || 1) - (1 * $nrof)); 955 $cnt = int (($obj->nrof || 1) - (1 * $nrof));
953 956
954 if ($cnt > 0) { 957 if ($cnt > 0) {
955 $obj->set_nrof ($cnt); 958 $obj->nrof ($cnt);
956 return 0; 959 return 0;
957 } 960 }
958 } 961 }
959 962
960 remove ($_) for ($obj->inv); 963 remove ($_) for $obj->inv;
961 $obj->remove; 964 $obj->remove;
962 $obj->free; 965 $obj->free;
963 return $cnt; 966 return $cnt;
964} 967}
965 968
978 and return 1; 981 and return 1;
979 } elsif ($i % 3 == 1) { 982 } elsif ($i % 3 == 1) {
980 $thing->title eq $match 983 $thing->title eq $match
981 and return 1; 984 and return 1;
982 } else { # $i % 3 == 2 985 } else { # $i % 3 == 2
983 $thing->archetype->name eq $match 986 $thing->arch->name eq $match
984 and return 1; 987 and return 1;
985 } 988 }
986 $i++; 989 $i++;
987 } 990 }
988 return 0; 991 return 0;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines