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.17 by elmex, Sat Jul 21 16:06:22 2007 UTC vs.
Revision 1.18 by elmex, Tue Jul 31 09:40:15 2007 UTC

162 $delta = 5 if $delta > 5; 162 $delta = 5 if $delta > 5;
163 return $LVL_DIFF_CHANCES{$delta} 163 return $LVL_DIFF_CHANCES{$delta}
164} 164}
165 165
166sub analyze { 166sub analyze {
167 my ($sk, $chdl, $pl) = @_; 167 my ($sk, $chdl, $pl, $input_level) = @_;
168 168
169 my $hadunid = 0; 169 my $hadunid = 0;
170 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { 170 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) {
171 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { 171 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) {
172 $hadunid = 1; 172 $hadunid = 1;
173 next; 173 next;
174 } 174 }
175 my $r = Jeweler::Object->new (object => $_); 175 my $r = Jeweler::Object->new (object => $_);
176 my $msg = $r->analyze ($sk, $pl); 176 my $msg = $r->analyze ($sk, $pl, $input_level);
177 $pl->message ($r->to_string . ": " . $msg); 177 $pl->message ($r->to_string . ": " . $msg);
178 if ($pl->flag (cf::FLAG_WIZ)) { 178 if ($pl->flag (cf::FLAG_WIZ)) {
179 $r->wiz_analyze ($pl); 179 $r->wiz_analyze ($pl);
180 } 180 }
181 } 181 }
641 return 1 if $self->{hash}->{resist}->{$resnum}; 641 return 1 if $self->{hash}->{resist}->{$resnum};
642 } 642 }
643 return undef; 643 return undef;
644} 644}
645 645
646sub projected_exp {
647 my ($self, $input_level) = @_;
648
649 my $lvl = max ($self->power_to_level, 1);
650 my $exp =
651 (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1))
652 / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring
653 # should get you to the rings level at least.
654
655 if (defined $input_level) {
656 my $subexp =
657 (cf::level_to_min_exp ($input_level)
658 - cf::level_to_min_exp ($input_level - 1))
659 / (10 + max ($input_level - 1, 0)); # see above for comment
660
661 $exp -= $subexp;
662 $exp = max ($exp, 0);
663
664 } else {
665 # the experience bonus here is to make level 1 rings give you at least
666 # 100 exp points when making them. This also makes leveling in the
667 # first few levels a bit easier. (probably until around level 5-6).
668 my $expbonus = cf::level_to_min_exp (2) / 10;
669 # this bonus should also only be given for _new_ rings and not for merged
670 # ones - to prevent infinite exp making.
671 $exp += $expbonus;
672 }
673
674 $exp
675}
676
646sub analyze { 677sub analyze {
647 my ($self, $sk, $pl) = @_; 678 my ($self, $sk, $pl, $input_level) = @_;
679 my $costs = $self->calc_costs;
680
681 unless (defined $costs) {
682 return "This ring has a resistancy above 99%, you can't make that.";
683 }
648 684
649 my $sklvl = cf::exp_to_level ($sk->stats->exp); 685 my $sklvl = cf::exp_to_level ($sk->stats->exp);
650 my $ringlvl = $self->power_to_level; 686 my $ringlvl = $self->power_to_level;
651 687
652 my $tmpl; 688 my $tmpl;
653 if ($pl->flag (cf::FLAG_WIZ)) { 689 if ($pl->flag (cf::FLAG_WIZ)) {
654 $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); 690 $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl);
655 } else { 691 } else {
656 $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); 692 $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl);
657 } 693 }
658 my $msg = sprintf "Projected success rate: %s", $tmpl; 694 my $msg = sprintf "Projected success rate: %s, you would get %d exp for this.", $tmpl, $self->projected_exp ($input_level);
659 return $msg; 695 return $msg;
660} 696}
661 697
662sub calc_value_from_cost { 698sub calc_value_from_cost {
663 my ($self, $costs) = @_; 699 my ($self, $costs) = @_;
676} 712}
677 713
678sub wiz_analyze { 714sub wiz_analyze {
679 my ($self, $pl) = @_; 715 my ($self, $pl) = @_;
680 my $costs = $self->calc_costs; 716 my $costs = $self->calc_costs;
717 if (defined $costs) {
681 my $desc = ""; 718 my $desc = "";
682 my $lvl = $self->power_to_level (\$desc); 719 my $lvl = $self->power_to_level (\$desc);
683 my $scosts = $self->calc_value_from_cost ($costs); 720 my $scosts = $self->calc_value_from_cost ($costs);
684 721
685 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); 722 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)");
686 $pl->message ("level: " . $desc); 723 $pl->message ("level: " . $desc);
724 } else {
725 $pl->message ("level: impossible to make, due to impossible resistancy configuration");
726 }
687} 727}
688 728
689sub get_chance_perc { 729sub get_chance_perc {
690 my ($self, $sk) = @_; 730 my ($self, $sk) = @_;
691 my $sklvl = cf::exp_to_level ($sk->stats->exp); 731 my $sklvl = cf::exp_to_level ($sk->stats->exp);
696sub fx { 736sub fx {
697 my ($res, $cfg) = @_; 737 my ($res, $cfg) = @_;
698 my $or = $res; 738 my $or = $res;
699 my $ar = $Jeweler::CFG->{functions}->{$cfg}; 739 my $ar = $Jeweler::CFG->{functions}->{$cfg};
700 740
701 if (ref $ar->[0] eq 'ARRAY') { 741 if (ref $ar && ref $ar->[0] eq 'ARRAY') {
702 $res = $res - 1; 742 $res = $res - 1;
703 return $ar->[max (min ($res, @$ar - 1), 0)]; 743 return $ar->[max (min ($res, @$ar - 1), 0)];
704 744
705 } else { 745 } else {
706 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3... 746 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3...
747 # old code:
707 my $idx = ceil (($res / 5) + 0.1) - 1; 748 #my $idx = ceil (($res / 5) + 0.1) - 1;
708 my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; 749 #my $a = $ar->[max (min ($idx, @$ar - 1), 0)];
709 my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; 750 #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 751 #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 752 #my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation
712 return $o_cost; 753 #return $o_cost;
754 return 0 if $res <= 0;
755 return ($ar / (1 - ($res * 0.01)) - $ar)
713 } 756 }
714} 757}
715 758
716sub improve_by_ring { 759sub improve_by_ring {
717 my ($self, @rings) = @_; 760 my ($self, @rings) = @_;
996 1039
997 my $res = $ring->{resist}->{$resnum}; 1040 my $res = $ring->{resist}->{$resnum};
998 1041
999 next unless $res > 0; 1042 next unless $res > 0;
1000 1043
1044 return undef if $res == 100;
1045
1001 $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; 1046 $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res;
1002 1047
1003 my $diamonds; 1048 my $diamonds;
1004 if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { 1049 if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) {
1005 $diamonds += fx ($res, 'effect_resist_diamonds'); 1050 $diamonds += fx ($res, 'effect_resist_diamonds_x');
1006 } else { 1051 } else {
1007 $diamonds += fx ($res, 'attack_resist_diamonds'); 1052 $diamonds += fx ($res, 'attack_resist_diamonds_x');
1008 } 1053 }
1009 1054
1010 split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); 1055 split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum});
1011 } 1056 }
1012 1057

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines