… | |
… | |
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 | |
38 | my $DEBUG = 1; |
42 | my $DEBUG = 1; |
39 | |
43 | |
40 | sub merge { |
44 | sub 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 | |
63 | sub make_ring { |
75 | sub 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)); # 10 + level times making such a ring |
|
|
95 | # should get you to the rings level at least. |
|
|
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)); # see above for comment |
|
|
102 | |
|
|
103 | $exp -= $subexp; |
|
|
104 | $exp = max ($exp, 0); |
|
|
105 | |
|
|
106 | } else { |
|
|
107 | # the experience bonus here is to make level 1 rings give you at least |
|
|
108 | # 100 exp points when making them. This also makes leveling in the |
|
|
109 | # first few levels a bit easier. (probably until around level 5-6). |
|
|
110 | my $expbonus = cf::level_to_min_exp (2) / 10; |
|
|
111 | # this bonus should also only be given for _new_ rings and not for merged |
|
|
112 | # ones - to prevent infinite exp making. |
|
|
113 | $exp += $expbonus; |
|
|
114 | } |
|
|
115 | |
77 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
116 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
78 | $pl->message ("You succeed and get $exp experience."); |
117 | $pl->message ("You succeed and get $exp experience points."); |
|
|
118 | $make_status = "succeeded"; |
|
|
119 | |
|
|
120 | $ring->set_value ($value * 0.8); # 20% of the input values will vanish |
|
|
121 | |
79 | } else { |
122 | } else { |
80 | $pl->message ("You fail!"); |
123 | $pl->message ("You fail!"); |
81 | $ring->negate; |
124 | $ring->negate; |
|
|
125 | $make_status = "fail"; |
|
|
126 | $exp = 0; |
|
|
127 | } |
|
|
128 | |
|
|
129 | my $ring_ob = $ring->to_object; |
|
|
130 | |
|
|
131 | { # some audit info calculation |
|
|
132 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
|
|
133 | |
|
|
134 | my $make_info = sprintf |
|
|
135 | "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s", |
|
|
136 | $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl, |
|
|
137 | $ring->power_to_level, $exp, $make_status; |
|
|
138 | |
|
|
139 | warn "$make_info\n" if $make_status eq 'succeeded'; |
|
|
140 | |
|
|
141 | $ring_ob->set_ob_key_value (ext_jeweler_made_by => $pl->name); |
|
|
142 | $ring_ob->set_ob_key_value (ext_jeweler_make_info => $make_info); |
|
|
143 | } |
|
|
144 | |
|
|
145 | $chdl->put ($ring_ob); |
|
|
146 | } |
|
|
147 | |
|
|
148 | sub get_ingred { |
|
|
149 | my ($pl, $chdl) = @_; |
|
|
150 | my $ingred = eval { $chdl->extract_jeweler_ingredients }; |
|
|
151 | if ($@ =~ /cursed/) { |
|
|
152 | $pl->message ("There are cursed items in the workbench, take them out before you do anything."). |
|
|
153 | return |
|
|
154 | } elsif ($@ =~ /unidentified/) { |
|
|
155 | $pl->message ("There are unidentified items in the workbench, identify them before you do anything."). |
|
|
156 | return |
|
|
157 | } elsif ($@) { |
|
|
158 | warn "error in jeweler ingredient extraction: $@"; |
|
|
159 | return; |
|
|
160 | } |
|
|
161 | $ingred; |
|
|
162 | } |
|
|
163 | |
|
|
164 | cf::object::attachment check_ring_drop_on => |
|
|
165 | on_drop_on => sub { |
|
|
166 | my ($self, $obj, $who) = @_; |
|
|
167 | my $cfg = $self->{check_ring_drop_on}; |
|
|
168 | if ($obj->type == cf::RING |
|
|
169 | && !$obj->flag (cf::FLAG_CURSED) |
|
|
170 | && !$obj->flag (cf::FLAG_DAMNED) |
|
|
171 | ) { |
|
|
172 | my $ringo = Jeweler::Object->new (object => $obj); |
|
|
173 | for (grep { /^resist_/ } keys %$cfg) { |
|
|
174 | if (/^resist_(\S+)$/) { |
|
|
175 | if ($ringo->has_resist ($1)) { |
|
|
176 | $self->map->trigger ( |
|
|
177 | $cfg->{connection}, |
|
|
178 | $cfg->{state} |
|
|
179 | ); |
|
|
180 | cf::override; |
|
|
181 | } |
|
|
182 | } |
|
|
183 | } |
|
|
184 | } |
82 | } |
185 | }; |
83 | $chdl->put ($ring->to_object); |
|
|
84 | } |
|
|
85 | |
186 | |
86 | cf::object->attach ( |
187 | cf::object->attach ( |
87 | type => cf::SKILL, |
188 | type => cf::SKILL, |
88 | subtype => cf::SK_JEWELER, |
189 | subtype => cf::SK_JEWELER, |
89 | on_use_skill => sub { |
190 | on_use_skill => sub { |
… | |
… | |
111 | |
212 | |
112 | } elsif ($msg =~ m/^\s*make\s*$/i) { |
213 | } elsif ($msg =~ m/^\s*make\s*$/i) { |
113 | $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); |
214 | $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); |
114 | |
215 | |
115 | } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { |
216 | } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { |
116 | my $ingred = $chdl->extract_jeweler_ingredients; |
217 | my $ingred = get_ingred ($pl, $chdl) || return; |
117 | |
218 | |
118 | unless ($Jeweler::CFG->{conversions}->{lc $1}) { |
219 | unless ($Jeweler::CFG->{conversions}->{lc $1}) { |
119 | $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); |
220 | $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); |
120 | return |
221 | return |
121 | } |
222 | } |
… | |
… | |
127 | |
228 | |
128 | } elsif ($msg =~ m/^\s*merge\s*$/i) { |
229 | } elsif ($msg =~ m/^\s*merge\s*$/i) { |
129 | merge ($chdl, $sk, $pl, 0); |
230 | merge ($chdl, $sk, $pl, 0); |
130 | |
231 | |
131 | } else { |
232 | } else { |
132 | my $ingred = $chdl->extract_jeweler_ingredients; |
233 | my $ingred = get_ingred ($pl, $chdl) || return; |
|
|
234 | |
133 | my $plan = $ingred->get_plan; |
235 | my $plan = $ingred->get_plan; |
134 | |
236 | |
135 | if ($plan) { |
237 | if ($plan) { |
136 | my @ring = $ingred->get_ring; |
238 | my @ring = $ingred->get_ring; |
137 | |
239 | |
… | |
… | |
146 | return; |
248 | return; |
147 | |
249 | |
148 | } else { |
250 | } else { |
149 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
251 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
150 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
252 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
151 | my $c1 = $ringo->calc_costs; |
253 | my $c1 = $ringo->calc_costs; |
152 | my $c2 = $iring->calc_costs; |
254 | my $c2 = $iring->calc_costs; |
|
|
255 | my $value = $iring->calc_value_from_cost ($c2); |
153 | |
256 | |
154 | my %keys; |
257 | my %keys; |
155 | my %cdiff; |
258 | my %cdiff; |
156 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
259 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
157 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_} } |
260 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } |
158 | |
261 | |
159 | unless (grep { $_ > 0 } values %cdiff) { |
262 | unless ($iring->is_better_than ($ringo)) { |
160 | $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); |
263 | $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); |
161 | return; |
264 | return; |
162 | } |
265 | } |
163 | |
266 | |
164 | my $remcosts = $ingred->check_costs (\%cdiff); |
267 | my $remcosts = $ingred->check_costs (\%cdiff); |
… | |
… | |
175 | } |
278 | } |
176 | } else { |
279 | } else { |
177 | if (!$pl->flag (cf::FLAG_WIZ)) { |
280 | if (!$pl->flag (cf::FLAG_WIZ)) { |
178 | $ingred->check_costs (\%cdiff, 1); |
281 | $ingred->check_costs (\%cdiff, 1); |
179 | } |
282 | } |
180 | make_ring ($chdl, $ingred, $iring, $sk, $pl); |
283 | make_ring ($chdl, $ingred, $iring, $value, $sk, $pl); |
181 | } |
284 | } |
182 | } |
285 | } |
183 | } else { |
286 | } else { |
184 | $pl->message ("You've got no idea what you are planning to do!"); |
287 | $pl->message ("You've got no idea what you are planning to do!"); |
185 | } |
288 | } |
… | |
… | |
187 | }; |
290 | }; |
188 | $@ and warn "ERROR: $@\n"; |
291 | $@ and warn "ERROR: $@\n"; |
189 | } |
292 | } |
190 | ); |
293 | ); |
191 | |
294 | |
192 | Jeweler::read_config (cf::datadir . '/jeweler.yaml'); |
295 | Jeweler::read_config "$DATADIR/jeweler.yaml"; |
|
|
296 | |