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.4 by elmex, Wed Jan 31 14:11:02 2007 UTC vs.
Revision 1.13 by elmex, Tue Apr 10 16:42:57 2007 UTC

226 my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); 226 my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact));
227 if ($nrof) { 227 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) 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) { 229 for (1..$nrof) {
230 $chdl->put (my $ob = cf::object::new $outarch); 230 $chdl->put (my $ob = cf::object::new $outarch);
231 $ob->set_animation (cf::rndm $ob->num_animations); 231 $ob->set_animation (cf::rndm $ob->num_animations)
232 if ($ob->type == cf::RING);
232 $ob->flag (cf::FLAG_IDENTIFIED, 1); 233 $ob->flag (cf::FLAG_IDENTIFIED, 1);
233 } 234 }
234 235
235 my $xp_sum = ($xp_gain * $nrof); 236 my $xp_sum = ($xp_gain * $nrof);
236 237
328 cf::POTION => 'potions', 329 cf::POTION => 'potions',
329 cf::SCROLL => 'scrolls', 330 cf::SCROLL => 'scrolls',
330 ); 331 );
331 332
332 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 }
333 339
334 if (my $k = $type_to_key{$_->type}) { 340 if (my $k = $type_to_key{$_->type}) {
335 push @{$ingreds->{$k}}, $_; 341 push @{$ingreds->{$k}}, $_;
336 } else { 342 } else {
337 push @{$ingreds->{other}}, $_; 343 push @{$ingreds->{other}}, $_;
570 my $costs = dclone ($costs); 576 my $costs = dclone ($costs);
571 577
572 for my $key (keys %$costs) { 578 for my $key (keys %$costs) {
573 my @grepar; 579 my @grepar;
574 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 580 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
575 @grepar = @{Jeweler::getcfg (plans => $key) || []}; 581 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
582 next if $@;
576 } else { # check the gems 583 } else { # check the gems
577 @grepar = ('gems', undef, undef, $key); 584 @grepar = ('gems', undef, undef, $key);
578 } 585 }
579 586
580 if ($do_remove) { 587 if ($do_remove) {
585 } 592 }
586 } else { 593 } else {
587 my $nr; 594 my $nr;
588 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); 595 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar);
589 $costs->{$key} -= $nr; 596 $costs->{$key} -= $nr;
590 warn "CHECKCOST $key <-> $nr -> $costs->{$key}\n";
591 } 597 }
592 598
593 } 599 }
594 600
595 return $costs; 601 return $costs;
622 my $self = bless { }, $class; 628 my $self = bless { }, $class;
623 629
624 $self->ring_or_ammy_to_hash ($arg{object}); 630 $self->ring_or_ammy_to_hash ($arg{object});
625 631
626 $self; 632 $self;
633}
634
635sub has_resist {
636 my ($self, $resistnam, $resistval) = @_;
637 my $resnum = $REV_RESMAP{uc $resistnam};
638 if (defined ($resistval)) {
639 return 1 if $self->{hash}->{resist}->{$resnum} == $resistval;
640 } else {
641 return 1 if $self->{hash}->{resist}->{$resnum};
642 }
643 return undef;
627} 644}
628 645
629sub analyze { 646sub analyze {
630 my ($self, $sk, $pl) = @_; 647 my ($self, $sk, $pl) = @_;
631 648
640 } 657 }
641 my $msg = sprintf "Projected success rate: %s", $tmpl; 658 my $msg = sprintf "Projected success rate: %s", $tmpl;
642 return $msg; 659 return $msg;
643} 660}
644 661
662sub calc_value_from_cost {
663 my ($self, $costs) = @_;
664 my $emarch = cf::arch::find 'emerald';
665 my $saarch = cf::arch::find 'sapphire';
666 my $pearch = cf::arch::find 'pearl';
667 my $ruarch = cf::arch::find 'ruby';
668 my $diarch = cf::arch::find 'gem';
669 my $value = $emarch->clone->value * $costs->{emerald}
670 + $saarch->clone->value * $costs->{sapphire}
671 + $pearch->clone->value * $costs->{pearl}
672 + $ruarch->clone->value * $costs->{ruby}
673 + $diarch->clone->value * $costs->{gem};
674
675 $value
676}
677
645sub wiz_analyze { 678sub wiz_analyze {
646 my ($self, $pl) = @_; 679 my ($self, $pl) = @_;
647 my $costs = $self->calc_costs; 680 my $costs = $self->calc_costs;
648 my $desc = ""; 681 my $desc = "";
649 my $lvl = $self->power_to_level (\$desc); 682 my $lvl = $self->power_to_level (\$desc);
683 my $scosts = $self->calc_value_from_cost ($costs);
684
650 $pl->message ("costs: " . join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)); 685 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)");
651 $pl->message ("level: " . $desc); 686 $pl->message ("level: " . $desc);
652} 687}
653
654 688
655sub get_chance_perc { 689sub get_chance_perc {
656 my ($self, $sk) = @_; 690 my ($self, $sk) = @_;
657 my $sklvl = cf::exp_to_level ($sk->stats->exp); 691 my $sklvl = cf::exp_to_level ($sk->stats->exp);
658 my $ringlvl = $self->power_to_level; 692 my $ringlvl = $self->power_to_level;
661 695
662sub fx { 696sub fx {
663 my ($res, $cfg) = @_; 697 my ($res, $cfg) = @_;
664 my $or = $res; 698 my $or = $res;
665 my $ar = $Jeweler::CFG->{functions}->{$cfg}; 699 my $ar = $Jeweler::CFG->{functions}->{$cfg};
700
666 if (ref $ar->[0] eq 'ARRAY') { 701 if (ref $ar->[0] eq 'ARRAY') {
667 $res = $res - 1; 702 $res = $res - 1;
703 return $ar->[max (min ($res, @$ar - 1), 0)];
704
668 } else { 705 } else {
706 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3...
669 $res = ceil ($res / 5) - 1; 707 my $idx = ceil (($res / 5) + 0.1) - 1;
670 }
671 $ar->[max (min ($res, @$ar - 1), 0)]; 708 my $a = $ar->[max (min ($idx, @$ar - 1), 0)];
709 my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)];
710 my $diff = $b - $a; # use the difference of the cost to the next cost
711 my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation
712 return $o_cost;
713 }
672} 714}
673 715
674sub improve_by_ring { 716sub improve_by_ring {
675 my ($self, @rings) = @_; 717 my ($self, @rings) = @_;
676 my $ring = $self; 718 my $ring = $self;
692 if ($self->{hash}->{$cat}->{$k} > 0) { 734 if ($self->{hash}->{$cat}->{$k} > 0) {
693 $self->{hash}->{$cat}->{$k} *= -1; 735 $self->{hash}->{$cat}->{$k} *= -1;
694 } 736 }
695 } 737 }
696 } 738 }
739 $self->{hash}{value} = 0;
697} 740}
698 741
699sub to_string { 742sub to_string {
700 my ($self) = @_; 743 my ($self) = @_;
701 my $r = $self->{hash}; 744 my $r = $self->{hash};
743 786
744 $obj->{name} = $thing->name; 787 $obj->{name} = $thing->name;
745 $obj->{arch} = $thing->arch->name; 788 $obj->{arch} = $thing->arch->name;
746 $obj->{face} = $thing->face; 789 $obj->{face} = $thing->face;
747 790
791 $obj->{value} = $thing->value;
792
748 $self->{hash} = $obj 793 $self->{hash} = $obj
749} 794}
750 795
751sub to_object { 796sub to_object {
752 my ($self) = @_; 797 my ($self) = @_;
753 798
754 my $obj = cf::object::new $self->{hash}->{arch}; 799 my $obj = cf::object::new $self->{hash}->{arch};
800
801 $obj->item_power ($self->power_to_level); # there have to be strings attached!
755 802
756 $obj->face ($self->{hash}{face}); 803 $obj->face ($self->{hash}{face});
757 804
758 my $stats = $obj->stats; 805 my $stats = $obj->stats;
759 806
772 $obj->resist ($_, $self->{hash}->{resist}->{$_}); 819 $obj->resist ($_, $self->{hash}->{resist}->{$_});
773 } 820 }
774 821
775 $obj->flag (cf::FLAG_IDENTIFIED, 1); 822 $obj->flag (cf::FLAG_IDENTIFIED, 1);
776 823
824 $obj->value ($self->{hash}{value});
825
777 return $obj; 826 return $obj;
778} 827}
828
829sub set_value { $_[0]->{hash}{value} = $_[1] }
779 830
780sub is_better_than { 831sub is_better_than {
781 my ($self, $other) = @_; 832 my ($self, $other) = @_;
782 833
783 for my $type (qw/spec stat resist/) { 834 for my $type (qw/spec stat resist/) {
1030 1081
1031sub check_for_match { 1082sub check_for_match {
1032 my ($thing, @matchar) = @_; 1083 my ($thing, @matchar) = @_;
1033 1084
1034 my $i = 0; 1085 my $i = 0;
1086 my $check_cnts = 0;
1087 my $check_true = 0;
1035 for my $match (@matchar) { 1088 for my $match (@matchar) {
1089 if ($i % 3 == 0) {
1090 return 1 if $check_true && $check_cnts == $check_true;
1091 $check_cnts = 0;
1092 $check_true = 0;
1093 }
1094
1036 if ($match =~ m/^\s*$/) { 1095 if ($match =~ m/^\s*$/) {
1037 $i++; 1096 $i++;
1038 next; 1097 next;
1039 } 1098 }
1040 1099
1100 $check_cnts++;
1041 if ($i % 3 == 0) { 1101 if ($i % 3 == 0) {
1042 $thing->name eq $match 1102 $thing->name eq $match
1043 and return 1; 1103 and $check_true++;
1044 } elsif ($i % 3 == 1) { 1104 } elsif ($i % 3 == 1) {
1045 $thing->title eq $match 1105 $thing->title eq $match
1046 and return 1; 1106 and $check_true++;
1047 } else { # $i % 3 == 2 1107 } else { # $i % 3 == 2
1048 $thing->arch->name eq $match 1108 $thing->arch->name eq $match
1049 and return 1; 1109 and $check_true++;
1050 } 1110 }
1051 $i++; 1111 $i++;
1052 } 1112 }
1113 #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->name))."\n";
1114 return 1 if $check_true && $check_cnts == $check_true;
1053 return 0; 1115 return 0;
1054} 1116}
1055 1117
1056sub grep_for_match { 1118sub grep_for_match {
1057 my ($ingred, $group, @matchar) = @_; 1119 my ($ingred, $group, @matchar) = @_;
1058 1120
1059 for my $thing (@{$ingred->{$group} || []}) { 1121 for my $thing (@{$ingred->{$group} || []}) {
1060 warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# 1122 #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d#
1061 if (check_for_match ($thing, @matchar)) { 1123 if (check_for_match ($thing, @matchar)) {
1062 return $thing; 1124 return $thing;
1063 } 1125 }
1064 } 1126 }
1065 return undef; 1127 return undef;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines