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.25 by root, Thu Apr 10 15:35:16 2008 UTC vs.
Revision 1.28 by root, Sat Dec 13 20:34:37 2008 UTC

479} 479}
480 480
481sub improve_ring_by_plan { 481sub improve_ring_by_plan {
482 my ($self, $plan, $ring) = @_; 482 my ($self, $plan, $ring) = @_;
483 483
484 $ring = do { my $guard = Coro::Storable::guard; dclone $ring }; 484 $ring = dclone $ring;
485 485
486 my $ingred = $self->{ingredients}; 486 my $ingred = $self->{ingredients};
487 my $impr = {}; 487 my $impr = {};
488 488
489 if ($plan =~ m/^stat_(\S+)$/) { 489 if ($plan =~ m/^stat_(\S+)$/) {
573} 573}
574 574
575sub check_costs { 575sub check_costs {
576 my ($self, $costs, $do_remove) = @_; 576 my ($self, $costs, $do_remove) = @_;
577 577
578 my $costs = do { my $guard = Coro::Storable::guard; dclone $costs }; 578 my $costs = dclone $costs;
579 579
580 for my $key (keys %$costs) { 580 for my $key (keys %$costs) {
581 my @grepar; 581 my @grepar;
582 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 582 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
583 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; 583 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
586 @grepar = ('gems', undef, undef, $key); 586 @grepar = ('gems', undef, undef, $key);
587 } 587 }
588 588
589 if ($do_remove) { 589 if ($do_remove) {
590 my $rem = $costs->{$key}; 590 my $rem = $costs->{$key};
591 $self->do_grep (sub {
591 $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);
592 if ($rem > 0) { 595 if ($rem > 0) {
593 warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; 596 warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!";
594 } 597 }
598
595 } else { 599 } else {
596 my $nr; 600 my $nr;
597 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); 601 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar);
598 $costs->{$key} -= $nr; 602 $costs->{$key} -= $nr;
599 } 603 }
663 $exp -= $subexp; 667 $exp -= $subexp;
664 $exp = max ($exp, 0); 668 $exp = max ($exp, 0);
665 669
666 } else { 670 } else {
667 # 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
668 # 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
669 # 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).
670 my $expbonus = cf::level_to_min_exp (2) / 10; 674 my $expbonus = cf::level_to_min_exp (2) / 5;
671 # 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
672 # ones - to prevent infinite exp making. 676 # ones - to prevent infinite exp making.
673 $exp += $expbonus; 677 $exp += $expbonus;
674 } 678 }
675 679
722 my $scosts = $self->calc_value_from_cost ($costs); 726 my $scosts = $self->calc_value_from_cost ($costs);
723 727
724 $pl->message ("costs: " 728 $pl->message ("costs: "
725 . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) 729 . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)
726 . " (" 730 . " ("
727 . ($scosts / "royalty"->cf::arch::find->value) 731 . ($scosts / "platinacoin"->cf::arch::find->value)
728 . " royalties)"); 732 . " platinum)");
729 $pl->message ("level: $desc"); 733 $pl->message ("level: $desc");
730 } else { 734 } else {
731 $pl->message ("level: impossible to make, due to impossible resistancy configuration"); 735 $pl->message ("level: impossible to make, due to impossible resistancy configuration");
732 } 736 }
733} 737}
1100=over 4 1104=over 4
1101 1105
1102=item remove ($object[, $nrof]) 1106=item remove ($object[, $nrof])
1103 1107
1104Removes 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.
1105The 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.
1106 1110
1107=cut 1111=cut
1108 1112
1109sub remove { 1113sub remove {
1110 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));
1111 1119
1112 my $cnt; 1120 $r
1113
1114 if (defined $nrof) {
1115 # TODO: Check tihis line:
1116 return 0 if ($nrof * 1) == 0; #XXX: ???
1117 $cnt = int (($obj->nrof || 1) - (1 * $nrof));
1118
1119 if ($cnt > 0) {
1120 $obj->nrof ($cnt);
1121 return 0;
1122 }
1123 }
1124
1125 remove ($_) for $obj->inv;
1126 $obj->destroy;
1127 return $cnt;
1128} 1121}
1129 1122
1130sub check_for_match { 1123sub check_for_match {
1131 my ($thing, @matchar) = @_; 1124 my ($thing, @matchar) = @_;
1132 1125

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines