Skip to content

Commit

Permalink
Tracker->is_nomessage
Browse files Browse the repository at this point in the history
  • Loading branch information
sartak committed Jul 5, 2013
1 parent ecdd3d3 commit 43404be
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
15 changes: 14 additions & 1 deletion lib/NetHack/ItemPool/Tracker/Wand.pm
Expand Up @@ -50,7 +50,20 @@ sub engrave_useful {

sub no_engrave_message {
my $self = shift;
$self->rule_out_all_but(map { "wand of $_" } 'locking', 'nothing', 'opening', 'probing', 'undead turning', 'secret door detection');
$self->rule_out_all_but('wand of locking', 'wand of nothing', 'wand of opening', 'wand of probing', 'wand of undead turning', 'wand of secret door detection');
}

sub is_nomessage {
my $self = shift;
my %is_nomessage = map { $_ => 1 } 'wand of locking', 'wand of nothing', 'wand of opening', 'wand of probing', 'wand of undead turning', 'wand of secret door detection';

for my $possibility ($self->possibilities) {
if (!$is_nomessage{$possibility}) {
return 0;
}
}

return 1;
}

__PACKAGE__->meta->make_immutable;
Expand Down
13 changes: 12 additions & 1 deletion t/701-wand-engrave.t
@@ -1,15 +1,18 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More tests => 6;
use Test::More tests => 14;
use NetHack::ItemPool;

my $pool = NetHack::ItemPool->new;
my $balsa = $pool->new_item("a balsa wand");
ok($balsa->tracker->engrave_useful);
ok(!$balsa->tracker->is_nomessage);
$balsa->tracker->rule_out_all_but('wand of fire', 'wand of sleep', 'wand of death');
ok(!$balsa->tracker->is_nomessage);
ok($balsa->tracker->engrave_useful, 'engrave is useful');
$balsa->tracker->rule_out('wand of fire');
ok(!$balsa->tracker->is_nomessage);
ok(!$balsa->tracker->engrave_useful, 'engrave is no longer useful');

my $other_balsa = $pool->new_item("a blessed balsa wand");
Expand All @@ -19,4 +22,12 @@ $other_balsa->tracker->rule_out('wand of sleep');

is($other_balsa->identity, 'wand of death');
is($balsa->identity, 'wand of death');
ok(!$balsa->tracker->is_nomessage);

my $glass = $pool->new_item("a glass wand");
ok(!$glass->tracker->is_nomessage);
ok($glass->tracker->engrave_useful);
$glass->tracker->no_engrave_message;
ok(!$glass->tracker->engrave_useful);
ok($glass->tracker->is_nomessage);

0 comments on commit 43404be

Please sign in to comment.