… | |
… | |
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 | |
… | |
… | |
21 | |
20 | |
22 | =cut |
21 | =cut |
23 | |
22 | |
24 | our $CFG; |
23 | our $CFG; |
25 | |
24 | |
26 | sub read_config { |
25 | sub load_config { |
27 | my ($filename) = @_; |
26 | cf::trace "loading jeweler config from $cf::DATADIR/jeweler\n"; |
28 | |
27 | |
29 | unless (-e $filename) { |
28 | 0 < Coro::AIO::aio_load "$cf::DATADIR/jeweler", my $data |
30 | warn "$filename doesn't exists! no config for jeweler skill loaded!\n"; |
29 | or die "$cf::DATADIR/jeweler: $!"; |
31 | $CFG = {}; |
|
|
32 | return |
|
|
33 | } |
|
|
34 | |
30 | |
35 | $CFG = YAML::LoadFile $filename; |
31 | $CFG = cf::decode_json $data; |
36 | } |
32 | } |
37 | |
33 | |
38 | sub getcfg { |
34 | sub getcfg { |
39 | my ($sect, $key) = @_; |
35 | my ($sect, $key) = @_; |
40 | return $CFG->{$sect} unless defined $key; |
36 | return $CFG->{$sect} unless defined $key; |
… | |
… | |
162 | $delta = 5 if $delta > 5; |
158 | $delta = 5 if $delta > 5; |
163 | return $LVL_DIFF_CHANCES{$delta} |
159 | return $LVL_DIFF_CHANCES{$delta} |
164 | } |
160 | } |
165 | |
161 | |
166 | sub analyze { |
162 | sub analyze { |
167 | my ($sk, $chdl, $pl) = @_; |
163 | my ($sk, $chdl, $pl, $input_level) = @_; |
168 | |
164 | |
169 | my $hadunid = 0; |
165 | my $hadunid = 0; |
|
|
166 | my $found = 0; |
170 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
167 | for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { |
171 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
168 | if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { |
172 | $hadunid = 1; |
169 | $hadunid = 1; |
173 | next; |
170 | next; |
174 | } |
171 | } |
|
|
172 | $found = 1; |
175 | my $r = Jeweler::Object->new (object => $_); |
173 | my $r = Jeweler::Object->new (object => $_); |
176 | my $msg = $r->analyze ($sk, $pl); |
174 | my $msg = $r->analyze ($sk, $pl, $input_level); |
177 | $pl->message ($r->to_string . ": " . $msg); |
175 | $pl->message ($r->to_string . ": " . $msg); |
178 | if ($pl->flag (cf::FLAG_WIZ)) { |
176 | if ($pl->flag (cf::FLAG_WIZ)) { |
179 | $r->wiz_analyze ($pl); |
177 | $r->wiz_analyze ($pl); |
180 | } |
178 | } |
181 | } |
179 | } |
182 | if ($hadunid) { |
|
|
183 | $pl->message ("You couldn't identify the other rings and not analyze them!"); |
180 | $pl->message ("You couldn't identify the other rings and not analyze them!") |
184 | } |
181 | if $hadunid; |
|
|
182 | $pl->message ("You couldn't find anything in the bench to analyse!") |
|
|
183 | unless $found; |
185 | } |
184 | } |
186 | |
185 | |
187 | # this function converts metals/minerals into a raw ring (of adornment) |
186 | # this function converts metals/minerals into a raw ring (of adornment) |
188 | sub simple_converter { |
187 | sub simple_converter { |
189 | my ($pl, $ingred, $chdl, $conv) = @_; |
188 | my ($pl, $ingred, $chdl, $conv, $sk_lvl, $low_skill_cb) = @_; |
190 | |
189 | |
191 | $conv = lc $conv; |
190 | $conv = lc $conv; |
192 | my $cnvs = $CFG->{conversions}; |
191 | my $cnvs = $CFG->{conversions}; |
193 | |
192 | |
194 | return unless $cnvs->{$conv}; |
193 | return unless $cnvs->{$conv}; |
… | |
… | |
203 | warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; |
202 | warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; |
204 | return; |
203 | return; |
205 | } |
204 | } |
206 | |
205 | |
207 | unless ($xp_gain > 0) { |
206 | unless ($xp_gain > 0) { |
208 | warn "WARNING: xp gain isn't > 0 in convesion '$outarch'\n"; |
207 | warn "WARNING: xp gain isn't > 0 in conversion '$outarch'\n"; |
209 | return; |
208 | return; |
210 | } |
209 | } |
211 | |
210 | |
212 | unless ($outarchvalfact) { |
211 | unless ($outarchvalfact) { |
213 | warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; |
212 | warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; |
… | |
… | |
216 | |
215 | |
217 | unless ($outarchvalfact >= 1) { |
216 | unless ($outarchvalfact >= 1) { |
218 | warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n"; |
217 | warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n"; |
219 | } |
218 | } |
220 | |
219 | |
221 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
220 | my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); |
222 | $ingred->remove ($ingr_grp, $srcarchname); |
|
|
223 | |
|
|
224 | my $outarchval = cf::arch::find ($outarch)->clone->value; |
221 | my $outarchval = cf::arch::find ($outarch)->value; |
225 | |
|
|
226 | my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); |
222 | my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact); |
|
|
223 | my $can_make_nr = int (($sk_lvl / 2) + 10); |
|
|
224 | |
|
|
225 | if ($nrof > $can_make_nr) { |
|
|
226 | $pl->ob->message ("Your jeweler level is too low to make $nrof rings, you can only make $can_make_nr at your current level."); |
|
|
227 | return; |
|
|
228 | } |
|
|
229 | |
227 | if ($nrof) { |
230 | if ($nrof) { |
228 | # XXX: yes, i know what i'm doing here, i don't set nrof, but it didn't work somehow (pls. chek sometimes) |
231 | # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes) |
|
|
232 | $ingred->remove ($ingr_grp, $srcarchname); |
229 | for (1..$nrof) { |
233 | for (1 .. $nrof) { |
230 | $chdl->put (my $ob = cf::object::new $outarch); |
234 | $chdl->put (my $ob = cf::object::new $outarch); |
231 | $ob->set_animation (cf::rndm $ob->num_animations); |
235 | $ob->set_animation (cf::rndm $ob->num_animations) |
|
|
236 | if ($ob->type == cf::RING); |
232 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
237 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
233 | } |
238 | } |
234 | |
239 | |
235 | my $xp_sum = ($xp_gain * $nrof); |
240 | my $xp_sum = $xp_gain * $nrof; |
236 | |
241 | |
237 | if ($xp_sum) { |
242 | if ($xp_sum) { |
238 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
243 | $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); |
239 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
244 | $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY); |
240 | } |
245 | } |
241 | } else { |
246 | } else { |
242 | $pl->ob->message ("You fail to make something, propably you used not enough source material?"); |
247 | $pl->ob->message ("You fail to make something, probably you used not enough source material?"); |
243 | } |
248 | } |
244 | } |
249 | } |
245 | |
250 | |
246 | |
251 | |
247 | package Jeweler::CauldronHandler; |
252 | package Jeweler::CauldronHandler; |
248 | |
253 | |
249 | use strict; |
254 | use common::sense; |
250 | |
255 | |
251 | =head2 CauldronHandler |
256 | =head2 CauldronHandler |
252 | |
257 | |
253 | The Jeweler::CauldronHandler package, that helps you with handling the |
258 | The Jeweler::CauldronHandler package, that helps you with handling the |
254 | cauldron stuff. Can also be used for other skills. |
259 | cauldron stuff. Can also be used for other skills. |
… | |
… | |
279 | my ($self, $arch_name, @map_stack) = @_; |
284 | my ($self, $arch_name, @map_stack) = @_; |
280 | |
285 | |
281 | my @c = |
286 | my @c = |
282 | grep { |
287 | grep { |
283 | $_->flag (cf::FLAG_IS_CAULDRON) |
288 | $_->flag (cf::FLAG_IS_CAULDRON) |
284 | and $_->arch->name eq $arch_name |
289 | and $_->arch->archname eq $arch_name |
285 | } @map_stack; |
290 | } @map_stack; |
286 | |
291 | |
287 | $self->{cauldron} = $c[0]; |
292 | $self->{cauldron} = $c[0]; |
288 | } |
293 | } |
289 | |
294 | |
… | |
… | |
354 | |
359 | |
355 | sub put { |
360 | sub put { |
356 | my ($self, $obj) = @_; |
361 | my ($self, $obj) = @_; |
357 | |
362 | |
358 | return undef unless $self->{cauldron}; |
363 | return undef unless $self->{cauldron}; |
359 | $obj->insert_ob_in_ob ($self->{cauldron}); |
364 | $self->{cauldron}->insert ($obj); |
360 | } |
365 | } |
361 | |
366 | |
362 | =back |
367 | =back |
363 | |
368 | |
364 | =cut |
369 | =cut |
365 | |
370 | |
366 | package Jeweler::Ingredients; |
371 | package Jeweler::Ingredients; |
|
|
372 | |
|
|
373 | use common::sense; |
|
|
374 | |
367 | use Storable qw/dclone/; |
375 | use Storable qw/dclone/; |
368 | use strict; |
|
|
369 | |
376 | |
370 | =head2 Ingredients |
377 | =head2 Ingredients |
371 | |
378 | |
372 | This class handles the ingredients. |
379 | This class handles the ingredients. |
373 | |
380 | |
… | |
… | |
397 | |
404 | |
398 | sub value { |
405 | sub value { |
399 | my ($self, $group, $archname) = @_; |
406 | my ($self, $group, $archname) = @_; |
400 | |
407 | |
401 | my @objs = grep { |
408 | my @objs = grep { |
402 | $_->arch->name eq $archname |
409 | $_->arch->archname eq $archname |
403 | } @{$self->{ingredients}->{$group} || []}; |
410 | } @{$self->{ingredients}->{$group} || []}; |
404 | |
411 | |
405 | my $sum = 0; |
412 | my $sum = 0; |
406 | for (@objs) { |
413 | for (@objs) { |
407 | $sum += ($_->nrof || 1) * $_->value; |
414 | $sum += ($_->nrof || 1) * $_->value; |
… | |
… | |
424 | |
431 | |
425 | my @out; |
432 | my @out; |
426 | |
433 | |
427 | for (@{$ingred->{$group}}) { |
434 | for (@{$ingred->{$group}}) { |
428 | if (defined $archname) { |
435 | if (defined $archname) { |
429 | if ($_->arch->name eq $archname) { |
436 | if ($_->arch->archname eq $archname) { |
430 | Jeweler::Util::remove ($_); |
437 | Jeweler::Util::remove ($_); |
431 | } else { |
438 | } else { |
432 | push @out, $_; |
439 | push @out, $_; |
433 | } |
440 | } |
434 | } else { |
441 | } else { |
… | |
… | |
476 | } |
483 | } |
477 | |
484 | |
478 | sub improve_ring_by_plan { |
485 | sub improve_ring_by_plan { |
479 | my ($self, $plan, $ring) = @_; |
486 | my ($self, $plan, $ring) = @_; |
480 | |
487 | |
481 | $ring = dclone ($ring); |
488 | $ring = dclone $ring; |
482 | |
489 | |
483 | my $ingred = $self->{ingredients}; |
490 | my $ingred = $self->{ingredients}; |
484 | my $impr = {}; |
491 | my $impr = {}; |
485 | |
492 | |
486 | if ($plan =~ m/^stat_(\S+)$/) { |
493 | if ($plan =~ m/^stat_(\S+)$/) { |
… | |
… | |
570 | } |
577 | } |
571 | |
578 | |
572 | sub check_costs { |
579 | sub check_costs { |
573 | my ($self, $costs, $do_remove) = @_; |
580 | my ($self, $costs, $do_remove) = @_; |
574 | |
581 | |
575 | my $costs = dclone ($costs); |
582 | my $costs = dclone $costs; |
576 | |
583 | |
577 | for my $key (keys %$costs) { |
584 | for my $key (keys %$costs) { |
578 | my @grepar; |
585 | my @grepar; |
579 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
586 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
580 | @grepar = @{Jeweler::getcfg (plans => $key) || []}; |
587 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
|
|
588 | next if $@; |
581 | } else { # check the gems |
589 | } else { # check the gems |
582 | @grepar = ('gems', undef, undef, $key); |
590 | @grepar = ('gems', undef, undef, $key); |
583 | } |
591 | } |
584 | |
592 | |
585 | if ($do_remove) { |
593 | if ($do_remove) { |
586 | my $rem = $costs->{$key}; |
594 | my $rem = $costs->{$key}; |
587 | $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); |
595 | $self->do_grep (sub { |
|
|
596 | if ($rem) { |
|
|
597 | $rem = Jeweler::Util::remove ($_[0], $rem); |
|
|
598 | } |
|
|
599 | 1 |
|
|
600 | }, @grepar); |
588 | if ($rem > 0) { |
601 | if ($rem > 0) { |
589 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
602 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
590 | } |
603 | } |
|
|
604 | |
591 | } else { |
605 | } else { |
592 | my $nr; |
606 | my $nr; |
593 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
607 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
594 | $costs->{$key} -= $nr; |
608 | $costs->{$key} -= $nr; |
595 | } |
609 | } |
… | |
… | |
614 | } |
628 | } |
615 | } |
629 | } |
616 | } |
630 | } |
617 | |
631 | |
618 | package Jeweler::Object; |
632 | package Jeweler::Object; |
619 | use strict; |
633 | |
|
|
634 | use common::sense; |
620 | use POSIX; |
635 | use POSIX; |
621 | use List::Util qw/max min sum/; |
636 | use List::Util qw/max min sum/; |
622 | |
637 | |
623 | sub new { |
638 | sub new { |
624 | my ($class, %arg) = @_; |
639 | my ($class, %arg) = @_; |
… | |
… | |
639 | return 1 if $self->{hash}->{resist}->{$resnum}; |
654 | return 1 if $self->{hash}->{resist}->{$resnum}; |
640 | } |
655 | } |
641 | return undef; |
656 | return undef; |
642 | } |
657 | } |
643 | |
658 | |
|
|
659 | sub lvl2exp { |
|
|
660 | my $lvl = shift; |
|
|
661 | (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) |
|
|
662 | / (20 + max ($lvl - 1, 0)) # 20 + level times making such a ring |
|
|
663 | # should get you to the rings level at least. |
|
|
664 | } |
|
|
665 | |
|
|
666 | sub projected_exp { |
|
|
667 | my ($self, $input_level) = @_; |
|
|
668 | |
|
|
669 | my $lvl = max ($self->power_to_level, 1); |
|
|
670 | my $exp = lvl2exp ($lvl); |
|
|
671 | |
|
|
672 | if (defined $input_level) { # in case we merge rings: |
|
|
673 | my $subexp = lvl2exp ($input_level); |
|
|
674 | $exp -= $subexp; |
|
|
675 | $exp = max ($exp, 0); |
|
|
676 | |
|
|
677 | } else { |
|
|
678 | # the experience bonus here is to make level 1 rings give you at least |
|
|
679 | # 200 exp points when making them. This also makes leveling in the |
|
|
680 | # first few levels a bit easier. (probably until around level 5-6). |
|
|
681 | my $expbonus = cf::level_to_min_exp (2) / 5; |
|
|
682 | # this bonus should also only be given for _new_ rings and not for merged |
|
|
683 | # ones - to prevent infinite exp making. |
|
|
684 | $exp += $expbonus; |
|
|
685 | } |
|
|
686 | |
|
|
687 | $exp |
|
|
688 | } |
|
|
689 | |
644 | sub analyze { |
690 | sub analyze { |
645 | my ($self, $sk, $pl) = @_; |
691 | my ($self, $sk, $pl, $input_level) = @_; |
|
|
692 | my $costs = $self->calc_costs; |
|
|
693 | |
|
|
694 | unless (defined $costs) { |
|
|
695 | return "This ring has a resistancy above 99%, you can't make that."; |
|
|
696 | } |
646 | |
697 | |
647 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
698 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
648 | my $ringlvl = $self->power_to_level; |
699 | my $ringlvl = $self->power_to_level; |
649 | |
700 | |
650 | my $tmpl; |
701 | my $tmpl; |
651 | if ($pl->flag (cf::FLAG_WIZ)) { |
702 | if ($pl->flag (cf::FLAG_WIZ)) { |
652 | $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); |
703 | $tmpl = Jeweler::level_diff_to_chance_perc ($sklvl - $ringlvl); |
653 | } else { |
704 | } else { |
654 | $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); |
705 | $tmpl = Jeweler::level_diff_to_str ($sklvl - $ringlvl); |
655 | } |
706 | } |
656 | my $msg = sprintf "Projected success rate: %s", $tmpl; |
707 | my $msg = sprintf "Projected success rate: %s, you would get %d exp for this.", $tmpl, $self->projected_exp ($input_level); |
657 | return $msg; |
708 | return $msg; |
658 | } |
709 | } |
659 | |
710 | |
660 | sub wiz_analyze { |
711 | sub calc_value_from_cost { |
661 | my ($self, $pl) = @_; |
712 | my ($self, $costs) = @_; |
662 | my $costs = $self->calc_costs; |
|
|
663 | my $desc = ""; |
|
|
664 | my $lvl = $self->power_to_level (\$desc); |
|
|
665 | my $emarch = cf::arch::find 'emerald'; |
713 | my $emarch = cf::arch::find 'emerald'; |
666 | my $saarch = cf::arch::find 'sapphire'; |
714 | my $saarch = cf::arch::find 'sapphire'; |
667 | my $pearch = cf::arch::find 'pearl'; |
715 | my $pearch = cf::arch::find 'pearl'; |
668 | my $ruarch = cf::arch::find 'ruby'; |
716 | my $ruarch = cf::arch::find 'ruby'; |
669 | my $diarch = cf::arch::find 'gem'; |
717 | my $diarch = cf::arch::find 'gem'; |
670 | my $scosts = $emarch->clone->value * $costs->{emerald} |
718 | my $value = $emarch->value * $costs->{emerald} |
671 | + $saarch->clone->value * $costs->{sapphire} |
719 | + $saarch->value * $costs->{sapphire} |
672 | + $pearch->clone->value * $costs->{pearl} |
720 | + $pearch->value * $costs->{pearl} |
673 | + $ruarch->clone->value * $costs->{ruby} |
721 | + $ruarch->value * $costs->{ruby} |
674 | + $diarch->clone->value * $costs->{gem}; |
722 | + $diarch->value * $costs->{gem}; |
675 | |
723 | |
676 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
724 | $value |
|
|
725 | } |
|
|
726 | |
|
|
727 | sub wiz_analyze { |
|
|
728 | my ($self, $pl) = @_; |
|
|
729 | my $costs = $self->calc_costs; |
|
|
730 | if (defined $costs) { |
|
|
731 | my $desc = ""; |
|
|
732 | my $lvl = $self->power_to_level (\$desc); |
|
|
733 | my $scosts = $self->calc_value_from_cost ($costs); |
|
|
734 | |
|
|
735 | $pl->message ("costs: " |
|
|
736 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
|
|
737 | . " (" |
|
|
738 | . ($scosts / "platinacoin"->cf::arch::find->value) |
|
|
739 | . " platinum)"); |
677 | $pl->message ("level: " . $desc); |
740 | $pl->message ("level: $desc"); |
|
|
741 | } else { |
|
|
742 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
|
|
743 | } |
678 | } |
744 | } |
679 | |
|
|
680 | |
745 | |
681 | sub get_chance_perc { |
746 | sub get_chance_perc { |
682 | my ($self, $sk) = @_; |
747 | my ($self, $sk) = @_; |
683 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
748 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
684 | my $ringlvl = $self->power_to_level; |
749 | my $ringlvl = $self->power_to_level; |
… | |
… | |
687 | |
752 | |
688 | sub fx { |
753 | sub fx { |
689 | my ($res, $cfg) = @_; |
754 | my ($res, $cfg) = @_; |
690 | my $or = $res; |
755 | my $or = $res; |
691 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
756 | my $ar = $Jeweler::CFG->{functions}->{$cfg}; |
|
|
757 | |
692 | if (ref $ar->[0] eq 'ARRAY') { |
758 | if (ref $ar && ref $ar->[0] eq 'ARRAY') { |
693 | $res = $res - 1; |
759 | $res = $res - 1; |
|
|
760 | return $ar->[max (min ($res, @$ar - 1), 0)]; |
|
|
761 | |
694 | } else { |
762 | } else { |
695 | $res = ceil ($res / 5) - 1; |
763 | # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3... |
696 | } |
764 | # old code: |
|
|
765 | #my $idx = ceil (($res / 5) + 0.1) - 1; |
697 | $ar->[max (min ($res, @$ar - 1), 0)]; |
766 | #my $a = $ar->[max (min ($idx, @$ar - 1), 0)]; |
|
|
767 | #my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)]; |
|
|
768 | #my $diff = $b - $a; # use the difference of the cost to the next cost |
|
|
769 | #my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation |
|
|
770 | #return $o_cost; |
|
|
771 | return 0 if $res <= 0; |
|
|
772 | return ($ar / (1 - ($res * 0.01)) - $ar) |
|
|
773 | } |
698 | } |
774 | } |
699 | |
775 | |
700 | sub improve_by_ring { |
776 | sub improve_by_ring { |
701 | my ($self, @rings) = @_; |
777 | my ($self, @rings) = @_; |
702 | my $ring = $self; |
778 | my $ring = $self; |
… | |
… | |
718 | if ($self->{hash}->{$cat}->{$k} > 0) { |
794 | if ($self->{hash}->{$cat}->{$k} > 0) { |
719 | $self->{hash}->{$cat}->{$k} *= -1; |
795 | $self->{hash}->{$cat}->{$k} *= -1; |
720 | } |
796 | } |
721 | } |
797 | } |
722 | } |
798 | } |
|
|
799 | $self->{hash}{value} = 0; |
723 | } |
800 | } |
724 | |
801 | |
725 | sub to_string { |
802 | sub to_string { |
726 | my ($self) = @_; |
803 | my ($self) = @_; |
727 | my $r = $self->{hash}; |
804 | my $r = $self->{hash}; |
… | |
… | |
766 | $obj->{spec}{ac} = $stats->ac; |
843 | $obj->{spec}{ac} = $stats->ac; |
767 | $obj->{spec}{speed} = $stats->exp; |
844 | $obj->{spec}{speed} = $stats->exp; |
768 | $obj->{spec}{food} = $stats->food; |
845 | $obj->{spec}{food} = $stats->food; |
769 | |
846 | |
770 | $obj->{name} = $thing->name; |
847 | $obj->{name} = $thing->name; |
771 | $obj->{arch} = $thing->arch->name; |
848 | $obj->{arch} = $thing->arch->archname; |
772 | $obj->{face} = $thing->face; |
849 | $obj->{face} = $thing->face; |
|
|
850 | |
|
|
851 | $obj->{value} = $thing->value; |
|
|
852 | |
|
|
853 | $obj->{is_ring} = ($thing->type == cf::RING); |
773 | |
854 | |
774 | $self->{hash} = $obj |
855 | $self->{hash} = $obj |
775 | } |
856 | } |
776 | |
857 | |
777 | sub to_object { |
858 | sub to_object { |
778 | my ($self) = @_; |
859 | my ($self) = @_; |
779 | |
860 | |
780 | my $obj = cf::object::new $self->{hash}->{arch}; |
861 | my $obj = cf::object::new $self->{hash}->{arch}; |
781 | |
862 | |
782 | $obj->item_power ($self->power_to_level); # there have to be strings attached! |
863 | $obj->item_power (floor ($self->power_to_level / 5)); # there have to be strings attached! |
783 | |
864 | |
784 | $obj->face ($self->{hash}{face}); |
865 | $obj->face ($self->{hash}{face}); |
785 | |
866 | |
786 | my $stats = $obj->stats; |
867 | my $stats = $obj->stats; |
787 | |
868 | |
… | |
… | |
800 | $obj->resist ($_, $self->{hash}->{resist}->{$_}); |
881 | $obj->resist ($_, $self->{hash}->{resist}->{$_}); |
801 | } |
882 | } |
802 | |
883 | |
803 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
884 | $obj->flag (cf::FLAG_IDENTIFIED, 1); |
804 | |
885 | |
|
|
886 | $obj->value ($self->{hash}{value}); |
|
|
887 | |
805 | return $obj; |
888 | return $obj; |
806 | } |
889 | } |
|
|
890 | |
|
|
891 | sub set_value { $_[0]->{hash}{value} = $_[1] } |
807 | |
892 | |
808 | sub is_better_than { |
893 | sub is_better_than { |
809 | my ($self, $other) = @_; |
894 | my ($self, $other) = @_; |
810 | |
895 | |
811 | for my $type (qw/spec stat resist/) { |
896 | for my $type (qw/spec stat resist/) { |
… | |
… | |
836 | sub resist_level { |
921 | sub resist_level { |
837 | my ($self) = @_; |
922 | my ($self) = @_; |
838 | |
923 | |
839 | my $resists = $self->{hash}->{resist} || {}; |
924 | my $resists = $self->{hash}->{resist} || {}; |
840 | |
925 | |
841 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
926 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
842 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
927 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
843 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
928 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
844 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
929 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
845 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
930 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
846 | |
931 | |
847 | my $ressum = 0; |
932 | my $ressum = 0; |
… | |
… | |
907 | sub power_to_level { |
992 | sub power_to_level { |
908 | my ($self, $lvldescr) = @_; |
993 | my ($self, $lvldescr) = @_; |
909 | |
994 | |
910 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
995 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
911 | my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); |
996 | my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); |
|
|
997 | my $ring_offs = Jeweler::getcfg (maxlevels => 'ring_offset'); |
912 | |
998 | |
913 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
999 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
914 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
1000 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
915 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
1001 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
916 | |
1002 | |
917 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
1003 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
918 | |
1004 | |
919 | my $impr_lvl = ceil (($max_impr_lvl / ($max_imprs + 1)) * ($impr_sum - 1)); # 1 improvemnt bonus |
1005 | my $impr_lvl = |
|
|
1006 | ceil (($max_impr_lvl / ($max_imprs + 1)) |
|
|
1007 | * ($impr_sum - 1)); # 1 improvemnt bonus |
920 | |
1008 | |
921 | my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); |
1009 | my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); |
|
|
1010 | |
|
|
1011 | if ($self->{hash}->{is_ring}) { |
|
|
1012 | $levl += $ring_offs; |
|
|
1013 | } |
|
|
1014 | |
|
|
1015 | $levl = min ($levl, cf::settings->max_level); |
922 | |
1016 | |
923 | if ($lvldescr) { |
1017 | if ($lvldescr) { |
924 | $$lvldescr = |
1018 | $$lvldescr = |
925 | sprintf "%3d: %s\n", $levl, |
1019 | sprintf "%3d: %s\n", $levl, |
926 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
1020 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
… | |
… | |
973 | |
1067 | |
974 | my $res = $ring->{resist}->{$resnum}; |
1068 | my $res = $ring->{resist}->{$resnum}; |
975 | |
1069 | |
976 | next unless $res > 0; |
1070 | next unless $res > 0; |
977 | |
1071 | |
|
|
1072 | return undef if $res == 100; |
|
|
1073 | |
978 | $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; |
1074 | $costs->{"resist_" . $Jeweler::RESMAP{$resnum}} += $res; |
979 | |
1075 | |
980 | my $diamonds; |
1076 | my $diamonds; |
981 | if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { |
1077 | if (grep { $resnum eq $_ } @Jeweler::EFFECT_RESISTS) { |
982 | $diamonds += fx ($res, 'effect_resist_diamonds'); |
1078 | $diamonds += fx ($res, 'effect_resist_diamonds_x'); |
983 | } else { |
1079 | } else { |
984 | $diamonds += fx ($res, 'attack_resist_diamonds'); |
1080 | $diamonds += fx ($res, 'attack_resist_diamonds_x'); |
985 | } |
1081 | } |
986 | |
1082 | |
987 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); |
1083 | split_diamonds ($costs, $diamonds, 'resist_' . $Jeweler::RESMAP{$resnum}); |
988 | } |
1084 | } |
989 | |
1085 | |
… | |
… | |
997 | my ($cost, $diamonds, $category) = @_; |
1093 | my ($cost, $diamonds, $category) = @_; |
998 | |
1094 | |
999 | my $stat_split = Jeweler::getcfg (diamond_split => $category); |
1095 | my $stat_split = Jeweler::getcfg (diamond_split => $category); |
1000 | |
1096 | |
1001 | my $sum = sum (@$stat_split); |
1097 | my $sum = sum (@$stat_split); |
1002 | if ($sum < (1 - 0.0001)) { |
|
|
1003 | warn "JEWELER BUG: sum (@$stat_split) = $sum < 1 for $category!"; |
|
|
1004 | } |
|
|
1005 | |
1098 | |
1006 | my $emarch = cf::arch::find 'emerald'; |
1099 | my $emarch = cf::arch::find 'emerald'; |
1007 | my $saarch = cf::arch::find 'sapphire'; |
1100 | my $saarch = cf::arch::find 'sapphire'; |
1008 | my $pearch = cf::arch::find 'pearl'; |
1101 | my $pearch = cf::arch::find 'pearl'; |
1009 | my $ruarch = cf::arch::find 'ruby'; |
1102 | my $ruarch = cf::arch::find 'ruby'; |
1010 | my $diarch = cf::arch::find 'gem'; |
1103 | my $diarch = cf::arch::find 'gem'; |
1011 | |
1104 | |
1012 | my $sumvalue = $diarch->clone->value * $diamonds; |
1105 | my $sumvalue = $diarch->value * $diamonds; |
1013 | |
1106 | |
1014 | $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->clone->value; |
1107 | $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->value; |
1015 | $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->clone->value; |
1108 | $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->value; |
1016 | $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->clone->value; |
1109 | $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->value; |
1017 | $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->clone->value; |
1110 | $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->value; |
1018 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->clone->value; |
1111 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1019 | } |
1112 | } |
1020 | |
1113 | |
1021 | package Jeweler::Util; |
1114 | package Jeweler::Util; |
1022 | |
1115 | |
1023 | use strict; |
1116 | use common::sense; |
1024 | |
1117 | |
1025 | =head2 Util |
1118 | =head2 Util |
1026 | |
1119 | |
1027 | Some utility functions for the Jeweler skill. |
1120 | Some utility functions for the Jeweler skill. |
1028 | |
1121 | |
1029 | =over 4 |
1122 | =over 4 |
1030 | |
1123 | |
1031 | =item remove ($object[, $nrof]) |
1124 | =item remove ($object[, $nrof]) |
1032 | |
1125 | |
1033 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1126 | Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. |
1034 | The returnvalue is the number of 'single' objects that couldn't be removed. |
1127 | The return value is the number of 'single' objects that couldn't be removed. |
1035 | |
1128 | |
1036 | =cut |
1129 | =cut |
1037 | |
1130 | |
1038 | sub remove { |
1131 | sub remove { |
1039 | my ($obj, $nrof) = @_; |
1132 | my ($obj, $nrof) = @_; |
1040 | |
1133 | |
1041 | my $cnt; |
1134 | my $c = $obj->number_of; |
|
|
1135 | my $r = $c > $nrof ? 0 : $nrof - $c; |
|
|
1136 | $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); |
1042 | |
1137 | |
1043 | if (defined $nrof) { |
1138 | $r |
1044 | # TODO: Check tihis line: |
|
|
1045 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
|
|
1046 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
|
|
1047 | |
|
|
1048 | if ($cnt > 0) { |
|
|
1049 | $obj->nrof ($cnt); |
|
|
1050 | return 0; |
|
|
1051 | } |
|
|
1052 | } |
|
|
1053 | |
|
|
1054 | remove ($_) for $obj->inv; |
|
|
1055 | $obj->destroy; |
|
|
1056 | return $cnt; |
|
|
1057 | } |
1139 | } |
1058 | |
1140 | |
1059 | sub check_for_match { |
1141 | sub check_for_match { |
1060 | my ($thing, @matchar) = @_; |
1142 | my ($thing, @matchar) = @_; |
1061 | |
1143 | |
1062 | my $i = 0; |
1144 | my $i = 0; |
|
|
1145 | my $check_cnts = 0; |
|
|
1146 | my $check_true = 0; |
1063 | for my $match (@matchar) { |
1147 | for my $match (@matchar) { |
|
|
1148 | if ($i % 3 == 0) { |
|
|
1149 | return 1 if $check_true && $check_cnts == $check_true; |
|
|
1150 | $check_cnts = 0; |
|
|
1151 | $check_true = 0; |
|
|
1152 | } |
|
|
1153 | |
1064 | if ($match =~ m/^\s*$/) { |
1154 | if ($match =~ m/^\s*$/) { |
1065 | $i++; |
1155 | $i++; |
1066 | next; |
1156 | next; |
1067 | } |
1157 | } |
1068 | |
1158 | |
|
|
1159 | $check_cnts++; |
1069 | if ($i % 3 == 0) { |
1160 | if ($i % 3 == 0) { |
1070 | $thing->name eq $match |
1161 | $thing->name eq $match |
1071 | and return 1; |
1162 | and $check_true++; |
1072 | } elsif ($i % 3 == 1) { |
1163 | } elsif ($i % 3 == 1) { |
1073 | $thing->title eq $match |
1164 | $thing->title eq $match |
1074 | and return 1; |
1165 | and $check_true++; |
1075 | } else { # $i % 3 == 2 |
1166 | } else { # $i % 3 == 2 |
1076 | $thing->arch->name eq $match |
1167 | $thing->arch->archname eq $match |
1077 | and return 1; |
1168 | and $check_true++; |
1078 | } |
1169 | } |
1079 | $i++; |
1170 | $i++; |
1080 | } |
1171 | } |
|
|
1172 | #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->archname))."\n"; |
|
|
1173 | return 1 if $check_true && $check_cnts == $check_true; |
1081 | return 0; |
1174 | return 0; |
1082 | } |
1175 | } |
1083 | |
1176 | |
1084 | sub grep_for_match { |
1177 | sub grep_for_match { |
1085 | my ($ingred, $group, @matchar) = @_; |
1178 | my ($ingred, $group, @matchar) = @_; |
1086 | |
1179 | |
1087 | for my $thing (@{$ingred->{$group} || []}) { |
1180 | for my $thing (@{$ingred->{$group} || []}) { |
1088 | warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# |
1181 | #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->archname, "@matchar"; #d# |
1089 | if (check_for_match ($thing, @matchar)) { |
1182 | if (check_for_match ($thing, @matchar)) { |
1090 | return $thing; |
1183 | return $thing; |
1091 | } |
1184 | } |
1092 | } |
1185 | } |
1093 | return undef; |
1186 | return undef; |