… | |
… | |
20 | |
20 | |
21 | =cut |
21 | =cut |
22 | |
22 | |
23 | our $CFG; |
23 | our $CFG; |
24 | |
24 | |
25 | sub read_config { |
25 | sub 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 | |
36 | sub getcfg { |
34 | sub getcfg { |
37 | my ($sect, $key) = @_; |
35 | my ($sect, $key) = @_; |
38 | return $CFG->{$sect} unless defined $key; |
36 | return $CFG->{$sect} unless defined $key; |
… | |
… | |
251 | } |
249 | } |
252 | |
250 | |
253 | |
251 | |
254 | package Jeweler::CauldronHandler; |
252 | package Jeweler::CauldronHandler; |
255 | |
253 | |
256 | use strict; |
254 | use common::sense; |
257 | |
255 | |
258 | =head2 CauldronHandler |
256 | =head2 CauldronHandler |
259 | |
257 | |
260 | The Jeweler::CauldronHandler package, that helps you with handling the |
258 | The Jeweler::CauldronHandler package, that helps you with handling the |
261 | cauldron stuff. Can also be used for other skills. |
259 | cauldron stuff. Can also be used for other skills. |
… | |
… | |
369 | =back |
367 | =back |
370 | |
368 | |
371 | =cut |
369 | =cut |
372 | |
370 | |
373 | package Jeweler::Ingredients; |
371 | package Jeweler::Ingredients; |
|
|
372 | |
|
|
373 | use common::sense; |
|
|
374 | |
374 | use Storable qw/dclone/; |
375 | use Storable qw/dclone/; |
375 | use strict; |
|
|
376 | |
376 | |
377 | =head2 Ingredients |
377 | =head2 Ingredients |
378 | |
378 | |
379 | This class handles the ingredients. |
379 | This class handles the ingredients. |
380 | |
380 | |
… | |
… | |
626 | } |
626 | } |
627 | } |
627 | } |
628 | } |
628 | } |
629 | |
629 | |
630 | package Jeweler::Object; |
630 | package Jeweler::Object; |
631 | use strict; |
631 | |
|
|
632 | use common::sense; |
632 | use POSIX; |
633 | use POSIX; |
633 | use List::Util qw/max min sum/; |
634 | use List::Util qw/max min sum/; |
634 | |
635 | |
635 | sub new { |
636 | sub new { |
636 | my ($class, %arg) = @_; |
637 | my ($class, %arg) = @_; |
… | |
… | |
845 | $obj->{arch} = $thing->arch->archname; |
846 | $obj->{arch} = $thing->arch->archname; |
846 | $obj->{face} = $thing->face; |
847 | $obj->{face} = $thing->face; |
847 | |
848 | |
848 | $obj->{value} = $thing->value; |
849 | $obj->{value} = $thing->value; |
849 | |
850 | |
|
|
851 | $obj->{is_ring} = ($thing->type == cf::RING); |
|
|
852 | |
850 | $self->{hash} = $obj |
853 | $self->{hash} = $obj |
851 | } |
854 | } |
852 | |
855 | |
853 | sub to_object { |
856 | sub to_object { |
854 | my ($self) = @_; |
857 | my ($self) = @_; |
… | |
… | |
916 | sub resist_level { |
919 | sub resist_level { |
917 | my ($self) = @_; |
920 | my ($self) = @_; |
918 | |
921 | |
919 | my $resists = $self->{hash}->{resist} || {}; |
922 | my $resists = $self->{hash}->{resist} || {}; |
920 | |
923 | |
921 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
924 | my $att_res_lvl = Jeweler::getcfg (maxlevels => 'resist_level'); |
922 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
925 | my $efc_res_lvl = Jeweler::getcfg (maxlevels => 'effect_resist_level'); |
923 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
926 | my $max_att_res = Jeweler::getcfg (maximprovements => 'attack_resistances'); |
924 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
927 | my $max_efc_res = Jeweler::getcfg (maximprovements => 'effect_resistances'); |
925 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
928 | my $max_ovr_res = Jeweler::getcfg (maximprovements => 'resistances'); |
926 | |
929 | |
927 | my $ressum = 0; |
930 | my $ressum = 0; |
… | |
… | |
987 | sub power_to_level { |
990 | sub power_to_level { |
988 | my ($self, $lvldescr) = @_; |
991 | my ($self, $lvldescr) = @_; |
989 | |
992 | |
990 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
993 | my $max_imprs = Jeweler::getcfg (maximprovements => 'improvements'); |
991 | 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'); |
992 | |
996 | |
993 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
997 | my ($stat_lvl, $stat_imprs) = $self->stat_level; |
994 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
998 | my ($resist_lvl, $res_imprs) = $self->resist_level; |
995 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
999 | my ($spec_lvl, $spec_imprs) = $self->special_level; |
996 | |
1000 | |
997 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
1001 | my $impr_sum = $stat_imprs + $res_imprs + $spec_imprs; |
998 | |
1002 | |
999 | 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 |
1000 | |
1006 | |
1001 | 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); |
1002 | |
1014 | |
1003 | if ($lvldescr) { |
1015 | if ($lvldescr) { |
1004 | $$lvldescr = |
1016 | $$lvldescr = |
1005 | sprintf "%3d: %s\n", $levl, |
1017 | sprintf "%3d: %s\n", $levl, |
1006 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
1018 | "stat: $stat_lvl, resist: $resist_lvl, improve: $impr_lvl, " |
… | |
… | |
1097 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1109 | $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; |
1098 | } |
1110 | } |
1099 | |
1111 | |
1100 | package Jeweler::Util; |
1112 | package Jeweler::Util; |
1101 | |
1113 | |
1102 | use strict; |
1114 | use common::sense; |
1103 | |
1115 | |
1104 | =head2 Util |
1116 | =head2 Util |
1105 | |
1117 | |
1106 | Some utility functions for the Jeweler skill. |
1118 | Some utility functions for the Jeweler skill. |
1107 | |
1119 | |