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.21 by root, Fri Oct 12 19:13:26 2007 UTC vs.
Revision 1.30 by elmex, Tue Jan 26 16:13:47 2010 UTC

8 8
9=cut 9=cut
10 10
11package Jeweler; 11package Jeweler;
12 12
13use strict; 13use common::sense;
14use YAML;
15 14
16=over 4 15=over 4
17 16
18=item @RESISTS 17=item @RESISTS
19 18
24our $CFG; 23our $CFG;
25 24
26sub read_config { 25sub read_config {
27 my ($filename) = @_; 26 my ($filename) = @_;
28 27
29 unless (-e $filename) { 28 if (my $meta = $cf::RESOURCE{$filename}) {
29 $CFG = cf::decode_json $meta->{data};
30 } else {
30 warn "$filename doesn't exists! no config for jeweler skill loaded!\n"; 31 warn "$filename doesn't exist! no config for jeweler skill loaded!\n";
31 $CFG = {}; 32 $CFG = {};
32 return
33 } 33 }
34
35 $CFG = YAML::LoadFile $filename;
36} 34}
37 35
38sub getcfg { 36sub getcfg {
39 my ($sect, $key) = @_; 37 my ($sect, $key) = @_;
40 return $CFG->{$sect} unless defined $key; 38 return $CFG->{$sect} unless defined $key;
165 163
166sub analyze { 164sub analyze {
167 my ($sk, $chdl, $pl, $input_level) = @_; 165 my ($sk, $chdl, $pl, $input_level) = @_;
168 166
169 my $hadunid = 0; 167 my $hadunid = 0;
168 my $found = 0;
170 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) { 169 for ($chdl->grep_by_type (cf::RING, cf::AMULET)) {
171 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) { 170 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) {
172 $hadunid = 1; 171 $hadunid = 1;
173 next; 172 next;
174 } 173 }
174 $found = 1;
175 my $r = Jeweler::Object->new (object => $_); 175 my $r = Jeweler::Object->new (object => $_);
176 my $msg = $r->analyze ($sk, $pl, $input_level); 176 my $msg = $r->analyze ($sk, $pl, $input_level);
177 $pl->message ($r->to_string . ": " . $msg); 177 $pl->message ($r->to_string . ": " . $msg);
178 if ($pl->flag (cf::FLAG_WIZ)) { 178 if ($pl->flag (cf::FLAG_WIZ)) {
179 $r->wiz_analyze ($pl); 179 $r->wiz_analyze ($pl);
180 } 180 }
181 } 181 }
182 if ($hadunid) {
183 $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!")
184 } 183 if $hadunid;
184 $pl->message ("You couldn't find anything in the bench to analyse!")
185 unless $found;
185} 186}
186 187
187# this function converts metals/minerals into a raw ring (of adornment) 188# this function converts metals/minerals into a raw ring (of adornment)
188sub simple_converter { 189sub simple_converter {
189 my ($pl, $ingred, $chdl, $conv) = @_; 190 my ($pl, $ingred, $chdl, $conv, $sk_lvl, $low_skill_cb) = @_;
190 191
191 $conv = lc $conv; 192 $conv = lc $conv;
192 my $cnvs = $CFG->{conversions}; 193 my $cnvs = $CFG->{conversions};
193 194
194 return unless $cnvs->{$conv}; 195 return unless $cnvs->{$conv};
203 warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!"; 204 warn "ERROR: Conversion for '$outarch' has only " . (@conv_cfg) . " arguments!";
204 return; 205 return;
205 } 206 }
206 207
207 unless ($xp_gain > 0) { 208 unless ($xp_gain > 0) {
208 warn "WARNING: xp gain isn't > 0 in convesion '$outarch'\n"; 209 warn "WARNING: xp gain isn't > 0 in conversion '$outarch'\n";
209 return; 210 return;
210 } 211 }
211 212
212 unless ($outarchvalfact) { 213 unless ($outarchvalfact) {
213 warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n"; 214 warn "ERROR: source-arch-value-multiplier == 0 in conversion '$outarch'\n";
216 217
217 unless ($outarchvalfact >= 1) { 218 unless ($outarchvalfact >= 1) {
218 warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n"; 219 warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n";
219 } 220 }
220 221
221 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); 222 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname);
222 $ingred->remove ($ingr_grp, $srcarchname);
223
224 my $outarchval = cf::arch::find ($outarch)->value; 223 my $outarchval = cf::arch::find ($outarch)->value;
225
226 my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); 224 my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact);
225 my $can_make_nr = int (($sk_lvl / 2) + 10);
226
227 if ($nrof > $can_make_nr) {
228 $pl->ob->message ("Your jeweler level is too low to make $nrof rings, you can only make $can_make_nr at your current level.");
229 return;
230 }
231
227 if ($nrof) { 232 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) 233 # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes)
234 $ingred->remove ($ingr_grp, $srcarchname);
229 for (1..$nrof) { 235 for (1 .. $nrof) {
230 $chdl->put (my $ob = cf::object::new $outarch); 236 $chdl->put (my $ob = cf::object::new $outarch);
231 $ob->set_animation (cf::rndm $ob->num_animations) 237 $ob->set_animation (cf::rndm $ob->num_animations)
232 if ($ob->type == cf::RING); 238 if ($ob->type == cf::RING);
233 $ob->flag (cf::FLAG_IDENTIFIED, 1); 239 $ob->flag (cf::FLAG_IDENTIFIED, 1);
234 } 240 }
235 241
236 my $xp_sum = ($xp_gain * $nrof); 242 my $xp_sum = $xp_gain * $nrof;
237 243
238 if ($xp_sum) { 244 if ($xp_sum) {
239 $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); 245 $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); 246 $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY);
241 } 247 }
477} 483}
478 484
479sub improve_ring_by_plan { 485sub improve_ring_by_plan {
480 my ($self, $plan, $ring) = @_; 486 my ($self, $plan, $ring) = @_;
481 487
482 $ring = do { my $guard = Coro::Storable::guard; 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
573sub check_costs { 579sub check_costs {
574 my ($self, $costs, $do_remove) = @_; 580 my ($self, $costs, $do_remove) = @_;
575 581
576 my $costs = do { my $guard = Coro::Storable::guard; 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};
595 $self->do_grep (sub {
589 $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); 596 if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); }
597 1
598 }, @grepar);
590 if ($rem > 0) { 599 if ($rem > 0) {
591 warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; 600 warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!";
592 } 601 }
602
593 } else { 603 } else {
594 my $nr; 604 my $nr;
595 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); 605 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar);
596 $costs->{$key} -= $nr; 606 $costs->{$key} -= $nr;
597 } 607 }
661 $exp -= $subexp; 671 $exp -= $subexp;
662 $exp = max ($exp, 0); 672 $exp = max ($exp, 0);
663 673
664 } else { 674 } else {
665 # the experience bonus here is to make level 1 rings give you at least 675 # 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 676 # 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). 677 # first few levels a bit easier. (probably until around level 5-6).
668 my $expbonus = cf::level_to_min_exp (2) / 10; 678 my $expbonus = cf::level_to_min_exp (2) / 5;
669 # this bonus should also only be given for _new_ rings and not for merged 679 # this bonus should also only be given for _new_ rings and not for merged
670 # ones - to prevent infinite exp making. 680 # ones - to prevent infinite exp making.
671 $exp += $expbonus; 681 $exp += $expbonus;
672 } 682 }
673 683
717 if (defined $costs) { 727 if (defined $costs) {
718 my $desc = ""; 728 my $desc = "";
719 my $lvl = $self->power_to_level (\$desc); 729 my $lvl = $self->power_to_level (\$desc);
720 my $scosts = $self->calc_value_from_cost ($costs); 730 my $scosts = $self->calc_value_from_cost ($costs);
721 731
722 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); 732 $pl->message ("costs: "
733 . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)
734 . " ("
735 . ($scosts / "platinacoin"->cf::arch::find->value)
736 . " platinum)");
723 $pl->message ("level: " . $desc); 737 $pl->message ("level: $desc");
724 } else { 738 } else {
725 $pl->message ("level: impossible to make, due to impossible resistancy configuration"); 739 $pl->message ("level: impossible to make, due to impossible resistancy configuration");
726 } 740 }
727} 741}
728 742
1094=over 4 1108=over 4
1095 1109
1096=item remove ($object[, $nrof]) 1110=item remove ($object[, $nrof])
1097 1111
1098Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. 1112Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects.
1099The returnvalue is the number of 'single' objects that couldn't be removed. 1113The return value is the number of 'single' objects that couldn't be removed.
1100 1114
1101=cut 1115=cut
1102 1116
1103sub remove { 1117sub remove {
1104 my ($obj, $nrof) = @_; 1118 my ($obj, $nrof) = @_;
1119
1120 my $c = $obj->nrof || 1;
1121 my $r = $c > $nrof ? 0 : $nrof - $c;
1122 $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1));
1105 1123
1106 my $cnt; 1124 $r
1107
1108 if (defined $nrof) {
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} 1125}
1123 1126
1124sub check_for_match { 1127sub check_for_match {
1125 my ($thing, @matchar) = @_; 1128 my ($thing, @matchar) = @_;
1126 1129

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines