--- deliantra/server/ext/jeweler.ext 2007/02/02 12:05:28 1.6 +++ deliantra/server/ext/jeweler.ext 2007/12/17 08:03:22 1.15 @@ -1,9 +1,9 @@ #! perl -use Data::Dumper; +use strict; + use Jeweler; use List::Util qw/max min sum/; -use strict; sub ingred_alias { my ($ing) = @_; @@ -16,6 +16,7 @@ dex => 'dexterity', con => 'constitution', str => 'strength', + gem => 'diamond', ); if ($ing =~ m/resist_(\S+)/) { @@ -30,6 +31,9 @@ my $a = $aliases{lc $1} || $1; "something for the ". lc ($a). "' special"; + } elsif ($aliases{$ing}) { + $aliases{$ing} + } else { $ing } @@ -48,24 +52,28 @@ @rings >= 2 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); - my $input_level; - $input_level = max ($_->power_to_level, $input_level) for @rings; + my $input_level = 0; + my $value; + for (@rings) { + $input_level = max ($_->power_to_level, $input_level); + $value += $_->{hash}->{value}; + } my $ring = shift @rings; $ring->improve_by_ring (@rings); if ($do_analyze) { - $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl)); + $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl, $input_level)); $ring->wiz_analyze ($pl) if $pl->flag (cf::FLAG_WIZ); return; } - make_ring ($chdl, $ingred, $ring, $sk, $pl, $input_level); + make_ring ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level); } sub make_ring { - my ($chdl, $ingred, $ring, $sk, $pl, $input_level) = @_; + my ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level) = @_; if (!$pl->flag (cf::FLAG_WIZ)) { $ingred->remove ('rings'); @@ -76,27 +84,39 @@ my $succ = 0; my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); - if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { - my $lvl = max ($ring->power_to_level, 1); - my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100; + my $make_status; + my $exp; - if (defined $input_level) { - my $subexp = - (cf::level_to_min_exp ($input_level) - - cf::level_to_min_exp ($input_level - 1)) - / 100; - warn "INPUT: $lvl <-> $input_level ($exp <-> $subexp)\n"; - $exp -= $subexp; - $exp = max ($exp, 0); - } + if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { + $exp = $ring->projected_exp ($input_level); $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); - $pl->message ("You succeed and get $exp experience."); + $pl->message ("You succeed and get $exp experience points."); + $make_status = "succeeded"; + + $ring->set_value ($value * 0.8); # 20% of the input values will vanish + } else { $pl->message ("You fail!"); $ring->negate; + $make_status = "fail"; + $exp = 0; + } + + my $ring_ob = $ring->to_object; + + { # some audit info calculation + my $sklvl = cf::exp_to_level ($sk->stats->exp); + + my $make_info = sprintf + "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s", + $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl, + $ring->power_to_level, $exp, $make_status; + + warn "$make_info\n" if $make_status eq 'succeeded'; } - $chdl->put ($ring->to_object); + + $chdl->put ($ring_ob); } sub get_ingred { @@ -191,26 +211,32 @@ if ($plan) { my @ring = $ingred->get_ring; - if ((@ring > 1) || ($ring[0]->nrof > 1)) { - # actually the algorithm cant handle more than one improvement at a time - $pl->message ("You can't manage to improve more than one thing at a time!"); - return; - - } elsif (@ring < 1) { + if (!@ring) { # actually the algorithm cant $pl->message ("You slap yourself, you forgot the jewelery!"); return; + } elsif ((@ring > 1) || (grep { $_->nrof > 1 } @ring)) { + # actually the algorithm cant handle more than one improvement at a time + $pl->message ("You can't manage to improve more than one thing at a time!"); + return; } else { my $ringo = Jeweler::Object->new (object => $ring[0]); my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); - my $c1 = $ringo->calc_costs; - my $c2 = $iring->calc_costs; + my $c1 = $ringo->calc_costs; + my $c2 = $iring->calc_costs; + my $value = $iring->calc_value_from_cost ($c2); + + if ((not defined $c1) || (not defined $c2)) { + $pl->message ("The jewel has or will become a resistancy above 99%,\n" + ."that is completly impossible to make!"); + return; + } my %keys; my %cdiff; for (keys %$c1, keys %$c2) { $keys{$_} = 1 } - for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; warn "$_: $c2->{$_} | $c1->{$_}\n"; } + for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } unless ($iring->is_better_than ($ringo)) { $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); @@ -233,7 +259,7 @@ if (!$pl->flag (cf::FLAG_WIZ)) { $ingred->check_costs (\%cdiff, 1); } - make_ring ($chdl, $ingred, $iring, $sk, $pl); + make_ring ($chdl, $ingred, $iring, $value, $sk, $pl); } } } else { @@ -245,4 +271,5 @@ } ); -Jeweler::read_config (cf::datadir . '/jeweler.yaml'); +Jeweler::read_config "res/jeweler.yaml"; +