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.34 by root, Wed Apr 28 21:07:41 2010 UTC vs.
Revision 1.38 by elmex, Mon Oct 25 09:08:31 2010 UTC

21=cut 21=cut
22 22
23our $CFG; 23our $CFG;
24 24
25sub load_config { 25sub load_config {
26 warn "loading jeweler config from $cf::DATADIR/jeweler\n"; 26 cf::trace "loading jeweler config from $cf::DATADIR/jeweler\n";
27 27
28 0 < Coro::AIO::aio_load "$cf::DATADIR/jeweler", my $data 28 0 < Coro::AIO::aio_load "$cf::DATADIR/jeweler", my $data
29 or die "$cf::DATADIR/jeweler: $!"; 29 or die "$cf::DATADIR/jeweler: $!";
30 30
31 $CFG = cf::decode_json $data; 31 $CFG = cf::decode_json $data;
170 next; 170 next;
171 } 171 }
172 $found = 1; 172 $found = 1;
173 my $r = Jeweler::Object->new (object => $_); 173 my $r = Jeweler::Object->new (object => $_);
174 my $msg = $r->analyze ($sk, $pl, $input_level); 174 my $msg = $r->analyze ($sk, $pl, $input_level);
175 $pl->message ($r->to_string . ": " . $msg); 175 $pl->message ("There is a '" . $r->to_string . "' in the workbench. Your analysis: " . $msg);
176 if ($pl->flag (cf::FLAG_WIZ)) { 176 if ($pl->flag (cf::FLAG_WIZ)) {
177 $r->wiz_analyze ($pl); 177 $r->wiz_analyze ($pl);
178 } 178 }
179 } 179 }
180 $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!")
249} 249}
250 250
251 251
252package Jeweler::CauldronHandler; 252package Jeweler::CauldronHandler;
253 253
254use strict; 254use common::sense;
255 255
256=head2 CauldronHandler 256=head2 CauldronHandler
257 257
258The Jeweler::CauldronHandler package, that helps you with handling the 258The Jeweler::CauldronHandler package, that helps you with handling the
259cauldron stuff. Can also be used for other skills. 259cauldron stuff. Can also be used for other skills.
367=back 367=back
368 368
369=cut 369=cut
370 370
371package Jeweler::Ingredients; 371package Jeweler::Ingredients;
372
373use common::sense;
374
372use Storable qw/dclone/; 375use Storable qw/dclone/;
373use strict;
374 376
375=head2 Ingredients 377=head2 Ingredients
376 378
377This class handles the ingredients. 379This class handles the ingredients.
378 380
589 } 591 }
590 592
591 if ($do_remove) { 593 if ($do_remove) {
592 my $rem = $costs->{$key}; 594 my $rem = $costs->{$key};
593 $self->do_grep (sub { 595 $self->do_grep (sub {
596 if ($rem) {
594 if ($rem) { $rem = Jeweler::Util::remove ($_[0], $rem); } 597 $rem = Jeweler::Util::remove ($_[0], $rem);
598 }
595 1 599 1
596 }, @grepar); 600 }, @grepar);
597 if ($rem > 0) { 601 if ($rem > 0) {
598 warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!"; 602 warn "JEWELER BUG: removed ingredients ($key) $rem > 0 after removing!";
599 } 603 }
624 } 628 }
625 } 629 }
626} 630}
627 631
628package Jeweler::Object; 632package Jeweler::Object;
629use strict; 633
634use common::sense;
630use POSIX; 635use POSIX;
631use List::Util qw/max min sum/; 636use List::Util qw/max min sum/;
632 637
633sub new { 638sub new {
634 my ($class, %arg) = @_; 639 my ($class, %arg) = @_;
649 return 1 if $self->{hash}->{resist}->{$resnum}; 654 return 1 if $self->{hash}->{resist}->{$resnum};
650 } 655 }
651 return undef; 656 return undef;
652} 657}
653 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
654sub projected_exp { 666sub projected_exp {
655 my ($self, $input_level) = @_; 667 my ($self, $input_level) = @_;
656 668
657 my $lvl = max ($self->power_to_level, 1); 669 my $lvl = max ($self->power_to_level, 1);
658 my $exp = 670 my $exp = lvl2exp ($lvl);
659 (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1))
660 / (10 + max ($lvl - 1, 0)); # 10 + level times making such a ring
661 # should get you to the rings level at least.
662 671
663 if (defined $input_level) { 672 if (defined $input_level) { # in case we merge rings:
664 my $subexp = 673 my $subexp = lvl2exp ($input_level);
665 (cf::level_to_min_exp ($input_level)
666 - cf::level_to_min_exp ($input_level - 1))
667 / (10 + max ($input_level - 1, 0)); # see above for comment
668
669 $exp -= $subexp; 674 $exp -= $subexp;
670 $exp = max ($exp, 0); 675 $exp = max ($exp, 0);
671 676
672 } else { 677 } else {
673 # 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
853sub to_object { 858sub to_object {
854 my ($self) = @_; 859 my ($self) = @_;
855 860
856 my $obj = cf::object::new $self->{hash}->{arch}; 861 my $obj = cf::object::new $self->{hash}->{arch};
857 862
858 $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!
859 864
860 $obj->face ($self->{hash}{face}); 865 $obj->face ($self->{hash}{face});
861 866
862 my $stats = $obj->stats; 867 my $stats = $obj->stats;
863 868
1106 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value; 1111 $cost->{gem} += ceil $sumvalue * $stat_split->[4] / max 1, $diarch->value;
1107} 1112}
1108 1113
1109package Jeweler::Util; 1114package Jeweler::Util;
1110 1115
1111use strict; 1116use common::sense;
1112 1117
1113=head2 Util 1118=head2 Util
1114 1119
1115Some utility functions for the Jeweler skill. 1120Some utility functions for the Jeweler skill.
1116 1121
1123 1128
1124=cut 1129=cut
1125 1130
1126sub remove { 1131sub remove {
1127 my ($obj, $nrof) = @_; 1132 my ($obj, $nrof) = @_;
1128 1133
1129 my $c = $obj->nrof || 1; 1134 my $c = $obj->number_of;
1130 my $r = $c > $nrof ? 0 : $nrof - $c; 1135 my $r = $c > $nrof ? 0 : $nrof - $c;
1131 $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1)); 1136 $obj->decrease (defined ($nrof) ? $nrof : ($obj->nrof || 1));
1132 1137
1133 $r 1138 $r
1134} 1139}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines