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.28 by root, Sat Dec 13 20:34:37 2008 UTC vs.
Revision 1.36 by root, Tue May 4 22:49:21 2010 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;
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_animation (cf::rndm $ob->num_animations)
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);
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
622 } 626 }
623 } 627 }
624} 628}
625 629
626package Jeweler::Object; 630package Jeweler::Object;
627use strict; 631
632use common::sense;
628use POSIX; 633use POSIX;
629use List::Util qw/max min sum/; 634use List::Util qw/max min sum/;
630 635
631sub new { 636sub new {
632 my ($class, %arg) = @_; 637 my ($class, %arg) = @_;
841 $obj->{arch} = $thing->arch->archname; 846 $obj->{arch} = $thing->arch->archname;
842 $obj->{face} = $thing->face; 847 $obj->{face} = $thing->face;
843 848
844 $obj->{value} = $thing->value; 849 $obj->{value} = $thing->value;
845 850
851 $obj->{is_ring} = ($thing->type == cf::RING);
852
846 $self->{hash} = $obj 853 $self->{hash} = $obj
847} 854}
848 855
849sub to_object { 856sub to_object {
850 my ($self) = @_; 857 my ($self) = @_;
912sub resist_level { 919sub resist_level {
913 my ($self) = @_; 920 my ($self) = @_;
914 921
915 my $resists = $self->{hash}->{resist} || {}; 922 my $resists = $self->{hash}->{resist} || {};
916 923
917 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); 924 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level');
918 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); 925 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level');
919 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); 926 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances');
920 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); 927 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances');
921 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); 928 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances');
922 929
923 my $ressum = 0; 930 my $ressum = 0;
983sub power_to_level { 990sub power_to_level {
984 my ($self, $lvldescr) = @_; 991 my ($self, $lvldescr) = @_;
985 992
986 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); 993 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements');
987 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');
988 996
989 my ($stat_lvl, $stat_imprs) = $self->stat_level; 997 my ($stat_lvl, $stat_imprs) = $self->stat_level;
990 my ($resist_lvl, $res_imprs) = $self->resist_level; 998 my ($resist_lvl, $res_imprs) = $self->resist_level;
991 my ($spec_lvl, $spec_imprs) = $self->special_level; 999 my ($spec_lvl, $spec_imprs) = $self->special_level;
992 1000
993 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; 1001 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs;
994 1002
995 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
996 1006
997 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);
998 1014
999 if ($lvldescr) { 1015 if ($lvldescr) {
1000 $$lvldescr = 1016 $$lvldescr =
1001 sprintf "%3d: %s\n", $levl, 1017 sprintf "%3d: %s\n", $levl,
1002 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " 1018 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, "
1093 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; 1109 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value;
1094} 1110}
1095 1111
1096package Jeweler::Util; 1112package Jeweler::Util;
1097 1113
1098use strict; 1114use common::sense;
1099 1115
1100=head2 Util 1116=head2 Util
1101 1117
1102Some utility functions for the Jeweler skill. 1118Some utility functions for the Jeweler skill.
1103 1119

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines