… | |
… | |
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; |
… | |
… | |
165 | |
161 | |
166 | sub analyze { |
162 | sub analyze { |
167 | my ($sk, $chdl, $pl, $input_level) = @_; |
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, $input_level); |
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)->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) |
232 | if ($ob->type == cf::RING); |
236 | if ($ob->type == cf::RING); |
233 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
237 | $ob->flag (cf::FLAG_IDENTIFIED, 1); |
234 | } |
238 | } |
235 | |
239 | |
236 | my $xp_sum = ($xp_gain * $nrof); |
240 | my $xp_sum = $xp_gain * $nrof; |
237 | |
241 | |
238 | if ($xp_sum) { |
242 | if ($xp_sum) { |
239 | $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"); |
240 | $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); |
241 | } |
245 | } |
… | |
… | |
245 | } |
249 | } |
246 | |
250 | |
247 | |
251 | |
248 | package Jeweler::CauldronHandler; |
252 | package Jeweler::CauldronHandler; |
249 | |
253 | |
250 | use strict; |
254 | use common::sense; |
251 | |
255 | |
252 | =head2 CauldronHandler |
256 | =head2 CauldronHandler |
253 | |
257 | |
254 | The Jeweler::CauldronHandler package, that helps you with handling the |
258 | The Jeweler::CauldronHandler package, that helps you with handling the |
255 | cauldron stuff. Can also be used for other skills. |
259 | cauldron stuff. Can also be used for other skills. |
… | |
… | |
363 | =back |
367 | =back |
364 | |
368 | |
365 | =cut |
369 | =cut |
366 | |
370 | |
367 | package Jeweler::Ingredients; |
371 | package Jeweler::Ingredients; |
|
|
372 | |
|
|
373 | use common::sense; |
|
|
374 | |
368 | use Storable qw/dclone/; |
375 | use Storable qw/dclone/; |
369 | use strict; |
|
|
370 | |
376 | |
371 | =head2 Ingredients |
377 | =head2 Ingredients |
372 | |
378 | |
373 | This class handles the ingredients. |
379 | This class handles the ingredients. |
374 | |
380 | |
… | |
… | |
477 | } |
483 | } |
478 | |
484 | |
479 | sub improve_ring_by_plan { |
485 | sub improve_ring_by_plan { |
480 | my ($self, $plan, $ring) = @_; |
486 | my ($self, $plan, $ring) = @_; |
481 | |
487 | |
482 | $ring = dclone ($ring); |
488 | $ring = dclone $ring; |
483 | |
489 | |
484 | my $ingred = $self->{ingredients}; |
490 | my $ingred = $self->{ingredients}; |
485 | my $impr = {}; |
491 | my $impr = {}; |
486 | |
492 | |
487 | if ($plan =~ m/^stat_(\S+)$/) { |
493 | if ($plan =~ m/^stat_(\S+)$/) { |
… | |
… | |
571 | } |
577 | } |
572 | |
578 | |
573 | sub check_costs { |
579 | sub check_costs { |
574 | my ($self, $costs, $do_remove) = @_; |
580 | my ($self, $costs, $do_remove) = @_; |
575 | |
581 | |
576 | my $costs = dclone ($costs); |
582 | my $costs = dclone $costs; |
577 | |
583 | |
578 | for my $key (keys %$costs) { |
584 | for my $key (keys %$costs) { |
579 | my @grepar; |
585 | my @grepar; |
580 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
586 | if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items |
581 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
587 | eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; |
… | |
… | |
584 | @grepar = ('gems', undef, undef, $key); |
590 | @grepar = ('gems', undef, undef, $key); |
585 | } |
591 | } |
586 | |
592 | |
587 | if ($do_remove) { |
593 | if ($do_remove) { |
588 | my $rem = $costs->{$key}; |
594 | my $rem = $costs->{$key}; |
589 | $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); |
590 | if ($rem > 0) { |
601 | if ($rem > 0) { |
591 | warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; |
602 | warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; |
592 | } |
603 | } |
|
|
604 | |
593 | } else { |
605 | } else { |
594 | my $nr; |
606 | my $nr; |
595 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
607 | $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); |
596 | $costs->{$key} -= $nr; |
608 | $costs->{$key} -= $nr; |
597 | } |
609 | } |
… | |
… | |
616 | } |
628 | } |
617 | } |
629 | } |
618 | } |
630 | } |
619 | |
631 | |
620 | package Jeweler::Object; |
632 | package Jeweler::Object; |
621 | use strict; |
633 | |
|
|
634 | use common::sense; |
622 | use POSIX; |
635 | use POSIX; |
623 | use List::Util qw/max min sum/; |
636 | use List::Util qw/max min sum/; |
624 | |
637 | |
625 | sub new { |
638 | sub new { |
626 | my ($class, %arg) = @_; |
639 | my ($class, %arg) = @_; |
… | |
… | |
641 | return 1 if $self->{hash}->{resist}->{$resnum}; |
654 | return 1 if $self->{hash}->{resist}->{$resnum}; |
642 | } |
655 | } |
643 | return undef; |
656 | return undef; |
644 | } |
657 | } |
645 | |
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 | |
646 | sub projected_exp { |
666 | sub projected_exp { |
647 | my ($self, $input_level) = @_; |
667 | my ($self, $input_level) = @_; |
648 | |
668 | |
649 | my $lvl = max ($self->power_to_level, 1); |
669 | my $lvl = max ($self->power_to_level, 1); |
650 | my $exp = |
670 | my $exp = lvl2exp ($lvl); |
651 | (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) |
|
|
652 | / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring |
|
|
653 | # should get you to the rings level at least. |
|
|
654 | |
671 | |
655 | if (defined $input_level) { |
672 | if (defined $input_level) { # in case we merge rings: |
656 | my $subexp = |
673 | my $subexp = lvl2exp ($input_level); |
657 | (cf::level_to_min_exp ($input_level) |
|
|
658 | - cf::level_to_min_exp ($input_level - 1)) |
|
|
659 | / (10 + max ($input_level - 1, 0)); # see above for comment |
|
|
660 | |
|
|
661 | $exp -= $subexp; |
674 | $exp -= $subexp; |
662 | $exp = max ($exp, 0); |
675 | $exp = max ($exp, 0); |
663 | |
676 | |
664 | } else { |
677 | } else { |
665 | # the experience bonus here is to make level 1 rings give you at least |
678 | # the experience bonus here is to make level 1 rings give you at least |
666 | # 100 exp points when making them. This also makes leveling in the |
679 | # 200 exp points when making them. This also makes leveling in the |
667 | # first few levels a bit easier. (probably until around level 5-6). |
680 | # first few levels a bit easier. (probably until around level 5-6). |
668 | my $expbonus = cf::level_to_min_exp (2) / 10; |
681 | my $expbonus = cf::level_to_min_exp (2) / 5; |
669 | # this bonus should also only be given for _new_ rings and not for merged |
682 | # this bonus should also only be given for _new_ rings and not for merged |
670 | # ones - to prevent infinite exp making. |
683 | # ones - to prevent infinite exp making. |
671 | $exp += $expbonus; |
684 | $exp += $expbonus; |
672 | } |
685 | } |
673 | |
686 | |
… | |
… | |
717 | if (defined $costs) { |
730 | if (defined $costs) { |
718 | my $desc = ""; |
731 | my $desc = ""; |
719 | my $lvl = $self->power_to_level (\$desc); |
732 | my $lvl = $self->power_to_level (\$desc); |
720 | my $scosts = $self->calc_value_from_cost ($costs); |
733 | my $scosts = $self->calc_value_from_cost ($costs); |
721 | |
734 | |
722 | $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); |
735 | $pl->message ("costs: " |
|
|
736 | . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) |
|
|
737 | . " (" |
|
|
738 | . ($scosts / "platinacoin"->cf::arch::find->value) |
|
|
739 | . " platinum)"); |
723 | $pl->message ("level: " . $desc); |
740 | $pl->message ("level: $desc"); |
724 | } else { |
741 | } else { |
725 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
742 | $pl->message ("level: impossible to make, due to impossible resistancy configuration"); |
726 | } |
743 | } |
727 | } |
744 | } |
728 | |
745 | |
… | |
… | |
831 | $obj->{arch} = $thing->arch->archname; |
848 | $obj->{arch} = $thing->arch->archname; |
832 | $obj->{face} = $thing->face; |
849 | $obj->{face} = $thing->face; |
833 | |
850 | |
834 | $obj->{value} = $thing->value; |
851 | $obj->{value} = $thing->value; |
835 | |
852 | |
|
|
853 | $obj->{is_ring} = ($thing->type == cf::RING); |
|
|
854 | |
836 | $self->{hash} = $obj |
855 | $self->{hash} = $obj |
837 | } |
856 | } |
838 | |
857 | |
839 | sub to_object { |
858 | sub to_object { |
840 | my ($self) = @_; |
859 | my ($self) = @_; |
841 | |
860 | |
842 | my $obj = cf::object::new $self->{hash}->{arch}; |
861 | my $obj = cf::object::new $self->{hash}->{arch}; |
843 | |
862 | |
844 | $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached! |
863 | $obj->item_power (floor ($self->power_to_level / 5)); # there have to be strings attached! |
845 | |
864 | |
846 | $obj->face ($self->{hash}{face}); |
865 | $obj->face ($self->{hash}{face}); |
847 | |
866 | |
848 | my $stats = $obj->stats; |
867 | my $stats = $obj->stats; |
849 | |
868 | |
… | |
… | |
902 | sub resist_level { |
921 | sub resist_level { |
903 | my ($self) = @_; |
922 | my ($self) = @_; |
904 | |
923 | |
905 | my $resists = $self->{hash}->{resist} || {}; |
924 | my $resists = $self->{hash}->{resist} || {}; |
906 | |
925 | |
907 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
926 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
908 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
927 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
909 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
928 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
910 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
929 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
911 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
930 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
912 | |
931 | |
913 | my $ressum = 0; |
932 | my $ressum = 0; |
… | |
… | |
973 | sub power_to_level { |
992 | sub power_to_level { |
974 | my ($self, $lvldescr) = @_; |
993 | my ($self, $lvldescr) = @_; |
975 | |
994 | |
976 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
995 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
977 | 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'); |
978 | |
998 | |
979 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
999 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
980 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
1000 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
981 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
1001 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
982 | |
1002 | |
983 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
1003 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
984 | |
1004 | |
985 | 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 |
986 | |
1008 | |
987 | 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); |
988 | |
1016 | |
989 | if ($lvldescr) { |
1017 | if ($lvldescr) { |
990 | $$lvldescr = |
1018 | $$lvldescr = |
991 | sprintf "%3d: %s\n", $levl, |
1019 | sprintf "%3d: %s\n", $levl, |
992 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
1020 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
… | |
… | |
1083 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1111 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1084 | } |
1112 | } |
1085 | |
1113 | |
1086 | package Jeweler::Util; |
1114 | package Jeweler::Util; |
1087 | |
1115 | |
1088 | use strict; |
1116 | use common::sense; |
1089 | |
1117 | |
1090 | =head2 Util |
1118 | =head2 Util |
1091 | |
1119 | |
1092 | Some utility functions for the Jeweler skill. |
1120 | Some utility functions for the Jeweler skill. |
1093 | |
1121 | |
1094 | =over 4 |
1122 | =over 4 |
1095 | |
1123 | |
1096 | =item remove ($object[, $nrof]) |
1124 | =item remove ($object[, $nrof]) |
1097 | |
1125 | |
1098 | 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. |
1099 | 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. |
1100 | |
1128 | |
1101 | =cut |
1129 | =cut |
1102 | |
1130 | |
1103 | sub remove { |
1131 | sub remove { |
1104 | my ($obj, $nrof) = @_; |
1132 | my ($obj, $nrof) = @_; |
1105 | |
1133 | |
1106 | 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)); |
1107 | |
1137 | |
1108 | if (defined $nrof) { |
1138 | $r |
1109 | # TODO: Check tihis line: |
|
|
1110 | return 0 if ($nrof * 1) == 0; #XXX: ??? |
|
|
1111 | $cnt = int (($obj->nrof || 1) - (1 * $nrof)); |
|
|
1112 | |
|
|
1113 | if ($cnt > 0) { |
|
|
1114 | $obj->nrof ($cnt); |
|
|
1115 | return 0; |
|
|
1116 | } |
|
|
1117 | } |
|
|
1118 | |
|
|
1119 | remove ($_) for $obj->inv; |
|
|
1120 | $obj->destroy; |
|
|
1121 | return $cnt; |
|
|
1122 | } |
1139 | } |
1123 | |
1140 | |
1124 | sub check_for_match { |
1141 | sub check_for_match { |
1125 | my ($thing, @matchar) = @_; |
1142 | my ($thing, @matchar) = @_; |
1126 | |
1143 | |