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.29 by root, Mon Oct 12 14:00:58 2009 UTC vs.
Revision 1.36 by root, Tue May 4 22:49:21 2010 UTC

20 20
21=cut 21=cut
22 22
23our $CFG; 23our $CFG;
24 24
25sub read_config { 25sub load_config {
26 my ($filename) = @_; 26 cf::trace "loading jeweler config from $cf::DATADIR/jeweler\n";
27 27
28 if (my $meta = $cf::RESOURCE{$filename}) { 28 0 < Coro::AIO::aio_load "$cf::DATADIR/jeweler", my $data
29 or die "$cf::DATADIR/jeweler: $!";
30
29 $CFG = cf::decode_json $meta->{data}; 31 $CFG = cf::decode_json $data;
30 } else {
31 warn "$filename doesn't exist! no config for jeweler skill loaded!\n";
32 $CFG = {};
33 }
34} 32}
35 33
36sub getcfg { 34sub getcfg {
37 my ($sect, $key) = @_; 35 my ($sect, $key) = @_;
38 return $CFG->{$sect} unless defined $key; 36 return $CFG->{$sect} unless defined $key;
185 unless $found; 183 unless $found;
186} 184}
187 185
188# this function converts metals/minerals into a raw ring (of adornment) 186# this function converts metals/minerals into a raw ring (of adornment)
189sub simple_converter { 187sub simple_converter {
190 my ($pl, $ingred, $chdl, $conv) = @_; 188 my ($pl, $ingred, $chdl, $conv, $sk_lvl, $low_skill_cb) = @_;
191 189
192 $conv = lc $conv; 190 $conv = lc $conv;
193 my $cnvs = $CFG->{conversions}; 191 my $cnvs = $CFG->{conversions};
194 192
195 return unless $cnvs->{$conv}; 193 return unless $cnvs->{$conv};
217 215
218 unless ($outarchvalfact >= 1) { 216 unless ($outarchvalfact >= 1) {
219 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";
220 } 218 }
221 219
222 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname); 220 my $archvalsum = $ingred->value ($ingr_grp, $srcarchname);
223 $ingred->remove ($ingr_grp, $srcarchname);
224
225 my $outarchval = cf::arch::find ($outarch)->value; 221 my $outarchval = cf::arch::find ($outarch)->value;
226
227 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
228 if ($nrof) { 230 if ($nrof) {
229 # 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);
230 for (1 .. $nrof) { 233 for (1 .. $nrof) {
231 $chdl->put (my $ob = cf::object::new $outarch); 234 $chdl->put (my $ob = cf::object::new $outarch);
232 $ob->set_animation (cf::rndm $ob->num_animations) 235 $ob->set_animation (cf::rndm $ob->num_animations)
233 if ($ob->type == cf::RING); 236 if ($ob->type == cf::RING);
234 $ob->flag (cf::FLAG_IDENTIFIED, 1); 237 $ob->flag (cf::FLAG_IDENTIFIED, 1);
246} 249}
247 250
248 251
249package Jeweler::CauldronHandler; 252package Jeweler::CauldronHandler;
250 253
251use strict; 254use common::sense;
252 255
253=head2 CauldronHandler 256=head2 CauldronHandler
254 257
255The Jeweler::CauldronHandler package, that helps you with handling the 258The Jeweler::CauldronHandler package, that helps you with handling the
256cauldron stuff. Can also be used for other skills. 259cauldron stuff. Can also be used for other skills.
364=back 367=back
365 368
366=cut 369=cut
367 370
368package Jeweler::Ingredients; 371package Jeweler::Ingredients;
372
373use common::sense;
374
369use Storable qw/dclone/; 375use Storable qw/dclone/;
370use strict;
371 376
372=head2 Ingredients 377=head2 Ingredients
373 378
374This class handles the ingredients. 379This class handles the ingredients.
375 380
621 } 626 }
622 } 627 }
623} 628}
624 629
625package Jeweler::Object; 630package Jeweler::Object;
626use strict; 631
632use common::sense;
627use POSIX; 633use POSIX;
628use List::Util qw/max min sum/; 634use List::Util qw/max min sum/;
629 635
630sub new { 636sub new {
631 my ($class, %arg) = @_; 637 my ($class, %arg) = @_;
840 $obj->{arch} = $thing->arch->archname; 846 $obj->{arch} = $thing->arch->archname;
841 $obj->{face} = $thing->face; 847 $obj->{face} = $thing->face;
842 848
843 $obj->{value} = $thing->value; 849 $obj->{value} = $thing->value;
844 850
851 $obj->{is_ring} = ($thing->type == cf::RING);
852
845 $self->{hash} = $obj 853 $self->{hash} = $obj
846} 854}
847 855
848sub to_object { 856sub to_object {
849 my ($self) = @_; 857 my ($self) = @_;
911sub resist_level { 919sub resist_level {
912 my ($self) = @_; 920 my ($self) = @_;
913 921
914 my $resists = $self->{hash}->{resist} || {}; 922 my $resists = $self->{hash}->{resist} || {};
915 923
916 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); 924 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level');
917 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); 925 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level');
918 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); 926 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances');
919 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); 927 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances');
920 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); 928 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances');
921 929
922 my $ressum = 0; 930 my $ressum = 0;
982sub power_to_level { 990sub power_to_level {
983 my ($self, $lvldescr) = @_; 991 my ($self, $lvldescr) = @_;
984 992
985 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); 993 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements');
986 my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); 994 my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level');
995 my $ring_offs = Jeweler::getcfg (maxlevels => 'ring_offset');
987 996
988 my ($stat_lvl, $stat_imprs) = $self->stat_level; 997 my ($stat_lvl, $stat_imprs) = $self->stat_level;
989 my ($resist_lvl, $res_imprs) = $self->resist_level; 998 my ($resist_lvl, $res_imprs) = $self->resist_level;
990 my ($spec_lvl, $spec_imprs) = $self->special_level; 999 my ($spec_lvl, $spec_imprs) = $self->special_level;
991 1000
992 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; 1001 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs;
993 1002
994 my $impr_lvl = ceil (($max_impr_lvl / ($max_imprs + 1)) * ($impr_sum - 1)); # 1 improvemnt bonus 1003 my $impr_lvl =
1004 ceil (($max_impr_lvl / ($max_imprs + 1))
1005 * ($impr_sum - 1)); # 1 improvemnt bonus
995 1006
996 my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); 1007 my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0);
1008
1009 if ($self->{hash}->{is_ring}) {
1010 $levl += $ring_offs;
1011 }
1012
1013 $levl = min ($levl, cf::settings->max_level);
997 1014
998 if ($lvldescr) { 1015 if ($lvldescr) {
999 $$lvldescr = 1016 $$lvldescr =
1000 sprintf "%3d: %s\n", $levl, 1017 sprintf "%3d: %s\n", $levl,
1001 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " 1018 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, "
1092 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; 1109 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value;
1093} 1110}
1094 1111
1095package Jeweler::Util; 1112package Jeweler::Util;
1096 1113
1097use strict; 1114use common::sense;
1098 1115
1099=head2 Util 1116=head2 Util
1100 1117
1101Some utility functions for the Jeweler skill. 1118Some utility functions for the Jeweler skill.
1102 1119

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines