1 |
elmex |
1.1 |
#! perl |
2 |
root |
1.4 |
#CONVERSION: NONE |
3 |
elmex |
1.1 |
use Data::Dumper; |
4 |
elmex |
1.5 |
use Jeweler; |
5 |
elmex |
1.1 |
use List::Util qw/max min sum/; |
6 |
|
|
use strict; |
7 |
|
|
|
8 |
elmex |
1.5 |
sub ingred_alias { |
9 |
|
|
my ($ing) = @_; |
10 |
elmex |
1.1 |
|
11 |
elmex |
1.5 |
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 |
elmex |
1.1 |
|
33 |
elmex |
1.5 |
} else { |
34 |
|
|
$ing |
35 |
elmex |
1.1 |
} |
36 |
|
|
} |
37 |
|
|
|
38 |
elmex |
1.5 |
my $DEBUG = 1; |
39 |
elmex |
1.1 |
|
40 |
elmex |
1.7 |
sub merge { |
41 |
|
|
my ($chdl, $sk, $pl, $do_analyze) = @_; |
42 |
|
|
|
43 |
|
|
my $ingred = $chdl->extract_jeweler_ingredients; |
44 |
|
|
my @ring = $ingred->get_ring; |
45 |
|
|
my @rings = map { Jeweler::Object->new (object => $_) } @ring; |
46 |
|
|
|
47 |
|
|
if (@rings < 2) { |
48 |
|
|
$pl->message ("You slap yourself, you forgot to put at least 2 jeweles in!"); |
49 |
elmex |
1.8 |
return; |
50 |
elmex |
1.7 |
} |
51 |
|
|
|
52 |
|
|
my $ring = shift @rings; |
53 |
|
|
$ring->improve_by_ring (@rings); |
54 |
|
|
|
55 |
|
|
if ($do_analyze) { |
56 |
|
|
$pl->message ("You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl)); |
57 |
root |
1.9 |
if ($pl->flag (cf::FLAG_WIZ)) { |
58 |
elmex |
1.7 |
$ring->wiz_analyze ($pl); |
59 |
|
|
} |
60 |
|
|
return; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
make_ring ($chdl, $ingred, $ring, $sk, $pl); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
sub make_ring { |
67 |
|
|
my ($chdl, $ingred, $ring, $sk, $pl) = @_; |
68 |
|
|
|
69 |
root |
1.9 |
if (!$pl->flag (cf::FLAG_WIZ)) { |
70 |
elmex |
1.7 |
$ingred->remove ('rings'); |
71 |
|
|
$ingred->remove ('ammys'); |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
my $ch = $ring->get_chance_perc ($sk); |
75 |
|
|
my $succ = 0; |
76 |
|
|
my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); |
77 |
root |
1.9 |
if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { |
78 |
elmex |
1.8 |
my $lvl = max ($ring->power_to_level, 1); |
79 |
|
|
my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100; |
80 |
|
|
$pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
81 |
|
|
$pl->message ("You succeed and get $exp experience."); |
82 |
elmex |
1.7 |
} else { |
83 |
|
|
$pl->message ("You fail!"); |
84 |
|
|
$ring->negate; |
85 |
|
|
} |
86 |
|
|
$chdl->put ($ring->to_object); |
87 |
|
|
} |
88 |
|
|
|
89 |
elmex |
1.5 |
cf::attach_to_type cf::SKILL, cf::SK_JEWELER, |
90 |
|
|
on_use_skill => sub { |
91 |
|
|
my ($sk, $ob, $part, $dir, $msg) = @_; |
92 |
|
|
my $pl = $ob; |
93 |
elmex |
1.6 |
warn ($pl->name . " uses jeweler skill [$msg]!\n"); |
94 |
elmex |
1.1 |
|
95 |
elmex |
1.5 |
my $skobj = $sk; |
96 |
elmex |
1.1 |
|
97 |
elmex |
1.5 |
my $chdl = new Jeweler::CauldronHandler; |
98 |
elmex |
1.1 |
|
99 |
elmex |
1.5 |
my $rv = 1; |
100 |
|
|
eval { |
101 |
|
|
Jeweler::read_config ($ENV{CROSSFIRE_LIBDIR} . '/jeweler.yaml'); |
102 |
|
|
$DEBUG = 1; |
103 |
elmex |
1.1 |
|
104 |
elmex |
1.5 |
my $player = $ob->contr; |
105 |
elmex |
1.1 |
|
106 |
elmex |
1.5 |
unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) { |
107 |
|
|
return; |
108 |
elmex |
1.1 |
} |
109 |
|
|
|
110 |
elmex |
1.5 |
cf::override; |
111 |
elmex |
1.1 |
|
112 |
elmex |
1.5 |
if ($msg =~ m/^\s*analy[sz]e\s*$/i) { |
113 |
|
|
Jeweler::analyze ($sk, $chdl, $pl); |
114 |
elmex |
1.1 |
|
115 |
elmex |
1.6 |
} elsif ($msg =~ m/^\s*make\s*$/i) { |
116 |
|
|
$pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); |
117 |
|
|
|
118 |
elmex |
1.5 |
} elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { |
119 |
|
|
my $ingred = $chdl->extract_jeweler_ingredients; |
120 |
elmex |
1.1 |
|
121 |
elmex |
1.5 |
unless ($Jeweler::CFG->{conversions}->{lc $1}) { |
122 |
|
|
$pl->message ("You don't know how to make '$1', is does such a thing even exist?"); |
123 |
|
|
return |
124 |
elmex |
1.1 |
} |
125 |
|
|
|
126 |
elmex |
1.6 |
Jeweler::simple_converter ($player, $ingred, $chdl, $1); |
127 |
|
|
|
128 |
elmex |
1.7 |
} elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) { |
129 |
|
|
merge ($chdl, $sk, $pl, 1); |
130 |
|
|
|
131 |
elmex |
1.5 |
} elsif ($msg =~ m/^\s*merge\s*$/i) { |
132 |
elmex |
1.7 |
merge ($chdl, $sk, $pl, 0); |
133 |
elmex |
1.1 |
|
134 |
elmex |
1.5 |
} else { |
135 |
|
|
my $ingred = $chdl->extract_jeweler_ingredients; |
136 |
|
|
my $plan = $ingred->get_plan; |
137 |
elmex |
1.1 |
|
138 |
elmex |
1.5 |
if ($plan) { |
139 |
|
|
my @ring = $ingred->get_ring; |
140 |
elmex |
1.1 |
|
141 |
elmex |
1.6 |
if ((@ring > 1) || ($ring[0]->nrof > 1)) { |
142 |
elmex |
1.5 |
# actually the algorithm cant handle more than one improvement at a time |
143 |
elmex |
1.6 |
$pl->message ("You can't manage to improve more than one thing at a time!"); |
144 |
elmex |
1.8 |
return; |
145 |
elmex |
1.5 |
|
146 |
|
|
} elsif (@ring < 1) { |
147 |
|
|
# actually the algorithm cant |
148 |
elmex |
1.6 |
$pl->message ("You slap yourself, you forgot the jewelery!"); |
149 |
elmex |
1.8 |
return; |
150 |
elmex |
1.5 |
|
151 |
|
|
} else { |
152 |
|
|
my $ringo = Jeweler::Object->new (object => $ring[0]); |
153 |
|
|
my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
154 |
|
|
my $c1 = $ringo->calc_costs; |
155 |
|
|
my $c2 = $iring->calc_costs; |
156 |
|
|
|
157 |
|
|
my %keys; |
158 |
|
|
my %cdiff; |
159 |
|
|
for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
160 |
elmex |
1.6 |
for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_} } |
161 |
elmex |
1.5 |
|
162 |
|
|
unless (grep { $_ > 0 } values %cdiff) { |
163 |
elmex |
1.6 |
$pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); |
164 |
elmex |
1.5 |
return; |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
my $remcosts = $ingred->check_costs (\%cdiff); |
168 |
|
|
|
169 |
|
|
if (grep { $_ > 0 } values %$remcosts) { |
170 |
elmex |
1.6 |
$pl->message ("You want to make a " . $iring->to_string . ": " . $iring->analyze ($sk, $pl)); |
171 |
elmex |
1.5 |
$pl->message ("You recognize that you are short of: " |
172 |
|
|
. (join ", ", |
173 |
|
|
map { my $cost = $remcosts->{$_}; $cost . " " . ($cost > 1 ? "times" : "time") . " " . ingred_alias ($_) } |
174 |
elmex |
1.6 |
grep { $remcosts->{$_} > 0 } keys %$remcosts)); |
175 |
elmex |
1.7 |
|
176 |
root |
1.9 |
if ($pl->flag (cf::FLAG_WIZ)) { |
177 |
elmex |
1.6 |
$iring->wiz_analyze ($pl); |
178 |
|
|
} |
179 |
elmex |
1.5 |
} else { |
180 |
root |
1.9 |
if (!$pl->flag (cf::FLAG_WIZ)) { |
181 |
elmex |
1.6 |
$ingred->check_costs (\%cdiff, 1); |
182 |
|
|
} |
183 |
elmex |
1.7 |
make_ring ($chdl, $ingred, $iring, $sk, $pl); |
184 |
elmex |
1.5 |
} |
185 |
|
|
} |
186 |
elmex |
1.1 |
} else { |
187 |
elmex |
1.5 |
$pl->message ("You've got no idea what you are planning to do!"); |
188 |
elmex |
1.1 |
} |
189 |
|
|
} |
190 |
elmex |
1.5 |
}; |
191 |
|
|
$@ and warn "ERROR: $@\n"; |
192 |
|
|
} |