#! perl =head1 CF+ map maker library and utilities =over 4 =cut # This extension loads some nice functionality for map makers sub rec_inv_by_slaying { my ($ob, $slaying, $cb) = @_; $cb->($ob) if $ob->slaying eq $slaying; for my $iob ($ob->inv) { rec_inv_by_slaying ($iob, $slaying, $cb) } } =item object attachment: 'check_inventory_on_apply' This attachment checks on apply whether the applyer has a specific item. Currently you can only match the slaying field of the inventory item of the player. On match the apply isn't inhibited. Following configuration can be supplied to this attachment: =over 4 =item key_string This is the string that will be matched against the slaying field of the inventory item of the player. The first found item will be decreased by the amount that can be passed in the 'decrease_by_cnt' option. =item decrease_by_cnt This is the amount the matching object will be decreased by from the inventory. Default is 0 and means nothing will be removed. =item message_on_match This is the message that will printed to the player if a matching object was found. =item message_on_nomatch This is the message that will printed to the player if NO matching object was found. =back =cut cf::object::attachment check_inventory_on_apply => on_apply => sub { my ($self, $pl) = @_; my $cfg = $self->{check_inventory_on_apply}; my $match; rec_inv_by_slaying ($pl, $cfg->{key_string}, sub { my ($ob) = @_; $match = $ob; }); if ($match) { $match->decrease_ob_nr ($cfg->{decrease_by_cnt}) if $cfg->{decrease_by_cnt}; $pl->message ($cfg->{message_on_match}, cf::NDI_UNIQUE) if defined $cfg->{message_on_match}; } else { $pl->message ($cfg->{message_on_nomatch}, cf::NDI_RED | cf::NDI_UNIQUE) if defined $cfg->{message_on_nomatch}; cf::override; } }; =back =cut