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.6 by elmex, Thu Feb 1 01:46:45 2007 UTC vs.
Revision 1.15 by root, Sat May 19 00:11:11 2007 UTC

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;
575 my $costs = dclone ($costs); 576 my $costs = dclone ($costs);
576 577
577 for my $key (keys %$costs) { 578 for my $key (keys %$costs) {
578 my @grepar; 579 my @grepar;
579 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 580 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
580 @grepar = @{Jeweler::getcfg (plans => $key) || []}; 581 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
582 next if $@;
581 } else { # check the gems 583 } else { # check the gems
582 @grepar = ('gems', undef, undef, $key); 584 @grepar = ('gems', undef, undef, $key);
583 } 585 }
584 586
585 if ($do_remove) { 587 if ($do_remove) {
628 $self->ring_or_ammy_to_hash ($arg{object}); 630 $self->ring_or_ammy_to_hash ($arg{object});
629 631
630 $self; 632 $self;
631} 633}
632 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
633sub analyze { 646sub analyze {
634 my ($self, $sk, $pl) = @_; 647 my ($self, $sk, $pl) = @_;
635 648
636 my $sklvl = cf::exp_to_level ($sk->stats->exp); 649 my $sklvl = cf::exp_to_level ($sk->stats->exp);
637 my $ringlvl = $self->power_to_level; 650 my $ringlvl = $self->power_to_level;
644 } 657 }
645 my $msg = sprintf "Projected success rate: %s", $tmpl; 658 my $msg = sprintf "Projected success rate: %s", $tmpl;
646 return $msg; 659 return $msg;
647} 660}
648 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->clone->value * $costs->{emerald}
670 + $saarch->clone->value * $costs->{sapphire}
671 + $pearch->clone->value * $costs->{pearl}
672 + $ruarch->clone->value * $costs->{ruby}
673 + $diarch->clone->value * $costs->{gem};
674
675 $value
676}
677
649sub wiz_analyze { 678sub wiz_analyze {
650 my ($self, $pl) = @_; 679 my ($self, $pl) = @_;
651 my $costs = $self->calc_costs; 680 my $costs = $self->calc_costs;
652 my $desc = ""; 681 my $desc = "";
653 my $lvl = $self->power_to_level (\$desc); 682 my $lvl = $self->power_to_level (\$desc);
654 my $emarch = cf::arch::find 'emerald'; 683 my $scosts = $self->calc_value_from_cost ($costs);
655 my $saarch = cf::arch::find 'sapphire';
656 my $pearch = cf::arch::find 'pearl';
657 my $ruarch = cf::arch::find 'ruby';
658 my $diarch = cf::arch::find 'gem';
659 my $scosts = $emarch->clone->value * $costs->{emerald}
660 + $saarch->clone->value * $costs->{sapphire}
661 + $pearch->clone->value * $costs->{pearl}
662 + $ruarch->clone->value * $costs->{ruby}
663 + $diarch->clone->value * $costs->{gem};
664 684
665 $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)");
666 $pl->message ("level: " . $desc); 686 $pl->message ("level: " . $desc);
667} 687}
668
669 688
670sub get_chance_perc { 689sub get_chance_perc {
671 my ($self, $sk) = @_; 690 my ($self, $sk) = @_;
672 my $sklvl = cf::exp_to_level ($sk->stats->exp); 691 my $sklvl = cf::exp_to_level ($sk->stats->exp);
673 my $ringlvl = $self->power_to_level; 692 my $ringlvl = $self->power_to_level;
676 695
677sub fx { 696sub fx {
678 my ($res, $cfg) = @_; 697 my ($res, $cfg) = @_;
679 my $or = $res; 698 my $or = $res;
680 my $ar = $Jeweler::CFG->{functions}->{$cfg}; 699 my $ar = $Jeweler::CFG->{functions}->{$cfg};
700
681 if (ref $ar->[0] eq 'ARRAY') { 701 if (ref $ar->[0] eq 'ARRAY') {
682 $res = $res - 1; 702 $res = $res - 1;
703 return $ar->[max (min ($res, @$ar - 1), 0)];
704
683 } else { 705 } else {
706 # +0.1 is for a jump to the next index when $res / 5 is exactly 1, 2, 3...
684 $res = ceil ($res / 5) - 1; 707 my $idx = ceil (($res / 5) + 0.1) - 1;
685 }
686 $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 }
687} 714}
688 715
689sub improve_by_ring { 716sub improve_by_ring {
690 my ($self, @rings) = @_; 717 my ($self, @rings) = @_;
691 my $ring = $self; 718 my $ring = $self;
707 if ($self->{hash}->{$cat}->{$k} > 0) { 734 if ($self->{hash}->{$cat}->{$k} > 0) {
708 $self->{hash}->{$cat}->{$k} *= -1; 735 $self->{hash}->{$cat}->{$k} *= -1;
709 } 736 }
710 } 737 }
711 } 738 }
739 $self->{hash}{value} = 0;
712} 740}
713 741
714sub to_string { 742sub to_string {
715 my ($self) = @_; 743 my ($self) = @_;
716 my $r = $self->{hash}; 744 my $r = $self->{hash};
758 786
759 $obj->{name} = $thing->name; 787 $obj->{name} = $thing->name;
760 $obj->{arch} = $thing->arch->name; 788 $obj->{arch} = $thing->arch->name;
761 $obj->{face} = $thing->face; 789 $obj->{face} = $thing->face;
762 790
791 $obj->{value} = $thing->value;
792
763 $self->{hash} = $obj 793 $self->{hash} = $obj
764} 794}
765 795
766sub to_object { 796sub to_object {
767 my ($self) = @_; 797 my ($self) = @_;
768 798
769 my $obj = cf::object::new $self->{hash}->{arch}; 799 my $obj = cf::object::new $self->{hash}->{arch};
770 800
771 $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!
772 802
773 $obj->face ($self->{hash}{face}); 803 $obj->face ($self->{hash}{face});
774 804
775 my $stats = $obj->stats; 805 my $stats = $obj->stats;
776 806
789 $obj->resist ($_, $self->{hash}->{resist}->{$_}); 819 $obj->resist ($_, $self->{hash}->{resist}->{$_});
790 } 820 }
791 821
792 $obj->flag (cf::FLAG_IDENTIFIED, 1); 822 $obj->flag (cf::FLAG_IDENTIFIED, 1);
793 823
824 $obj->value ($self->{hash}{value});
825
794 return $obj; 826 return $obj;
795} 827}
828
829sub set_value { $_[0]->{hash}{value} = $_[1] }
796 830
797sub is_better_than { 831sub is_better_than {
798 my ($self, $other) = @_; 832 my ($self, $other) = @_;
799 833
800 for my $type (qw/spec stat resist/) { 834 for my $type (qw/spec stat resist/) {
1047 1081
1048sub check_for_match { 1082sub check_for_match {
1049 my ($thing, @matchar) = @_; 1083 my ($thing, @matchar) = @_;
1050 1084
1051 my $i = 0; 1085 my $i = 0;
1086 my $check_cnts = 0;
1087 my $check_true = 0;
1052 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
1053 if ($match =~ m/^\s*$/) { 1095 if ($match =~ m/^\s*$/) {
1054 $i++; 1096 $i++;
1055 next; 1097 next;
1056 } 1098 }
1057 1099
1100 $check_cnts++;
1058 if ($i % 3 == 0) { 1101 if ($i % 3 == 0) {
1059 $thing->name eq $match 1102 $thing->name eq $match
1060 and return 1; 1103 and $check_true++;
1061 } elsif ($i % 3 == 1) { 1104 } elsif ($i % 3 == 1) {
1062 $thing->title eq $match 1105 $thing->title eq $match
1063 and return 1; 1106 and $check_true++;
1064 } else { # $i % 3 == 2 1107 } else { # $i % 3 == 2
1065 $thing->arch->name eq $match 1108 $thing->arch->name eq $match
1066 and return 1; 1109 and $check_true++;
1067 } 1110 }
1068 $i++; 1111 $i++;
1069 } 1112 }
1113 #d# warn "CHECK $check_true | $check_cnts | [".(join ',', @matchar).":".join (",", ($thing->name, $thing->title, $thing->arch->name))."\n";
1114 return 1 if $check_true && $check_cnts == $check_true;
1070 return 0; 1115 return 0;
1071} 1116}
1072 1117
1073sub grep_for_match { 1118sub grep_for_match {
1074 my ($ingred, $group, @matchar) = @_; 1119 my ($ingred, $group, @matchar) = @_;
1075 1120
1076 for my $thing (@{$ingred->{$group} || []}) { 1121 for my $thing (@{$ingred->{$group} || []}) {
1077 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->name, "@matchar"; #d#
1078 if (check_for_match ($thing, @matchar)) { 1123 if (check_for_match ($thing, @matchar)) {
1079 return $thing; 1124 return $thing;
1080 } 1125 }
1081 } 1126 }
1082 return undef; 1127 return undef;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines