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.1 by root, Fri Dec 15 19:29:18 2006 UTC vs.
Revision 1.8 by elmex, Tue Apr 10 17:09:13 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 = $chdl->extract_jeweler_ingredients; 47 my $ingred = get_ingred ($pl, $chdl) || return;
48
44 my @ring = $ingred->get_ring; 49 my @ring = $ingred->get_ring;
45 my @rings = map { Jeweler::Object->new (object => $_) } @ring; 50 my @rings = map { Jeweler::Object->new (object => $_) } @ring;
46 51
47 @rings >= 2 52 @rings >= 2
48 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 }
49 61
50 my $ring = shift @rings; 62 my $ring = shift @rings;
51 $ring->improve_by_ring (@rings); 63 $ring->improve_by_ring (@rings);
52 64
53 if ($do_analyze) { 65 if ($do_analyze) {
55 $ring->wiz_analyze ($pl) 67 $ring->wiz_analyze ($pl)
56 if $pl->flag (cf::FLAG_WIZ); 68 if $pl->flag (cf::FLAG_WIZ);
57 return; 69 return;
58 } 70 }
59 71
60 make_ring ($chdl, $ingred, $ring, $sk, $pl); 72 make_ring ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level);
61} 73}
62 74
63sub make_ring { 75sub make_ring {
64 my ($chdl, $ingred, $ring, $sk, $pl) = @_; 76 my ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level) = @_;
65 77
66 if (!$pl->flag (cf::FLAG_WIZ)) { 78 if (!$pl->flag (cf::FLAG_WIZ)) {
67 $ingred->remove ('rings'); 79 $ingred->remove ('rings');
68 $ingred->remove ('ammys'); 80 $ingred->remove ('ammys');
69 } 81 }
70 82
71 my $ch = $ring->get_chance_perc ($sk); 83 my $ch = $ring->get_chance_perc ($sk);
72 my $succ = 0; 84 my $succ = 0;
73 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
74 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { 90 if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) {
75 my $lvl = max ($ring->power_to_level, 1); 91 my $lvl = max ($ring->power_to_level, 1);
92 $exp =
76 my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100; 93 (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1))
94 / (10 + max ($lvl - 1, 0));
95 # divided by 10 + level
96
97 if (defined $input_level) {
98 my $subexp =
99 (cf::level_to_min_exp ($input_level)
100 - cf::level_to_min_exp ($input_level - 1))
101 / (10 + max ($input_level - 1, 0));
102 $exp -= $subexp;
103 $exp = max ($exp, 0);
104 }
105
77 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); 106 $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY);
78 $pl->message ("You succeed and get $exp experience."); 107 $pl->message ("You succeed and get $exp experience points.");
108 $make_status = "succeeded";
109
110 $ring->set_value ($value * 0.8); # 20% of the input values will vanish
111
79 } else { 112 } else {
80 $pl->message ("You fail!"); 113 $pl->message ("You fail!");
81 $ring->negate; 114 $ring->negate;
115 $make_status = "fail";
116 $exp = 0;
117 }
118
119 my $ring_ob = $ring->to_object;
120
121 { # some audit info calculation
122 my $sklvl = cf::exp_to_level ($sk->stats->exp);
123
124 my $make_info = sprintf
125 "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s",
126 $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl,
127 $ring->power_to_level, $exp, $make_status;
128
129 warn "$make_info\n" if $make_status eq 'succeeded';
130
131 $ring_ob->set_ob_key_value (ext_jeweler_made_by => $pl->name);
132 $ring_ob->set_ob_key_value (ext_jeweler_make_info => $make_info);
133 }
134
135 $chdl->put ($ring_ob);
136}
137
138sub get_ingred {
139 my ($pl, $chdl) = @_;
140 my $ingred = eval { $chdl->extract_jeweler_ingredients };
141 if ($@ =~ /cursed/) {
142 $pl->message ("There are cursed items in the workbench, take them out before you do anything.").
143 return
144 } elsif ($@ =~ /unidentified/) {
145 $pl->message ("There are unidentified items in the workbench, identify them before you do anything.").
146 return
147 } elsif ($@) {
148 warn "error in jeweler ingredient extraction: $@";
149 return;
150 }
151 $ingred;
152}
153
154cf::object::attachment check_ring_drop_on =>
155 on_drop_on => sub {
156 my ($self, $obj, $who) = @_;
157 my $cfg = $self->{check_ring_drop_on};
158 if ($obj->type == cf::RING
159 && !$obj->flag (cf::FLAG_CURSED)
160 && !$obj->flag (cf::FLAG_DAMNED)
161 ) {
162 my $ringo = Jeweler::Object->new (object => $obj);
163 for (grep { /^resist_/ } keys %$cfg) {
164 if (/^resist_(\S+)$/) {
165 if ($ringo->has_resist ($1)) {
166 $self->map->trigger (
167 $cfg->{connection},
168 $cfg->{state}
169 );
170 cf::override;
171 }
172 }
173 }
174 }
82 } 175 };
83 $chdl->put ($ring->to_object);
84}
85 176
86cf::attach_to_type cf::SKILL, cf::SK_JEWELER, 177cf::object->attach (
178 type => cf::SKILL,
179 subtype => cf::SK_JEWELER,
87 on_use_skill => sub { 180 on_use_skill => sub {
88 my ($sk, $ob, $part, $dir, $msg) = @_; 181 my ($sk, $ob, $part, $dir, $msg) = @_;
89 my $pl = $ob; 182 my $pl = $ob;
90 183
91 my $skobj = $sk; 184 my $skobj = $sk;
92 185
93 my $chdl = new Jeweler::CauldronHandler; 186 my $chdl = new Jeweler::CauldronHandler;
94 187
95 my $rv = 1; 188 my $rv = 1;
96 eval { 189 eval {
97 Jeweler::read_config ($ENV{CROSSFIRE_LIBDIR} . '/jeweler.yaml');
98 $DEBUG = 1; 190 $DEBUG = 1;
99 191
100 my $player = $ob->contr; 192 my $player = $ob->contr;
101 193
102 unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) { 194 unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) {
110 202
111 } elsif ($msg =~ m/^\s*make\s*$/i) { 203 } elsif ($msg =~ m/^\s*make\s*$/i) {
112 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); 204 $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}}));
113 205
114 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { 206 } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) {
115 my $ingred = $chdl->extract_jeweler_ingredients; 207 my $ingred = get_ingred ($pl, $chdl) || return;
116 208
117 unless ($Jeweler::CFG->{conversions}->{lc $1}) { 209 unless ($Jeweler::CFG->{conversions}->{lc $1}) {
118 $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); 210 $pl->message ("You don't know how to make '$1', is does such a thing even exist?");
119 return 211 return
120 } 212 }
126 218
127 } elsif ($msg =~ m/^\s*merge\s*$/i) { 219 } elsif ($msg =~ m/^\s*merge\s*$/i) {
128 merge ($chdl, $sk, $pl, 0); 220 merge ($chdl, $sk, $pl, 0);
129 221
130 } else { 222 } else {
131 my $ingred = $chdl->extract_jeweler_ingredients; 223 my $ingred = get_ingred ($pl, $chdl) || return;
224
132 my $plan = $ingred->get_plan; 225 my $plan = $ingred->get_plan;
133 226
134 if ($plan) { 227 if ($plan) {
135 my @ring = $ingred->get_ring; 228 my @ring = $ingred->get_ring;
136 229
145 return; 238 return;
146 239
147 } else { 240 } else {
148 my $ringo = Jeweler::Object->new (object => $ring[0]); 241 my $ringo = Jeweler::Object->new (object => $ring[0]);
149 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); 242 my $iring = $ingred->improve_ring_by_plan ($plan, $ringo);
150 my $c1 = $ringo->calc_costs; 243 my $c1 = $ringo->calc_costs;
151 my $c2 = $iring->calc_costs; 244 my $c2 = $iring->calc_costs;
245 my $value = $iring->calc_value_from_cost ($c2);
152 246
153 my %keys; 247 my %keys;
154 my %cdiff; 248 my %cdiff;
155 for (keys %$c1, keys %$c2) { $keys{$_} = 1 } 249 for (keys %$c1, keys %$c2) { $keys{$_} = 1 }
156 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_} } 250 for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; }
157 251
158 unless (grep { $_ > 0 } values %cdiff) { 252 unless ($iring->is_better_than ($ringo)) {
159 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); 253 $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed...");
160 return; 254 return;
161 } 255 }
162 256
163 my $remcosts = $ingred->check_costs (\%cdiff); 257 my $remcosts = $ingred->check_costs (\%cdiff);
174 } 268 }
175 } else { 269 } else {
176 if (!$pl->flag (cf::FLAG_WIZ)) { 270 if (!$pl->flag (cf::FLAG_WIZ)) {
177 $ingred->check_costs (\%cdiff, 1); 271 $ingred->check_costs (\%cdiff, 1);
178 } 272 }
179 make_ring ($chdl, $ingred, $iring, $sk, $pl); 273 make_ring ($chdl, $ingred, $iring, $value, $sk, $pl);
180 } 274 }
181 } 275 }
182 } else { 276 } else {
183 $pl->message ("You've got no idea what you are planning to do!"); 277 $pl->message ("You've got no idea what you are planning to do!");
184 } 278 }
185 } 279 }
186 }; 280 };
187 $@ and warn "ERROR: $@\n"; 281 $@ and warn "ERROR: $@\n";
188 } 282 }
189; 283);
190 284
285Jeweler::read_config (cf::datadir . '/jeweler.yaml');

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines