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 = ( |
… | |
… | |
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 | |
… | |
… | |
46 | my @rings = map { Jeweler::Object->new (object => $_) } @ring; |
50 | my @rings = map { Jeweler::Object->new (object => $_) } @ring; |
47 | |
51 | |
48 | @rings >= 2 |
52 | @rings >= 2 |
49 | 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!"); |
50 | |
54 | |
51 | my $input_level; |
55 | my $input_level = 0; |
|
|
56 | my $value; |
|
|
57 | for (@rings) { |
52 | $input_level = max ($_->power_to_level, $input_level) for @rings; |
58 | $input_level = max ($_->power_to_level, $input_level); |
|
|
59 | $value += $_->{hash}->{value}; |
|
|
60 | } |
53 | |
61 | |
54 | my $ring = shift @rings; |
62 | my $ring = shift @rings; |
55 | $ring->improve_by_ring (@rings); |
63 | $ring->improve_by_ring (@rings); |
56 | |
64 | |
57 | if ($do_analyze) { |
65 | if ($do_analyze) { |
58 | $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl)); |
66 | $pl->reply (undef, "You want to make a " . $ring->to_string . ": " . $ring->analyze ($sk, $pl, $input_level)); |
59 | $ring->wiz_analyze ($pl) |
67 | $ring->wiz_analyze ($pl) |
60 | if $pl->flag (cf::FLAG_WIZ); |
68 | if $pl->flag (cf::FLAG_WIZ); |
61 | return; |
69 | return; |
62 | } |
70 | } |
63 | |
71 | |
64 | make_ring ($chdl, $ingred, $ring, $sk, $pl, $input_level); |
72 | make_ring ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level); |
65 | } |
73 | } |
66 | |
74 | |
67 | sub make_ring { |
75 | sub make_ring { |
68 | my ($chdl, $ingred, $ring, $sk, $pl, $input_level) = @_; |
76 | my ($chdl, $ingred, $ring, $value, $sk, $pl, $input_level) = @_; |
69 | |
77 | |
70 | if (!$pl->flag (cf::FLAG_WIZ)) { |
78 | if (!$pl->flag (cf::FLAG_WIZ)) { |
71 | $ingred->remove ('rings'); |
79 | $ingred->remove ('rings'); |
72 | $ingred->remove ('ammys'); |
80 | $ingred->remove ('ammys'); |
73 | } |
81 | } |
74 | |
82 | |
75 | my $ch = $ring->get_chance_perc ($sk); |
83 | my $ch = $ring->get_chance_perc ($sk); |
76 | my $succ = 0; |
84 | my $succ = 0; |
77 | my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); |
85 | my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); |
78 | |
86 | |
|
|
87 | my $make_status; |
|
|
88 | my $exp; |
|
|
89 | |
79 | if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { |
90 | if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { |
80 | my $lvl = max ($ring->power_to_level, 1); |
91 | $exp = $ring->projected_exp ($input_level); |
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 | |
92 | |
93 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
93 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
94 | $pl->message ("You succeed and get $exp experience."); |
94 | $pl->message ("You succeed and get $exp experience points."); |
|
|
95 | $make_status = "succeeded"; |
|
|
96 | |
|
|
97 | $ring->set_value ($value * 0.8); # 20% of the input values will vanish |
|
|
98 | |
95 | } else { |
99 | } else { |
96 | $pl->message ("You fail!"); |
100 | $pl->message ("You fail!"); |
97 | $ring->negate; |
101 | $ring->negate; |
|
|
102 | $make_status = "fail"; |
|
|
103 | $exp = 0; |
98 | } |
104 | } |
|
|
105 | |
|
|
106 | my $ring_ob = $ring->to_object; |
|
|
107 | |
|
|
108 | { # some audit info calculation |
|
|
109 | my $sklvl = cf::exp_to_level ($sk->stats->exp); |
|
|
110 | |
|
|
111 | my $make_info = sprintf |
|
|
112 | "JEWELER AUDIT: '%s' made '%s' (%s) (sk lvl %d, ring lvl %d, got %d exp): %s", |
|
|
113 | $pl->name, $ring->to_string, $ring_ob->uuid, $sklvl, |
|
|
114 | $ring->power_to_level, $exp, $make_status; |
|
|
115 | |
|
|
116 | warn "$make_info\n" if $make_status eq 'succeeded'; |
|
|
117 | } |
|
|
118 | |
99 | $chdl->put ($ring->to_object); |
119 | $chdl->put ($ring_ob); |
100 | } |
120 | } |
101 | |
121 | |
102 | sub get_ingred { |
122 | sub get_ingred { |
103 | my ($pl, $chdl) = @_; |
123 | my ($pl, $chdl) = @_; |
104 | my $ingred = eval { $chdl->extract_jeweler_ingredients }; |
124 | my $ingred = eval { $chdl->extract_jeweler_ingredients }; |
… | |
… | |
189 | my $plan = $ingred->get_plan; |
209 | my $plan = $ingred->get_plan; |
190 | |
210 | |
191 | if ($plan) { |
211 | if ($plan) { |
192 | my @ring = $ingred->get_ring; |
212 | my @ring = $ingred->get_ring; |
193 | |
213 | |
|
|
214 | if (!@ring) { |
|
|
215 | # actually the algorithm cant |
|
|
216 | $pl->message ("You slap yourself, you forgot the jewelery!"); |
|
|
217 | return; |
|
|
218 | |
194 | if ((@ring > 1) || ($ring[0]->nrof > 1)) { |
219 | } elsif ((@ring > 1) || (grep { $_->nrof > 1 } @ring)) { |
195 | # actually the algorithm cant handle more than one improvement at a time |
220 | # actually the algorithm cant handle more than one improvement at a time |
196 | $pl->message ("You can't manage to improve more than one thing at a time!"); |
221 | $pl->message ("You can't manage to improve more than one thing at a time!"); |
197 | return; |
222 | return; |
198 | |
|
|
199 | } elsif (@ring < 1) { |
|
|
200 | # actually the algorithm cant |
|
|
201 | $pl->message ("You slap yourself, you forgot the jewelery!"); |
|
|
202 | return; |
|
|
203 | |
|
|
204 | } else { |
223 | } else { |
205 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
224 | my $ringo = Jeweler::Object->new (object => $ring[0]); |
206 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
225 | my $iring = $ingred->improve_ring_by_plan ($plan, $ringo); |
207 | my $c1 = $ringo->calc_costs; |
226 | my $c1 = $ringo->calc_costs; |
208 | my $c2 = $iring->calc_costs; |
227 | my $c2 = $iring->calc_costs; |
|
|
228 | my $value = $iring->calc_value_from_cost ($c2); |
|
|
229 | |
|
|
230 | if ((not defined $c1) || (not defined $c2)) { |
|
|
231 | $pl->message ("The jewel has or will become a resistancy above 99%,\n" |
|
|
232 | ."that is completly impossible to make!"); |
|
|
233 | return; |
|
|
234 | } |
209 | |
235 | |
210 | my %keys; |
236 | my %keys; |
211 | my %cdiff; |
237 | my %cdiff; |
212 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
238 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
213 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; warn "$_: $c2->{$_} | $c1->{$_}\n"; } |
239 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; } |
214 | |
240 | |
215 | unless ($iring->is_better_than ($ringo)) { |
241 | unless ($iring->is_better_than ($ringo)) { |
216 | $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); |
242 | $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); |
217 | return; |
243 | return; |
218 | } |
244 | } |
… | |
… | |
231 | } |
257 | } |
232 | } else { |
258 | } else { |
233 | if (!$pl->flag (cf::FLAG_WIZ)) { |
259 | if (!$pl->flag (cf::FLAG_WIZ)) { |
234 | $ingred->check_costs (\%cdiff, 1); |
260 | $ingred->check_costs (\%cdiff, 1); |
235 | } |
261 | } |
236 | make_ring ($chdl, $ingred, $iring, $sk, $pl); |
262 | make_ring ($chdl, $ingred, $iring, $value, $sk, $pl); |
237 | } |
263 | } |
238 | } |
264 | } |
239 | } else { |
265 | } else { |
240 | $pl->message ("You've got no idea what you are planning to do!"); |
266 | $pl->message ("You've got no idea what you are planning to do!"); |
241 | } |
267 | } |
… | |
… | |
243 | }; |
269 | }; |
244 | $@ and warn "ERROR: $@\n"; |
270 | $@ and warn "ERROR: $@\n"; |
245 | } |
271 | } |
246 | ); |
272 | ); |
247 | |
273 | |
248 | Jeweler::read_config (cf::datadir . '/jeweler.yaml'); |
274 | Jeweler::read_config "res/jeweler.yaml"; |
|
|
275 | |