1 | #! perl |
1 | #! perl |
2 | |
2 | |
3 | use Data::Dumper; |
3 | use strict; |
|
|
4 | |
4 | use Jeweler; |
5 | use Jeweler; |
5 | use List::Util qw/max min sum/; |
6 | use List::Util qw/max min sum/; |
6 | use strict; |
|
|
7 | |
7 | |
8 | sub ingred_alias { |
8 | sub ingred_alias { |
9 | my ($ing) = @_; |
9 | my ($ing) = @_; |
10 | |
10 | |
11 | my %aliases = ( |
11 | my %aliases = ( |
… | |
… | |
48 | |
48 | |
49 | my @ring = $ingred->get_ring; |
49 | my @ring = $ingred->get_ring; |
50 | my @rings = map { Jeweler::Object->new (object => $_) } @ring; |
50 | my @rings = map { Jeweler::Object->new (object => $_) } @ring; |
51 | |
51 | |
52 | @rings >= 2 |
52 | @rings >= 2 |
53 | or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); |
53 | or return $pl->message ("You slap yourself, you forgot to put at least 2 jewels in!"); |
54 | |
54 | |
55 | my $input_level; |
55 | my $input_level = 0; |
56 | my $value; |
56 | my $value; |
57 | for (@rings) { |
57 | for (@rings) { |
58 | $input_level = max ($_->power_to_level, $input_level); |
58 | $input_level = max ($_->power_to_level, $input_level); |
59 | $value += $_->{hash}->{value}; |
59 | $value += $_->{hash}->{value}; |
60 | } |
60 | } |
61 | |
61 | |
62 | my $ring = shift @rings; |
62 | my $ring = shift @rings; |
63 | $ring->improve_by_ring (@rings); |
63 | $ring->improve_by_ring (@rings); |
64 | |
64 | |
65 | if ($do_analyze) { |
65 | if ($do_analyze) { |
66 | $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl)); |
66 | $pl->message ("You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl, $input_level)); |
67 | $ring->wiz_analyze ($pl) |
67 | $ring->wiz_analyze ($pl) |
68 | if $pl->flag (cf::FLAG_WIZ); |
68 | if $pl->flag (cf::FLAG_WIZ); |
69 | return; |
69 | return; |
70 | } |
70 | } |
71 | |
71 | |
… | |
… | |
80 | $ingred->remove ('ammys'); |
80 | $ingred->remove ('ammys'); |
81 | } |
81 | } |
82 | |
82 | |
83 | my $ch = $ring->get_chance_perc ($sk); |
83 | my $ch = $ring->get_chance_perc ($sk); |
84 | my $succ = 0; |
84 | my $succ = 0; |
85 | my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); |
85 | my $r = cf::random_roll (0, 100, $pl, cf::PREFER_LOW); |
86 | |
86 | |
87 | my $make_status; |
87 | my $make_status; |
88 | my $exp; |
88 | my $exp; |
89 | |
89 | |
90 | if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { |
90 | if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { |
91 | my $lvl = max ($ring->power_to_level, 1); |
91 | $exp = $ring->projected_exp ($input_level); |
92 | $exp = |
|
|
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 | |
92 | |
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. (Propably 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 | |
|
|
116 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
93 | $pl->change_exp ($exp, "jeweler"); |
|
|
94 | $pl->message ( |
117 | $pl->message ("You succeed and get $exp experience points."); |
95 | "You succeed and get " . int ($exp) . " experience points."); |
118 | $make_status = "succeeded"; |
96 | $make_status = "succeeded"; |
119 | |
97 | |
120 | $ring->set_value ($value * 0.8); # 20% of the input values will vanish |
98 | $ring->set_value ($value); |
121 | |
99 | |
122 | } else { |
100 | } else { |
123 | $pl->message ("You fail!"); |
101 | $pl->message ("You fail!"); |
124 | $ring->negate; |
102 | $ring->negate; |
125 | $make_status = "fail"; |
103 | $make_status = "fail"; |
… | |
… | |
134 | my $make_info = sprintf |
112 | my $make_info = sprintf |
135 | "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s", |
113 | "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, |
114 | $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl, |
137 | $ring->power_to_level, $exp, $make_status; |
115 | $ring->power_to_level, $exp, $make_status; |
138 | |
116 | |
|
|
117 | cf::debug "$make_info\n" |
139 | warn "$make_info\n" if $make_status eq 'succeeded'; |
118 | 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 | } |
119 | } |
144 | |
120 | |
145 | $chdl->put ($ring_ob); |
121 | $chdl->put ($ring_ob); |
146 | } |
122 | } |
147 | |
123 | |
… | |
… | |
153 | return |
129 | return |
154 | } elsif ($@ =~ /unidentified/) { |
130 | } elsif ($@ =~ /unidentified/) { |
155 | $pl->message ("There are unidentified items in the workbench, identify them before you do anything."). |
131 | $pl->message ("There are unidentified items in the workbench, identify them before you do anything."). |
156 | return |
132 | return |
157 | } elsif ($@) { |
133 | } elsif ($@) { |
158 | warn "error in jeweler ingredient extraction: $@"; |
134 | cf::error "error in jeweler ingredient extraction: $@"; |
159 | return; |
135 | return; |
160 | } |
136 | } |
161 | $ingred; |
137 | $ingred; |
162 | } |
138 | } |
163 | |
139 | |
… | |
… | |
175 | if ($ringo->has_resist ($1)) { |
151 | if ($ringo->has_resist ($1)) { |
176 | $self->map->trigger ( |
152 | $self->map->trigger ( |
177 | $cfg->{connection}, |
153 | $cfg->{connection}, |
178 | $cfg->{state} |
154 | $cfg->{state} |
179 | ); |
155 | ); |
|
|
156 | $obj->decrease (1); |
180 | cf::override; |
157 | cf::override; |
181 | } |
158 | } |
182 | } |
159 | } |
183 | } |
160 | } |
184 | } |
161 | } |
… | |
… | |
219 | unless ($Jeweler::CFG->{conversions}->{lc $1}) { |
196 | unless ($Jeweler::CFG->{conversions}->{lc $1}) { |
220 | $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); |
197 | $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); |
221 | return |
198 | return |
222 | } |
199 | } |
223 | |
200 | |
224 | Jeweler::simple_converter ($player, $ingred, $chdl, $1); |
201 | Jeweler::simple_converter ( |
|
|
202 | $player, $ingred, $chdl, $1, |
|
|
203 | cf::exp_to_level ($sk->stats->exp)); |
225 | |
204 | |
226 | } elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) { |
205 | } elsif ($msg =~ m/^\s*merge\s*analy[sz]e\s*$/i) { |
227 | merge ($chdl, $sk, $pl, 1); |
206 | merge ($chdl, $sk, $pl, 1); |
228 | |
207 | |
229 | } elsif ($msg =~ m/^\s*merge\s*$/i) { |
208 | } elsif ($msg =~ m/^\s*merge\s*$/i) { |
… | |
… | |
235 | my $plan = $ingred->get_plan; |
214 | my $plan = $ingred->get_plan; |
236 | |
215 | |
237 | if ($plan) { |
216 | if ($plan) { |
238 | my @ring = $ingred->get_ring; |
217 | my @ring = $ingred->get_ring; |
239 | |
218 | |
|
|
219 | if (!@ring) { |
|
|
220 | # actually the algorithm cant |
|
|
221 | $pl->message ("You slap yourself, you forgot the jewelery!"); |
|
|
222 | return; |
|
|
223 | |
240 | if ((@ring > 1) || ($ring[0]->nrof > 1)) { |
224 | } elsif ((@ring > 1) || (grep { $_->nrof > 1 } @ring)) { |
241 | # actually the algorithm cant handle more than one improvement at a time |
225 | # actually the algorithm cant handle more than one improvement at a time |
242 | $pl->message ("You can't manage to improve more than one thing at a time!"); |
226 | $pl->message ("You can't manage to improve more than one thing at a time!"); |
243 | return; |
227 | return; |
244 | |
|
|
245 | } elsif (@ring < 1) { |
|
|
246 | # actually the algorithm cant |
|
|
247 | $pl->message ("You slap yourself, you forgot the jewelery!"); |
|
|
248 | return; |
|
|
249 | |
|
|
250 | } else { |
228 | } else { |
251 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
229 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
252 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
230 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
253 | my $c1 = $ringo->calc_costs; |
231 | my $c1 = $ringo->calc_costs; |
254 | my $c2 = $iring->calc_costs; |
232 | my $c2 = $iring->calc_costs; |
255 | my $value = $iring->calc_value_from_cost ($c2); |
233 | my $value = $iring->calc_value_from_cost ($c2); |
|
|
234 | |
|
|
235 | if ((not defined $c1) || (not defined $c2)) { |
|
|
236 | $pl->message ("The jewel has or will become a resistancy above 99%,\n" |
|
|
237 | ."that is completly impossible to make!"); |
|
|
238 | return; |
|
|
239 | } |
256 | |
240 | |
257 | my %keys; |
241 | my %keys; |
258 | my %cdiff; |
242 | my %cdiff; |
259 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
243 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
260 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } |
244 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } |
… | |
… | |
286 | } else { |
270 | } else { |
287 | $pl->message ("You've got no idea what you are planning to do!"); |
271 | $pl->message ("You've got no idea what you are planning to do!"); |
288 | } |
272 | } |
289 | } |
273 | } |
290 | }; |
274 | }; |
291 | $@ and warn "ERROR: $@\n"; |
275 | $@ and cf::error "$@\n"; |
292 | } |
276 | } |
293 | ); |
277 | ); |
294 | |
278 | |
295 | Jeweler::read_config (cf::datadir . '/jeweler.yaml'); |
279 | Jeweler::load_config; |
|
|
280 | |