… | |
… | |
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 | } |
|
|
101 | |
|
|
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 | }; |
85 | |
140 | |
86 | cf::object->attach ( |
141 | cf::object->attach ( |
87 | type => cf::SKILL, |
142 | type => cf::SKILL, |
88 | subtype => cf::SK_JEWELER, |
143 | subtype => cf::SK_JEWELER, |
89 | on_use_skill => sub { |
144 | on_use_skill => sub { |
… | |
… | |
111 | |
166 | |
112 | } elsif ($msg =~ m/^\s*make\s*$/i) { |
167 | } elsif ($msg =~ m/^\s*make\s*$/i) { |
113 | $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); |
168 | $pl->message ("You can make: " . (join ', ', keys %{Jeweler::getcfg ('conversions') || {}})); |
114 | |
169 | |
115 | } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { |
170 | } elsif ($msg =~ m/^\s*make\s+(\S+)\s*$/i) { |
116 | my $ingred = $chdl->extract_jeweler_ingredients; |
171 | my $ingred = get_ingred ($pl, $chdl) || return; |
117 | |
172 | |
118 | unless ($Jeweler::CFG->{conversions}->{lc $1}) { |
173 | unless ($Jeweler::CFG->{conversions}->{lc $1}) { |
119 | $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?"); |
120 | return |
175 | return |
121 | } |
176 | } |
… | |
… | |
127 | |
182 | |
128 | } elsif ($msg =~ m/^\s*merge\s*$/i) { |
183 | } elsif ($msg =~ m/^\s*merge\s*$/i) { |
129 | merge ($chdl, $sk, $pl, 0); |
184 | merge ($chdl, $sk, $pl, 0); |
130 | |
185 | |
131 | } else { |
186 | } else { |
132 | my $ingred = $chdl->extract_jeweler_ingredients; |
187 | my $ingred = get_ingred ($pl, $chdl) || return; |
|
|
188 | |
133 | my $plan = $ingred->get_plan; |
189 | my $plan = $ingred->get_plan; |
134 | |
190 | |
135 | if ($plan) { |
191 | if ($plan) { |
136 | my @ring = $ingred->get_ring; |
192 | my @ring = $ingred->get_ring; |
137 | |
193 | |