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.10 by elmex, Sun Feb 4 11:44:43 2007 UTC vs.
Revision 1.17 by elmex, Sat Jul 21 16:06:22 2007 UTC

219 } 219 }
220 220
221 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); 221 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname);
222 $ingred->remove ($ingr_grp, $srcarchname); 222 $ingred->remove ($ingr_grp, $srcarchname);
223 223
224 my $outarchval = cf::arch::find ($outarch)->clone->value; 224 my $outarchval = cf::arch::find ($outarch)->value;
225 225
226 my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact)); 226 my $nrof = int ($archvalsum / (($outarchval || 1000) * $outarchvalfact));
227 if ($nrof) { 227 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) 228 # XXX: yes, i know what i'm doing here, i don't set nrof, but it didn't work somehow (pls. chek sometimes)
229 for (1..$nrof) { 229 for (1..$nrof) {
238 if ($xp_sum) { 238 if ($xp_sum) {
239 $pl->ob->message ("You got $xp_sum xp by making $nrof ${outarch}s"); 239 $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); 240 $pl->ob->change_exp ($xp_sum, "jeweler", cf::SK_EXP_SKILL_ONLY);
241 } 241 }
242 } else { 242 } else {
243 $pl->ob->message ("You fail to make something, propably you used not enough source material?"); 243 $pl->ob->message ("You fail to make something, probably you used not enough source material?");
244 } 244 }
245} 245}
246 246
247 247
248package Jeweler::CauldronHandler; 248package Jeweler::CauldronHandler;
280 my ($self, $arch_name, @map_stack) = @_; 280 my ($self, $arch_name, @map_stack) = @_;
281 281
282 my @c = 282 my @c =
283 grep { 283 grep {
284 $_->flag (cf::FLAG_IS_CAULDRON) 284 $_->flag (cf::FLAG_IS_CAULDRON)
285 and $_->arch->name eq $arch_name 285 and $_->arch->archname eq $arch_name
286 } @map_stack; 286 } @map_stack;
287 287
288 $self->{cauldron} = $c[0]; 288 $self->{cauldron} = $c[0];
289} 289}
290 290
398 398
399sub value { 399sub value {
400 my ($self, $group, $archname) = @_; 400 my ($self, $group, $archname) = @_;
401 401
402 my @objs = grep { 402 my @objs = grep {
403 $_->arch->name eq $archname 403 $_->arch->archname eq $archname
404 } @{$self->{ingredients}->{$group} || []}; 404 } @{$self->{ingredients}->{$group} || []};
405 405
406 my $sum = 0; 406 my $sum = 0;
407 for (@objs) { 407 for (@objs) {
408 $sum += ($_->nrof || 1) * $_->value; 408 $sum += ($_->nrof || 1) * $_->value;
425 425
426 my @out; 426 my @out;
427 427
428 for (@{$ingred->{$group}}) { 428 for (@{$ingred->{$group}}) {
429 if (defined $archname) { 429 if (defined $archname) {
430 if ($_->arch->name eq $archname) { 430 if ($_->arch->archname eq $archname) {
431 Jeweler::Util::remove ($_); 431 Jeweler::Util::remove ($_);
432 } else { 432 } else {
433 push @out, $_; 433 push @out, $_;
434 } 434 }
435 } else { 435 } else {
576 my $costs = dclone ($costs); 576 my $costs = dclone ($costs);
577 577
578 for my $key (keys %$costs) { 578 for my $key (keys %$costs) {
579 my @grepar; 579 my @grepar;
580 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 580 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
581 @grepar = @{Jeweler::getcfg (plans => $key) || []}; 581 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
582 next if $@;
582 } else { # check the gems 583 } else { # check the gems
583 @grepar = ('gems', undef, undef, $key); 584 @grepar = ('gems', undef, undef, $key);
584 } 585 }
585 586
586 if ($do_remove) { 587 if ($do_remove) {
663 my $emarch = cf::arch::find 'emerald'; 664 my $emarch = cf::arch::find 'emerald';
664 my $saarch = cf::arch::find 'sapphire'; 665 my $saarch = cf::arch::find 'sapphire';
665 my $pearch = cf::arch::find 'pearl'; 666 my $pearch = cf::arch::find 'pearl';
666 my $ruarch = cf::arch::find 'ruby'; 667 my $ruarch = cf::arch::find 'ruby';
667 my $diarch = cf::arch::find 'gem'; 668 my $diarch = cf::arch::find 'gem';
668 my $value = $emarch->clone->value * $costs->{emerald} 669 my $value = $emarch->value * $costs->{emerald}
669 + $saarch->clone->value * $costs->{sapphire} 670 + $saarch->value * $costs->{sapphire}
670 + $pearch->clone->value * $costs->{pearl} 671 + $pearch->value * $costs->{pearl}
671 + $ruarch->clone->value * $costs->{ruby} 672 + $ruarch->value * $costs->{ruby}
672 + $diarch->clone->value * $costs->{gem}; 673 + $diarch->value * $costs->{gem};
673 674
674 $value 675 $value
675} 676}
676 677
677sub wiz_analyze { 678sub wiz_analyze {
782 $obj->{spec}{ac} = $stats->ac; 783 $obj->{spec}{ac} = $stats->ac;
783 $obj->{spec}{speed} = $stats->exp; 784 $obj->{spec}{speed} = $stats->exp;
784 $obj->{spec}{food} = $stats->food; 785 $obj->{spec}{food} = $stats->food;
785 786
786 $obj->{name} = $thing->name; 787 $obj->{name} = $thing->name;
787 $obj->{arch} = $thing->arch->name; 788 $obj->{arch} = $thing->arch->archname;
788 $obj->{face} = $thing->face; 789 $obj->{face} = $thing->face;
789 790
790 $obj->{value} = $thing->value; 791 $obj->{value} = $thing->value;
791 792
792 $self->{hash} = $obj 793 $self->{hash} = $obj
795sub to_object { 796sub to_object {
796 my ($self) = @_; 797 my ($self) = @_;
797 798
798 my $obj = cf::object::new $self->{hash}->{arch}; 799 my $obj = cf::object::new $self->{hash}->{arch};
799 800
800 $obj->item_power ($self->power_to_level); # there have to be strings attached! 801 $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached!
801 802
802 $obj->face ($self->{hash}{face}); 803 $obj->face ($self->{hash}{face});
803 804
804 my $stats = $obj->stats; 805 my $stats = $obj->stats;
805 806
1029 my $saarch = cf::arch::find 'sapphire'; 1030 my $saarch = cf::arch::find 'sapphire';
1030 my $pearch = cf::arch::find 'pearl'; 1031 my $pearch = cf::arch::find 'pearl';
1031 my $ruarch = cf::arch::find 'ruby'; 1032 my $ruarch = cf::arch::find 'ruby';
1032 my $diarch = cf::arch::find 'gem'; 1033 my $diarch = cf::arch::find 'gem';
1033 1034
1034 my $sumvalue = $diarch->clone->value * $diamonds; 1035 my $sumvalue = $diarch->value * $diamonds;
1035 1036
1036 $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->clone->value; 1037 $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->value;
1037 $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->clone->value; 1038 $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->value;
1038 $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->clone->value; 1039 $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->value;
1039 $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->clone->value; 1040 $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->value;
1040 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->clone->value; 1041 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value;
1041} 1042}
1042 1043
1043package Jeweler::Util; 1044package Jeweler::Util;
1044 1045
1045use strict; 1046use strict;
1083 1084
1084 my $i = 0; 1085 my $i = 0;
1085 my $check_cnts = 0; 1086 my $check_cnts = 0;
1086 my $check_true = 0; 1087 my $check_true = 0;
1087 for my $match (@matchar) { 1088 for my $match (@matchar) {
1088 $check_cnts = 0 if $i % 3 == 0; 1089 if ($i % 3 == 0) {
1090 return 1 if $check_true && $check_cnts == $check_true;
1091 $check_cnts = 0;
1092 $check_true = 0;
1093 }
1089 1094
1090 if ($match =~ m/^\s*$/) { 1095 if ($match =~ m/^\s*$/) {
1091 $i++; 1096 $i++;
1092 next; 1097 next;
1093 } 1098 }
1098 and $check_true++; 1103 and $check_true++;
1099 } elsif ($i % 3 == 1) { 1104 } elsif ($i % 3 == 1) {
1100 $thing->title eq $match 1105 $thing->title eq $match
1101 and $check_true++; 1106 and $check_true++;
1102 } else { # $i % 3 == 2 1107 } else { # $i % 3 == 2
1103 $thing->arch->name eq $match 1108 $thing->arch->archname eq $match
1104 and $check_true++; 1109 and $check_true++;
1105 } 1110 }
1106 $i++; 1111 $i++;
1107 } 1112 }
1113 #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->archname))."\n";
1108 if ($check_true && $check_cnts == $check_true) { 1114 return 1 if $check_true && $check_cnts == $check_true;
1109 return 1;
1110 }
1111 return 0; 1115 return 0;
1112} 1116}
1113 1117
1114sub grep_for_match { 1118sub grep_for_match {
1115 my ($ingred, $group, @matchar) = @_; 1119 my ($ingred, $group, @matchar) = @_;
1116 1120
1117 for my $thing (@{$ingred->{$group} || []}) { 1121 for my $thing (@{$ingred->{$group} || []}) {
1118 #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->name, "@matchar"; #d# 1122 #d# warn sprintf "DEB:(%s,%s,%s)<->%s\n", $thing->name, $thing->title, $thing->arch->archname, "@matchar"; #d#
1119 if (check_for_match ($thing, @matchar)) { 1123 if (check_for_match ($thing, @matchar)) {
1120 return $thing; 1124 return $thing;
1121 } 1125 }
1122 } 1126 }
1123 return undef; 1127 return undef;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines