ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/Jeweler.pm
(Generate patch)

Comparing deliantra/server/ext/Jeweler.pm (file contents):
Revision 1.23 by root, Mon Dec 17 08:03:22 2007 UTC vs.
Revision 1.28 by root, Sat Dec 13 20:34:37 2008 UTC

164 164
165sub analyze { 165sub analyze {
166 my ($sk, $chdl, $pl, $input_level) = @_; 166 my ($sk, $chdl, $pl, $input_level) = @_;
167 167
168 my $hadunid = 0; 168 my $hadunid = 0;
169 my $found = 0;
169 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { 170 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) {
170 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { 171 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) {
171 $hadunid = 1; 172 $hadunid = 1;
172 next; 173 next;
173 } 174 }
175 $found = 1;
174 my $r = Jeweler::Object->new (object => $_); 176 my $r = Jeweler::Object->new (object => $_);
175 my $msg = $r->analyze ($sk, $pl, $input_level); 177 my $msg = $r->analyze ($sk, $pl, $input_level);
176 $pl->message ($r->to_string . ": " . $msg); 178 $pl->message ($r->to_string . ": " . $msg);
177 if ($pl->flag (cf::FLAG_WIZ)) { 179 if ($pl->flag (cf::FLAG_WIZ)) {
178 $r->wiz_analyze ($pl); 180 $r->wiz_analyze ($pl);
179 } 181 }
180 } 182 }
181 $pl->message ("You couldn't identify the other rings and not analyze them!") 183 $pl->message ("You couldn't identify the other rings and not analyze them!")
182 if $hadunid; 184 if $hadunid;
185 $pl->message ("You couldn't find anything in the bench to analyse!")
186 unless $found;
183} 187}
184 188
185# this function converts metals/minerals into a raw ring (of adornment) 189# this function converts metals/minerals into a raw ring (of adornment)
186sub simple_converter { 190sub simple_converter {
187 my ($pl, $ingred, $chdl, $conv) = @_; 191 my ($pl, $ingred, $chdl, $conv) = @_;
475} 479}
476 480
477sub improve_ring_by_plan { 481sub improve_ring_by_plan {
478 my ($self, $plan, $ring) = @_; 482 my ($self, $plan, $ring) = @_;
479 483
480 $ring = do { my $guard = Coro::Storable::guard; dclone $ring }; 484 $ring = dclone $ring;
481 485
482 my $ingred = $self->{ingredients}; 486 my $ingred = $self->{ingredients};
483 my $impr = {}; 487 my $impr = {};
484 488
485 if ($plan =~ m/^stat_(\S+)$/) { 489 if ($plan =~ m/^stat_(\S+)$/) {
569} 573}
570 574
571sub check_costs { 575sub check_costs {
572 my ($self, $costs, $do_remove) = @_; 576 my ($self, $costs, $do_remove) = @_;
573 577
574 my $costs = do { my $guard = Coro::Storable::guard; dclone $costs }; 578 my $costs = dclone $costs;
575 579
576 for my $key (keys %$costs) { 580 for my $key (keys %$costs) {
577 my @grepar; 581 my @grepar;
578 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 582 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
579 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; 583 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
582 @grepar = ('gems', undef, undef, $key); 586 @grepar = ('gems', undef, undef, $key);
583 } 587 }
584 588
585 if ($do_remove) { 589 if ($do_remove) {
586 my $rem = $costs->{$key}; 590 my $rem = $costs->{$key};
591 $self->do_grep (sub {
587 $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); 592 if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); }
593 1
594 }, @grepar);
588 if ($rem > 0) { 595 if ($rem > 0) {
589 warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; 596 warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!";
590 } 597 }
598
591 } else { 599 } else {
592 my $nr; 600 my $nr;
593 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); 601 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar);
594 $costs->{$key} -= $nr; 602 $costs->{$key} -= $nr;
595 } 603 }
659 $exp -= $subexp; 667 $exp -= $subexp;
660 $exp = max ($exp, 0); 668 $exp = max ($exp, 0);
661 669
662 } else { 670 } else {
663 # the experience bonus here is to make level 1 rings give you at least 671 # the experience bonus here is to make level 1 rings give you at least
664 # 100 exp points when making them. This also makes leveling in the 672 # 200 exp points when making them. This also makes leveling in the
665 # first few levels a bit easier. (probably until around level 5-6). 673 # first few levels a bit easier. (probably until around level 5-6).
666 my $expbonus = cf::level_to_min_exp (2) / 10; 674 my $expbonus = cf::level_to_min_exp (2) / 5;
667 # this bonus should also only be given for _new_ rings and not for merged 675 # this bonus should also only be given for _new_ rings and not for merged
668 # ones - to prevent infinite exp making. 676 # ones - to prevent infinite exp making.
669 $exp += $expbonus; 677 $exp += $expbonus;
670 } 678 }
671 679
715 if (defined $costs) { 723 if (defined $costs) {
716 my $desc = ""; 724 my $desc = "";
717 my $lvl = $self->power_to_level (\$desc); 725 my $lvl = $self->power_to_level (\$desc);
718 my $scosts = $self->calc_value_from_cost ($costs); 726 my $scosts = $self->calc_value_from_cost ($costs);
719 727
720 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); 728 $pl->message ("costs: "
729 . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)
730 . " ("
731 . ($scosts / "platinacoin"->cf::arch::find->value)
732 . " platinum)");
721 $pl->message ("level: " . $desc); 733 $pl->message ("level: $desc");
722 } else { 734 } else {
723 $pl->message ("level: impossible to make, due to impossible resistancy configuration"); 735 $pl->message ("level: impossible to make, due to impossible resistancy configuration");
724 } 736 }
725} 737}
726 738
1092=over 4 1104=over 4
1093 1105
1094=item remove ($object[, $nrof]) 1106=item remove ($object[, $nrof])
1095 1107
1096Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. 1108Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects.
1097The returnvalue is the number of 'single' objects that couldn't be removed. 1109The return value is the number of 'single' objects that couldn't be removed.
1098 1110
1099=cut 1111=cut
1100 1112
1101sub remove { 1113sub remove {
1102 my ($obj, $nrof) = @_; 1114 my ($obj, $nrof) = @_;
1115
1116 my $c = $obj->nrof || 1;
1117 my $r = $c > $nrof ? 0 : $nrof - $c;
1118 $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1));
1103 1119
1104 my $cnt; 1120 $r
1105
1106 if (defined $nrof) {
1107 # TODO: Check tihis line:
1108 return 0 if ($nrof * 1) == 0; #XXX: ???
1109 $cnt = int (($obj->nrof || 1) - (1 * $nrof));
1110
1111 if ($cnt > 0) {
1112 $obj->nrof ($cnt);
1113 return 0;
1114 }
1115 }
1116
1117 remove ($_) for $obj->inv;
1118 $obj->destroy;
1119 return $cnt;
1120} 1121}
1121 1122
1122sub check_for_match { 1123sub check_for_match {
1123 my ($thing, @matchar) = @_; 1124 my ($thing, @matchar) = @_;
1124 1125

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines