Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[bin/crypt] add on_try_exit hook

  • Loading branch information...
commit 6759b92a4a9e0fb8a56a2821e9f663c007761e98 1 parent c9841be
Carl Mäsak authored
Showing with 13 additions and 0 deletions.
  1. +13 −0 bin/crypt
13 bin/crypt
View
@@ -289,6 +289,7 @@ class Adventure::Engine {
has %!exits;
has %!exit_aliases;
has %!seen_room;
+ has %!try_exit_hooks;
method connect(@rooms, $direction) {
die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -314,6 +315,10 @@ class Adventure::Engine {
die X::Adventure::NoExitThere.new(:$direction)
unless defined $to;
+ if %!try_exit_hooks{$!player_location}{$actual_direction} -> &hook {
+ return unless &hook();
+ }
+
my @events = Adventure::PlayerWalked.new(:$to);
unless %!seen_room{$to}++ {
@events.push(Adventure::PlayerLooked.new(
@@ -354,6 +359,10 @@ class Adventure::Engine {
@events;
}
+ method on_try_exit($room, $direction, &hook) {
+ %!try_exit_hooks{$room}{$direction} = &hook;
+ }
+
my class Save {
has @.events;
}
@@ -421,6 +430,10 @@ class Crypt::Game {
.connect(<chamber hall>, 'south');
.connect(<hall cave>, 'down');
.connect(<cave crypt>, 'northwest');
+ .on_try_exit('cave', 'northwest', {
+ say "You try to walk past the fire, but it's too hot!";
+ False;
+ });
.place_player('clearing');
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.