Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit d51648ba83db766b610d6c2af9fd9f5e45793d9b 1 parent 48c7575
@masak authored
Showing with 47 additions and 2 deletions.
  1. +44 −2 bin/crypt
  2. +3 −0  game-data/descriptions
View
46 bin/crypt
@@ -497,6 +497,7 @@ class Adventure::Engine {
has %!light_sources;
has %!things_shining;
has %!remove_from_hooks;
+ has %!take_hooks;
method connect(@rooms, $direction) {
die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -819,13 +820,19 @@ class Adventure::Engine {
die X::Adventure::ThingNotCarryable.new(:action<take>, :$thing)
unless %!carryable_things{$thing};
- my @events = Adventure::PlayerTook.new(:$thing);
+ my @events;
for %!remove_from_hooks.kv -> $container, &hook {
if self!is_thing_in($thing, "contents:$container") {
@events.push($_) when Event for &hook($thing);
}
}
- self!apply_and_return: @events;
+ # XXX: Need to apply this event early so that hooks can drop the thing.
+ self!apply(Adventure::PlayerTook.new(:$thing));
+ if %!take_hooks{$thing} -> &hook {
+ @events.push($_) when Event for &hook();
+ }
+ self!apply($_) for @events;
+ return Adventure::PlayerTook.new(:$thing), @events;
}
method drop($thing) {
@@ -893,6 +900,10 @@ class Adventure::Engine {
%!remove_from_hooks{$thing} = &hook;
}
+ method on_take($thing, &hook) {
+ %!take_hooks{$thing} = &hook;
+ }
+
my class Save {
has @.events;
}
@@ -1070,6 +1081,11 @@ class Crypt::Game {
}
};
.place_thing: 'water', 'hill';
+ .on_take: 'water',
+ {
+ $!engine.remark('bare-hands-carry-water'),
+ $!engine.drop('water');
+ };
.make_thing_implicit: 'water';
.make_thing_carryable: 'water';
@@ -1127,6 +1143,10 @@ class Crypt::Game {
return $!engine.take($thing);
}
+ method drop($thing) {
+ return $!engine.drop($thing);
+ }
+
method put_thing_in($thing, $in) {
return $!engine.put_thing_in($thing, $in);
}
@@ -1350,6 +1370,9 @@ multi MAIN() {
when Adventure::PlayerTook {
say "You take the {.thing}.";
}
+ when Adventure::PlayerDropped {
+ say "You drop the {.thing} on the ground.";
+ }
when Adventure::PlayerOpened {
say "You open the {.thing}.";
}
@@ -2467,6 +2490,25 @@ multi MAIN('test') {
'picking helmet up from brook fills it with water';
}
+ {
+ my $game = Crypt::Game.new();
+
+ $game.walk('east');
+ is $game.take('water'),
+ [
+ Adventure::PlayerTook.new(
+ :thing<water>,
+ ),
+ Adventure::GameRemarked.new(
+ :remark<bare-hands-carry-water>,
+ ),
+ Adventure::PlayerDropped.new(
+ :thing<water>,
+ ),
+ ],
+ 'picking up water with your bare hands fails';
+ }
+
done;
}
View
3  game-data/descriptions
@@ -77,3 +77,6 @@ The whole floor tips, and reveals a hole beneath the wall.
== remark:floor-hides-hole
The whole floor tips back, hiding the hole again.
+
+== remark:bare-hands-carry-water
+Your bare hands aren't very good at carrying water.
Please sign in to comment.
Something went wrong with that request. Please try again.