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.25 by root, Thu Apr 10 15:35:16 2008 UTC vs.
Revision 1.39 by root, Sun Nov 18 15:19:48 2018 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 cf::trace "loading jeweler config from $cf::DATADIR/jeweler\n";
28 27
29 if (my $meta = $cf::RESOURCE{$filename}) { 28 0 < Coro::AIO::aio_load "$cf::DATADIR/jeweler", my $data
29 or die "$cf::DATADIR/jeweler: $!";
30
30 $CFG = cf::decode_json $meta->{data}; 31 $CFG = cf::decode_json $data;
31 } else {
32 warn "$filename doesn't exist! no config for jeweler skill loaded!\n";
33 $CFG = {};
34 }
35} 32}
36 33
37sub getcfg { 34sub getcfg {
38 my ($sect, $key) = @_; 35 my ($sect, $key) = @_;
39 return $CFG->{$sect} unless defined $key; 36 return $CFG->{$sect} unless defined $key;
173 next; 170 next;
174 } 171 }
175 $found = 1; 172 $found = 1;
176 my $r = Jeweler::Object->new (object => $_); 173 my $r = Jeweler::Object->new (object => $_);
177 my $msg = $r->analyze ($sk, $pl, $input_level); 174 my $msg = $r->analyze ($sk, $pl, $input_level);
178 $pl->message ($r->to_string . ": " . $msg); 175 $pl->message ("There is a '" . $r->to_string . "' in the workbench. Your analysis: " . $msg);
179 if ($pl->flag (cf::FLAG_WIZ)) { 176 if ($pl->flag (cf::FLAG_WIZ)) {
180 $r->wiz_analyze ($pl); 177 $r->wiz_analyze ($pl);
181 } 178 }
182 } 179 }
183 $pl->message ("You couldn't identify the other rings and not analyze them!") 180 $pl->message ("You couldn't identify the other rings and not analyze them!")
186 unless $found; 183 unless $found;
187} 184}
188 185
189# this function converts metals/minerals into a raw ring (of adornment) 186# this function converts metals/minerals into a raw ring (of adornment)
190sub simple_converter { 187sub simple_converter {
191 my ($pl, $ingred, $chdl, $conv) = @_; 188 my ($pl, $ingred, $chdl, $conv, $sk_lvl, $low_skill_cb) = @_;
192 189
193 $conv = lc $conv; 190 $conv = lc $conv;
194 my $cnvs = $CFG->{conversions}; 191 my $cnvs = $CFG->{conversions};
195 192
196 return unless $cnvs->{$conv}; 193 return unless $cnvs->{$conv};
218 215
219 unless ($outarchvalfact >= 1) { 216 unless ($outarchvalfact >= 1) {
220 warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n"; 217 warn "WARNING: source-arch-value-multiplier < 1 in conversion '$outarch', results in more valuable output!\n";
221 } 218 }
222 219
223 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); 220 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname);
224 $ingred->remove ($ingr_grp, $srcarchname);
225
226 my $outarchval = cf::arch::find ($outarch)->value; 221 my $outarchval = cf::arch::find ($outarch)->value;
227
228 my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact); 222 my $nrof = int $archvalsum / (($outarchval || 1000) * $outarchvalfact);
223 my $can_make_nr = int (($sk_lvl / 2) + 10);
224
225 if ($nrof > $can_make_nr) {
226 $pl->ob->message ("Your jeweler level is too low to make $nrof rings, you can only make $can_make_nr at your current level.");
227 return;
228 }
229
229 if ($nrof) { 230 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) 231 # XXX: yes, I know what I'm doing here, I don't set nrof, but it didn't work somehow (pls. check sometimes)
232 $ingred->remove ($ingr_grp, $srcarchname);
231 for (1 .. $nrof) { 233 for (1 .. $nrof) {
232 $chdl->put (my $ob = cf::object::new $outarch); 234 $chdl->put (my $ob = cf::object::new $outarch);
233 $ob->set_animation (cf::rndm $ob->num_animations) 235 $ob->set_anim_frame (cf::rndm $ob->anim_frames)
234 if ($ob->type == cf::RING); 236 if ($ob->type == cf::RING);
235 $ob->flag (cf::FLAG_IDENTIFIED, 1); 237 $ob->flag (cf::FLAG_IDENTIFIED, 1);
236 } 238 }
237 239
238 my $xp_sum = $xp_gain * $nrof; 240 my $xp_sum = $xp_gain * $nrof;
247} 249}
248 250
249 251
250package Jeweler::CauldronHandler; 252package Jeweler::CauldronHandler;
251 253
252use strict; 254use common::sense;
253 255
254=head2 CauldronHandler 256=head2 CauldronHandler
255 257
256The Jeweler::CauldronHandler package, that helps you with handling the 258The Jeweler::CauldronHandler package, that helps you with handling the
257cauldron stuff. Can also be used for other skills. 259cauldron stuff. Can also be used for other skills.
365=back 367=back
366 368
367=cut 369=cut
368 370
369package Jeweler::Ingredients; 371package Jeweler::Ingredients;
372
373use common::sense;
374
370use Storable qw/dclone/; 375use Storable qw/dclone/;
371use strict;
372 376
373=head2 Ingredients 377=head2 Ingredients
374 378
375This class handles the ingredients. 379This class handles the ingredients.
376 380
479} 483}
480 484
481sub improve_ring_by_plan { 485sub improve_ring_by_plan {
482 my ($self, $plan, $ring) = @_; 486 my ($self, $plan, $ring) = @_;
483 487
484 $ring = do { my $guard = Coro::Storable::guard; dclone $ring }; 488 $ring = dclone $ring;
485 489
486 my $ingred = $self->{ingredients}; 490 my $ingred = $self->{ingredients};
487 my $impr = {}; 491 my $impr = {};
488 492
489 if ($plan =~ m/^stat_(\S+)$/) { 493 if ($plan =~ m/^stat_(\S+)$/) {
573} 577}
574 578
575sub check_costs { 579sub check_costs {
576 my ($self, $costs, $do_remove) = @_; 580 my ($self, $costs, $do_remove) = @_;
577 581
578 my $costs = do { my $guard = Coro::Storable::guard; dclone $costs }; 582 my $costs = dclone $costs;
579 583
580 for my $key (keys %$costs) { 584 for my $key (keys %$costs) {
581 my @grepar; 585 my @grepar;
582 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items 586 if ($key =~ m/^(resist_|spec_|stat_)/) { # check the special items
583 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} }; 587 eval { @grepar = @{Jeweler::getcfg (plans => $key) || []} };
586 @grepar = ('gems', undef, undef, $key); 590 @grepar = ('gems', undef, undef, $key);
587 } 591 }
588 592
589 if ($do_remove) { 593 if ($do_remove) {
590 my $rem = $costs->{$key}; 594 my $rem = $costs->{$key};
591 $self->do_grep (sub { if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 1 }, @grepar); 595 $self->do_grep (sub {
596 if ($rem) {
597 $rem = Jeweler::Util::remove ($_[0], $rem);
598 }
599 1
600 }, @grepar);
592 if ($rem > 0) { 601 if ($rem > 0) {
593 warn "JEWELER BUG: removed ingredients $rem > 0 after removing!"; 602 warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!";
594 } 603 }
604
595 } else { 605 } else {
596 my $nr; 606 my $nr;
597 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar); 607 $self->do_grep (sub { $nr += ($_[0]->nrof || 1); 0 }, @grepar);
598 $costs->{$key} -= $nr; 608 $costs->{$key} -= $nr;
599 } 609 }
618 } 628 }
619 } 629 }
620} 630}
621 631
622package Jeweler::Object; 632package Jeweler::Object;
623use strict; 633
634use common::sense;
624use POSIX; 635use POSIX;
625use List::Util qw/max min sum/; 636use List::Util qw/max min sum/;
626 637
627sub new { 638sub new {
628 my ($class, %arg) = @_; 639 my ($class, %arg) = @_;
643 return 1 if $self->{hash}->{resist}->{$resnum}; 654 return 1 if $self->{hash}->{resist}->{$resnum};
644 } 655 }
645 return undef; 656 return undef;
646} 657}
647 658
659sub lvl2exp {
660 my $lvl = shift;
661 (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1))
662 / (20 + max ($lvl - 1, 0)) # 20 + level times making such a ring
663 # should get you to the rings level at least.
664}
665
648sub projected_exp { 666sub projected_exp {
649 my ($self, $input_level) = @_; 667 my ($self, $input_level) = @_;
650 668
651 my $lvl = max ($self->power_to_level, 1); 669 my $lvl = max ($self->power_to_level, 1);
652 my $exp = 670 my $exp = lvl2exp ($lvl);
653 (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1))
654 / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring
655 # should get you to the rings level at least.
656 671
657 if (defined $input_level) { 672 if (defined $input_level) { # in case we merge rings:
658 my $subexp = 673 my $subexp = lvl2exp ($input_level);
659 (cf::level_to_min_exp ($input_level)
660 - cf::level_to_min_exp ($input_level - 1))
661 / (10 + max ($input_level - 1, 0)); # see above for comment
662
663 $exp -= $subexp; 674 $exp -= $subexp;
664 $exp = max ($exp, 0); 675 $exp = max ($exp, 0);
665 676
666 } else { 677 } else {
667 # the experience bonus here is to make level 1 rings give you at least 678 # the experience bonus here is to make level 1 rings give you at least
668 # 100 exp points when making them. This also makes leveling in the 679 # 200 exp points when making them. This also makes leveling in the
669 # first few levels a bit easier. (probably until around level 5-6). 680 # first few levels a bit easier. (probably until around level 5-6).
670 my $expbonus = cf::level_to_min_exp (2) / 10; 681 my $expbonus = cf::level_to_min_exp (2) / 5;
671 # this bonus should also only be given for _new_ rings and not for merged 682 # this bonus should also only be given for _new_ rings and not for merged
672 # ones - to prevent infinite exp making. 683 # ones - to prevent infinite exp making.
673 $exp += $expbonus; 684 $exp += $expbonus;
674 } 685 }
675 686
722 my $scosts = $self->calc_value_from_cost ($costs); 733 my $scosts = $self->calc_value_from_cost ($costs);
723 734
724 $pl->message ("costs: " 735 $pl->message ("costs: "
725 . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs) 736 . (join ', ', map { "$_: " . sprintf "%.2f", $costs->{$_} } keys %$costs)
726 . " (" 737 . " ("
727 . ($scosts / "royalty"->cf::arch::find->value) 738 . ($scosts / "platinacoin"->cf::arch::find->value)
728 . " royalties)"); 739 . " platinum)");
729 $pl->message ("level: $desc"); 740 $pl->message ("level: $desc");
730 } else { 741 } else {
731 $pl->message ("level: impossible to make, due to impossible resistancy configuration"); 742 $pl->message ("level: impossible to make, due to impossible resistancy configuration");
732 } 743 }
733} 744}
837 $obj->{arch} = $thing->arch->archname; 848 $obj->{arch} = $thing->arch->archname;
838 $obj->{face} = $thing->face; 849 $obj->{face} = $thing->face;
839 850
840 $obj->{value} = $thing->value; 851 $obj->{value} = $thing->value;
841 852
853 $obj->{is_ring} = ($thing->type == cf::RING);
854
842 $self->{hash} = $obj 855 $self->{hash} = $obj
843} 856}
844 857
845sub to_object { 858sub to_object {
846 my ($self) = @_; 859 my ($self) = @_;
847 860
848 my $obj = cf::object::new $self->{hash}->{arch}; 861 my $obj = cf::object::new $self->{hash}->{arch};
849 862
850 $obj->item_power (floor ($self->power_to_level / 3)); # there have to be strings attached! 863 $obj->item_power (floor ($self->power_to_level / 5)); # there have to be strings attached!
851 864
852 $obj->face ($self->{hash}{face}); 865 $obj->face ($self->{hash}{face});
853 866
854 my $stats = $obj->stats; 867 my $stats = $obj->stats;
855 868
908sub resist_level { 921sub resist_level {
909 my ($self) = @_; 922 my ($self) = @_;
910 923
911 my $resists = $self->{hash}->{resist} || {}; 924 my $resists = $self->{hash}->{resist} || {};
912 925
913 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); 926 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level');
914 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); 927 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level');
915 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); 928 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances');
916 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); 929 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances');
917 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); 930 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances');
918 931
919 my $ressum = 0; 932 my $ressum = 0;
979sub power_to_level { 992sub power_to_level {
980 my ($self, $lvldescr) = @_; 993 my ($self, $lvldescr) = @_;
981 994
982 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); 995 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements');
983 my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); 996 my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level');
997 my $ring_offs = Jeweler::getcfg (maxlevels => 'ring_offset');
984 998
985 my ($stat_lvl, $stat_imprs) = $self->stat_level; 999 my ($stat_lvl, $stat_imprs) = $self->stat_level;
986 my ($resist_lvl, $res_imprs) = $self->resist_level; 1000 my ($resist_lvl, $res_imprs) = $self->resist_level;
987 my ($spec_lvl, $spec_imprs) = $self->special_level; 1001 my ($spec_lvl, $spec_imprs) = $self->special_level;
988 1002
989 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; 1003 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs;
990 1004
991 my $impr_lvl = ceil (($max_impr_lvl / ($max_imprs + 1)) * ($impr_sum - 1)); # 1 improvemnt bonus 1005 my $impr_lvl =
1006 ceil (($max_impr_lvl / ($max_imprs + 1))
1007 * ($impr_sum - 1)); # 1 improvemnt bonus
992 1008
993 my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); 1009 my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0);
1010
1011 if ($self->{hash}->{is_ring}) {
1012 $levl += $ring_offs;
1013 }
1014
1015 $levl = min ($levl, cf::settings->max_level);
994 1016
995 if ($lvldescr) { 1017 if ($lvldescr) {
996 $$lvldescr = 1018 $$lvldescr =
997 sprintf "%3d: %s\n", $levl, 1019 sprintf "%3d: %s\n", $levl,
998 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " 1020 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, "
1089 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; 1111 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value;
1090} 1112}
1091 1113
1092package Jeweler::Util; 1114package Jeweler::Util;
1093 1115
1094use strict; 1116use common::sense;
1095 1117
1096=head2 Util 1118=head2 Util
1097 1119
1098Some utility functions for the Jeweler skill. 1120Some utility functions for the Jeweler skill.
1099 1121
1100=over 4 1122=over 4
1101 1123
1102=item remove ($object[, $nrof]) 1124=item remove ($object[, $nrof])
1103 1125
1104Removes the C<$object>. If C<$nrof> is given, remove only C<$nrof> objects. 1126Removes 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. 1127The return value is the number of 'single' objects that couldn't be removed.
1106 1128
1107=cut 1129=cut
1108 1130
1109sub remove { 1131sub remove {
1110 my ($obj, $nrof) = @_; 1132 my ($obj, $nrof) = @_;
1111 1133
1112 my $cnt; 1134 my $c = $obj->number_of;
1135 my $r = $c > $nrof ? 0 : $nrof - $c;
1136 $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1));
1113 1137
1114 if (defined $nrof) { 1138 $r
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} 1139}
1129 1140
1130sub check_for_match { 1141sub check_for_match {
1131 my ($thing, @matchar) = @_; 1142 my ($thing, @matchar) = @_;
1132 1143

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines