--- deliantra/server/ext/Jeweler.pm 2007/07/21 16:06:22 1.17 +++ deliantra/server/ext/Jeweler.pm 2007/07/31 09:40:15 1.18 @@ -164,7 +164,7 @@ } sub analyze { - my ($sk, $chdl, $pl) = @_; + my ($sk, $chdl, $pl, $input_level) = @_; my $hadunid = 0; for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { @@ -173,7 +173,7 @@ next; } my $r = Jeweler::Object->new (object => $_); - my $msg = $r->analyze ($sk, $pl); + my $msg = $r->analyze ($sk, $pl, $input_level); $pl->message ($r->to_string . ": " . $msg); if ($pl->flag (cf::FLAG_WIZ)) { $r->wiz_analyze ($pl); @@ -643,8 +643,44 @@ return undef; } +sub projected_exp { + my ($self, $input_level) = @_; + + my $lvl = max ($self->power_to_level, 1); + my $exp = + (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) + / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring + # should get you to the rings level at least. + + if (defined $input_level) { + my $subexp = + (cf::level_to_min_exp ($input_level) + - cf::level_to_min_exp ($input_level - 1)) + / (10 + max ($input_level - 1, 0)); # see above for comment + + $exp -= $subexp; + $exp = max ($exp, 0); + + } else { + # the experience bonus here is to make level 1 rings give you at least + # 100 exp points when making them. This also makes leveling in the + # first few levels a bit easier. (probably until around level 5-6). + my $expbonus = cf::level_to_min_exp (2) / 10; + # this bonus should also only be given for _new_ rings and not for merged + # ones - to prevent infinite exp making. + $exp += $expbonus; + } + + $exp +} + sub analyze { - my ($self, $sk, $pl) = @_; + my ($self, $sk, $pl, $input_level) = @_; + my $costs = $self->calc_costs; + + unless (defined $costs) { + return "This ring has a resistancy above 99%, you can't make that."; + } my $sklvl = cf::exp_to_level ($sk->stats->exp); my $ringlvl = $self->power_to_level; @@ -655,7 +691,7 @@ } else { $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); } - my $msg = sprintf "Projected success rate: %s", $tmpl; + my $msg = sprintf "Projected success rate: %s, you would get %d exp for this.", $tmpl, $self->projected_exp ($input_level); return $msg; } @@ -678,12 +714,16 @@ sub wiz_analyze { my ($self, $pl) = @_; my $costs = $self->calc_costs; - my $desc = ""; - my $lvl = $self->power_to_level (\$desc); - my $scosts = $self->calc_value_from_cost ($costs); + if (defined $costs) { + my $desc = ""; + my $lvl = $self->power_to_level (\$desc); + my $scosts = $self->calc_value_from_cost ($costs); - $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); - $pl->message ("level: " . $desc); + $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); + $pl->message ("level: " . $desc); + } else { + $pl->message ("level: impossible to make, due to impossible resistancy configuration"); + } } sub get_chance_perc { @@ -698,18 +738,21 @@ my $or = $res; my $ar = $Jeweler::CFG->{functions}->{$cfg}; - if (ref $ar->[0] eq 'ARRAY') { + if (ref $ar && ref $ar->[0] eq 'ARRAY') { $res = $res - 1; return $ar->[max (min ($res, @$ar - 1), 0)]; } else { # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3... - my $idx = ceil (($res / 5) + 0.1) - 1; - my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; - my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; - my $diff = $b - $a; # use the difference of the cost to the next cost - my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation - return $o_cost; + # old code: + #my $idx = ceil (($res / 5) + 0.1) - 1; + #my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; + #my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; + #my $diff = $b - $a; # use the difference of the cost to the next cost + #my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation + #return $o_cost; + return 0 if $res <= 0; + return ($ar / (1 - ($res * 0.01)) - $ar) } } @@ -998,13 +1041,15 @@ next unless $res > 0; + return undef if $res == 100; + $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; my $diamonds; if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { - $diamonds += fx ($res, 'effect_resist_diamonds'); + $diamonds += fx ($res, 'effect_resist_diamonds_x'); } else { - $diamonds += fx ($res, 'attack_resist_diamonds'); + $diamonds += fx ($res, 'attack_resist_diamonds_x'); } split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum});