ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/jeweler.ext
(Generate patch)

Comparing deliantra/server/ext/jeweler.ext (file contents):
Revision 1.3 by elmex, Wed Jan 31 14:11:02 2007 UTC vs.
Revision 1.5 by elmex, Thu Feb 1 01:46:45 2007 UTC

38my $DEBUG = 1; 38my $DEBUG = 1;
39 39
40sub merge { 40sub merge {
41 my ($chdl, $sk, $pl, $do_analyze) = @_; 41 my ($chdl, $sk, $pl, $do_analyze) = @_;
42 42
43 my $ingred = $chdl->extract_jeweler_ingredients; 43 my $ingred = get_ingred ($pl, $chdl) || return;
44
44 my @ring = $ingred->get_ring; 45 my @ring = $ingred->get_ring;
45 my @rings = map { Jeweler::Object->new (object => $_) } @ring; 46 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
46 47
47 @rings >= 2 48 @rings >= 2
48 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); 49 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!");
50
51 my $input_level;
52 $input_level = max ($_->power_to_level, $input_level) for @rings;
49 53
50 my $ring = shift @rings; 54 my $ring = shift @rings;
51 $ring->improve_by_ring (@rings); 55 $ring->improve_by_ring (@rings);
52 56
53 if ($do_analyze) { 57 if ($do_analyze) {
55 $ring->wiz_analyze ($pl) 59 $ring->wiz_analyze ($pl)
56 if $pl->flag (cf::FLAG_WIZ); 60 if $pl->flag (cf::FLAG_WIZ);
57 return; 61 return;
58 } 62 }
59 63
60 make_ring ($chdl, $ingred, $ring, $sk, $pl); 64 make_ring ($chdl, $ingred, $ring, $sk, $pl, $input_level);
61} 65}
62 66
63sub make_ring { 67sub make_ring {
64 my ($chdl, $ingred, $ring, $sk, $pl) = @_; 68 my ($chdl, $ingred, $ring, $sk, $pl, $input_level) = @_;
65 69
66 if (!$pl->flag (cf::FLAG_WIZ)) { 70 if (!$pl->flag (cf::FLAG_WIZ)) {
67 $ingred->remove ('rings'); 71 $ingred->remove ('rings');
68 $ingred->remove ('ammys'); 72 $ingred->remove ('ammys');
69 } 73 }
70 74
71 my $ch = $ring->get_chance_perc ($sk); 75 my $ch = $ring->get_chance_perc ($sk);
72 my $succ = 0; 76 my $succ = 0;
73 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); 77 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH);
78
74 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { 79 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) {
75 my $lvl = max ($ring->power_to_level, 1); 80 my $lvl = max ($ring->power_to_level, 1);
76 my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100; 81 my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100;
82
83 if (defined $input_level) {
84 my $subexp =
85 (cf::level_to_min_exp ($input_level)
86 - cf::level_to_min_exp ($input_level - 1))
87 / 100;
88 warn "INPUT: $lvl <-> $input_level ($exp <-> $subexp)\n";
89 $exp -= $subexp;
90 $exp = max ($exp, 0);
91 }
92
77 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); 93 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY);
78 $pl->message ("You succeed and get $exp experience."); 94 $pl->message ("You succeed and get $exp experience.");
79 } else { 95 } else {
80 $pl->message ("You fail!"); 96 $pl->message ("You fail!");
81 $ring->negate; 97 $ring->negate;
82 } 98 }
83 $chdl->put ($ring->to_object); 99 $chdl->put ($ring->to_object);
100}
101
102sub get_ingred {
103 my ($pl, $chdl) = @_;
104 my $ingred = eval { $chdl->extract_jeweler_ingredients };
105 if ($@ =~ /cursed/) {
106 $pl->message ("There are cursed items in the workbench, take them out before you do anything.").
107 return
108 } elsif ($@ =~ /unidentified/) {
109 $pl->message ("There are unidentified items in the workbench, identify them before you do anything.").
110 return
111 } elsif ($@) {
112 warn "error in jeweler ingredient extraction: $@";
113 return;
114 }
115 $ingred;
84} 116}
85 117
86cf::object->attach ( 118cf::object->attach (
87 type => cf::SKILL, 119 type => cf::SKILL,
88 subtype => cf::SK_JEWELER, 120 subtype => cf::SK_JEWELER,
111 143
112 } elsif ($msg =~ m/^\s*make\s*$/i) { 144 } elsif ($msg =~ m/^\s*make\s*$/i) {
113 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); 145 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
114 146
115 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { 147 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
116 my $ingred = $chdl->extract_jeweler_ingredients; 148 my $ingred = get_ingred ($pl, $chdl) || return;
117 149
118 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 150 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
119 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 151 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
120 return 152 return
121 } 153 }
127 159
128 } elsif ($msg =~ m/^\s*merge\s*$/i) { 160 } elsif ($msg =~ m/^\s*merge\s*$/i) {
129 merge ($chdl, $sk, $pl, 0); 161 merge ($chdl, $sk, $pl, 0);
130 162
131 } else { 163 } else {
132 my $ingred = $chdl->extract_jeweler_ingredients; 164 my $ingred = get_ingred ($pl, $chdl) || return;
165
133 my $plan = $ingred->get_plan; 166 my $plan = $ingred->get_plan;
134 167
135 if ($plan) { 168 if ($plan) {
136 my @ring = $ingred->get_ring; 169 my @ring = $ingred->get_ring;
137 170

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines