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