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.10 by elmex, Sun Feb 4 11:44:43 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
655 } 656 }
656 my $msg = sprintf "Projected success rate: %s", $tmpl; 657 my $msg = sprintf "Projected success rate: %s", $tmpl;
657 return $msg; 658 return $msg;
658} 659}
659 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
660sub wiz_analyze { 677sub wiz_analyze {
661 my ($self, $pl) = @_; 678 my ($self, $pl) = @_;
662 my $costs = $self->calc_costs; 679 my $costs = $self->calc_costs;
663 my $desc = ""; 680 my $desc = "";
664 my $lvl = $self->power_to_level (\$desc); 681 my $lvl = $self->power_to_level (\$desc);
665 my $emarch = cf::arch::find 'emerald'; 682 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 683
676 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); 684 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)");
677 $pl->message ("level: " . $desc); 685 $pl->message ("level: " . $desc);
678} 686}
679
680 687
681sub get_chance_perc { 688sub get_chance_perc {
682 my ($self, $sk) = @_; 689 my ($self, $sk) = @_;
683 my $sklvl = cf::exp_to_level ($sk->stats->exp); 690 my $sklvl = cf::exp_to_level ($sk->stats->exp);
684 my $ringlvl = $self->power_to_level; 691 my $ringlvl = $self->power_to_level;
687 694
688sub fx { 695sub fx {
689 my ($res, $cfg) = @_; 696 my ($res, $cfg) = @_;
690 my $or = $res; 697 my $or = $res;
691 my $ar = $Jeweler::CFG->{functions}->{$cfg}; 698 my $ar = $Jeweler::CFG->{functions}->{$cfg};
699
692 if (ref $ar->[0] eq 'ARRAY') { 700 if (ref $ar->[0] eq 'ARRAY') {
693 $res = $res - 1; 701 $res = $res - 1;
702 return $ar->[max (min ($res, @$ar - 1), 0)];
703
694 } else { 704 } else {
705 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3...
695 $res = ceil ($res / 5) - 1; 706 my $idx = ceil (($res / 5) + 0.1) - 1;
696 }
697 $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 }
698} 713}
699 714
700sub improve_by_ring { 715sub improve_by_ring {
701 my ($self, @rings) = @_; 716 my ($self, @rings) = @_;
702 my $ring = $self; 717 my $ring = $self;
718 if ($self->{hash}->{$cat}->{$k} > 0) { 733 if ($self->{hash}->{$cat}->{$k} > 0) {
719 $self->{hash}->{$cat}->{$k} *= -1; 734 $self->{hash}->{$cat}->{$k} *= -1;
720 } 735 }
721 } 736 }
722 } 737 }
738 $self->{hash}{value} = 0;
723} 739}
724 740
725sub to_string { 741sub to_string {
726 my ($self) = @_; 742 my ($self) = @_;
727 my $r = $self->{hash}; 743 my $r = $self->{hash};
769 785
770 $obj->{name} = $thing->name; 786 $obj->{name} = $thing->name;
771 $obj->{arch} = $thing->arch->name; 787 $obj->{arch} = $thing->arch->name;
772 $obj->{face} = $thing->face; 788 $obj->{face} = $thing->face;
773 789
790 $obj->{value} = $thing->value;
791
774 $self->{hash} = $obj 792 $self->{hash} = $obj
775} 793}
776 794
777sub to_object { 795sub to_object {
778 my ($self) = @_; 796 my ($self) = @_;
800 $obj->resist ($_, $self->{hash}->{resist}->{$_}); 818 $obj->resist ($_, $self->{hash}->{resist}->{$_});
801 } 819 }
802 820
803 $obj->flag (cf::FLAG_IDENTIFIED, 1); 821 $obj->flag (cf::FLAG_IDENTIFIED, 1);
804 822
823 $obj->value ($self->{hash}{value});
824
805 return $obj; 825 return $obj;
806} 826}
827
828sub set_value { $_[0]->{hash}{value} = $_[1] }
807 829
808sub is_better_than { 830sub is_better_than {
809 my ($self, $other) = @_; 831 my ($self, $other) = @_;
810 832
811 for my $type (qw/spec stat resist/) { 833 for my $type (qw/spec stat resist/) {
1058 1080
1059sub check_for_match { 1081sub check_for_match {
1060 my ($thing, @matchar) = @_; 1082 my ($thing, @matchar) = @_;
1061 1083
1062 my $i = 0; 1084 my $i = 0;
1085 my $check_cnts = 0;
1086 my $check_true = 0;
1063 for my $match (@matchar) { 1087 for my $match (@matchar) {
1088 $check_cnts = 0 if $i % 3 == 0;
1089
1064 if ($match =~ m/^\s*$/) { 1090 if ($match =~ m/^\s*$/) {
1065 $i++; 1091 $i++;
1066 next; 1092 next;
1067 } 1093 }
1068 1094
1095 $check_cnts++;
1069 if ($i % 3 == 0) { 1096 if ($i % 3 == 0) {
1070 $thing->name eq $match 1097 $thing->name eq $match
1071 and return 1; 1098 and $check_true++;
1072 } elsif ($i % 3 == 1) { 1099 } elsif ($i % 3 == 1) {
1073 $thing->title eq $match 1100 $thing->title eq $match
1074 and return 1; 1101 and $check_true++;
1075 } else { # $i % 3 == 2 1102 } else { # $i % 3 == 2
1076 $thing->arch->name eq $match 1103 $thing->arch->name eq $match
1077 and return 1; 1104 and $check_true++;
1078 } 1105 }
1079 $i++; 1106 $i++;
1107 }
1108 if ($check_true && $check_cnts == $check_true) {
1109 return 1;
1080 } 1110 }
1081 return 0; 1111 return 0;
1082} 1112}
1083 1113
1084sub grep_for_match { 1114sub grep_for_match {
1085 my ($ingred, $group, @matchar) = @_; 1115 my ($ingred, $group, @matchar) = @_;
1086 1116
1087 for my $thing (@{$ingred->{$group} || []}) { 1117 for my $thing (@{$ingred->{$group} || []}) {
1088 warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# 1118 #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)) { 1119 if (check_for_match ($thing, @matchar)) {
1090 return $thing; 1120 return $thing;
1091 } 1121 }
1092 } 1122 }
1093 return undef; 1123 return undef;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines