--- deliantra/server/ext/jeweler.ext 2007/01/31 15:53:17 1.4 +++ deliantra/server/ext/jeweler.ext 2007/05/19 00:11:11 1.11 @@ -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 } @@ -40,14 +44,7 @@ sub merge { my ($chdl, $sk, $pl, $do_analyze) = @_; - my $ingred = eval { $chdl->extract_jeweler_ingredients }; - if ($@ =~ /cursed/) { - $pl->reply ("There are cursed items in the workbench, take them out before you do anything."). - return - } elsif ($@) { - warn "error in jeweler ingredient extraction: $@"; - return; - } + my $ingred = get_ingred ($pl, $chdl) || return; my @ring = $ingred->get_ring; my @rings = map { Jeweler::Object->new (object => $_) } @ring; @@ -55,6 +52,13 @@ @rings >= 2 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); + my $input_level; + my $value; + for (@rings) { + $input_level = max ($_->power_to_level, $input_level); + $value += $_->{hash}->{value}; + } + my $ring = shift @rings; $ring->improve_by_ring (@rings); @@ -65,11 +69,11 @@ return; } - make_ring ($chdl, $ingred, $ring, $sk, $pl); + make_ring ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level); } sub make_ring { - my ($chdl, $ingred, $ring, $sk, $pl) = @_; + my ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level) = @_; if (!$pl->flag (cf::FLAG_WIZ)) { $ingred->remove ('rings'); @@ -79,18 +83,107 @@ my $ch = $ring->get_chance_perc ($sk); my $succ = 0; my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); + + my $make_status; + my $exp; + 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; + $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; + } + $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'; + + $ring_ob->set_ob_key_value (ext_jeweler_made_by => $pl->name); + $ring_ob->set_ob_key_value (ext_jeweler_make_info => $make_info); } - $chdl->put ($ring->to_object); + + $chdl->put ($ring_ob); +} + +sub get_ingred { + my ($pl, $chdl) = @_; + my $ingred = eval { $chdl->extract_jeweler_ingredients }; + if ($@ =~ /cursed/) { + $pl->message ("There are cursed items in the workbench, take them out before you do anything."). + return + } elsif ($@ =~ /unidentified/) { + $pl->message ("There are unidentified items in the workbench, identify them before you do anything."). + return + } elsif ($@) { + warn "error in jeweler ingredient extraction: $@"; + return; + } + $ingred; } +cf::object::attachment check_ring_drop_on => + on_drop_on => sub { + my ($self, $obj, $who) = @_; + my $cfg = $self->{check_ring_drop_on}; + if ($obj->type == cf::RING + && !$obj->flag (cf::FLAG_CURSED) + && !$obj->flag (cf::FLAG_DAMNED) + ) { + my $ringo = Jeweler::Object->new (object => $obj); + for (grep { /^resist_/ } keys %$cfg) { + if (/^resist_(\S+)$/) { + if ($ringo->has_resist ($1)) { + $self->map->trigger ( + $cfg->{connection}, + $cfg->{state} + ); + cf::override; + } + } + } + } + }; + cf::object->attach ( type => cf::SKILL, subtype => cf::SK_JEWELER, @@ -121,14 +214,7 @@ $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { - my $ingred = eval { $chdl->extract_jeweler_ingredients }; - if ($@ =~ /cursed/) { - $pl->message ("There are cursed items in the workbench, take them out before you do anything."). - return - } elsif ($@) { - warn "error in jeweler ingredient extraction: $@"; - return; - } + my $ingred = get_ingred ($pl, $chdl) || return; unless ($Jeweler::CFG->{conversions}->{lc $1}) { $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); @@ -144,14 +230,7 @@ merge ($chdl, $sk, $pl, 0); } else { - my $ingred = eval { $chdl->extract_jeweler_ingredients }; - if ($@ =~ /cursed/) { - $pl->message ("There are cursed items in the workbench, take them out before you do anything."). - return - } elsif ($@) { - warn "error in jeweler ingredient extraction: $@"; - return; - } + my $ingred = get_ingred ($pl, $chdl) || return; my $plan = $ingred->get_plan; @@ -171,13 +250,14 @@ } 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); 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..."); @@ -200,7 +280,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 { @@ -212,4 +292,5 @@ } ); -Jeweler::read_config (cf::datadir . '/jeweler.yaml'); +Jeweler::read_config "$DATADIR/jeweler.yaml"; +