… | |
… | |
8 | |
8 | |
9 | =cut |
9 | =cut |
10 | |
10 | |
11 | package Jeweler; |
11 | package Jeweler; |
12 | |
12 | |
13 | use strict; |
13 | use common::sense; |
14 | use YAML; |
|
|
15 | |
14 | |
16 | =over 4 |
15 | =over 4 |
17 | |
16 | |
18 | =item @RESISTS |
17 | =item @RESISTS |
19 | |
18 | |
… | |
… | |
24 | our $CFG; |
23 | our $CFG; |
25 | |
24 | |
26 | sub read_config { |
25 | sub read_config { |
27 | my ($filename) = @_; |
26 | my ($filename) = @_; |
28 | |
27 | |
29 | unless (-e $filename) { |
28 | if (my $meta = $cf::RESOURCE{$filename}) { |
|
|
29 | $CFG = cf::decode_json $meta->{data}; |
|
|
30 | } else { |
30 | warn "$filename doesn't exists! no config for jeweler skill loaded!\n"; |
31 | warn "$filename doesn't exist! no config for jeweler skill loaded!\n"; |
31 | $CFG = {}; |
32 | $CFG = {}; |
32 | return |
|
|
33 | } |
33 | } |
34 | |
|
|
35 | $CFG = YAML::LoadFile $filename; |
|
|
36 | } |
34 | } |
37 | |
35 | |
38 | sub getcfg { |
36 | sub getcfg { |
39 | my ($sect, $key) = @_; |
37 | my ($sect, $key) = @_; |
40 | return $CFG->{$sect} unless defined $key; |
38 | return $CFG->{$sect} unless defined $key; |
… | |
… | |
117 | cf::ATNR_LIFE_STEALING => "LIFE_STEALING", |
115 | cf::ATNR_LIFE_STEALING => "LIFE_STEALING", |
118 | cf::ATNR_BLIND => "BLIND", |
116 | cf::ATNR_BLIND => "BLIND", |
119 | cf::ATNR_DISEASE => "DISEASE", |
117 | cf::ATNR_DISEASE => "DISEASE", |
120 | ); |
118 | ); |
121 | |
119 | |
|
|
120 | our %REV_RESMAP = map { $RESMAP{$_} => $_ } keys %RESMAP; |
|
|
121 | |
122 | our %LVL_DIFF_CHANCES = ( |
122 | our %LVL_DIFF_CHANCES = ( |
123 | +5 => 100, |
123 | +5 => 100, |
124 | +4 => 95, |
124 | +4 => 95, |
125 | +3 => 85, |
125 | +3 => 85, |
126 | +2 => 75, |
126 | +2 => 75, |
… | |
… | |
160 | $delta = 5 if $delta > 5; |
160 | $delta = 5 if $delta > 5; |
161 | return $LVL_DIFF_CHANCES{$delta} |
161 | return $LVL_DIFF_CHANCES{$delta} |
162 | } |
162 | } |
163 | |
163 | |
164 | sub analyze { |
164 | sub analyze { |
165 | my ($sk, $chdl, $pl) = @_; |
165 | my ($sk, $chdl, $pl, $input_level) = @_; |
166 | |
166 | |
167 | my $hadunid = 0; |
167 | my $hadunid = 0; |
|
|
168 | my $found = 0; |
168 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
169 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
169 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
170 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
170 | $hadunid = 1; |
171 | $hadunid = 1; |
171 | next; |
172 | next; |
172 | } |
173 | } |
|
|
174 | $found = 1; |
173 | my $r = Jeweler::Object->new (object => $_); |
175 | my $r = Jeweler::Object->new (object => $_); |
174 | my $msg = $r->analyze ($sk, $pl); |
176 | my $msg = $r->analyze ($sk, $pl, $input_level); |
175 | $pl->message ($r->to_string . ": " . $msg); |
177 | $pl->message ($r->to_string . ": " . $msg); |
176 | if ($pl->flag (cf::FLAG_WIZ)) { |
178 | if ($pl->flag (cf::FLAG_WIZ)) { |
177 | $r->wiz_analyze ($pl); |
179 | $r->wiz_analyze ($pl); |
178 | } |
180 | } |
179 | } |
181 | } |
180 | if ($hadunid) { |
|
|
181 | $pl->message ("You couldn't identify the other rings and not analyze them!"); |
182 | $pl->message ("You couldn't identify the other rings and not analyze them!") |
182 | } |
183 | if $hadunid; |
|
|
184 | $pl->message ("You couldn't find anything in the bench to analyse!") |
|
|
185 | unless $found; |
183 | } |
186 | } |
184 | |
187 | |
185 | # this function converts metals/minerals into a raw ring (of adornment) |
188 | # this function converts metals/minerals into a raw ring (of adornment) |
186 | sub simple_converter { |
189 | sub simple_converter { |
187 | my ($pl, $ingred, $chdl, $conv) = @_; |
190 | my ($pl, $ingred, $chdl, $conv) = @_; |
… | |
… | |
201 | warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; |
204 | warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; |
202 | return; |
205 | return; |
203 | } |
206 | } |
204 | |
207 | |
205 | unless ($xp_gain > 0) { |
208 | unless ($xp_gain > 0) { |
206 | warn "WARNING: xp gain isn't > 0 in convesion '$outarch'\n"; |
209 | warn "WARNING: xp gain isn't > 0 in conversion '$outarch'\n"; |
207 | return; |
210 | return; |
208 | } |
211 | } |
209 | |
212 | |
210 | unless ($outarchvalfact) { |
213 | unless ($outarchvalfact) { |
211 | warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; |
214 | warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; |
… | |
… | |
217 | } |
220 | } |
218 | |
221 | |
219 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
222 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
220 | $ingred->remove ($ingr_grp, $srcarchname); |
223 | $ingred->remove ($ingr_grp, $srcarchname); |
221 | |
224 | |
222 | my $outarchval = cf::arch::find ($outarch)->clone->value; |
225 | my $outarchval = cf::arch::find ($outarch)->value; |
223 | |
226 | |
224 | my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); |
227 | my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact); |
225 | if ($nrof) { |
228 | if ($nrof) { |
226 | # XXX: yes, i know what i'm doing here, i don't set nrof, but it didn't work somehow (pls. chek sometimes) |
229 | # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes) |
|
|
230 | for (1 .. $nrof) { |
227 | $chdl->put (cf::object::new $outarch) for 1..$nrof; |
231 | $chdl->put (my $ob = cf::object::new $outarch); |
|
|
232 | $ob->set_animation (cf::rndm $ob->num_animations) |
|
|
233 | if ($ob->type == cf::RING); |
|
|
234 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
|
|
235 | } |
228 | |
236 | |
229 | my $xp_sum = ($xp_gain * $nrof); |
237 | my $xp_sum = $xp_gain * $nrof; |
230 | |
238 | |
231 | if ($xp_sum) { |
239 | if ($xp_sum) { |
232 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
240 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
233 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_ADD_SKILL); |
241 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
234 | } |
242 | } |
|
|
243 | } else { |
|
|
244 | $pl->ob->message ("You fail to make something, probably you used not enough source material?"); |
235 | } |
245 | } |
236 | } |
246 | } |
237 | |
247 | |
238 | |
248 | |
239 | package Jeweler::CauldronHandler; |
249 | package Jeweler::CauldronHandler; |
… | |
… | |
271 | my ($self, $arch_name, @map_stack) = @_; |
281 | my ($self, $arch_name, @map_stack) = @_; |
272 | |
282 | |
273 | my @c = |
283 | my @c = |
274 | grep { |
284 | grep { |
275 | $_->flag (cf::FLAG_IS_CAULDRON) |
285 | $_->flag (cf::FLAG_IS_CAULDRON) |
276 | and $_->arch->name eq $arch_name |
286 | and $_->arch->archname eq $arch_name |
277 | } @map_stack; |
287 | } @map_stack; |
278 | |
288 | |
279 | $self->{cauldron} = $c[0]; |
289 | $self->{cauldron} = $c[0]; |
280 | } |
290 | } |
281 | |
291 | |
… | |
… | |
320 | cf::POTION => 'potions', |
330 | cf::POTION => 'potions', |
321 | cf::SCROLL => 'scrolls', |
331 | cf::SCROLL => 'scrolls', |
322 | ); |
332 | ); |
323 | |
333 | |
324 | for ($self->{cauldron}->inv) { |
334 | for ($self->{cauldron}->inv) { |
|
|
335 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
|
|
336 | die "unidentified"; |
|
|
337 | } elsif ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { |
|
|
338 | die "cursed"; |
|
|
339 | } |
325 | |
340 | |
326 | if (my $k = $type_to_key{$_->type}) { |
341 | if (my $k = $type_to_key{$_->type}) { |
327 | push @{$ingreds->{$k}}, $_; |
342 | push @{$ingreds->{$k}}, $_; |
|
|
343 | } else { |
|
|
344 | push @{$ingreds->{other}}, $_; |
328 | } |
345 | } |
329 | } |
346 | } |
330 | |
347 | |
331 | return Jeweler::Ingredients->new (ingredients => $ingreds, cauldron_helper => $self) |
348 | return Jeweler::Ingredients->new (ingredients => $ingreds, cauldron_helper => $self) |
332 | } |
349 | } |
… | |
… | |
339 | |
356 | |
340 | sub put { |
357 | sub put { |
341 | my ($self, $obj) = @_; |
358 | my ($self, $obj) = @_; |
342 | |
359 | |
343 | return undef unless $self->{cauldron}; |
360 | return undef unless $self->{cauldron}; |
344 | $obj->insert_ob_in_ob ($self->{cauldron}); |
361 | $self->{cauldron}->insert ($obj); |
345 | } |
362 | } |
346 | |
363 | |
347 | =back |
364 | =back |
348 | |
365 | |
349 | =cut |
366 | =cut |
… | |
… | |
382 | |
399 | |
383 | sub value { |
400 | sub value { |
384 | my ($self, $group, $archname) = @_; |
401 | my ($self, $group, $archname) = @_; |
385 | |
402 | |
386 | my @objs = grep { |
403 | my @objs = grep { |
387 | $_->arch->name eq $archname |
404 | $_->arch->archname eq $archname |
388 | } @{$self->{ingredients}->{$group} || []}; |
405 | } @{$self->{ingredients}->{$group} || []}; |
389 | |
406 | |
390 | my $sum = 0; |
407 | my $sum = 0; |
391 | for (@objs) { |
408 | for (@objs) { |
392 | $sum += ($_->nrof || 1) * $_->value; |
409 | $sum += ($_->nrof || 1) * $_->value; |
… | |
… | |
409 | |
426 | |
410 | my @out; |
427 | my @out; |
411 | |
428 | |
412 | for (@{$ingred->{$group}}) { |
429 | for (@{$ingred->{$group}}) { |
413 | if (defined $archname) { |
430 | if (defined $archname) { |
414 | if ($_->arch->name eq $archname) { |
431 | if ($_->arch->archname eq $archname) { |
415 | Jeweler::Util::remove ($_); |
432 | Jeweler::Util::remove ($_); |
416 | } else { |
433 | } else { |
417 | push @out, $_; |
434 | push @out, $_; |
418 | } |
435 | } |
419 | } else { |
436 | } else { |
… | |
… | |
427 | sub get_plan { |
444 | sub get_plan { |
428 | my ($self) = @_; |
445 | my ($self) = @_; |
429 | |
446 | |
430 | my $ingred = $self->{ingredients}; |
447 | my $ingred = $self->{ingredients}; |
431 | |
448 | |
432 | for my $grp (keys %$ingred) { |
|
|
433 | for my $pot (@{$ingred->{$grp}}) { |
|
|
434 | for my $plan (keys %{$Jeweler::CFG->{plans}}) { |
449 | for my $plan (keys %{$Jeweler::CFG->{plans}}) { |
435 | my $plg = $Jeweler::CFG->{plans}->{$plan}; |
450 | my $plg = $Jeweler::CFG->{plans}->{$plan}; |
436 | my @plga = (); |
451 | my @plga = (); |
437 | unless (ref $plg eq 'ARRAY') { |
452 | unless (ref $plg eq 'ARRAY') { |
438 | push @plga, $plg; |
453 | push @plga, $plg; |
439 | } else { |
454 | } else { |
440 | @plga = @$plg; |
455 | @plga = @$plg; |
441 | } |
456 | } |
442 | next unless @plga > 0; |
457 | next unless @plga > 0; |
443 | if (Jeweler::Util::grep_for_match ($pot, @plga)) { |
458 | if (Jeweler::Util::grep_for_match ($ingred, @plga)) { |
444 | return $plan; |
459 | return $plan; |
445 | } |
|
|
446 | } |
|
|
447 | } |
460 | } |
448 | } |
461 | } |
449 | } |
462 | } |
450 | |
463 | |
451 | sub get_ring { |
464 | sub get_ring { |
… | |
… | |
454 | @{$self->{ingredients}->{ammys} || []}, |
467 | @{$self->{ingredients}->{ammys} || []}, |
455 | @{$self->{ingredients}->{rings} || []} |
468 | @{$self->{ingredients}->{rings} || []} |
456 | ); |
469 | ); |
457 | } |
470 | } |
458 | |
471 | |
|
|
472 | sub improve_max { |
|
|
473 | my ($stat, $impro) = @_; |
|
|
474 | if ($stat >= 0) { |
|
|
475 | $stat = $impro > $stat ? $impro : $stat; |
|
|
476 | } |
|
|
477 | $stat |
|
|
478 | } |
|
|
479 | |
459 | sub improve_ring_by_plan { |
480 | sub improve_ring_by_plan { |
460 | my ($self, $plan, $ring) = @_; |
481 | my ($self, $plan, $ring) = @_; |
461 | |
482 | |
462 | $ring = dclone ($ring); |
483 | $ring = dclone $ring; |
463 | |
484 | |
464 | my $ingred = $self->{ingredients}; |
485 | my $ingred = $self->{ingredients}; |
465 | my $impr = {}; |
486 | my $impr = {}; |
466 | |
487 | |
467 | if ($plan =~ m/^stat_(\S+)$/) { |
488 | if ($plan =~ m/^stat_(\S+)$/) { |
468 | my $statname = $1; |
489 | my $statname = $1; |
469 | my $plingred = Jeweler::getcfg (plans => $plan) |
490 | my $plingred = Jeweler::getcfg (plans => $plan) |
470 | or die "ingredients for plan '$plan' not defined!"; |
491 | or die "ingredients for plan '$plan' not defined!"; |
471 | |
492 | |
472 | my $cnt = 0; |
493 | my $cnt = 0; |
473 | for my $pot (@{$ingred->{potions}}) { |
|
|
474 | if (Jeweler::Util::grep_for_match ($pot, @$plingred)) { |
494 | if (my $pot = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { |
475 | $cnt += $pot->nrof; |
495 | $cnt += $pot->nrof; |
476 | } |
|
|
477 | } |
496 | } |
478 | |
497 | |
479 | my $maxstat = Jeweler::getcfg (maximprovements => 'stats'); |
498 | my $maxstat = Jeweler::getcfg (maximprovements => 'stats'); |
480 | my $did_impr = 0; |
|
|
481 | for my $x (1..$maxstat) { |
499 | for my $x (1..$maxstat) { |
482 | my $y = Jeweler::Object::fx ($x, 'stat_potions'); |
500 | my $y = Jeweler::Object::fx ($x, 'stat_items'); |
483 | |
501 | |
484 | if ($cnt <= $y->[0]) { |
502 | if ($cnt <= $y->[0]) { |
485 | $ring->{hash}->{stat}->{$statname} += $x; |
503 | $ring->{hash}->{stat}->{$statname} = |
486 | $did_impr = 1; |
504 | improve_max $ring->{hash}->{stat}->{$statname}, $x; |
487 | last; |
505 | last; |
488 | } |
506 | } |
489 | } |
507 | } |
490 | |
508 | |
491 | # we want at least this improvement if we have a plan... |
|
|
492 | $ring->{hash}->{stat}->{$statname} += 1 unless $did_impr; |
|
|
493 | |
|
|
494 | } elsif ($plan =~ m/^spec_(\S+)$/) { |
509 | } elsif ($plan =~ m/^spec_(\S+)$/) { |
|
|
510 | my $specname = $1; |
|
|
511 | my $plingred = Jeweler::getcfg (plans => $plan) |
|
|
512 | or die "ingredients for plan '$plan' not defined!"; |
|
|
513 | |
|
|
514 | my $cnt = 0; |
|
|
515 | if (my $pot = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { |
|
|
516 | $cnt += $pot->nrof; |
|
|
517 | } |
|
|
518 | |
|
|
519 | my $maxspec = Jeweler::getcfg (maximprovements => 'specials'); |
|
|
520 | for my $x (1..$maxspec) { |
|
|
521 | my $y = Jeweler::Object::fx ($x, 'spec_items'); |
|
|
522 | |
|
|
523 | if ($cnt <= $y->[0]) { |
|
|
524 | $ring->{hash}->{spec}->{$specname} = |
|
|
525 | improve_max $ring->{hash}->{spec}->{$specname}, $x; |
|
|
526 | last; |
|
|
527 | } |
|
|
528 | } |
|
|
529 | |
495 | } elsif ($plan =~ m/^resist_(\S+)$/) { |
530 | } elsif ($plan =~ m/^resist_(\S+)$/) { |
|
|
531 | my $resname = $1; |
|
|
532 | my $resnum = $REV_RESMAP{$resname}; |
|
|
533 | my $plingred = Jeweler::getcfg (plans => $plan) |
|
|
534 | or die "ingredients for plan '$plan' not defined!"; |
|
|
535 | |
|
|
536 | my $cnt = 0; |
|
|
537 | if (my $it = Jeweler::Util::grep_for_match ($ingred, @$plingred)) { |
|
|
538 | $cnt += $it->nrof; |
|
|
539 | } |
|
|
540 | my $resist_item_nr = 0; |
|
|
541 | $self->do_grep (sub { $resist_item_nr += ($_[0]->nrof || 1); 0 }, @$plingred); |
|
|
542 | |
|
|
543 | my $maximprovname = (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) |
|
|
544 | ? 'effect_resistances' |
|
|
545 | : 'attack_resistances'; |
|
|
546 | |
|
|
547 | my $maxres = Jeweler::getcfg (maximprovements => $maximprovname); |
|
|
548 | $resist_item_nr = $maxres if ($resist_item_nr > $maxres); |
|
|
549 | $ring->{hash}->{resist}->{$resnum} = |
|
|
550 | improve_max $ring->{hash}->{resist}->{$resnum}, $resist_item_nr; |
496 | } |
551 | } |
497 | |
552 | |
498 | return $ring; |
553 | return $ring; |
499 | } |
554 | } |
500 | |
555 | |
501 | sub do_grep { |
556 | sub do_grep { |
502 | my ($self, $cb, @grepar) = @_; |
557 | my ($self, $cb, $cat, @grepar) = @_; |
503 | |
558 | |
504 | my $ingred = $self->{ingredients}; |
559 | my $ingred = $self->{ingredients}; |
505 | |
560 | |
506 | |
|
|
507 | for my $cat (keys %$ingred) { |
|
|
508 | my @rem; |
561 | my @rem; |
509 | for my $ing (@{$ingred->{$cat}}) { |
562 | for my $ing (@{$ingred->{$cat}}) { |
510 | if (Jeweler::Util::grep_for_match ($ing, @grepar)) { |
563 | if (Jeweler::Util::check_for_match ($ing, @grepar)) { |
511 | unless ($cb->($ing)) { |
564 | unless ($cb->($ing)) { |
512 | push @rem, $ing; |
|
|
513 | } |
|
|
514 | } else { |
|
|
515 | push @rem, $ing; |
565 | push @rem, $ing; |
516 | } |
566 | } |
|
|
567 | } else { |
|
|
568 | push @rem, $ing; |
517 | } |
569 | } |
|
|
570 | } |
518 | @{$ingred->{$cat}} = @rem; |
571 | @{$ingred->{$cat}} = @rem; |
519 | } |
|
|
520 | } |
572 | } |
521 | |
573 | |
522 | sub check_costs { |
574 | sub check_costs { |
523 | my ($self, $costs, $do_remove) = @_; |
575 | my ($self, $costs, $do_remove) = @_; |
524 | |
576 | |
525 | my $costs = dclone ($costs); |
577 | my $costs = dclone $costs; |
526 | |
578 | |
527 | for my $key (keys %$costs) { |
579 | for my $key (keys %$costs) { |
528 | my @grepar; |
580 | my @grepar; |
529 | if ($key =~ m/^stat_(\S+)$/) { |
581 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
530 | @grepar = @{Jeweler::getcfg (plans => $key) || []}; |
582 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
531 | } else { |
583 | next if $@; |
|
|
584 | } else { # check the gems |
532 | @grepar = (undef, undef, $key); |
585 | @grepar = ('gems', undef, undef, $key); |
533 | } |
586 | } |
534 | |
587 | |
535 | if ($do_remove) { |
588 | if ($do_remove) { |
536 | my $rem = $costs->{$key}; |
589 | my $rem = $costs->{$key}; |
|
|
590 | $self->do_grep (sub { |
537 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
591 | if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } |
|
|
592 | 1 |
|
|
593 | }, @grepar); |
538 | if ($rem > 0) { |
594 | if ($rem > 0) { |
539 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
595 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
540 | } |
596 | } |
|
|
597 | |
541 | } else { |
598 | } else { |
542 | my $nr; |
599 | my $nr; |
543 | $self->do_grep (sub { $nr += $_[0]->nrof; 0 }, @grepar); |
600 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
544 | $costs->{$key} -= $nr; |
601 | $costs->{$key} -= $nr; |
545 | } |
602 | } |
|
|
603 | |
546 | } |
604 | } |
547 | |
605 | |
548 | return $costs; |
606 | return $costs; |
549 | } |
607 | } |
550 | |
608 | |
… | |
… | |
577 | $self->ring_or_ammy_to_hash ($arg{object}); |
635 | $self->ring_or_ammy_to_hash ($arg{object}); |
578 | |
636 | |
579 | $self; |
637 | $self; |
580 | } |
638 | } |
581 | |
639 | |
|
|
640 | sub has_resist { |
|
|
641 | my ($self, $resistnam, $resistval) = @_; |
|
|
642 | my $resnum = $REV_RESMAP{uc $resistnam}; |
|
|
643 | if (defined ($resistval)) { |
|
|
644 | return 1 if $self->{hash}->{resist}->{$resnum} == $resistval; |
|
|
645 | } else { |
|
|
646 | return 1 if $self->{hash}->{resist}->{$resnum}; |
|
|
647 | } |
|
|
648 | return undef; |
|
|
649 | } |
|
|
650 | |
|
|
651 | sub projected_exp { |
|
|
652 | my ($self, $input_level) = @_; |
|
|
653 | |
|
|
654 | my $lvl = max ($self->power_to_level, 1); |
|
|
655 | my $exp = |
|
|
656 | (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) |
|
|
657 | / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring |
|
|
658 | # should get you to the rings level at least. |
|
|
659 | |
|
|
660 | if (defined $input_level) { |
|
|
661 | my $subexp = |
|
|
662 | (cf::level_to_min_exp ($input_level) |
|
|
663 | - cf::level_to_min_exp ($input_level - 1)) |
|
|
664 | / (10 + max ($input_level - 1, 0)); # see above for comment |
|
|
665 | |
|
|
666 | $exp -= $subexp; |
|
|
667 | $exp = max ($exp, 0); |
|
|
668 | |
|
|
669 | } else { |
|
|
670 | # the experience bonus here is to make level 1 rings give you at least |
|
|
671 | # 200 exp points when making them. This also makes leveling in the |
|
|
672 | # first few levels a bit easier. (probably until around level 5-6). |
|
|
673 | my $expbonus = cf::level_to_min_exp (2) / 5; |
|
|
674 | # this bonus should also only be given for _new_ rings and not for merged |
|
|
675 | # ones - to prevent infinite exp making. |
|
|
676 | $exp += $expbonus; |
|
|
677 | } |
|
|
678 | |
|
|
679 | $exp |
|
|
680 | } |
|
|
681 | |
582 | sub analyze { |
682 | sub analyze { |
583 | my ($self, $sk, $pl) = @_; |
683 | my ($self, $sk, $pl, $input_level) = @_; |
|
|
684 | my $costs = $self->calc_costs; |
|
|
685 | |
|
|
686 | unless (defined $costs) { |
|
|
687 | return "This ring has a resistancy above 99%, you can't make that."; |
|
|
688 | } |
584 | |
689 | |
585 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
690 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
586 | my $ringlvl = $self->power_to_level; |
691 | my $ringlvl = $self->power_to_level; |
587 | |
692 | |
588 | my $tmpl; |
693 | my $tmpl; |
589 | if ($pl->flag (cf::FLAG_WIZ)) { |
694 | if ($pl->flag (cf::FLAG_WIZ)) { |
590 | $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); |
695 | $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); |
591 | } else { |
696 | } else { |
592 | $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); |
697 | $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); |
593 | } |
698 | } |
594 | my $msg = sprintf "Projected success rate: %s", $tmpl; |
699 | my $msg = sprintf "Projected success rate: %s, you would get %d exp for this.", $tmpl, $self->projected_exp ($input_level); |
595 | return $msg; |
700 | return $msg; |
|
|
701 | } |
|
|
702 | |
|
|
703 | sub calc_value_from_cost { |
|
|
704 | my ($self, $costs) = @_; |
|
|
705 | my $emarch = cf::arch::find 'emerald'; |
|
|
706 | my $saarch = cf::arch::find 'sapphire'; |
|
|
707 | my $pearch = cf::arch::find 'pearl'; |
|
|
708 | my $ruarch = cf::arch::find 'ruby'; |
|
|
709 | my $diarch = cf::arch::find 'gem'; |
|
|
710 | my $value = $emarch->value * $costs->{emerald} |
|
|
711 | + $saarch->value * $costs->{sapphire} |
|
|
712 | + $pearch->value * $costs->{pearl} |
|
|
713 | + $ruarch->value * $costs->{ruby} |
|
|
714 | + $diarch->value * $costs->{gem}; |
|
|
715 | |
|
|
716 | $value |
596 | } |
717 | } |
597 | |
718 | |
598 | sub wiz_analyze { |
719 | sub wiz_analyze { |
599 | my ($self, $pl) = @_; |
720 | my ($self, $pl) = @_; |
600 | my $costs = $self->calc_costs; |
721 | my $costs = $self->calc_costs; |
|
|
722 | if (defined $costs) { |
601 | my $desc = ""; |
723 | my $desc = ""; |
602 | my $lvl = $self->power_to_level (\$desc); |
724 | my $lvl = $self->power_to_level (\$desc); |
|
|
725 | my $scosts = $self->calc_value_from_cost ($costs); |
|
|
726 | |
|
|
727 | $pl->message ("costs: " |
603 | $pl->message ("costs: " . join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)); |
728 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
|
|
729 | . " (" |
|
|
730 | . ($scosts / "platinacoin"->cf::arch::find->value) |
|
|
731 | . " platinum)"); |
604 | $pl->message ("level: " . $desc); |
732 | $pl->message ("level: $desc"); |
|
|
733 | } else { |
|
|
734 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
|
|
735 | } |
605 | } |
736 | } |
606 | |
|
|
607 | |
737 | |
608 | sub get_chance_perc { |
738 | sub get_chance_perc { |
609 | my ($self, $sk) = @_; |
739 | my ($self, $sk) = @_; |
610 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
740 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
611 | my $ringlvl = $self->power_to_level; |
741 | my $ringlvl = $self->power_to_level; |
… | |
… | |
614 | |
744 | |
615 | sub fx { |
745 | sub fx { |
616 | my ($res, $cfg) = @_; |
746 | my ($res, $cfg) = @_; |
617 | my $or = $res; |
747 | my $or = $res; |
618 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
748 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
|
|
749 | |
619 | if (ref $ar->[0] eq 'ARRAY') { |
750 | if (ref $ar && ref $ar->[0] eq 'ARRAY') { |
620 | $res = $res - 1; |
751 | $res = $res - 1; |
|
|
752 | return $ar->[max (min ($res, @$ar - 1), 0)]; |
|
|
753 | |
621 | } else { |
754 | } else { |
622 | $res = ceil ($res / 5) - 1; |
755 | # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3... |
623 | } |
756 | # old code: |
|
|
757 | #my $idx = ceil (($res / 5) + 0.1) - 1; |
624 | $ar->[max (min ($res, @$ar - 1), 0)]; |
758 | #my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; |
|
|
759 | #my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; |
|
|
760 | #my $diff = $b - $a; # use the difference of the cost to the next cost |
|
|
761 | #my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation |
|
|
762 | #return $o_cost; |
|
|
763 | return 0 if $res <= 0; |
|
|
764 | return ($ar / (1 - ($res * 0.01)) - $ar) |
|
|
765 | } |
625 | } |
766 | } |
626 | |
767 | |
627 | sub improve_by_ring { |
768 | sub improve_by_ring { |
628 | my ($self, @rings) = @_; |
769 | my ($self, @rings) = @_; |
629 | my $ring = $self; |
770 | my $ring = $self; |
… | |
… | |
645 | if ($self->{hash}->{$cat}->{$k} > 0) { |
786 | if ($self->{hash}->{$cat}->{$k} > 0) { |
646 | $self->{hash}->{$cat}->{$k} *= -1; |
787 | $self->{hash}->{$cat}->{$k} *= -1; |
647 | } |
788 | } |
648 | } |
789 | } |
649 | } |
790 | } |
|
|
791 | $self->{hash}{value} = 0; |
650 | } |
792 | } |
651 | |
793 | |
652 | sub to_string { |
794 | sub to_string { |
653 | my ($self) = @_; |
795 | my ($self) = @_; |
654 | my $r = $self->{hash}; |
796 | my $r = $self->{hash}; |
… | |
… | |
675 | my ($self, $thing) = @_; |
817 | my ($self, $thing) = @_; |
676 | |
818 | |
677 | my $obj = {}; |
819 | my $obj = {}; |
678 | |
820 | |
679 | for (@Jeweler::RESISTS) { |
821 | for (@Jeweler::RESISTS) { |
680 | $obj->{resist}->{$_} = $thing->resistance ($_); |
822 | $obj->{resist}->{$_} = $thing->resist ($_); |
681 | } |
823 | } |
682 | |
824 | |
683 | my $stats = $thing->stats; |
825 | my $stats = $thing->stats; |
684 | |
826 | |
685 | for (qw/Str Dex Con Wis Cha Int Pow/) { |
827 | for (qw/Str Dex Con Wis Cha Int Pow/) { |
… | |
… | |
693 | $obj->{spec}{ac} = $stats->ac; |
835 | $obj->{spec}{ac} = $stats->ac; |
694 | $obj->{spec}{speed} = $stats->exp; |
836 | $obj->{spec}{speed} = $stats->exp; |
695 | $obj->{spec}{food} = $stats->food; |
837 | $obj->{spec}{food} = $stats->food; |
696 | |
838 | |
697 | $obj->{name} = $thing->name; |
839 | $obj->{name} = $thing->name; |
698 | $obj->{arch} = $thing->arch->name; |
840 | $obj->{arch} = $thing->arch->archname; |
699 | $obj->{face} = $thing->face; |
841 | $obj->{face} = $thing->face; |
|
|
842 | |
|
|
843 | $obj->{value} = $thing->value; |
700 | |
844 | |
701 | $self->{hash} = $obj |
845 | $self->{hash} = $obj |
702 | } |
846 | } |
703 | |
847 | |
704 | sub to_object { |
848 | sub to_object { |
705 | my ($self) = @_; |
849 | my ($self) = @_; |
706 | |
850 | |
707 | my $obj = cf::object::new $self->{hash}->{arch}; |
851 | my $obj = cf::object::new $self->{hash}->{arch}; |
|
|
852 | |
|
|
853 | $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached! |
708 | |
854 | |
709 | $obj->face ($self->{hash}{face}); |
855 | $obj->face ($self->{hash}{face}); |
710 | |
856 | |
711 | my $stats = $obj->stats; |
857 | my $stats = $obj->stats; |
712 | |
858 | |
… | |
… | |
720 | |
866 | |
721 | $stats->$_ ($self->{hash}{stat}{lc $_}) |
867 | $stats->$_ ($self->{hash}{stat}{lc $_}) |
722 | for qw/Str Dex Con Wis Cha Int Pow/; |
868 | for qw/Str Dex Con Wis Cha Int Pow/; |
723 | |
869 | |
724 | for (@Jeweler::RESISTS) { |
870 | for (@Jeweler::RESISTS) { |
725 | $obj->resistance ($_, $self->{hash}->{resist}->{$_}); |
871 | $obj->resist ($_, $self->{hash}->{resist}->{$_}); |
726 | } |
872 | } |
727 | |
873 | |
728 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
874 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
729 | |
875 | |
|
|
876 | $obj->value ($self->{hash}{value}); |
|
|
877 | |
730 | return $obj; |
878 | return $obj; |
|
|
879 | } |
|
|
880 | |
|
|
881 | sub set_value { $_[0]->{hash}{value} = $_[1] } |
|
|
882 | |
|
|
883 | sub is_better_than { |
|
|
884 | my ($self, $other) = @_; |
|
|
885 | |
|
|
886 | for my $type (qw/spec stat resist/) { |
|
|
887 | for my $stat (keys %{$self->{hash}->{$type}}) { |
|
|
888 | if ($self->{hash}->{$type}->{$stat} > $other->{hash}->{$type}->{$stat}) { |
|
|
889 | return 1; |
|
|
890 | } |
|
|
891 | } |
|
|
892 | } |
|
|
893 | |
|
|
894 | return 0; |
731 | } |
895 | } |
732 | |
896 | |
733 | sub stat_level { |
897 | sub stat_level { |
734 | my ($self) = @_; |
898 | my ($self) = @_; |
735 | my $stats = $self->{hash}->{stat} || {}; |
899 | my $stats = $self->{hash}->{stat} || {}; |
… | |
… | |
849 | for my $stat (keys %$stats) { |
1013 | for my $stat (keys %$stats) { |
850 | my $sum = $stats->{$stat}; |
1014 | my $sum = $stats->{$stat}; |
851 | |
1015 | |
852 | next unless $sum > 0; |
1016 | next unless $sum > 0; |
853 | |
1017 | |
854 | my $statfx = fx ($sum, 'stat_potions'); |
1018 | my $statfx = fx ($sum, 'stat_items'); |
855 | $cost->{"stat_$stat"} += $statfx->[0]; |
1019 | $cost->{"stat_$stat"} += $statfx->[0]; |
856 | split_diamonds ($cost, $statfx->[1], 'stat_' . $stat); |
1020 | split_diamonds ($cost, $statfx->[1], 'stat_' . $stat); |
857 | } |
1021 | } |
858 | } |
1022 | } |
859 | |
1023 | |
… | |
… | |
865 | for my $spec (keys %$specials) { |
1029 | for my $spec (keys %$specials) { |
866 | my $sum = $specials->{$spec}; |
1030 | my $sum = $specials->{$spec}; |
867 | |
1031 | |
868 | next unless $sum > 0; |
1032 | next unless $sum > 0; |
869 | |
1033 | |
870 | my $specfx = fx ($sum, 'spec_potions'); |
1034 | my $specfx = fx ($sum, 'spec_items'); |
871 | $cost->{"spec_$spec"} += $specfx->[0]; |
1035 | $cost->{"spec_$spec"} += $specfx->[0]; |
872 | split_diamonds ($cost, $specfx->[1], 'spec_' . $spec); |
1036 | split_diamonds ($cost, $specfx->[1], 'spec_' . $spec); |
873 | } |
1037 | } |
874 | } |
1038 | } |
875 | |
1039 | |
… | |
… | |
878 | |
1042 | |
879 | my $costs = {}; |
1043 | my $costs = {}; |
880 | |
1044 | |
881 | my $ring = $self->{hash}; |
1045 | my $ring = $self->{hash}; |
882 | |
1046 | |
883 | for my $resnam (keys %{$ring->{resist} || {}}) { |
1047 | for my $resnum (keys %{$ring->{resist} || {}}) { |
884 | |
1048 | |
885 | my $res = $ring->{resist}->{$resnam}; |
1049 | my $res = $ring->{resist}->{$resnum}; |
886 | |
1050 | |
887 | next unless $res > 0; |
1051 | next unless $res > 0; |
888 | |
1052 | |
|
|
1053 | return undef if $res == 100; |
|
|
1054 | |
889 | $costs->{"resist_" . $Jeweler::RESMAP{$resnam} . "_item"} += $res; |
1055 | $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; |
890 | |
1056 | |
891 | my $diamonds; |
1057 | my $diamonds; |
892 | if (grep { $resnam eq $_ } @Jeweler::EFFECT_RESISTS) { |
1058 | if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { |
893 | $diamonds += fx ($res, 'effect_resist_diamonds'); |
1059 | $diamonds += fx ($res, 'effect_resist_diamonds_x'); |
894 | } else { |
1060 | } else { |
895 | $diamonds += fx ($res, 'attack_resist_diamonds'); |
1061 | $diamonds += fx ($res, 'attack_resist_diamonds_x'); |
896 | } |
1062 | } |
897 | |
1063 | |
898 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnam}); |
1064 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); |
899 | } |
1065 | } |
900 | |
1066 | |
901 | $self->add_stat_costs ($costs); |
1067 | $self->add_stat_costs ($costs); |
902 | $self->add_special_costs ($costs); |
1068 | $self->add_special_costs ($costs); |
903 | |
1069 | |
… | |
… | |
908 | my ($cost, $diamonds, $category) = @_; |
1074 | my ($cost, $diamonds, $category) = @_; |
909 | |
1075 | |
910 | my $stat_split = Jeweler::getcfg (diamond_split => $category); |
1076 | my $stat_split = Jeweler::getcfg (diamond_split => $category); |
911 | |
1077 | |
912 | my $sum = sum (@$stat_split); |
1078 | my $sum = sum (@$stat_split); |
913 | if ($sum < (1 - 0.0001)) { |
|
|
914 | warn "JEWELER BUG: sum (@$stat_split) = $sum < 1 for $category!"; |
|
|
915 | } |
|
|
916 | |
1079 | |
917 | my $emarch = cf::arch::find 'emerald'; |
1080 | my $emarch = cf::arch::find 'emerald'; |
918 | my $saarch = cf::arch::find 'sapphire'; |
1081 | my $saarch = cf::arch::find 'sapphire'; |
919 | my $pearch = cf::arch::find 'pearl'; |
1082 | my $pearch = cf::arch::find 'pearl'; |
920 | my $ruarch = cf::arch::find 'ruby'; |
1083 | my $ruarch = cf::arch::find 'ruby'; |
921 | my $diarch = cf::arch::find 'gem'; |
1084 | my $diarch = cf::arch::find 'gem'; |
922 | |
1085 | |
923 | my $sumvalue = $diarch->clone->value * $diamonds; |
1086 | my $sumvalue = $diarch->value * $diamonds; |
924 | |
1087 | |
925 | $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->clone->value; |
1088 | $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->value; |
926 | $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->clone->value; |
1089 | $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->value; |
927 | $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->clone->value; |
1090 | $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->value; |
928 | $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->clone->value; |
1091 | $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->value; |
929 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->clone->value; |
1092 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
930 | } |
1093 | } |
931 | |
1094 | |
932 | package Jeweler::Util; |
1095 | package Jeweler::Util; |
933 | |
1096 | |
934 | use strict; |
1097 | use strict; |
… | |
… | |
940 | =over 4 |
1103 | =over 4 |
941 | |
1104 | |
942 | =item remove ($object[, $nrof]) |
1105 | =item remove ($object[, $nrof]) |
943 | |
1106 | |
944 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1107 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
945 | The returnvalue is the number of 'single' objects that couldn't be removed. |
1108 | The return value is the number of 'single' objects that couldn't be removed. |
946 | |
1109 | |
947 | =cut |
1110 | =cut |
948 | |
1111 | |
949 | sub remove { |
1112 | sub remove { |
950 | my ($obj, $nrof) = @_; |
1113 | my ($obj, $nrof) = @_; |
|
|
1114 | |
|
|
1115 | my $c = $obj->nrof || 1; |
|
|
1116 | my $r = $c > $nrof ? 0 : $nrof - $c; |
|
|
1117 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
951 | |
1118 | |
952 | my $cnt; |
1119 | $r |
953 | |
|
|
954 | if (defined $nrof) { |
|
|
955 | return 0 if ($nrof * 1) == 0; |
|
|
956 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
|
|
957 | |
|
|
958 | if ($cnt > 0) { |
|
|
959 | $obj->nrof ($cnt); |
|
|
960 | return 0; |
|
|
961 | } |
|
|
962 | } |
|
|
963 | |
|
|
964 | remove ($_) for $obj->inv; |
|
|
965 | $obj->destroy; |
|
|
966 | return $cnt; |
|
|
967 | } |
1120 | } |
968 | |
1121 | |
969 | sub grep_for_match { |
1122 | sub check_for_match { |
970 | my ($thing, @matchar) = @_; |
1123 | my ($thing, @matchar) = @_; |
971 | |
1124 | |
972 | my $i = 0; |
1125 | my $i = 0; |
|
|
1126 | my $check_cnts = 0; |
|
|
1127 | my $check_true = 0; |
973 | for my $match (@matchar) { |
1128 | for my $match (@matchar) { |
|
|
1129 | if ($i % 3 == 0) { |
|
|
1130 | return 1 if $check_true && $check_cnts == $check_true; |
|
|
1131 | $check_cnts = 0; |
|
|
1132 | $check_true = 0; |
|
|
1133 | } |
|
|
1134 | |
974 | if ($match =~ m/^\s*$/) { |
1135 | if ($match =~ m/^\s*$/) { |
975 | $i++; |
1136 | $i++; |
976 | next; |
1137 | next; |
977 | } |
1138 | } |
978 | |
1139 | |
|
|
1140 | $check_cnts++; |
979 | if ($i % 3 == 0) { |
1141 | if ($i % 3 == 0) { |
980 | $thing->name eq $match |
1142 | $thing->name eq $match |
981 | and return 1; |
1143 | and $check_true++; |
982 | } elsif ($i % 3 == 1) { |
1144 | } elsif ($i % 3 == 1) { |
983 | $thing->title eq $match |
1145 | $thing->title eq $match |
984 | and return 1; |
1146 | and $check_true++; |
985 | } else { # $i % 3 == 2 |
1147 | } else { # $i % 3 == 2 |
986 | $thing->arch->name eq $match |
1148 | $thing->arch->archname eq $match |
987 | and return 1; |
1149 | and $check_true++; |
988 | } |
1150 | } |
989 | $i++; |
1151 | $i++; |
990 | } |
1152 | } |
|
|
1153 | #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->archname))."\n"; |
|
|
1154 | return 1 if $check_true && $check_cnts == $check_true; |
991 | return 0; |
1155 | return 0; |
992 | } |
1156 | } |
993 | |
1157 | |
|
|
1158 | sub grep_for_match { |
|
|
1159 | my ($ingred, $group, @matchar) = @_; |
|
|
1160 | |
|
|
1161 | for my $thing (@{$ingred->{$group} || []}) { |
|
|
1162 | #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->archname, "@matchar"; #d# |
|
|
1163 | if (check_for_match ($thing, @matchar)) { |
|
|
1164 | return $thing; |
|
|
1165 | } |
|
|
1166 | } |
|
|
1167 | return undef; |
|
|
1168 | } |
|
|
1169 | |
994 | =back |
1170 | =back |
995 | |
1171 | |
996 | =back |
|
|
997 | |
|
|
998 | 1 |
1172 | 1 |