#! perl #CONVERSION: NONE use Data::Dumper; use Jeweler; use List::Util qw/max min sum/; use strict; sub ingred_alias { my ($ing) = @_; my %aliases = ( pow => 'power', cha => 'charisma', wis => 'wisdom', int => 'intelligence', dex => 'dexterity', con => 'constitution', str => 'strength', ); if ($ing =~ m/resist_(\S+)/) { my $a = $aliases{lc $1} || $1; "something for '". lc ($a). "' resistance"; } elsif ($ing =~ m/stat_(\S+)/) { my $a = $aliases{lc $1} || $1; "something for the ". lc ($a). " stat"; } elsif ($ing =~ m/spec_(\S+)/) { my $a = $aliases{lc $1} || $1; "something for the ". lc ($a). "' special"; } else { $ing } } my $DEBUG = 1; cf::attach_to_type cf::SKILL, cf::SK_JEWELER, on_use_skill => sub { my ($sk, $ob, $part, $dir, $msg) = @_; my $pl = $ob; warn "USE SKILL JEWEL[$msg]!\n"; my $skobj = $sk; my $chdl = new Jeweler::CauldronHandler; my $rv = 1; eval { Jeweler::read_config ($ENV{CROSSFIRE_LIBDIR} . '/jeweler.yaml'); $DEBUG = 1; my $player = $ob->contr; unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) { return; } cf::override; if ($msg =~ m/^\s*analy[sz]e\s*$/i) { Jeweler::analyze ($sk, $chdl, $pl); } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { my $ingred = $chdl->extract_jeweler_ingredients; unless ($Jeweler::CFG->{conversions}->{lc $1}) { $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); return } simple_converter ($player, $ingred, $chdl, $1); } elsif ($msg =~ m/^\s*merge\s*$/i) { my $ingred = $chdl->extract_jeweler_ingredients; my @ring = $ingred->get_ring; my @rings = map { Jeweler::Object->new (object => $_) } @ring; my $ring = shift @rings; $ring->improve_by_ring (@rings); $ring->power_to_level; } else { my $ingred = $chdl->extract_jeweler_ingredients; my $plan = $ingred->get_plan; if ($plan) { my @ring = $ingred->get_ring; if (@ring > 1) { # actually the algorithm cant handle more than one improvement at a time $pl->message ("You can't manage to improve more than one ring!"); } elsif (@ring < 1) { # actually the algorithm cant $pl->message ("You slap yourself, you forgot the ring!"); } 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 %keys; my %cdiff; for (keys %$c1, keys %$c2) { $keys{$_} = 1 } warn 'COSTS[' . (join ",", map { $cdiff{$_} = $c2->{$_} - $c1->{$_}; "$_: $cdiff{$_}" } keys %keys) . "]\n"; unless (grep { $_ > 0 } values %cdiff) { $pl->message ("This plan doesn't improve the ring, you find yourself puzzled about what you missed..."); return; } my $remcosts = $ingred->check_costs (\%cdiff); warn 'REMCOSTS[' . (join ",", map { "$_: $remcosts->{$_}" } keys %$remcosts) . "]\n"; if (grep { $_ > 0 } values %$remcosts) { $pl->message ("You recognize that you are short of: " . (join ", ", map { my $cost = $remcosts->{$_}; $cost . " " . ($cost > 1 ? "times" : "time") . " " . ingred_alias ($_) } grep { $remcosts->{$_} > 0 } keys %$remcosts)) } else { $ingred->check_costs (\%cdiff, 1); $ingred->remove ('rings'); $ingred->remove ('ammys'); $chdl->put ($iring->to_object); $pl->message ("You succeed!"); } } } else { $pl->message ("You've got no idea what you are planning to do!"); } } }; $@ and warn "ERROR: $@\n"; my $r = cf::random_roll (0, 101, $pl, cf::PREFER_LOW); }