… | |
… | |
38 | my $DEBUG = 1; |
38 | my $DEBUG = 1; |
39 | |
39 | |
40 | sub merge { |
40 | sub merge { |
41 | my ($chdl, $sk, $pl, $do_analyze) = @_; |
41 | my ($chdl, $sk, $pl, $do_analyze) = @_; |
42 | |
42 | |
43 | my $ingred = $chdl->extract_jeweler_ingredients; |
43 | my $ingred = get_ingred ($pl, $chdl) || return; |
|
|
44 | |
44 | my @ring = $ingred->get_ring; |
45 | my @ring = $ingred->get_ring; |
45 | my @rings = map { Jeweler::Object->new (object => $_) } @ring; |
46 | my @rings = map { Jeweler::Object->new (object => $_) } @ring; |
46 | |
47 | |
47 | @rings >= 2 |
48 | @rings >= 2 |
48 | or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); |
49 | or return $pl->reply (undef, "You slap yourself, you forgot to put at least 2 jewels in!"); |
|
|
50 | |
|
|
51 | my $input_level; |
|
|
52 | $input_level = max ($_->power_to_level, $input_level) for @rings; |
49 | |
53 | |
50 | my $ring = shift @rings; |
54 | my $ring = shift @rings; |
51 | $ring->improve_by_ring (@rings); |
55 | $ring->improve_by_ring (@rings); |
52 | |
56 | |
53 | if ($do_analyze) { |
57 | if ($do_analyze) { |
… | |
… | |
55 | $ring->wiz_analyze ($pl) |
59 | $ring->wiz_analyze ($pl) |
56 | if $pl->flag (cf::FLAG_WIZ); |
60 | if $pl->flag (cf::FLAG_WIZ); |
57 | return; |
61 | return; |
58 | } |
62 | } |
59 | |
63 | |
60 | make_ring ($chdl, $ingred, $ring, $sk, $pl); |
64 | make_ring ($chdl, $ingred, $ring, $sk, $pl, $input_level); |
61 | } |
65 | } |
62 | |
66 | |
63 | sub make_ring { |
67 | sub make_ring { |
64 | my ($chdl, $ingred, $ring, $sk, $pl) = @_; |
68 | my ($chdl, $ingred, $ring, $sk, $pl, $input_level) = @_; |
65 | |
69 | |
66 | if (!$pl->flag (cf::FLAG_WIZ)) { |
70 | if (!$pl->flag (cf::FLAG_WIZ)) { |
67 | $ingred->remove ('rings'); |
71 | $ingred->remove ('rings'); |
68 | $ingred->remove ('ammys'); |
72 | $ingred->remove ('ammys'); |
69 | } |
73 | } |
70 | |
74 | |
71 | my $ch = $ring->get_chance_perc ($sk); |
75 | my $ch = $ring->get_chance_perc ($sk); |
72 | my $succ = 0; |
76 | my $succ = 0; |
73 | my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); |
77 | my $r = cf::random_roll (0, 100, $pl, cf::PREFER_HIGH); |
|
|
78 | |
74 | if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { |
79 | if ($r <= $ch or $pl->flag (cf::FLAG_WIZ)) { |
75 | my $lvl = max ($ring->power_to_level, 1); |
80 | my $lvl = max ($ring->power_to_level, 1); |
76 | my $exp = (cf::level_to_min_exp ($lvl) - cf::level_to_min_exp ($lvl - 1)) / 100; |
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 | |
77 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
93 | $pl->change_exp ($exp, "jeweler", cf::SK_EXP_SKILL_ONLY); |
78 | $pl->message ("You succeed and get $exp experience."); |
94 | $pl->message ("You succeed and get $exp experience."); |
79 | } else { |
95 | } else { |
80 | $pl->message ("You fail!"); |
96 | $pl->message ("You fail!"); |
81 | $ring->negate; |
97 | $ring->negate; |
82 | } |
98 | } |
83 | $chdl->put ($ring->to_object); |
99 | $chdl->put ($ring->to_object); |
84 | } |
100 | } |
85 | |
101 | |
86 | cf::attach_to_type cf::SKILL, cf::SK_JEWELER, |
102 | sub get_ingred { |
|
|
103 | my ($pl, $chdl) = @_; |
|
|
104 | my $ingred = eval { $chdl->extract_jeweler_ingredients }; |
|
|
105 | if ($@ =~ /cursed/) { |
|
|
106 | $pl->message ("There are cursed items in the workbench, take them out before you do anything."). |
|
|
107 | return |
|
|
108 | } elsif ($@ =~ /unidentified/) { |
|
|
109 | $pl->message ("There are unidentified items in the workbench, identify them before you do anything."). |
|
|
110 | return |
|
|
111 | } elsif ($@) { |
|
|
112 | warn "error in jeweler ingredient extraction: $@"; |
|
|
113 | return; |
|
|
114 | } |
|
|
115 | $ingred; |
|
|
116 | } |
|
|
117 | |
|
|
118 | cf::object::attachment check_ring_drop_on => |
|
|
119 | on_drop_on => sub { |
|
|
120 | my ($self, $obj, $who) = @_; |
|
|
121 | my $cfg = $self->{check_ring_drop_on}; |
|
|
122 | if ($obj->type == cf::RING |
|
|
123 | && !$obj->flag (cf::FLAG_CURSED) |
|
|
124 | && !$obj->flag (cf::FLAG_DAMNED) |
|
|
125 | ) { |
|
|
126 | my $ringo = Jeweler::Object->new (object => $obj); |
|
|
127 | for (grep { /^resist_/ } keys %$cfg) { |
|
|
128 | if (/^resist_(\S+)$/) { |
|
|
129 | if ($ringo->has_resist ($1)) { |
|
|
130 | $self->map->trigger ( |
|
|
131 | $cfg->{connection}, |
|
|
132 | $cfg->{state} |
|
|
133 | ); |
|
|
134 | cf::override; |
|
|
135 | } |
|
|
136 | } |
|
|
137 | } |
|
|
138 | } |
|
|
139 | }; |
|
|
140 | |
|
|
141 | cf::object->attach ( |
|
|
142 | type => cf::SKILL, |
|
|
143 | subtype => cf::SK_JEWELER, |
87 | on_use_skill => sub { |
144 | on_use_skill => sub { |
88 | my ($sk, $ob, $part, $dir, $msg) = @_; |
145 | my ($sk, $ob, $part, $dir, $msg) = @_; |
89 | my $pl = $ob; |
146 | my $pl = $ob; |
90 | |
147 | |
91 | my $skobj = $sk; |
148 | my $skobj = $sk; |
92 | |
149 | |
93 | my $chdl = new Jeweler::CauldronHandler; |
150 | my $chdl = new Jeweler::CauldronHandler; |
94 | |
151 | |
95 | my $rv = 1; |
152 | my $rv = 1; |
96 | eval { |
153 | eval { |
97 | Jeweler::read_config ($ENV{CROSSFIRE_LIBDIR} . '/jeweler.yaml'); |
|
|
98 | $DEBUG = 1; |
154 | $DEBUG = 1; |
99 | |
155 | |
100 | my $player = $ob->contr; |
156 | my $player = $ob->contr; |
101 | |
157 | |
102 | unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) { |
158 | unless ($chdl->find_cauldron ('jeweler_bench', $ob->map->at ($ob->x, $ob->y))) { |
… | |
… | |
110 | |
166 | |
111 | } elsif ($msg =~ m/^\s*make\s*$/i) { |
167 | } elsif ($msg =~ m/^\s*make\s*$/i) { |
112 | $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); |
168 | $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); |
113 | |
169 | |
114 | } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { |
170 | } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { |
115 | my $ingred = $chdl->extract_jeweler_ingredients; |
171 | my $ingred = get_ingred ($pl, $chdl) || return; |
116 | |
172 | |
117 | unless ($Jeweler::CFG->{conversions}->{lc $1}) { |
173 | unless ($Jeweler::CFG->{conversions}->{lc $1}) { |
118 | $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); |
174 | $pl->message ("You don't know how to make '$1', is does such a thing even exist?"); |
119 | return |
175 | return |
120 | } |
176 | } |
… | |
… | |
126 | |
182 | |
127 | } elsif ($msg =~ m/^\s*merge\s*$/i) { |
183 | } elsif ($msg =~ m/^\s*merge\s*$/i) { |
128 | merge ($chdl, $sk, $pl, 0); |
184 | merge ($chdl, $sk, $pl, 0); |
129 | |
185 | |
130 | } else { |
186 | } else { |
131 | my $ingred = $chdl->extract_jeweler_ingredients; |
187 | my $ingred = get_ingred ($pl, $chdl) || return; |
|
|
188 | |
132 | my $plan = $ingred->get_plan; |
189 | my $plan = $ingred->get_plan; |
133 | |
190 | |
134 | if ($plan) { |
191 | if ($plan) { |
135 | my @ring = $ingred->get_ring; |
192 | my @ring = $ingred->get_ring; |
136 | |
193 | |
… | |
… | |
151 | my $c2 = $iring->calc_costs; |
208 | my $c2 = $iring->calc_costs; |
152 | |
209 | |
153 | my %keys; |
210 | my %keys; |
154 | my %cdiff; |
211 | my %cdiff; |
155 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
212 | for (keys %$c1, keys %$c2) { $keys{$_} = 1 } |
156 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_} } |
213 | for (keys %keys) { $cdiff{$_} = $c2->{$_} - $c1->{$_}; warn "$_: $c2->{$_} | $c1->{$_}\n"; } |
157 | |
214 | |
158 | unless (grep { $_ > 0 } values %cdiff) { |
215 | unless ($iring->is_better_than ($ringo)) { |
159 | $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); |
216 | $pl->message ("This plan doesn't improve anything, you find yourself puzzled about what you missed..."); |
160 | return; |
217 | return; |
161 | } |
218 | } |
162 | |
219 | |
163 | my $remcosts = $ingred->check_costs (\%cdiff); |
220 | my $remcosts = $ingred->check_costs (\%cdiff); |
… | |
… | |
184 | } |
241 | } |
185 | } |
242 | } |
186 | }; |
243 | }; |
187 | $@ and warn "ERROR: $@\n"; |
244 | $@ and warn "ERROR: $@\n"; |
188 | } |
245 | } |
189 | ; |
246 | ); |
190 | |
247 | |
|
|
248 | Jeweler::read_config (cf::datadir . '/jeweler.yaml'); |