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.34 by root, Wed Apr 28 21:07:41 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 warn "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);
840 $obj->{arch} = $thing->arch->archname; 843 $obj->{arch} = $thing->arch->archname;
841 $obj->{face} = $thing->face; 844 $obj->{face} = $thing->face;
842 845
843 $obj->{value} = $thing->value; 846 $obj->{value} = $thing->value;
844 847
848 $obj->{is_ring} = ($thing->type == cf::RING);
849
845 $self->{hash} = $obj 850 $self->{hash} = $obj
846} 851}
847 852
848sub to_object { 853sub to_object {
849 my ($self) = @_; 854 my ($self) = @_;
911sub resist_level { 916sub resist_level {
912 my ($self) = @_; 917 my ($self) = @_;
913 918
914 my $resists = $self->{hash}->{resist} || {}; 919 my $resists = $self->{hash}->{resist} || {};
915 920
916 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); 921 my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level');
917 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); 922 my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level');
918 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); 923 my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances');
919 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); 924 my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances');
920 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); 925 my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances');
921 926
922 my $ressum = 0; 927 my $ressum = 0;
982sub power_to_level { 987sub power_to_level {
983 my ($self, $lvldescr) = @_; 988 my ($self, $lvldescr) = @_;
984 989
985 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); 990 my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements');
986 my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level'); 991 my $max_impr_lvl = Jeweler::getcfg (maxlevels => 'improve_level');
992 my $ring_offs = Jeweler::getcfg (maxlevels => 'ring_offset');
987 993
988 my ($stat_lvl, $stat_imprs) = $self->stat_level; 994 my ($stat_lvl, $stat_imprs) = $self->stat_level;
989 my ($resist_lvl, $res_imprs) = $self->resist_level; 995 my ($resist_lvl, $res_imprs) = $self->resist_level;
990 my ($spec_lvl, $spec_imprs) = $self->special_level; 996 my ($spec_lvl, $spec_imprs) = $self->special_level;
991 997
992 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; 998 my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs;
993 999
994 my $impr_lvl = ceil (($max_impr_lvl / ($max_imprs + 1)) * ($impr_sum - 1)); # 1 improvemnt bonus 1000 my $impr_lvl =
1001 ceil (($max_impr_lvl / ($max_imprs + 1))
1002 * ($impr_sum - 1)); # 1 improvemnt bonus
995 1003
996 my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0); 1004 my $levl = int max ($stat_lvl, $resist_lvl, $impr_lvl, $spec_lvl, 0);
1005
1006 if ($self->{hash}->{is_ring}) {
1007 $levl += $ring_offs;
1008 }
1009
1010 $levl = min ($levl, cf::settings->max_level);
997 1011
998 if ($lvldescr) { 1012 if ($lvldescr) {
999 $$lvldescr = 1013 $$lvldescr =
1000 sprintf "%3d: %s\n", $levl, 1014 sprintf "%3d: %s\n", $levl,
1001 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " 1015 "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, "

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines