| 1 |
elmex |
1.1 |
#! perl |
| 2 |
|
|
|
| 3 |
|
|
=head1 CF+ map maker library and utilities |
| 4 |
|
|
|
| 5 |
|
|
=over 4 |
| 6 |
|
|
|
| 7 |
|
|
=cut |
| 8 |
|
|
# This extension loads some nice functionality for map makers |
| 9 |
|
|
|
| 10 |
|
|
sub rec_inv_by_slaying { |
| 11 |
|
|
my ($ob, $slaying, $cb) = @_; |
| 12 |
|
|
$cb->($ob) if $ob->slaying eq $slaying; |
| 13 |
|
|
for my $iob ($ob->inv) { rec_inv_by_slaying ($iob, $slaying, $cb) } |
| 14 |
|
|
} |
| 15 |
|
|
|
| 16 |
|
|
=item object attachment: 'check_inventory_on_apply' |
| 17 |
|
|
|
| 18 |
|
|
This attachment checks on apply whether the applyer |
| 19 |
|
|
has a specific item. Currently you can only match the slaying |
| 20 |
|
|
field of the inventory item of the player. |
| 21 |
|
|
|
| 22 |
|
|
On match the apply isn't inhibited. |
| 23 |
|
|
|
| 24 |
|
|
Following configuration can be supplied to this attachment: |
| 25 |
|
|
|
| 26 |
|
|
=over 4 |
| 27 |
|
|
|
| 28 |
|
|
=item key_string |
| 29 |
|
|
|
| 30 |
|
|
This is the string that will be matched against the slaying field |
| 31 |
|
|
of the inventory item of the player. The first found item will be |
| 32 |
|
|
decreased by the amount that can be passed in the 'decrease_by_cnt' |
| 33 |
|
|
option. |
| 34 |
|
|
|
| 35 |
|
|
=item decrease_by_cnt |
| 36 |
|
|
|
| 37 |
|
|
This is the amount the matching object will be decreased by from the inventory. |
| 38 |
|
|
Default is 0 and means nothing will be removed. |
| 39 |
|
|
|
| 40 |
|
|
=item message_on_match |
| 41 |
|
|
|
| 42 |
|
|
This is the message that will printed to the player if a matching |
| 43 |
|
|
object was found. |
| 44 |
|
|
|
| 45 |
|
|
=item message_on_nomatch |
| 46 |
|
|
|
| 47 |
|
|
This is the message that will printed to the player if NO matching |
| 48 |
|
|
object was found. |
| 49 |
|
|
|
| 50 |
|
|
=back |
| 51 |
|
|
|
| 52 |
|
|
=cut |
| 53 |
|
|
|
| 54 |
|
|
cf::register_attachment check_inventory_on_apply => |
| 55 |
|
|
on_apply => sub { |
| 56 |
|
|
my ($self, $pl) = @_; |
| 57 |
|
|
my $cfg = $self->{check_inventory_on_apply}; |
| 58 |
|
|
my $match; |
| 59 |
|
|
rec_inv_by_slaying ($pl, $cfg->{key_string}, sub { |
| 60 |
|
|
my ($ob) = @_; |
| 61 |
|
|
$match = $ob; |
| 62 |
|
|
}); |
| 63 |
|
|
if ($match) { |
| 64 |
|
|
$match->decrease_ob_nr ($cfg->{decrease_by_cnt}) if $cfg->{decrease_by_cnt}; |
| 65 |
|
|
$pl->message ($cfg->{message_on_match}) if defined $cfg->{message_on_match}; |
| 66 |
|
|
} else { |
| 67 |
|
|
$pl->message ($cfg->{message_on_nomatch}) if defined $cfg->{message_on_nomatch}; |
| 68 |
|
|
cf::override; |
| 69 |
|
|
} |
| 70 |
|
|
}; |
| 71 |
|
|
|
| 72 |
|
|
=back |
| 73 |
|
|
|
| 74 |
|
|
=cut |