Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

full encounter replacement test

  • Loading branch information...
commit a221c28d836b35d828028f4e14fb8968331f8546 1 parent 2366865
@rjbs authored
View
21 eg/monster/elf
@@ -0,0 +1,21 @@
+type: monster
+name: Elf
+ac: 6
+hd: 3
+mv: 180'
+attacks: 2
+damage: 2d6, 2d6
+num: 1d6
+save: M6
+morale: 9
+loot: ~
+alignment: Neutral
+xp-bonuses:
+ - Pointy ears
+description: Pointed ears, the whole thing.
+extras:
+- label: Robots?
+ dice: 1d100
+ results:
+ 1: { replace: { file: eg/monster/roboelf } }
+ 2-100: ~
View
16 eg/monster/roboelf
@@ -0,0 +1,16 @@
+type: monster
+name: Robo-Elf
+ac: 2
+hd: 6
+mv: 180'
+attacks: 2
+damage: 2d8, 2d8
+num: 1d3
+save: M6
+morale: 10
+loot: ~
+alignment: Lawful
+xp-bonuses:
+ - Pointy ears
+ - Metal skin
+description: Built by OCP to replace traditional elfs.
View
5 lib/Roland/Result/Monster.pm
@@ -56,7 +56,8 @@ $name
END_MONSTER
for my $key ($self->_extra_keys) {
- next unless defined(my $v = $self->_get_extra($key));
+ my $v = $self->_get_extra($key);
+ next if $v->isa('Roland::Result::None');
$v = $v->as_text;
if ($indent * 2 + length($v) + length($key) + 4 > 79) {
$v = autoformat $v, { left => 4, right => 79, all => 1 };
@@ -71,7 +72,7 @@ END_MONSTER
my $hp = delete $unit->{hp};
$text .= "- Hit points: $hp\n";
for my $key (sort keys %$unit) {
- next unless defined $unit->{$key};
+ next if $unit->{$key}->isa('Roland::Result::None');
$text .= " $key: " . $unit->{$key}->as_text . "\n";
}
} else {
View
28 lib/Roland/Table/Monster.pm
@@ -31,6 +31,7 @@ sub roll_table {
# TODO: barf about extra table entries?
my $main = { %{ $self->_guts }, %$override };
+
my $name = $main->{name} // "(unknown)";
my $num_dice = $main->{num} // '?';
$num_dice = $num_dice->{wandering} if ref $num_dice;
@@ -38,21 +39,7 @@ sub roll_table {
? $self->hub->roll_dice($num_dice, "number of $name")
: $num_dice;
- # hd is hit dice; either "int1" or "int1 ± int2" or "< 1"
- # hd is used for monster level, xp, etc
- # hp is the hp generator; default based on hd
- # hd eq "< 1", 1d4
- # otherwise max(1, roll( "1d{int1} ± {int2}") )
- my $hd = $main->{hd} // '?';
-
- my $hp = $main->{hp}
- //($hd eq '?' ? '1d8'
- : $hd =~ /\A<\s*1\z/ ? '1d4'
- : $hd =~ $HD_RE ? $1 . 'd8' . ($2 ? "$2$3" : '')
- : '?'); # warn? -- rjbs, 2012-12-06
-
my @also;
-
my %extra;
EXTRA: for my $extra (@{ $main->{extras} || [] }) {
my $desc = $extra->{label};
@@ -74,6 +61,19 @@ sub roll_table {
$extra{ $desc } = $result;
}
+ # hd is hit dice; either "int1" or "int1 ± int2" or "< 1"
+ # hd is used for monster level, xp, etc
+ # hp is the hp generator; default based on hd
+ # hd eq "< 1", 1d4
+ # otherwise max(1, roll( "1d{int1} ± {int2}") )
+ my $hd = $main->{hd} // '?';
+
+ my $hp = $main->{hp}
+ //($hd eq '?' ? '1d8'
+ : $hd =~ /\A<\s*1\z/ ? '1d4'
+ : $hd =~ $HD_RE ? $1 . 'd8' . ($2 ? "$2$3" : '')
+ : '?'); # warn? -- rjbs, 2012-12-06
+
my @units;
if ($num ne '?') {
UNIT: for (1 .. $num) {
View
40 t/redir.t
@@ -37,4 +37,44 @@ test_result("monster/man, with zombies" => {
},
});
+test_result("elfs (meaty kind)" => {
+ file => 'eg/monster/elf',
+ rolls => [
+ 2, # number appearing
+ 29, # robots? no
+ 12, # hit points
+ 12, # hit points
+ ],
+ test => sub {
+ my @results = flatten_multi($_[0]);
+ is(@results, 1, "we got just one encounter");
+
+ my @elfs = $results[0]->units;
+
+ is(@elfs, 2, "...two units");
+ is($results[0]->name, 'Elf');
+ is($elfs[0]{hp}, 12, "... ...first with 12 hp");
+ is($elfs[1]{hp}, 12, "... ...second with 12 hp");
+ },
+});
+
+test_result("elfs (shiny kind)" => {
+ file => 'eg/monster/elf',
+ rolls => [
+ 4, # number appearing (elfs)
+ 1, # robots? HECK YES!
+ 1, # number appearing (roboelfs)
+ 20, # hit points
+ ],
+ test => sub {
+ my @results = flatten_multi($_[0]);
+ is(@results, 1, "we got just one encounter");
+
+ my @roboelfs = $results[0]->units;
+
+ is(@roboelfs, 1, "...one unit, too");
+ is($roboelfs[0]{hp}, 20, "... with 20 hp");
+ },
+});
+
done_testing;
Please sign in to comment.
Something went wrong with that request. Please try again.