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.4 by elmex, Wed Jan 31 15:53:17 2007 UTC vs.
Revision 1.7 by elmex, Sun Feb 4 11:17:52 2007 UTC

14 wis => 'wisdom', 14 wis => 'wisdom',
15 int => 'intelligence', 15 int => 'intelligence',
16 dex => 'dexterity', 16 dex => 'dexterity',
17 con => 'constitution', 17 con => 'constitution',
18 str => 'strength', 18 str => 'strength',
19 gem => 'diamond',
19 ); 20 );
20 21
21 if ($ing =~ m/resist_(\S+)/) { 22 if ($ing =~ m/resist_(\S+)/) {
22 my $a = $aliases{lc $1} || $1; 23 my $a = $aliases{lc $1} || $1;
23 "something for '". lc ($a). "' resistance"; 24 "something for '". lc ($a). "' resistance";
28 29
29 } elsif ($ing =~ m/spec_(\S+)/) { 30 } elsif ($ing =~ m/spec_(\S+)/) {
30 my $a = $aliases{lc $1} || $1; 31 my $a = $aliases{lc $1} || $1;
31 "something for the ". lc ($a). "' special"; 32 "something for the ". lc ($a). "' special";
32 33
34 } elsif ($aliases{$ing}) {
35 $aliases{$ing}
36
33 } else { 37 } else {
34 $ing 38 $ing
35 } 39 }
36} 40}
37 41
38my $DEBUG = 1; 42my $DEBUG = 1;
39 43
40sub merge { 44sub merge {
41 my ($chdl, $sk, $pl, $do_analyze) = @_; 45 my ($chdl, $sk, $pl, $do_analyze) = @_;
42 46
43 my $ingred = eval { $chdl->extract_jeweler_ingredients }; 47 my $ingred = get_ingred ($pl, $chdl) || return;
44 if ($@ =~ /cursed/) {
45 $pl->reply ("There are cursed items in the workbench, take them out before you do anything.").
46 return
47 } elsif ($@) {
48 warn "error in jeweler ingredient extraction: $@";
49 return;
50 }
51 48
52 my @ring = $ingred->get_ring; 49 my @ring = $ingred->get_ring;
53 my @rings = map { Jeweler::Object->new (object => $_) } @ring; 50 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
54 51
55 @rings >= 2 52 @rings >= 2
56 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); 53 or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!");
54
55 my $input_level;
56 my $value;
57 for (@rings) {
58 $input_level = max ($_->power_to_level, $input_level);
59 $value += $_->{hash}->{value};
60 }
57 61
58 my $ring = shift @rings; 62 my $ring = shift @rings;
59 $ring->improve_by_ring (@rings); 63 $ring->improve_by_ring (@rings);
60 64
61 if ($do_analyze) { 65 if ($do_analyze) {
63 $ring->wiz_analyze ($pl) 67 $ring->wiz_analyze ($pl)
64 if $pl->flag (cf::FLAG_WIZ); 68 if $pl->flag (cf::FLAG_WIZ);
65 return; 69 return;
66 } 70 }
67 71
68 make_ring ($chdl, $ingred, $ring, $sk, $pl); 72 make_ring ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level);
69} 73}
70 74
71sub make_ring { 75sub make_ring {
72 my ($chdl, $ingred, $ring, $sk, $pl) = @_; 76 my ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level) = @_;
73 77
74 if (!$pl->flag (cf::FLAG_WIZ)) { 78 if (!$pl->flag (cf::FLAG_WIZ)) {
75 $ingred->remove ('rings'); 79 $ingred->remove ('rings');
76 $ingred->remove ('ammys'); 80 $ingred->remove ('ammys');
77 } 81 }
78 82
79 my $ch = $ring->get_chance_perc ($sk); 83 my $ch = $ring->get_chance_perc ($sk);
80 my $succ = 0; 84 my $succ = 0;
81 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); 85 my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH);
86
87 my $make_status;
88 my $exp;
89
82 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { 90 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) {
83 my $lvl = max ($ring->power_to_level, 1); 91 my $lvl = max ($ring->power_to_level, 1);
84 my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100; 92 $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100;
93
94 if (defined $input_level) {
95 my $subexp =
96 (cf::level_to_min_exp ($input_level)
97 - cf::level_to_min_exp ($input_level - 1))
98 / 100;
99 $exp -= $subexp;
100 $exp = max ($exp, 0);
101 }
102
85 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); 103 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY);
86 $pl->message ("You succeed and get $exp experience."); 104 $pl->message ("You succeed and get $exp experience points.");
105 $make_status = "succeeded";
106
107 $ring->set_value ($value * 0.8); # 20% of the input values will vanish
108
87 } else { 109 } else {
88 $pl->message ("You fail!"); 110 $pl->message ("You fail!");
89 $ring->negate; 111 $ring->negate;
112 $make_status = "fail";
113 $exp = 0;
114 }
115
116 my $ring_ob = $ring->to_object;
117
118 { # some audit info calculation
119 my $sklvl = cf::exp_to_level ($sk->stats->exp);
120
121 my $make_info = sprintf
122 "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s",
123 $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl,
124 $ring->power_to_level, $exp, $make_status;
125
126 warn "$make_info\n" if $make_status eq 'succeeded';
127
128 $ring_ob->set_ob_key_value (ext_jeweler_made_by => $pl->name);
129 $ring_ob->set_ob_key_value (ext_jeweler_make_info => $make_info);
130 }
131
132 $chdl->put ($ring_ob);
133}
134
135sub get_ingred {
136 my ($pl, $chdl) = @_;
137 my $ingred = eval { $chdl->extract_jeweler_ingredients };
138 if ($@ =~ /cursed/) {
139 $pl->message ("There are cursed items in the workbench, take them out before you do anything.").
140 return
141 } elsif ($@ =~ /unidentified/) {
142 $pl->message ("There are unidentified items in the workbench, identify them before you do anything.").
143 return
144 } elsif ($@) {
145 warn "error in jeweler ingredient extraction: $@";
146 return;
147 }
148 $ingred;
149}
150
151cf::object::attachment check_ring_drop_on =>
152 on_drop_on => sub {
153 my ($self, $obj, $who) = @_;
154 my $cfg = $self->{check_ring_drop_on};
155 if ($obj->type == cf::RING
156 && !$obj->flag (cf::FLAG_CURSED)
157 && !$obj->flag (cf::FLAG_DAMNED)
158 ) {
159 my $ringo = Jeweler::Object->new (object => $obj);
160 for (grep { /^resist_/ } keys %$cfg) {
161 if (/^resist_(\S+)$/) {
162 if ($ringo->has_resist ($1)) {
163 $self->map->trigger (
164 $cfg->{connection},
165 $cfg->{state}
166 );
167 cf::override;
168 }
169 }
170 }
171 }
90 } 172 };
91 $chdl->put ($ring->to_object);
92}
93 173
94cf::object->attach ( 174cf::object->attach (
95 type => cf::SKILL, 175 type => cf::SKILL,
96 subtype => cf::SK_JEWELER, 176 subtype => cf::SK_JEWELER,
97 on_use_skill => sub { 177 on_use_skill => sub {
119 199
120 } elsif ($msg =~ m/^\s*make\s*$/i) { 200 } elsif ($msg =~ m/^\s*make\s*$/i) {
121 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); 201 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
122 202
123 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { 203 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
124 my $ingred = eval { $chdl->extract_jeweler_ingredients }; 204 my $ingred = get_ingred ($pl, $chdl) || return;
125 if ($@ =~ /cursed/) {
126 $pl->message ("There are cursed items in the workbench, take them out before you do anything.").
127 return
128 } elsif ($@) {
129 warn "error in jeweler ingredient extraction: $@";
130 return;
131 }
132 205
133 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 206 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
134 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 207 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
135 return 208 return
136 } 209 }
142 215
143 } elsif ($msg =~ m/^\s*merge\s*$/i) { 216 } elsif ($msg =~ m/^\s*merge\s*$/i) {
144 merge ($chdl, $sk, $pl, 0); 217 merge ($chdl, $sk, $pl, 0);
145 218
146 } else { 219 } else {
147 my $ingred = eval { $chdl->extract_jeweler_ingredients }; 220 my $ingred = get_ingred ($pl, $chdl) || return;
148 if ($@ =~ /cursed/) {
149 $pl->message ("There are cursed items in the workbench, take them out before you do anything.").
150 return
151 } elsif ($@) {
152 warn "error in jeweler ingredient extraction: $@";
153 return;
154 }
155 221
156 my $plan = $ingred->get_plan; 222 my $plan = $ingred->get_plan;
157 223
158 if ($plan) { 224 if ($plan) {
159 my @ring = $ingred->get_ring; 225 my @ring = $ingred->get_ring;
169 return; 235 return;
170 236
171 } else { 237 } else {
172 my $ringo = Jeweler::Object->new (object => $ring[0]); 238 my $ringo = Jeweler::Object->new (object => $ring[0]);
173 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); 239 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo);
174 my $c1 = $ringo->calc_costs; 240 my $c1 = $ringo->calc_costs;
175 my $c2 = $iring->calc_costs; 241 my $c2 = $iring->calc_costs;
242 my $value = $iring->calc_value_from_cost ($c2);
176 243
177 my %keys; 244 my %keys;
178 my %cdiff; 245 my %cdiff;
179 for (keys %$c1, keys %$c2) { $keys{$_} = 1 } 246 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
180 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; warn "$_: $c2->{$_} | $c1->{$_}\n"; } 247 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; }
181 248
182 unless ($iring->is_better_than ($ringo)) { 249 unless ($iring->is_better_than ($ringo)) {
183 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); 250 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed...");
184 return; 251 return;
185 } 252 }
198 } 265 }
199 } else { 266 } else {
200 if (!$pl->flag (cf::FLAG_WIZ)) { 267 if (!$pl->flag (cf::FLAG_WIZ)) {
201 $ingred->check_costs (\%cdiff, 1); 268 $ingred->check_costs (\%cdiff, 1);
202 } 269 }
203 make_ring ($chdl, $ingred, $iring, $sk, $pl); 270 make_ring ($chdl, $ingred, $iring, $value, $sk, $pl);
204 } 271 }
205 } 272 }
206 } else { 273 } else {
207 $pl->message ("You've got no idea what you are planning to do!"); 274 $pl->message ("You've got no idea what you are planning to do!");
208 } 275 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines