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.26 by elmex, Sun Jul 13 20:15:51 2008 UTC vs.
Revision 1.33 by root, Wed Apr 28 21:05:33 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
21 20
22=cut 21=cut
23 22
24our $CFG; 23our $CFG;
25 24
26sub read_config { 25sub load_config {
27 my ($filename) = @_; 26 0 < Coro::AIO::aio_load "$cf::DATADIR/jeweler", my $data
27 or die "$cf::DATADIR/jeweler: $!";
28 28
29 if (my $meta = $cf::RESOURCE{$filename}) {
30 $CFG = cf::decode_json $meta->{data}; 29 $CFG = cf::decode_json $data;
31 } else {
32 warn "$filename doesn't exist! no config for jeweler skill loaded!\n";
33 $CFG = {};
34 }
35} 30}
36 31
37sub getcfg { 32sub getcfg {
38 my ($sect, $key) = @_; 33 my ($sect, $key) = @_;
39 return $CFG->{$sect} unless defined $key; 34 return $CFG->{$sect} unless defined $key;
186 unless $found; 181 unless $found;
187} 182}
188 183
189# this function converts metals/minerals into a raw ring (of adornment) 184# this function converts metals/minerals into a raw ring (of adornment)
190sub simple_converter { 185sub simple_converter {
191 my ($pl, $ingred, $chdl, $conv) = @_; 186 my ($pl, $ingred, $chdl, $conv, $sk_lvl, $low_skill_cb) = @_;
192 187
193 $conv = lc $conv; 188 $conv = lc $conv;
194 my $cnvs = $CFG->{conversions}; 189 my $cnvs = $CFG->{conversions};
195 190
196 return unless $cnvs->{$conv}; 191 return unless $cnvs->{$conv};
218 213
219 unless ($outarchvalfact >= 1) { 214 unless ($outarchvalfact >= 1) {
220 warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n"; 215 warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n";
221 } 216 }
222 217
223 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); 218 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname);
224 $ingred->remove ($ingr_grp, $srcarchname);
225
226 my $outarchval = cf::arch::find ($outarch)->value; 219 my $outarchval = cf::arch::find ($outarch)->value;
227
228 my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact); 220 my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact);
221 my $can_make_nr = int (($sk_lvl / 2) + 10);
222
223 if ($nrof > $can_make_nr) {
224 $pl->ob->message ("Your jeweler level is too low to make $nrof rings, you can only make $can_make_nr at your current level.");
225 return;
226 }
227
229 if ($nrof) { 228 if ($nrof) {
230 # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes) 229 # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes)
230 $ingred->remove ($ingr_grp, $srcarchname);
231 for (1 .. $nrof) { 231 for (1 .. $nrof) {
232 $chdl->put (my $ob = cf::object::new $outarch); 232 $chdl->put (my $ob = cf::object::new $outarch);
233 $ob->set_animation (cf::rndm $ob->num_animations) 233 $ob->set_animation (cf::rndm $ob->num_animations)
234 if ($ob->type == cf::RING); 234 if ($ob->type == cf::RING);
235 $ob->flag (cf::FLAG_IDENTIFIED, 1); 235 $ob->flag (cf::FLAG_IDENTIFIED, 1);
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 }
837 $obj->{arch} = $thing->arch->archname; 841 $obj->{arch} = $thing->arch->archname;
838 $obj->{face} = $thing->face; 842 $obj->{face} = $thing->face;
839 843
840 $obj->{value} = $thing->value; 844 $obj->{value} = $thing->value;
841 845
846 $obj->{is_ring} = ($thing->type == cf::RING);
847
842 $self->{hash} = $obj 848 $self->{hash} = $obj
843} 849}
844 850
845sub to_object { 851sub to_object {
846 my ($self) = @_; 852 my ($self) = @_;
908sub resist_level { 914sub resist_level {
909 my ($self) = @_; 915 my ($self) = @_;
910 916
911 my $resists = $self->{hash}->{resist} || {}; 917 my $resists = $self->{hash}->{resist} || {};
912 918
913 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); 919 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level');
914 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); 920 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level');
915 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); 921 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances');
916 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); 922 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances');
917 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); 923 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances');
918 924
919 my $ressum = 0; 925 my $ressum = 0;
979sub power_to_level { 985sub power_to_level {
980 my ($self, $lvldescr) = @_; 986 my ($self, $lvldescr) = @_;
981 987
982 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); 988 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements');
983 my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); 989 my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level');
990 my $ring_offs = Jeweler::getcfg (maxlevels => 'ring_offset');
984 991
985 my ($stat_lvl, $stat_imprs) = $self->stat_level; 992 my ($stat_lvl, $stat_imprs) = $self->stat_level;
986 my ($resist_lvl, $res_imprs) = $self->resist_level; 993 my ($resist_lvl, $res_imprs) = $self->resist_level;
987 my ($spec_lvl, $spec_imprs) = $self->special_level; 994 my ($spec_lvl, $spec_imprs) = $self->special_level;
988 995
989 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; 996 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs;
990 997
991 my $impr_lvl = ceil (($max_impr_lvl / ($max_imprs + 1)) * ($impr_sum - 1)); # 1 improvemnt bonus 998 my $impr_lvl =
999 ceil (($max_impr_lvl / ($max_imprs + 1))
1000 * ($impr_sum - 1)); # 1 improvemnt bonus
992 1001
993 my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); 1002 my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0);
1003
1004 if ($self->{hash}->{is_ring}) {
1005 $levl += $ring_offs;
1006 }
1007
1008 $levl = min ($levl, cf::settings->max_level);
994 1009
995 if ($lvldescr) { 1010 if ($lvldescr) {
996 $$lvldescr = 1011 $$lvldescr =
997 sprintf "%3d: %s\n", $levl, 1012 sprintf "%3d: %s\n", $levl,
998 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " 1013 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, "
1100=over 4 1115=over 4
1101 1116
1102=item remove ($object[, $nrof]) 1117=item remove ($object[, $nrof])
1103 1118
1104Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. 1119Removes 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. 1120The return value is the number of 'single' objects that couldn't be removed.
1106 1121
1107=cut 1122=cut
1108 1123
1109sub remove { 1124sub remove {
1110 my ($obj, $nrof) = @_; 1125 my ($obj, $nrof) = @_;
1126
1127 my $c = $obj->nrof || 1;
1128 my $r = $c > $nrof ? 0 : $nrof - $c;
1129 $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1));
1111 1130
1112 my $cnt; 1131 $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} 1132}
1129 1133
1130sub check_for_match { 1134sub check_for_match {
1131 my ($thing, @matchar) = @_; 1135 my ($thing, @matchar) = @_;
1132 1136

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines