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.8 by elmex, Sun Feb 4 00:35:23 2007 UTC vs.
Revision 1.9 by elmex, Sun Feb 4 11:17:52 2007 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines