Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] putting helmet in brook and taking it

...also fills it with water.
  • Loading branch information...
commit 48c757550e531083bb32e825749f3d57cb429d63 1 parent 45e6ac8
Carl Mäsak authored July 25, 2012

Showing 1 changed file with 43 additions and 1 deletion. Show diff stats Hide diff stats

  1. 44  bin/crypt
44  bin/crypt
@@ -496,6 +496,7 @@ class Adventure::Engine {
496 496
     has %!dark_rooms;
497 497
     has %!light_sources;
498 498
     has %!things_shining;
  499
+    has %!remove_from_hooks;
499 500
 
500 501
     method connect(@rooms, $direction) {
501 502
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -542,7 +543,8 @@ class Adventure::Engine {
542 543
             return True
543 544
                 if $thing eq $sought;
544 545
             return True
545  
-                if %!open_things{$thing}
  546
+                if %!containers{$thing}
  547
+                && (!%!openable_things{$thing} || %!open_things{$thing})
546 548
                 && self!is_thing_in($sought, "contents:$thing");
547 549
         }
548 550
         return False;
@@ -818,6 +820,11 @@ class Adventure::Engine {
818 820
             unless %!carryable_things{$thing};
819 821
 
820 822
         my @events = Adventure::PlayerTook.new(:$thing);
  823
+        for %!remove_from_hooks.kv -> $container, &hook {
  824
+            if self!is_thing_in($thing, "contents:$container") {
  825
+                @events.push($_) when Event for &hook($thing);
  826
+            }
  827
+        }
821 828
         self!apply_and_return: @events;
822 829
     }
823 830
 
@@ -882,6 +889,10 @@ class Adventure::Engine {
882 889
         %!put_hooks{$thing} = &hook;
883 890
     }
884 891
 
  892
+    method on_remove_from($thing, &hook) {
  893
+        %!remove_from_hooks{$thing} = &hook;
  894
+    }
  895
+
885 896
     my class Save {
886 897
         has @.events;
887 898
     }
@@ -981,6 +992,9 @@ class Adventure::Engine {
981 992
         when Adventure::LightSourceSwitchedOn {
982 993
             %!things_shining{.thing} = True;
983 994
         }
  995
+        when Adventure::PlayerPutIn {
  996
+            %!thing_rooms{.thing} = "contents:{.in}";
  997
+        }
984 998
     }
985 999
 }
986 1000
 
@@ -1048,6 +1062,13 @@ class Crypt::Game {
1048 1062
             .make_thing_implicit: 'leaves';
1049 1063
             .make_thing_carryable: 'leaves';
1050 1064
             .place_thing: 'brook', 'hill';
  1065
+            .make_thing_a_container: 'brook';
  1066
+            .on_remove_from: 'brook',
  1067
+                -> $_ {
  1068
+                    when 'helmet' {
  1069
+                        $!engine.place_thing('water', 'contents:helmet');
  1070
+                    }
  1071
+                };
1051 1072
             .place_thing: 'water', 'hill';
1052 1073
             .make_thing_implicit: 'water';
1053 1074
             .make_thing_carryable: 'water';
@@ -2425,6 +2446,27 @@ multi MAIN('test') {
2425 2446
             'filling the helmet with water';
2426 2447
     }
2427 2448
 
  2449
+    {
  2450
+        my $game = game_from_hall();
  2451
+
  2452
+        $game.use('flashlight');
  2453
+        $game.take('helmet');
  2454
+        $game.walk('north');
  2455
+        $game.walk('north');
  2456
+        $game.put_thing_in('helmet', 'brook');
  2457
+        is $game.take('helmet'),
  2458
+            [
  2459
+                Adventure::PlayerTook.new(
  2460
+                    :thing<helmet>,
  2461
+                ),
  2462
+                Adventure::ThingPlaced.new(
  2463
+                    :thing<water>,
  2464
+                    :room<contents:helmet>,
  2465
+                ),
  2466
+            ],
  2467
+            'picking helmet up from brook fills it with water';
  2468
+    }
  2469
+
2428 2470
     done;
2429 2471
 }
2430 2472
 

0 notes on commit 48c7575

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