Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] can't pick up the water with bare hands

  • Loading branch information...
commit d51648ba83db766b610d6c2af9fd9f5e45793d9b 1 parent 48c7575
Carl Mäsak authored July 25, 2012
46  bin/crypt
@@ -497,6 +497,7 @@ class Adventure::Engine {
497 497
     has %!light_sources;
498 498
     has %!things_shining;
499 499
     has %!remove_from_hooks;
  500
+    has %!take_hooks;
500 501
 
501 502
     method connect(@rooms, $direction) {
502 503
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -819,13 +820,19 @@ class Adventure::Engine {
819 820
         die X::Adventure::ThingNotCarryable.new(:action<take>, :$thing)
820 821
             unless %!carryable_things{$thing};
821 822
 
822  
-        my @events = Adventure::PlayerTook.new(:$thing);
  823
+        my @events;
823 824
         for %!remove_from_hooks.kv -> $container, &hook {
824 825
             if self!is_thing_in($thing, "contents:$container") {
825 826
                 @events.push($_) when Event for &hook($thing);
826 827
             }
827 828
         }
828  
-        self!apply_and_return: @events;
  829
+        # XXX: Need to apply this event early so that hooks can drop the thing.
  830
+        self!apply(Adventure::PlayerTook.new(:$thing));
  831
+        if %!take_hooks{$thing} -> &hook {
  832
+            @events.push($_) when Event for &hook();
  833
+        }
  834
+        self!apply($_) for @events;
  835
+        return Adventure::PlayerTook.new(:$thing), @events;
829 836
     }
830 837
 
831 838
     method drop($thing) {
@@ -893,6 +900,10 @@ class Adventure::Engine {
893 900
         %!remove_from_hooks{$thing} = &hook;
894 901
     }
895 902
 
  903
+    method on_take($thing, &hook) {
  904
+        %!take_hooks{$thing} = &hook;
  905
+    }
  906
+
896 907
     my class Save {
897 908
         has @.events;
898 909
     }
@@ -1070,6 +1081,11 @@ class Crypt::Game {
1070 1081
                     }
1071 1082
                 };
1072 1083
             .place_thing: 'water', 'hill';
  1084
+            .on_take: 'water',
  1085
+                {
  1086
+                    $!engine.remark('bare-hands-carry-water'),
  1087
+                    $!engine.drop('water');
  1088
+                };
1073 1089
             .make_thing_implicit: 'water';
1074 1090
             .make_thing_carryable: 'water';
1075 1091
 
@@ -1127,6 +1143,10 @@ class Crypt::Game {
1127 1143
         return $!engine.take($thing);
1128 1144
     }
1129 1145
 
  1146
+    method drop($thing) {
  1147
+        return $!engine.drop($thing);
  1148
+    }
  1149
+
1130 1150
     method put_thing_in($thing, $in) {
1131 1151
         return $!engine.put_thing_in($thing, $in);
1132 1152
     }
@@ -1350,6 +1370,9 @@ multi MAIN() {
1350 1370
                     when Adventure::PlayerTook {
1351 1371
                         say "You take the {.thing}.";
1352 1372
                     }
  1373
+                    when Adventure::PlayerDropped {
  1374
+                        say "You drop the {.thing} on the ground.";
  1375
+                    }
1353 1376
                     when Adventure::PlayerOpened {
1354 1377
                         say "You open the {.thing}.";
1355 1378
                     }
@@ -2467,6 +2490,25 @@ multi MAIN('test') {
2467 2490
             'picking helmet up from brook fills it with water';
2468 2491
     }
2469 2492
 
  2493
+    {
  2494
+        my $game = Crypt::Game.new();
  2495
+
  2496
+        $game.walk('east');
  2497
+        is $game.take('water'),
  2498
+            [
  2499
+                Adventure::PlayerTook.new(
  2500
+                    :thing<water>,
  2501
+                ),
  2502
+                Adventure::GameRemarked.new(
  2503
+                    :remark<bare-hands-carry-water>,
  2504
+                ),
  2505
+                Adventure::PlayerDropped.new(
  2506
+                    :thing<water>,
  2507
+                ),
  2508
+            ],
  2509
+            'picking up water with your bare hands fails';
  2510
+    }
  2511
+
2470 2512
     done;
2471 2513
 }
2472 2514
 
3  game-data/descriptions
@@ -77,3 +77,6 @@ The whole floor tips, and reveals a hole beneath the wall.
77 77
 
78 78
 == remark:floor-hides-hole
79 79
 The whole floor tips back, hiding the hole again.
  80
+
  81
+== remark:bare-hands-carry-water
  82
+Your bare hands aren't very good at carrying water.

0 notes on commit d51648b

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