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.5 by elmex, Wed Jan 31 15:53:17 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) {
230 $chdl->put (my $ob = cf::object::new $outarch); 230 $chdl->put (my $ob = cf::object::new $outarch);
231 $ob->set_animation (cf::rndm $ob->num_animations); 231 $ob->set_animation (cf::rndm $ob->num_animations)
232 if ($ob->type == cf::RING);
232 $ob->flag (cf::FLAG_IDENTIFIED, 1); 233 $ob->flag (cf::FLAG_IDENTIFIED, 1);
233 } 234 }
234 235
235 my $xp_sum = ($xp_gain * $nrof); 236 my $xp_sum = ($xp_gain * $nrof);
236 237
237 if ($xp_sum) { 238 if ($xp_sum) {
238 $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");
239 $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);
240 } 241 }
241 } else { 242 } else {
242 $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?");
243 } 244 }
244} 245}
245 246
246 247
247package Jeweler::CauldronHandler; 248package Jeweler::CauldronHandler;
279 my ($self, $arch_name, @map_stack) = @_; 280 my ($self, $arch_name, @map_stack) = @_;
280 281
281 my @c = 282 my @c =
282 grep { 283 grep {
283 $_->flag (cf::FLAG_IS_CAULDRON) 284 $_->flag (cf::FLAG_IS_CAULDRON)
284 and $_->arch->name eq $arch_name 285 and $_->arch->archname eq $arch_name
285 } @map_stack; 286 } @map_stack;
286 287
287 $self->{cauldron} = $c[0]; 288 $self->{cauldron} = $c[0];
288} 289}
289 290
328 cf::POTION => 'potions', 329 cf::POTION => 'potions',
329 cf::SCROLL => 'scrolls', 330 cf::SCROLL => 'scrolls',
330 ); 331 );
331 332
332 for ($self->{cauldron}->inv) { 333 for ($self->{cauldron}->inv) {
334 if (!$_->flag (cf::FLAG_IDENTIFIED) && $_->need_identify) {
335 die "unidentified";
333 if ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) { 336 } elsif ($_->flag (cf::FLAG_CURSED) || $_->flag (cf::FLAG_DAMNED)) {
334 die "cursed"; 337 die "cursed";
335 } 338 }
336 339
337 if (my $k = $type_to_key{$_->type}) { 340 if (my $k = $type_to_key{$_->type}) {
338 push @{$ingreds->{$k}}, $_; 341 push @{$ingreds->{$k}}, $_;
395 398
396sub value { 399sub value {
397 my ($self, $group, $archname) = @_; 400 my ($self, $group, $archname) = @_;
398 401
399 my @objs = grep { 402 my @objs = grep {
400 $_->arch->name eq $archname 403 $_->arch->archname eq $archname
401 } @{$self->{ingredients}->{$group} || []}; 404 } @{$self->{ingredients}->{$group} || []};
402 405
403 my $sum = 0; 406 my $sum = 0;
404 for (@objs) { 407 for (@objs) {
405 $sum += ($_->nrof || 1) * $_->value; 408 $sum += ($_->nrof || 1) * $_->value;
422 425
423 my @out; 426 my @out;
424 427
425 for (@{$ingred->{$group}}) { 428 for (@{$ingred->{$group}}) {
426 if (defined $archname) { 429 if (defined $archname) {
427 if ($_->arch->name eq $archname) { 430 if ($_->arch->archname eq $archname) {
428 Jeweler::Util::remove ($_); 431 Jeweler::Util::remove ($_);
429 } else { 432 } else {
430 push @out, $_; 433 push @out, $_;
431 } 434 }
432 } else { 435 } else {
573 my $costs = dclone ($costs); 576 my $costs = dclone ($costs);
574 577
575 for my $key (keys %$costs) { 578 for my $key (keys %$costs) {
576 my @grepar; 579 my @grepar;
577 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 580 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
578 @grepar = @{Jeweler::getcfg (plans => $key) || []}; 581 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
582 next if $@;
579 } else { # check the gems 583 } else { # check the gems
580 @grepar = ('gems', undef, undef, $key); 584 @grepar = ('gems', undef, undef, $key);
581 } 585 }
582 586
583 if ($do_remove) { 587 if ($do_remove) {
626 $self->ring_or_ammy_to_hash ($arg{object}); 630 $self->ring_or_ammy_to_hash ($arg{object});
627 631
628 $self; 632 $self;
629} 633}
630 634
635sub has_resist {
636 my ($self, $resistnam, $resistval) = @_;
637 my $resnum = $REV_RESMAP{uc $resistnam};
638 if (defined ($resistval)) {
639 return 1 if $self->{hash}->{resist}->{$resnum} == $resistval;
640 } else {
641 return 1 if $self->{hash}->{resist}->{$resnum};
642 }
643 return undef;
644}
645
631sub analyze { 646sub analyze {
632 my ($self, $sk, $pl) = @_; 647 my ($self, $sk, $pl) = @_;
633 648
634 my $sklvl = cf::exp_to_level ($sk->stats->exp); 649 my $sklvl = cf::exp_to_level ($sk->stats->exp);
635 my $ringlvl = $self->power_to_level; 650 my $ringlvl = $self->power_to_level;
642 } 657 }
643 my $msg = sprintf "Projected success rate: %s", $tmpl; 658 my $msg = sprintf "Projected success rate: %s", $tmpl;
644 return $msg; 659 return $msg;
645} 660}
646 661
662sub calc_value_from_cost {
663 my ($self, $costs) = @_;
664 my $emarch = cf::arch::find 'emerald';
665 my $saarch = cf::arch::find 'sapphire';
666 my $pearch = cf::arch::find 'pearl';
667 my $ruarch = cf::arch::find 'ruby';
668 my $diarch = cf::arch::find 'gem';
669 my $value = $emarch->value * $costs->{emerald}
670 + $saarch->value * $costs->{sapphire}
671 + $pearch->value * $costs->{pearl}
672 + $ruarch->value * $costs->{ruby}
673 + $diarch->value * $costs->{gem};
674
675 $value
676}
677
647sub wiz_analyze { 678sub wiz_analyze {
648 my ($self, $pl) = @_; 679 my ($self, $pl) = @_;
649 my $costs = $self->calc_costs; 680 my $costs = $self->calc_costs;
650 my $desc = ""; 681 my $desc = "";
651 my $lvl = $self->power_to_level (\$desc); 682 my $lvl = $self->power_to_level (\$desc);
652 my $emarch = cf::arch::find 'emerald'; 683 my $scosts = $self->calc_value_from_cost ($costs);
653 my $saarch = cf::arch::find 'sapphire';
654 my $pearch = cf::arch::find 'pearl';
655 my $ruarch = cf::arch::find 'ruby';
656 my $diarch = cf::arch::find 'gem';
657 my $scosts = $emarch->clone->value * $costs->{emerald}
658 + $saarch->clone->value * $costs->{sapphire}
659 + $pearch->clone->value * $costs->{pearl}
660 + $ruarch->clone->value * $costs->{ruby}
661 + $diarch->clone->value * $costs->{gem};
662 684
663 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)"); 685 $pl->message ("costs: " . (join (', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)) . " (".($scosts / 5000)." royalties)");
664 $pl->message ("level: " . $desc); 686 $pl->message ("level: " . $desc);
665} 687}
666
667 688
668sub get_chance_perc { 689sub get_chance_perc {
669 my ($self, $sk) = @_; 690 my ($self, $sk) = @_;
670 my $sklvl = cf::exp_to_level ($sk->stats->exp); 691 my $sklvl = cf::exp_to_level ($sk->stats->exp);
671 my $ringlvl = $self->power_to_level; 692 my $ringlvl = $self->power_to_level;
674 695
675sub fx { 696sub fx {
676 my ($res, $cfg) = @_; 697 my ($res, $cfg) = @_;
677 my $or = $res; 698 my $or = $res;
678 my $ar = $Jeweler::CFG->{functions}->{$cfg}; 699 my $ar = $Jeweler::CFG->{functions}->{$cfg};
700
679 if (ref $ar->[0] eq 'ARRAY') { 701 if (ref $ar->[0] eq 'ARRAY') {
680 $res = $res - 1; 702 $res = $res - 1;
703 return $ar->[max (min ($res, @$ar - 1), 0)];
704
681 } else { 705 } else {
706 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3...
682 $res = ceil ($res / 5) - 1; 707 my $idx = ceil (($res / 5) + 0.1) - 1;
683 }
684 $ar->[max (min ($res, @$ar - 1), 0)]; 708 my $a = $ar->[max (min ($idx, @$ar - 1), 0)];
709 my $b = $ar->[max (min ($idx + 1, @$ar - 1), 0)];
710 my $diff = $b - $a; # use the difference of the cost to the next cost
711 my $o_cost = $a + ($diff / 5) * ($res % 5); # and do some linear interpolation
712 return $o_cost;
713 }
685} 714}
686 715
687sub improve_by_ring { 716sub improve_by_ring {
688 my ($self, @rings) = @_; 717 my ($self, @rings) = @_;
689 my $ring = $self; 718 my $ring = $self;
705 if ($self->{hash}->{$cat}->{$k} > 0) { 734 if ($self->{hash}->{$cat}->{$k} > 0) {
706 $self->{hash}->{$cat}->{$k} *= -1; 735 $self->{hash}->{$cat}->{$k} *= -1;
707 } 736 }
708 } 737 }
709 } 738 }
739 $self->{hash}{value} = 0;
710} 740}
711 741
712sub to_string { 742sub to_string {
713 my ($self) = @_; 743 my ($self) = @_;
714 my $r = $self->{hash}; 744 my $r = $self->{hash};
753 $obj->{spec}{ac} = $stats->ac; 783 $obj->{spec}{ac} = $stats->ac;
754 $obj->{spec}{speed} = $stats->exp; 784 $obj->{spec}{speed} = $stats->exp;
755 $obj->{spec}{food} = $stats->food; 785 $obj->{spec}{food} = $stats->food;
756 786
757 $obj->{name} = $thing->name; 787 $obj->{name} = $thing->name;
758 $obj->{arch} = $thing->arch->name; 788 $obj->{arch} = $thing->arch->archname;
759 $obj->{face} = $thing->face; 789 $obj->{face} = $thing->face;
790
791 $obj->{value} = $thing->value;
760 792
761 $self->{hash} = $obj 793 $self->{hash} = $obj
762} 794}
763 795
764sub to_object { 796sub to_object {
765 my ($self) = @_; 797 my ($self) = @_;
766 798
767 my $obj = cf::object::new $self->{hash}->{arch}; 799 my $obj = cf::object::new $self->{hash}->{arch};
800
801 $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached!
768 802
769 $obj->face ($self->{hash}{face}); 803 $obj->face ($self->{hash}{face});
770 804
771 my $stats = $obj->stats; 805 my $stats = $obj->stats;
772 806
785 $obj->resist ($_, $self->{hash}->{resist}->{$_}); 819 $obj->resist ($_, $self->{hash}->{resist}->{$_});
786 } 820 }
787 821
788 $obj->flag (cf::FLAG_IDENTIFIED, 1); 822 $obj->flag (cf::FLAG_IDENTIFIED, 1);
789 823
824 $obj->value ($self->{hash}{value});
825
790 return $obj; 826 return $obj;
791} 827}
828
829sub set_value { $_[0]->{hash}{value} = $_[1] }
792 830
793sub is_better_than { 831sub is_better_than {
794 my ($self, $other) = @_; 832 my ($self, $other) = @_;
795 833
796 for my $type (qw/spec stat resist/) { 834 for my $type (qw/spec stat resist/) {
992 my $saarch = cf::arch::find 'sapphire'; 1030 my $saarch = cf::arch::find 'sapphire';
993 my $pearch = cf::arch::find 'pearl'; 1031 my $pearch = cf::arch::find 'pearl';
994 my $ruarch = cf::arch::find 'ruby'; 1032 my $ruarch = cf::arch::find 'ruby';
995 my $diarch = cf::arch::find 'gem'; 1033 my $diarch = cf::arch::find 'gem';
996 1034
997 my $sumvalue = $diarch->clone->value * $diamonds; 1035 my $sumvalue = $diarch->value * $diamonds;
998 1036
999 $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->clone->value; 1037 $cost->{emerald} += ceil $sumvalue * $stat_split->[0] / max 1, $emarch->value;
1000 $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->clone->value; 1038 $cost->{sapphire} += ceil $sumvalue * $stat_split->[1] / max 1, $saarch->value;
1001 $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->clone->value; 1039 $cost->{pearl} += ceil $sumvalue * $stat_split->[2] / max 1, $pearch->value;
1002 $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->clone->value; 1040 $cost->{ruby} += ceil $sumvalue * $stat_split->[3] / max 1, $ruarch->value;
1003 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->clone->value; 1041 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value;
1004} 1042}
1005 1043
1006package Jeweler::Util; 1044package Jeweler::Util;
1007 1045
1008use strict; 1046use strict;
1043 1081
1044sub check_for_match { 1082sub check_for_match {
1045 my ($thing, @matchar) = @_; 1083 my ($thing, @matchar) = @_;
1046 1084
1047 my $i = 0; 1085 my $i = 0;
1086 my $check_cnts = 0;
1087 my $check_true = 0;
1048 for my $match (@matchar) { 1088 for my $match (@matchar) {
1089 if ($i % 3 == 0) {
1090 return 1 if $check_true && $check_cnts == $check_true;
1091 $check_cnts = 0;
1092 $check_true = 0;
1093 }
1094
1049 if ($match =~ m/^\s*$/) { 1095 if ($match =~ m/^\s*$/) {
1050 $i++; 1096 $i++;
1051 next; 1097 next;
1052 } 1098 }
1053 1099
1100 $check_cnts++;
1054 if ($i % 3 == 0) { 1101 if ($i % 3 == 0) {
1055 $thing->name eq $match 1102 $thing->name eq $match
1056 and return 1; 1103 and $check_true++;
1057 } elsif ($i % 3 == 1) { 1104 } elsif ($i % 3 == 1) {
1058 $thing->title eq $match 1105 $thing->title eq $match
1059 and return 1; 1106 and $check_true++;
1060 } else { # $i % 3 == 2 1107 } else { # $i % 3 == 2
1061 $thing->arch->name eq $match 1108 $thing->arch->archname eq $match
1062 and return 1; 1109 and $check_true++;
1063 } 1110 }
1064 $i++; 1111 $i++;
1065 } 1112 }
1113 #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->archname))."\n";
1114 return 1 if $check_true && $check_cnts == $check_true;
1066 return 0; 1115 return 0;
1067} 1116}
1068 1117
1069sub grep_for_match { 1118sub grep_for_match {
1070 my ($ingred, $group, @matchar) = @_; 1119 my ($ingred, $group, @matchar) = @_;
1071 1120
1072 for my $thing (@{$ingred->{$group} || []}) { 1121 for my $thing (@{$ingred->{$group} || []}) {
1073 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#
1074 if (check_for_match ($thing, @matchar)) { 1123 if (check_for_match ($thing, @matchar)) {
1075 return $thing; 1124 return $thing;
1076 } 1125 }
1077 } 1126 }
1078 return undef; 1127 return undef;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines