ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/jeweler.ext
Revision: 1.5
Committed: Thu Aug 31 00:58:17 2006 UTC (17 years, 8 months ago) by elmex
Branch: MAIN
Changes since 1.4: +108 -568 lines
Log Message:
revived the jeweler skill!

File Contents

# Content
1 #! perl
2 #CONVERSION: NONE
3 use Data::Dumper;
4 use Jeweler;
5 use List::Util qw/max min sum/;
6 use strict;
7
8 sub ingred_alias {
9 my ($ing) = @_;
10
11 my %aliases = (
12 pow => 'power',
13 cha => 'charisma',
14 wis => 'wisdom',
15 int => 'intelligence',
16 dex => 'dexterity',
17 con => 'constitution',
18 str => 'strength',
19 );
20
21 if ($ing =~ m/resist_(\S+)/) {
22 my $a = $aliases{lc $1} || $1;
23 "something for '". lc ($a). "' resistance";
24
25 } elsif ($ing =~ m/stat_(\S+)/) {
26 my $a = $aliases{lc $1} || $1;
27 "something for the ". lc ($a). " stat";
28
29 } elsif ($ing =~ m/spec_(\S+)/) {
30 my $a = $aliases{lc $1} || $1;
31 "something for the ". lc ($a). "' special";
32
33 } else {
34 $ing
35 }
36 }
37
38 my $DEBUG = 1;
39
40 cf::attach_to_type cf::SKILL, cf::SK_JEWELER,
41 on_use_skill => sub {
42 my ($sk, $ob, $part, $dir, $msg) = @_;
43 my $pl = $ob;
44 warn "USE SKILL JEWEL[$msg]!\n";
45
46 my $skobj = $sk;
47
48 my $chdl = new Jeweler::CauldronHandler;
49
50 my $rv = 1;
51 eval {
52 Jeweler::read_config ($ENV{CROSSFIRE_LIBDIR} . '/jeweler.yaml');
53 $DEBUG = 1;
54
55 my $player = $ob->contr;
56
57 unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) {
58 return;
59 }
60
61 cf::override;
62
63 if ($msg =~ m/^\s*analy[sz]e\s*$/i) {
64 Jeweler::analyze ($sk, $chdl, $pl);
65
66 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
67 my $ingred = $chdl->extract_jeweler_ingredients;
68
69 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
70 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
71 return
72 }
73
74 simple_converter ($player, $ingred, $chdl, $1);
75 } elsif ($msg =~ m/^\s*merge\s*$/i) {
76 my $ingred = $chdl->extract_jeweler_ingredients;
77 my @ring = $ingred->get_ring;
78 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
79
80 my $ring = shift @rings;
81 $ring->improve_by_ring (@rings);
82 $ring->power_to_level;
83
84 } else {
85 my $ingred = $chdl->extract_jeweler_ingredients;
86 my $plan = $ingred->get_plan;
87
88 if ($plan) {
89 my @ring = $ingred->get_ring;
90
91 if (@ring > 1) {
92 # actually the algorithm cant handle more than one improvement at a time
93 $pl->message ("You can't manage to improve more than one ring!");
94
95 } elsif (@ring < 1) {
96 # actually the algorithm cant
97 $pl->message ("You slap yourself, you forgot the ring!");
98
99 } else {
100 my $ringo = Jeweler::Object->new (object => $ring[0]);
101 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo);
102 my $c1 = $ringo->calc_costs;
103 my $c2 = $iring->calc_costs;
104
105 my %keys;
106 my %cdiff;
107 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
108 warn 'COSTS[' . (join ",", map { $cdiff{$_} = $c2->{$_} - $c1->{$_}; "$_: $cdiff{$_}" } keys %keys) . "]\n";
109
110 unless (grep { $_ > 0 } values %cdiff) {
111 $pl->message ("This plan doesn't improve the ring, you find yourself puzzled about what you missed...");
112 return;
113 }
114
115 my $remcosts = $ingred->check_costs (\%cdiff);
116 warn 'REMCOSTS[' . (join ",", map { "$_: $remcosts->{$_}" } keys %$remcosts) . "]\n";
117
118 if (grep { $_ > 0 } values %$remcosts) {
119 $pl->message ("You recognize that you are short of: "
120 . (join ", ",
121 map { my $cost = $remcosts->{$_}; $cost . " " . ($cost > 1 ? "times" : "time") . " " . ingred_alias ($_) }
122 grep { $remcosts->{$_} > 0 } keys %$remcosts))
123 } else {
124 $ingred->check_costs (\%cdiff, 1);
125 $ingred->remove ('rings');
126 $ingred->remove ('ammys');
127 $chdl->put ($iring->to_object);
128 $pl->message ("You succeed!");
129 }
130 }
131 } else {
132 $pl->message ("You've got no idea what you are planning to do!");
133 }
134 }
135 };
136 $@ and warn "ERROR: $@\n";
137
138 my $r = cf::random_roll (0, 101, $pl, cf::PREFER_LOW);
139 }