… | |
… | |
9 | |
9 | |
10 | sub rec_inv_by_slaying { |
10 | sub rec_inv_by_slaying { |
11 | my ($ob, $slaying, $cb) = @_; |
11 | my ($ob, $slaying, $cb) = @_; |
12 | $cb->($ob) if $ob->slaying eq $slaying; |
12 | $cb->($ob) if $ob->slaying eq $slaying; |
13 | for my $iob ($ob->inv) { rec_inv_by_slaying ($iob, $slaying, $cb) } |
13 | for my $iob ($ob->inv) { rec_inv_by_slaying ($iob, $slaying, $cb) } |
|
|
14 | } |
|
|
15 | |
|
|
16 | =item count_linked ($map, $connected) |
|
|
17 | |
|
|
18 | Counts the number of objects with the connected value C<$connected> on |
|
|
19 | the map C<$map>. |
|
|
20 | |
|
|
21 | =cut |
|
|
22 | |
|
|
23 | sub count_linked { |
|
|
24 | my ($map, $connected) = @_; |
|
|
25 | my (@a) = $map->find_link ($connected); |
|
|
26 | scalar @a |
14 | } |
27 | } |
15 | |
28 | |
16 | =item object attachment: 'check_inventory_on_apply' |
29 | =item object attachment: 'check_inventory_on_apply' |
17 | |
30 | |
18 | This attachment checks on apply whether the applyer |
31 | This attachment checks on apply whether the applyer |
… | |
… | |
107 | } |
120 | } |
108 | cf::override; |
121 | cf::override; |
109 | } |
122 | } |
110 | }; |
123 | }; |
111 | |
124 | |
|
|
125 | |
|
|
126 | =item object attachment: 'ratelimit_converter' |
|
|
127 | |
|
|
128 | This is an attachment that allows a converter to be ratelimited in terms of |
|
|
129 | items per hour. |
|
|
130 | |
|
|
131 | The attachment has following configuration: |
|
|
132 | |
|
|
133 | =over 4 |
|
|
134 | |
|
|
135 | =item match |
|
|
136 | |
|
|
137 | This field should contain a L<cf::match> match string, that should match the |
|
|
138 | input object. |
|
|
139 | |
|
|
140 | =item generate_arch |
|
|
141 | |
|
|
142 | This field should contain the archetype name of the output. |
|
|
143 | |
|
|
144 | =item items_per_hour |
|
|
145 | |
|
|
146 | This field should contain the number of items to generate at maximum per hour. |
|
|
147 | Default is: 20 |
|
|
148 | |
|
|
149 | =item converter_tag |
|
|
150 | |
|
|
151 | This is the tag of the converter, it should be unique per converter. You can |
|
|
152 | also use this to make the limit hit for multiple converters. |
|
|
153 | |
|
|
154 | =item msg |
|
|
155 | |
|
|
156 | This is the message when the player successfully converted. |
|
|
157 | |
|
|
158 | =item failmsg |
|
|
159 | |
|
|
160 | This is the failure message, which will be presented to the player when he hits |
|
|
161 | the rate limit. |
|
|
162 | |
|
|
163 | =back |
|
|
164 | |
|
|
165 | =cut |
|
|
166 | |
|
|
167 | cf::object::attachment ratelimit_converter => |
|
|
168 | on_drop_on => sub { |
|
|
169 | my ($self, $obj, $who) = @_; |
|
|
170 | |
|
|
171 | my $cfg = $self->{ratelimit_converter}; |
|
|
172 | |
|
|
173 | my $output_arch = $cfg->{generate_arch}; |
|
|
174 | my $match = $cfg->{match}; |
|
|
175 | my $mitems = $cfg->{items_per_hour} || 20; |
|
|
176 | my $tag = 'ratelimit_converter_' . $cfg->{converter_tag}; |
|
|
177 | |
|
|
178 | return unless cf::match::match $match, $obj; |
|
|
179 | |
|
|
180 | my $items = $mitems; |
|
|
181 | |
|
|
182 | if (!$who->flag (cf::FLAG_WIZ) && defined $who->{$tag . '_ts'}) { |
|
|
183 | my $itemtime = time - $who->{$tag . '_ts'}; |
|
|
184 | if ($itemtime < 3600) { |
|
|
185 | $items = int ($items * ($itemtime / 3600)); |
|
|
186 | } |
|
|
187 | } |
|
|
188 | |
|
|
189 | my $nr = $obj->nrof ? $obj->nrof : 1; |
|
|
190 | $nr = $items if $nr > $items; |
|
|
191 | |
|
|
192 | if ($nr > 0) { |
|
|
193 | $obj->decrease ($nr); |
|
|
194 | |
|
|
195 | my $out = cf::object::generate ($output_arch, $self); |
|
|
196 | $out->nrof ($nr); |
|
|
197 | $out->insert_at ($self, $self); |
|
|
198 | |
|
|
199 | if ($nr >= $mitems) { |
|
|
200 | $who->{$tag . '_ts'} = time; |
|
|
201 | } else { |
|
|
202 | # give player credit for the unused refills. |
|
|
203 | $who->{$tag . '_ts'} = |
|
|
204 | time - int ((($items - $nr) * 3600) / $mitems); |
|
|
205 | } |
|
|
206 | |
|
|
207 | $who->message ($cfg->{msg}) |
|
|
208 | if $cfg->{msg} ne ''; |
|
|
209 | } else { |
|
|
210 | if ($who->contr) { |
|
|
211 | $who->contr->failmsg ($cfg->{failmsg}) |
|
|
212 | if $cfg->{failmsg} ne ''; |
|
|
213 | } |
|
|
214 | } |
|
|
215 | |
|
|
216 | if ($who->flag (cf::FLAG_WIZ)) { |
|
|
217 | delete $who->{$tag . '_ts'}; |
|
|
218 | } |
|
|
219 | }; |
|
|
220 | |
|
|
221 | |
112 | =item object attachment: 'display_info_window' |
222 | =item object attachment: 'display_info_window' |
113 | |
223 | |
114 | If you attach this attachment to a sign a window containing the |
224 | If you attach this attachment to a sign a window containing the |
115 | message will open in the client when the player applies it. |
225 | message will open in the client when the player applies it. |
116 | |
226 | |
… | |
… | |
151 | }; |
261 | }; |
152 | |
262 | |
153 | =back |
263 | =back |
154 | |
264 | |
155 | =cut |
265 | =cut |
|
|
266 | |