ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/maps/perl/jeweler.ext
(Generate patch)

Comparing deliantra/maps/perl/jeweler.ext (file contents):
Revision 1.3 by elmex, Wed Aug 9 11:54:02 2006 UTC vs.
Revision 1.12 by root, Thu Oct 5 19:10:42 2006 UTC

1#! perl 1#! perl
2use POSIX; 2
3use Data::Dumper; 3use Data::Dumper;
4use Jeweler;
4use List::Util qw/max min sum/; 5use List::Util qw/max min sum/;
5use Jeweler;
6use strict; 6use strict;
7 7
8my $DEBUG = 1; 8sub ingred_alias {
9my $CFG; 9 my ($ing) = @_;
10 10
11# this is a simple quad polynom, it takes it's factors from 11 my %aliases = (
12# the configuration 12 pow => 'power',
13sub fx { 13 cha => 'charisma',
14 my ($x, $setting) = @_; 14 wis => 'wisdom',
15 my $facts = getcfg (functions => $setting); 15 int => 'intelligence',
16 return $facts->[0] * ($x ** 2) + $facts->[1] * $x + $facts->[2]; 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 }
17} 36}
18 37
19# makes a template arch (for example to get the value) 38my $DEBUG = 1;
20sub get_arch {
21 my ($outarch) = @_;
22 unless ($CFG->{arch}->{$outarch}) {
23 $CFG->{arch}->{$outarch} = cf::object::new $outarch;
24 39
25 unless ($CFG->{arch}->{$outarch}) { 40sub merge {
26 warn "ERROR: Couldn't make $outarch in conversion for $outarch!"; 41 my ($chdl, $sk, $pl, $do_analyze) = @_;
27 return;
28 }
29 }
30 $CFG->{arch}->{$outarch}
31}
32 42
33sub calc_costs { 43 my $ingred = $chdl->extract_jeweler_ingredients;
34 my ($ring) = @_; 44 my @ring = $ingred->get_ring;
45 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
35 46
36 my $costs = {}; 47 @rings >= 2
48 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!");
37 49
38 for my $resnam (keys %{$ring->{resist} || {}}) { 50 my $ring = shift @rings;
51 $ring->improve_by_ring (@rings);
39 52
40 my $res = $ring->{resist}->{$resnam}; 53 if ($do_analyze) {
41 54 $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl));
42 next unless $res > 0; 55 $ring->wiz_analyze ($pl)
43 56 if $pl->flag (cf::FLAG_WIZ);
44 $costs->{"food_$resnam"} += $res;
45 $costs->{"resist_" . $Jeweler::RESMAP{$resnam} . "_potion"}++;
46
47 my $diamonds;
48 if (grep { $resnam eq $_ } @Jeweler::EFFECT_RESISTS) {
49 $diamonds += fx ($res, 'effect_resist_diamonds');
50 } else {
51 $diamonds += fx ($res, 'attack_resist_diamonds');
52 }
53 $costs->{diamonds} += $diamonds;
54 }
55
56 $costs = calc_stat_costs ($ring->{stat}, $costs);
57 $costs = calc_special_costs ($ring->{spec}, $costs);
58
59 warn
60 sprintf "JEWEL ANALYSE: %40s: %s" ,
61 $ring->{name},
62 join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs);
63 return $costs;
64}
65
66sub read_config {
67 my ($filename) = @_;
68
69# open my $fh, $filename
70# or die "Couldn't open '$filename': $!";
71
72 my $cfg = {}; #LoadFile $filename;
73
74# my $section = 'main';
75#
76# my $cont = join '', <$fh>;
77#
78# for (<$fh>) {
79# s/#.*$//;
80#
81# if (m/^\[([^\]]+)\]/) {
82# $section = $1;
83#
84# } elsif (m/^\s*(\S+)\s*=\s*(.*?)\s*$/) {
85# my ($k, $v) = ($1, $2);
86#
87# my @v = split /\s*,\s*/, $v;
88#
89# if (@v > 1) {
90# $v = [ @v ];
91# }
92#
93# $cfg->{$section}->{$k} = $v;
94# }
95# }
96
97 return $cfg;
98}
99
100sub getcfg {
101 my ($sect, $key) = @_;
102 my $cfg = $CFG->{$sect}->{$key}
103 or die "Couldn't find $sect/$key in configuration!";
104
105 $cfg
106}
107
108sub ring_or_ammy_to_hash {
109 my ($thing) = @_;
110
111 my $obj = {};
112
113 for (@Jeweler::RESISTS) {
114 $obj->{resist}->{$_} = $thing->get_resistance ($_);
115 }
116
117 my $stats = $thing->stats;
118
119 for (qw/Str Dex Con Wis Cha Int Pow/) {
120 $obj->{stat}->{$_} = $stats->$_;
121 }
122
123 $obj->{spec}->{regen} = $thing->hp;
124 $obj->{spec}->{magic} = $thing->sp;
125 $obj->{spec}->{wc} = $thing->wc;
126 $obj->{spec}->{dam} = $thing->dam;
127 $obj->{spec}->{ac} = $thing->ac;
128 $obj->{spec}->{speed} = $thing->stats->exp;
129 $obj->{spec}->{suste} = $thing->food;
130
131 $obj->{name} = $thing->name;
132
133 $obj
134}
135
136sub split_diamonds {
137 my ($cost, $diamonds, $category) = @_;
138
139 my $stat_split = getcfg (diamond_split => $category);
140
141 my $emarch = get_arch ('emerald');
142 my $saarch = get_arch ('sapphire');
143 my $pearch = get_arch ('pearl');
144 my $ruarch = get_arch ('ruby');
145 my $diarch = get_arch ('gem');
146
147 my $sumvalue = $diarch->value * $diamonds;
148
149 $cost->{emeralds} += ceil (($sumvalue * $stat_split->[0]) / $emarch->{value});
150 $cost->{sapphires} += ceil (($sumvalue * $stat_split->[1]) / $saarch->{value});
151 $cost->{pearls} += ceil (($sumvalue * $stat_split->[2]) / $pearch->{value});
152 $cost->{rubies} += ceil (($sumvalue * $stat_split->[3]) / $ruarch->{value});
153 $cost->{diamonds} += ceil (($sumvalue * $stat_split->[4]) / $diarch->{value});
154
155 return $cost;
156}
157
158sub calc_stat_level {
159 my ($stats) = @_;
160
161 my $maxlevel = getcfg (maxlevels => 'stat_level');
162 my $maxstat = getcfg (maximprovements => 'stats');
163
164 my $stat_cnt = scalar (grep { $_ > 0 } values %$stats);
165 my $stat_sum = sum (values %$stats);
166 my $level = int (($maxlevel / $maxstat) * $stat_sum);
167
168 ($level, $stat_cnt)
169}
170
171sub calc_resist_level {
172 my ($resists) = @_;
173
174 my $att_res_lvl = getcfg (maxlevels => 'resist_level');
175 my $efc_res_lvl = getcfg (maxlevels => 'effect_resist_level');
176 my $max_att_res = getcfg (maximprovements => 'attack_resistances');
177 my $max_efc_res = getcfg (maximprovements => 'effect_resistances');
178 my $max_ovr_res = getcfg (maximprovements => 'resistances');
179
180 my $ressum = 0;
181 my $rescnt = 0;
182 my @reslevels;
183
184 for my $resnam (keys %$resists) {
185 my $res = $resists->{$resnam};
186
187 $rescnt++
188 if $res > 0; # negative resistancies are not an improvement
189
190 $ressum += $res; # note: negative resistancies lower the sum
191
192 next unless $res > 0;
193
194 my $level = 0;
195 if (grep { $resnam eq $_ } @Jeweler::EFFECT_RESISTS) {
196 $level = ceil (($efc_res_lvl / $max_efc_res) * $res);
197 } else {
198 $level = ceil (($att_res_lvl / $max_att_res) * $res);
199 }
200 push @reslevels, $level;
201 }
202
203 my $overall_lvl = ($att_res_lvl / $max_ovr_res) * $ressum;
204
205 (max (@reslevels, $overall_lvl), $rescnt);
206}
207
208sub calc_special_level {
209 my ($specials) = @_;
210
211 my $max_spc_lvl = getcfg (maxlevels => 'spec_level');
212 my $max_specials = getcfg (maximprovements => 'specials');
213
214 my @speclvls;
215 my $specsum = 0;
216 my $imprs = 0;
217
218 for my $spcnam (keys %$specials) {
219 my $spc = $specials->{$spcnam};
220 next unless $spc > 0;
221
222 $specsum += $spc;
223 $imprs++;
224
225 my $max_spc = getcfg (maxspecial => $spcnam);
226
227 my $lvl = ($max_spc_lvl / $max_spc) * $spc;
228 push @speclvls, $lvl;
229 }
230
231 my $sumlvl = ($max_spc_lvl / $max_specials) * $specsum;
232
233 (max (@speclvls, $sumlvl), $imprs)
234}
235
236sub calc_stat_costs {
237 my ($stats, $cost) = @_;
238
239 my $sum = sum grep { $_ > 0 } values %$stats;
240
241 return $cost unless $sum > 0;
242
243 $cost->{stat_potions} += fx ($sum, 'stat_potions');
244 $cost->{diamonds} += fx ($sum, 'stat_diamonds');
245
246 $cost
247}
248
249sub calc_special_costs {
250 my ($specials, $cost) = @_;
251
252 my $sum = sum grep { $_ > 0 } values %$specials;
253
254 return $cost unless $sum > 0;
255
256 $cost->{spec_potions} += fx ($sum, 'spec_potions');
257 $cost->{diamonds} += fx ($sum, 'spec_diamonds');
258
259 $cost
260}
261
262# this function calculated the 'level' of an amulet or a ring
263sub power_to_level {
264 my ($ring) = @_;
265
266 my $max_imprs = getcfg (maximprovements => 'improvements');
267 my $max_impr_lvl = getcfg (maxlevels => 'improve_level');
268
269 my ($stat_lvl, $stat_imprs) = calc_stat_level ($ring->{stat} || {});
270 my ($resist_lvl, $res_imprs) = calc_resist_level ($ring->{resist} || {});
271 my ($spec_lvl, $spec_imprs) = calc_special_level ($ring->{spec} || {});
272
273 my $impr_lvl = ceil (($max_impr_lvl / ($max_imprs + 1)) * ($stat_imprs + $res_imprs + $spec_imprs - 1));
274
275 my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0);
276
277 my $cost = calc_costs ($ring);
278 warn sprintf "%3d: %50s: %s\n", $levl, $ring->{name}, "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, spec: $spec_lvl (num impr $stat_imprs + $res_imprs + $spec_imprs - 1)";
279# warn sprintf " %s\n", join (',', map { sprintf "$_: %5d", $cost->{$_} } keys %$cost);
280
281 $levl
282}
283
284# this function converts metals/minerals into a raw ring (of adornment)
285sub simple_converter {
286 my ($pl, $ingred, $chdl, $conv) = @_;
287
288 $conv = lc $conv;
289 my $cnvs = $CFG->{conversions};
290
291 return unless $cnvs->{$conv};
292
293 my %ingred_groups;
294
295 my @conv_cfg = @{$cnvs->{$conv}};
296 my $outarch = $conv;
297 my ($ingr_grp, $outarchvalfact, $srcarchname, $xp_gain) = @conv_cfg;
298
299 unless (@conv_cfg <= 4) {
300 warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!";
301 return; 57 return;
302 } 58 }
303 59
304 unless ($xp_gain > 0) { 60 make_ring ($chdl, $ingred, $ring, $sk, $pl);
305 warn "WARNING: xp gain isn't > 0 in convesion '$outarch'\n"; 61}
306 return; 62
63sub make_ring {
64 my ($chdl, $ingred, $ring, $sk, $pl) = @_;
65
66 if (!$pl->flag (cf::FLAG_WIZ)) {
67 $ingred->remove ('rings');
68 $ingred->remove ('ammys');
307 } 69 }
308 70
309 unless ($outarchvalfact) { 71 my $ch = $ring->get_chance_perc ($sk);
310 warn "ERROR: source-arch-value-multiplier == 0 in convesion '$outarch'\n"; 72 my $succ = 0;
311 return; 73 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH);
74 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) {
75 my $lvl = max ($ring->power_to_level, 1);
76 my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100;
77 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY);
78 $pl->message ("You succeed and get $exp experience.");
79 } else {
80 $pl->message ("You fail!");
81 $ring->negate;
312 } 82 }
313 83 $chdl->put ($ring->to_object);
314 unless ($outarchvalfact >= 1) {
315 warn "WARNING: source-arch-value-multiplier < 1 in convesion '$outarch', results in more valuable output!\n";
316 }
317
318 my $archvalsum = $ingred->value ($cnvs->{$outarch}->[0], $cnvs->{$outarch}->[2]);
319 $ingred->remove ($cnvs->{$outarch}->[0], $cnvs->{$outarch}->[2]);
320
321 my $outarchval = get_arch ($outarch)->value;
322
323 my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact));
324 if ($nrof) {
325 # XXX: yes, i know what i'm doing here, i don't set nrof, but it didn't work somehow (pls. chek sometimes)
326 $chdl->put (cf::object::new $outarch) for 1..$nrof;
327
328 my $xp_sum = ($xp_gain * $nrof);
329
330 if ($xp_sum) {
331 $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s");
332 $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_ADD_SKILL);
333 }
334 }
335} 84}
336 85
86cf::attach_to_type cf::SKILL, cf::SK_JEWELER,
87 on_use_skill => sub {
88 my ($sk, $ob, $part, $dir, $msg) = @_;
89 my $pl = $ob;
337 90
91 my $skobj = $sk;
338 92
339sub put_ingred_to_bench { 93 my $chdl = new Jeweler::CauldronHandler;
340 my ($ingred, $bench) = @_;
341 94
342 for my $ik (keys %$ingred) { 95 my $rv = 1;
343 for (@{$ingred->{$ik} || []}) { 96 eval {
344 $_->insert_ob_in_ob ($bench); 97 Jeweler::read_config ($ENV{CROSSFIRE_LIBDIR} . '/jeweler.yaml');
345 } 98 $DEBUG = 1;
346 }
347}
348 99
349my %lvl_diff_chances = ( 100 my $player = $ob->contr;
350 +5 => 100,
351 +4 => 95,
352 +3 => 85,
353 +2 => 75,
354 +1 => 65,
355 0 => 50,
356 -1 => 45,
357 -2 => 35,
358 -3 => 25,
359 -4 => 10,
360 -5 => 0
361);
362 101
363my %lvl_diff_msg = ( 102 unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) {
364 -5 => '%s is way above your skill', 103 return;
365 -4 => 'The chance to make %s is very low', 104 }
366 -3 => 'You hava a slight chance to make %s',
367 -2 => 'There is a low chance you finish %s',
368 -1 => 'You could make %s with a chance of nearly 50:50',
369 0 => 'The chances to fininsh %s is 50:50',
370 1 => 'To make %s your chance is slightly above 50:50',
371 2 => 'You could make with a good chance %s if you concentrate a lot',
372 3 => 'The chance you finish %s with some efford is high',
373 4 => 'You are nearly confident to finish %s',
374 5 => 'There is no chance you could fail to make %s',
375);
376 105
377sub level_diff_to_str { 106 cf::override;
378 my ($delta) = @_;
379 $delta = -5 if $delta < -5;
380 $delta = 5 if $delta > 5;
381 return $lvl_diff_msg{$delta}
382}
383 107
384sub level_diff_to_chance_perc { 108 if ($msg =~ m/^\s*analy[sz]e\s*$/i) {
385 my ($delta) = @_; 109 Jeweler::analyze ($sk, $chdl, $pl);
386 $delta = -5 if $delta < -5;
387 $delta = 5 if $delta > 5;
388 return $lvl_diff_chances{$delta}
389}
390 110
391sub grep_for_match { 111 } elsif ($msg =~ m/^\s*make\s*$/i) {
392 my ($thing, @matchar) = @_; 112 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
393 113
394 my $i = 0; 114 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
395 for my $match (@matchar) { 115 my $ingred = $chdl->extract_jeweler_ingredients;
396 if ($match =~ m/^\s*$/) {
397 $i++;
398 next;
399 }
400 116
401 if ($i % 3 == 0) { 117 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
402# warn ":FE1:" . $thing->name . ": $match\n"; 118 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
403 $thing->name eq $match
404 and return 1; 119 return
405 } elsif ($i % 3 == 1) { 120 }
406# warn ":FE2:" . $thing->title . ": $match\n";
407 $thing->title eq $match
408 and return 1;
409 } else { # $i % 3 == 2
410# warn ":FE3:" . $thing->archetype->name . ": $match\n";
411 $thing->archetype->name eq $match
412 and return 1;
413 }
414 $i++;
415 }
416 return 0;
417}
418 121
419sub get_plan { 122 Jeweler::simple_converter ($player, $ingred, $chdl, $1);
420 my ($ingred) = @_;
421 123
422 for my $pot (@{$ingred->{potions}}) { 124 } elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) {
423 for my $plan (keys %{$CFG->{plans}}) { 125 merge ($chdl, $sk, $pl, 1);
424 my $plg = $CFG->{plans}->{$plan}; 126
425 my @plga = (); 127 } elsif ($msg =~ m/^\s*merge\s*$/i) {
426 unless (ref $plg eq 'ARRAY') { 128 merge ($chdl, $sk, $pl, 0);
427 push @plga, $plg; 129
428 } else { 130 } else {
429 @plga = @$plg; 131 my $ingred = $chdl->extract_jeweler_ingredients;
430 } 132 my $plan = $ingred->get_plan;
431 next unless @plga > 0;
432 if (grep_for_match ($pot, @plga)) {
433 warn "MATCHED: $plan: @plga\n";
434 return $plan;
435 }
436 }
437 }
438}
439 133
440sub get_ring { 134 if ($plan) {
441 my ($ingred) = @_; 135 my @ring = $ingred->get_ring;
442 return @{$ingred->{rings} || []};
443}
444 136
445sub get_improv_amount { 137 if ((@ring > 1) || ($ring[0]->nrof > 1)) {
446 my ($plan, $ingred) = @_; 138 # actually the algorithm cant handle more than one improvement at a time
139 $pl->message ("You can't manage to improve more than one thing at a time!");
140 return;
447 141
448 if ($plan =~ m/^stat_(\S+)$/) { 142 } elsif (@ring < 1) {
449 my $plingred = getcfg (plan_ingred => $plan) 143 # actually the algorithm cant
450 or die "ingredients for plan '$plan' not defined!"; 144 $pl->message ("You slap yourself, you forgot the jewelery!");
145 return;
451 146
452 my $cnt = 0; 147 } else {
453 for my $pot (@{$ingred->{potions}}) { 148 my $ringo = Jeweler::Object->new (object => $ring[0]);
454 if (grep_for_match ($pot, @$plingred)) { 149 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo);
455 $cnt += $pot->nrof; 150 my $c1 = $ringo->calc_costs;
456 } 151 my $c2 = $iring->calc_costs;
457 }
458 warn "Found $cnt potions for plan $plan\n";
459 152
460 my $amount = 0; 153 my %keys;
461 for my $x (1..10) { 154 my %cdiff;
462 my $y = fx ($x, 'stat_potions'); 155 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
463 warn "TEST: fx($x): $y <= $cnt \n"; 156 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_} }
464 warn "FE: " . ($y == $cnt) . "\n";
465 if ($y <= $cnt) {
466 $amount = $x;
467 warn "Found stat increase at: $x\n";
468 last;
469 }
470 }
471 157
472 return $amount; 158 unless (grep { $_ > 0 } values %cdiff) {
473 } elsif ($plan =~ m/^spec_(\S+)$/) { 159 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed...");
474 return 0; 160 return;
475 } elsif ($plan =~ m/^resist_(\S+)$/) { 161 }
476 return 0;
477 }
478}
479 162
480sub get_plan_costs { 163 my $remcosts = $ingred->check_costs (\%cdiff);
481 my ($plan, $ring, $amount) = @_;
482 164
483 my $pre_costs = calc_costs ($ring); 165 if (grep { $_ > 0 } values %$remcosts) {
166 $pl->message ("You want to make a " . $iring->to_string . ": " . $iring->analyze ($sk, $pl));
167 $pl->message ("You recognize that you are short of: "
168 . (join ", ",
169 map { my $cost = $remcosts->{$_}; $cost . " " . ($cost > 1 ? "times" : "time") . " " . ingred_alias ($_) }
170 grep { $remcosts->{$_} > 0 } keys %$remcosts));
484 171
485 # alter ring spec
486 if ($plan =~ m/^stat_(\S+)$/) {
487 } elsif ($plan =~ m/^spec_(\S+)$/) {
488 } elsif ($plan =~ m/^resist_(\S+)$/) {
489 my ($resid) = map { $Jeweler::RESMAP{$_} } grep { $Jeweler::RESMAP{$_} eq $1 } keys %Jeweler::RESMAP;
490 unless (defined $resid) {
491 die "Couldn't find resistancy for plan: '$plan'\n";
492 }
493
494 $ring->{resist}->{$resid} += $amount;
495 }
496
497 my $post_costs = calc_costs ($ring);
498
499 my $delta_costs = {};
500 for (keys %{$post_costs}) {
501 my $cost = $post_costs->{$_} - $pre_costs->{$_};
502 if ($cost > 0) {
503 warn "DELTA COST: $_ => $cost\n";
504 $delta_costs->{$_} = $cost;
505 }
506 }
507 return $delta_costs
508}
509
510sub on_player_use_skill {
511 return 0; # disabled not yet ready#d##TODO#
512 my ($ob, $part, $sk, $dir, $msg) = @_;
513 my $pl = $ob;
514
515 my $skobj = $sk;
516
517 my $chdl = new Jeweler::CauldronHandler;
518
519 return 0 unless $sk->subtype == cf::SK_JEWELER;
520
521 my $rv = 1;
522 eval {
523 $CFG = read_config ($ENV{CROSSFIRE_LIBDIR} . '/jeweler.yaml'); #XXX: This has to become cached properly!
524 $DEBUG ||= $CFG->{main}->{debug};
525
526 my $player = $ob->contr;#cf::player::find $ob->name;
527
528 unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) {
529 $rv = 0;
530 return # return 0 if no cauldron found (default action: identify)
531 }
532
533 my $ingred = $chdl->extract_jeweler_ingredients;
534
535 if ($msg =~ m/^\s*analy[sz]e\s*$/i) {
536 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) {
537 my $sklvl = cf::exp_to_level ($sk->stats->exp);
538 my $ringlvl = power_to_level (ring_or_ammy_to_hash ($_));
539
540 if ($pl->get_flag (cf::FLAG_WIZ)) { 172 if ($pl->flag (cf::FLAG_WIZ)) {
541 $pl->message ("The " . $_->name . " is at level $ringlvl chance for you: " . level_diff_to_chance_perc ($sklvl - $ringlvl)); 173 $iring->wiz_analyze ($pl);
174 }
175 } else {
176 if (!$pl->flag (cf::FLAG_WIZ)) {
177 $ingred->check_costs (\%cdiff, 1);
178 }
179 make_ring ($chdl, $ingred, $iring, $sk, $pl);
180 }
181 }
542 } else { 182 } else {
543 my $tmpl = level_diff_to_str ($sklvl - $ringlvl); 183 $pl->message ("You've got no idea what you are planning to do!");
544 my $msg = sprintf $tmpl, $_->name;
545 $pl->message ($msg);
546 } 184 }
547 } 185 }
186 };
187 $@ and warn "ERROR: $@\n";
188 }
189;
548 190
549 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
550 unless ($CFG->{conversions}->{lc $1}) {
551 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
552 return
553 }
554
555 simple_converter ($player, $ingred, $chdl, $1);
556
557# for (@{$ingred->{rings}}) {
558# ring_or_ammy_to_hash ($_);
559# }
560 #put_ingred_to_bench ($ingred, $c[0]);
561
562 } else {
563 my $plan = get_plan ($ingred);
564
565 if ($plan) {
566 my @ring = get_ring ($ingred);
567
568 if (@ring > 1) {
569 # actually the algorithm cant handle more than one improvement at a time
570 $pl->message ("You can't manage to improve more than one ring!");
571
572 } elsif (@ring < 1) {
573 # actually the algorithm cant
574 $pl->message ("You slap yourself, you forgot the ring!");
575
576 } else {
577 my $ringh = ring_or_ammy_to_hash ($ring[0]);
578 my $amount = get_improv_amount ($plan, $ingred);
579# my $costs = get_plan_costs ($plan[0], $ringh, $amount);
580#
581# if (my $chk = check_plan_costs ($costs, $ingred)) {
582# # output some error that he lacks the ingredients
583# } else {
584# execute_plan ($costs, $ringh, $ingred);
585# }
586 }
587
588 } else {
589 $pl->message ("You've got no idea what you are planning to do!");
590 }
591 }
592 };
593 $@ and warn "ERROR: $@\n";
594
595 my $r = cf::random_roll (0, 101, $pl, cf::PREFER_LOW);
596 $rv;
597}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines