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.7 by elmex, Fri Feb 2 12:05:28 2007 UTC vs.
Revision 1.14 by elmex, Tue Apr 10 17:46:22 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
575 my $costs = dclone ($costs); 576 my $costs = dclone ($costs);
576 577
577 for my $key (keys %$costs) { 578 for my $key (keys %$costs) {
578 my @grepar; 579 my @grepar;
579 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 580 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
580 @grepar = @{Jeweler::getcfg (plans => $key) || []}; 581 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
582 next if $@;
581 } else { # check the gems 583 } else { # check the gems
582 @grepar = ('gems', undef, undef, $key); 584 @grepar = ('gems', undef, undef, $key);
583 } 585 }
584 586
585 if ($do_remove) { 587 if ($do_remove) {
655 } 657 }
656 my $msg = sprintf "Projected success rate: %s", $tmpl; 658 my $msg = sprintf "Projected success rate: %s", $tmpl;
657 return $msg; 659 return $msg;
658} 660}
659 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
660sub wiz_analyze { 678sub wiz_analyze {
661 my ($self, $pl) = @_; 679 my ($self, $pl) = @_;
662 my $costs = $self->calc_costs; 680 my $costs = $self->calc_costs;
663 my $desc = ""; 681 my $desc = "";
664 my $lvl = $self->power_to_level (\$desc); 682 my $lvl = $self->power_to_level (\$desc);
665 my $emarch = cf::arch::find 'emerald'; 683 my $scosts = $self->calc_value_from_cost ($costs);
666 my $saarch = cf::arch::find 'sapphire';
667 my $pearch = cf::arch::find 'pearl';
668 my $ruarch = cf::arch::find 'ruby';
669 my $diarch = cf::arch::find 'gem';
670 my $scosts = $emarch->clone->value * $costs->{emerald}
671 + $saarch->clone->value * $costs->{sapphire}
672 + $pearch->clone->value * $costs->{pearl}
673 + $ruarch->clone->value * $costs->{ruby}
674 + $diarch->clone->value * $costs->{gem};
675 684
676 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); 685 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)");
677 $pl->message ("level: " . $desc); 686 $pl->message ("level: " . $desc);
678} 687}
679
680 688
681sub get_chance_perc { 689sub get_chance_perc {
682 my ($self, $sk) = @_; 690 my ($self, $sk) = @_;
683 my $sklvl = cf::exp_to_level ($sk->stats->exp); 691 my $sklvl = cf::exp_to_level ($sk->stats->exp);
684 my $ringlvl = $self->power_to_level; 692 my $ringlvl = $self->power_to_level;
687 695
688sub fx { 696sub fx {
689 my ($res, $cfg) = @_; 697 my ($res, $cfg) = @_;
690 my $or = $res; 698 my $or = $res;
691 my $ar = $Jeweler::CFG->{functions}->{$cfg}; 699 my $ar = $Jeweler::CFG->{functions}->{$cfg};
700
692 if (ref $ar->[0] eq 'ARRAY') { 701 if (ref $ar->[0] eq 'ARRAY') {
693 $res = $res - 1; 702 $res = $res - 1;
703 return $ar->[max (min ($res, @$ar - 1), 0)];
704
694 } else { 705 } else {
706 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3...
695 $res = ceil ($res / 5) - 1; 707 my $idx = ceil (($res / 5) + 0.1) - 1;
696 }
697 $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 }
698} 714}
699 715
700sub improve_by_ring { 716sub improve_by_ring {
701 my ($self, @rings) = @_; 717 my ($self, @rings) = @_;
702 my $ring = $self; 718 my $ring = $self;
718 if ($self->{hash}->{$cat}->{$k} > 0) { 734 if ($self->{hash}->{$cat}->{$k} > 0) {
719 $self->{hash}->{$cat}->{$k} *= -1; 735 $self->{hash}->{$cat}->{$k} *= -1;
720 } 736 }
721 } 737 }
722 } 738 }
739 $self->{hash}{value} = 0;
723} 740}
724 741
725sub to_string { 742sub to_string {
726 my ($self) = @_; 743 my ($self) = @_;
727 my $r = $self->{hash}; 744 my $r = $self->{hash};
769 786
770 $obj->{name} = $thing->name; 787 $obj->{name} = $thing->name;
771 $obj->{arch} = $thing->arch->name; 788 $obj->{arch} = $thing->arch->name;
772 $obj->{face} = $thing->face; 789 $obj->{face} = $thing->face;
773 790
791 $obj->{value} = $thing->value;
792
774 $self->{hash} = $obj 793 $self->{hash} = $obj
775} 794}
776 795
777sub to_object { 796sub to_object {
778 my ($self) = @_; 797 my ($self) = @_;
779 798
780 my $obj = cf::object::new $self->{hash}->{arch}; 799 my $obj = cf::object::new $self->{hash}->{arch};
781 800
782 $obj->item_power ($self->power_to_level); # there have to be strings attached! 801 $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached!
783 802
784 $obj->face ($self->{hash}{face}); 803 $obj->face ($self->{hash}{face});
785 804
786 my $stats = $obj->stats; 805 my $stats = $obj->stats;
787 806
800 $obj->resist ($_, $self->{hash}->{resist}->{$_}); 819 $obj->resist ($_, $self->{hash}->{resist}->{$_});
801 } 820 }
802 821
803 $obj->flag (cf::FLAG_IDENTIFIED, 1); 822 $obj->flag (cf::FLAG_IDENTIFIED, 1);
804 823
824 $obj->value ($self->{hash}{value});
825
805 return $obj; 826 return $obj;
806} 827}
828
829sub set_value { $_[0]->{hash}{value} = $_[1] }
807 830
808sub is_better_than { 831sub is_better_than {
809 my ($self, $other) = @_; 832 my ($self, $other) = @_;
810 833
811 for my $type (qw/spec stat resist/) { 834 for my $type (qw/spec stat resist/) {
1058 1081
1059sub check_for_match { 1082sub check_for_match {
1060 my ($thing, @matchar) = @_; 1083 my ($thing, @matchar) = @_;
1061 1084
1062 my $i = 0; 1085 my $i = 0;
1086 my $check_cnts = 0;
1087 my $check_true = 0;
1063 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
1064 if ($match =~ m/^\s*$/) { 1095 if ($match =~ m/^\s*$/) {
1065 $i++; 1096 $i++;
1066 next; 1097 next;
1067 } 1098 }
1068 1099
1100 $check_cnts++;
1069 if ($i % 3 == 0) { 1101 if ($i % 3 == 0) {
1070 $thing->name eq $match 1102 $thing->name eq $match
1071 and return 1; 1103 and $check_true++;
1072 } elsif ($i % 3 == 1) { 1104 } elsif ($i % 3 == 1) {
1073 $thing->title eq $match 1105 $thing->title eq $match
1074 and return 1; 1106 and $check_true++;
1075 } else { # $i % 3 == 2 1107 } else { # $i % 3 == 2
1076 $thing->arch->name eq $match 1108 $thing->arch->name eq $match
1077 and return 1; 1109 and $check_true++;
1078 } 1110 }
1079 $i++; 1111 $i++;
1080 } 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;
1081 return 0; 1115 return 0;
1082} 1116}
1083 1117
1084sub grep_for_match { 1118sub grep_for_match {
1085 my ($ingred, $group, @matchar) = @_; 1119 my ($ingred, $group, @matchar) = @_;
1086 1120
1087 for my $thing (@{$ingred->{$group} || []}) { 1121 for my $thing (@{$ingred->{$group} || []}) {
1088 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#
1089 if (check_for_match ($thing, @matchar)) { 1123 if (check_for_match ($thing, @matchar)) {
1090 return $thing; 1124 return $thing;
1091 } 1125 }
1092 } 1126 }
1093 return undef; 1127 return undef;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines