Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] add on_try_exit hook

  • Loading branch information...
commit 6759b92a4a9e0fb8a56a2821e9f663c007761e98 1 parent c9841be
Carl Mäsak authored

Showing 1 changed file with 13 additions and 0 deletions. Show diff stats Hide diff stats

  1. 13  bin/crypt
13  bin/crypt
@@ -289,6 +289,7 @@ class Adventure::Engine {
289 289
     has %!exits;
290 290
     has %!exit_aliases;
291 291
     has %!seen_room;
  292
+    has %!try_exit_hooks;
292 293
 
293 294
     method connect(@rooms, $direction) {
294 295
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -314,6 +315,10 @@ class Adventure::Engine {
314 315
         die X::Adventure::NoExitThere.new(:$direction)
315 316
             unless defined $to;
316 317
 
  318
+        if %!try_exit_hooks{$!player_location}{$actual_direction} -> &hook {
  319
+            return unless &hook();
  320
+        }
  321
+
317 322
         my @events = Adventure::PlayerWalked.new(:$to);
318 323
         unless %!seen_room{$to}++ {
319 324
             @events.push(Adventure::PlayerLooked.new(
@@ -354,6 +359,10 @@ class Adventure::Engine {
354 359
         @events;
355 360
     }
356 361
 
  362
+    method on_try_exit($room, $direction, &hook) {
  363
+        %!try_exit_hooks{$room}{$direction} = &hook;
  364
+    }
  365
+
357 366
     my class Save {
358 367
         has @.events;
359 368
     }
@@ -421,6 +430,10 @@ class Crypt::Game {
421 430
             .connect(<chamber hall>, 'south');
422 431
             .connect(<hall cave>, 'down');
423 432
             .connect(<cave crypt>, 'northwest');
  433
+            .on_try_exit('cave', 'northwest', {
  434
+                say "You try to walk past the fire, but it's too hot!";
  435
+                False;
  436
+            });
424 437
             .place_player('clearing');
425 438
         }
426 439
     }

0 notes on commit 6759b92

Please sign in to comment.
Something went wrong with that request. Please try again.