--- deliantra/server/ext/jeweler.ext 2006/12/15 19:29:18 1.1 +++ deliantra/server/ext/jeweler.ext 2007/02/02 12:05:28 1.6 @@ -40,13 +40,17 @@ sub merge { my ($chdl, $sk, $pl, $do_analyze) = @_; - my $ingred = $chdl->extract_jeweler_ingredients; + my $ingred = get_ingred ($pl, $chdl) || return; + my @ring = $ingred->get_ring; my @rings = map { Jeweler::Object->new (object => $_) } @ring; @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 $ring = shift @rings; $ring->improve_by_ring (@rings); @@ -57,11 +61,11 @@ return; } - make_ring ($chdl, $ingred, $ring, $sk, $pl); + make_ring ($chdl, $ingred, $ring, $sk, $pl, $input_level); } sub make_ring { - my ($chdl, $ingred, $ring, $sk, $pl) = @_; + my ($chdl, $ingred, $ring, $sk, $pl, $input_level) = @_; if (!$pl->flag (cf::FLAG_WIZ)) { $ingred->remove ('rings'); @@ -71,9 +75,21 @@ my $ch = $ring->get_chance_perc ($sk); 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; + + 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); + } + $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); $pl->message ("You succeed and get $exp experience."); } else { @@ -83,7 +99,48 @@ $chdl->put ($ring->to_object); } -cf::attach_to_type cf::SKILL, cf::SK_JEWELER, +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, on_use_skill => sub { my ($sk, $ob, $part, $dir, $msg) = @_; my $pl = $ob; @@ -94,7 +151,6 @@ my $rv = 1; eval { - Jeweler::read_config ($ENV{CROSSFIRE_LIBDIR} . '/jeweler.yaml'); $DEBUG = 1; my $player = $ob->contr; @@ -112,7 +168,7 @@ $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { - my $ingred = $chdl->extract_jeweler_ingredients; + 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?"); @@ -128,7 +184,8 @@ merge ($chdl, $sk, $pl, 0); } else { - my $ingred = $chdl->extract_jeweler_ingredients; + my $ingred = get_ingred ($pl, $chdl) || return; + my $plan = $ingred->get_plan; if ($plan) { @@ -153,9 +210,9 @@ my %keys; my %cdiff; for (keys %$c1, keys %$c2) { $keys{$_} = 1 } - for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_} } + for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; warn "$_: $c2->{$_} | $c1->{$_}\n"; } - unless (grep { $_ > 0 } values %cdiff) { + unless ($iring->is_better_than ($ringo)) { $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); return; } @@ -186,5 +243,6 @@ }; $@ and warn "ERROR: $@\n"; } -; +); +Jeweler::read_config (cf::datadir . '/jeweler.yaml');