Skip to content

Commit

Permalink
Add tests for dodge-while-grabbed
Browse files Browse the repository at this point in the history
  • Loading branch information
wapcaplet committed Apr 12, 2020
1 parent 287bbcc commit 6134549
Showing 1 changed file with 70 additions and 7 deletions.
77 changes: 70 additions & 7 deletions tests/melee_dodge_hit_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@

#include "catch/catch.hpp"
#include "player_helpers.h"
#include "map_helpers.h"

static const efftype_id effect_grabbed( "grabbed" );
static const efftype_id effect_grabbing( "grabbing" );

// Return the avatar's `get_hit_base` with a given DEX stat.
static float hit_base_with_dex( avatar &dummy, int dexterity )
Expand Down Expand Up @@ -66,7 +70,7 @@ TEST_CASE( "get_hit_base", "[hit][dex]" )
}
}

TEST_CASE( "get_dodge_base", "[dodge][dex]" )
TEST_CASE( "get_dodge_base", "[dodge][dex][skill]" )
{
avatar &dummy = g->u;

Expand Down Expand Up @@ -106,13 +110,17 @@ TEST_CASE( "get_dodge_base", "[dodge][dex]" )
}
}

TEST_CASE( "get_dodge", "[dodge]" )
TEST_CASE( "get_dodge", "[dodge][effect][grab]" )
{
avatar &dummy = g->u;
clear_character( dummy );

const float base_dodge = dummy.get_dodge_base();

// TODO:
// - Each dodge after the first subtracts 2 points of skill (?)
// - Speed below 100 linearly decreases dodge effectiveness

SECTION( "DEX = 8, dodge skill = 0" ) {
REQUIRE( dummy.dex_cur == 8 );
REQUIRE( dummy.get_skill_level( skill_id( "dodge" ) ) == 0 );
Expand All @@ -130,6 +138,10 @@ TEST_CASE( "get_dodge", "[dodge]" )

SECTION( "trapped" ) {
CHECK( base_dodge / 2 == dodge_with_effect( dummy, "beartrap" ) );
// FIXME: lightsnare and heavysnare effects cannot be added with add_effect
// src/creature.cpp:943 in add_effecty: "Invalid effect, ID: heavysnare"
//CHECK( base_dodge / 2 == dodge_with_effect( dummy, "lightsnare" ) );
//CHECK( base_dodge / 2 == dodge_with_effect( dummy, "heavysnare" ) );
}

SECTION( "bouldering" ) {
Expand Down Expand Up @@ -164,13 +176,64 @@ TEST_CASE( "get_dodge", "[dodge]" )
}

SECTION( "grabbed" ) {
}
clear_creatures();
tripoint mon1_pos = dummy.pos() + tripoint_north;
tripoint mon2_pos = dummy.pos() + tripoint_east;
tripoint mon3_pos = dummy.pos() + tripoint_south;
tripoint mon4_pos = dummy.pos() + tripoint_west;

monster *zed1 = g->place_critter_at( mtype_id( "debug_mon" ), mon1_pos );
monster *zed2 = g->place_critter_at( mtype_id( "debug_mon" ), mon2_pos );
monster *zed3 = g->place_critter_at( mtype_id( "debug_mon" ), mon3_pos );
monster *zed4 = g->place_critter_at( mtype_id( "debug_mon" ), mon4_pos );

REQUIRE( g->critter_at<monster>( mon1_pos ) );
REQUIRE( g->critter_at<monster>( mon2_pos ) );
REQUIRE( g->critter_at<monster>( mon3_pos ) );
REQUIRE( g->critter_at<monster>( mon4_pos ) );

dummy.add_effect( efftype_id( "grabbed" ), 1_minutes );
REQUIRE( dummy.has_effect( efftype_id( "grabbed" ) ) );

SECTION( "1 grab: 1/2 dodge" ) {
zed1->add_effect( efftype_id( "grabbing" ), 1_minutes );
REQUIRE( zed1->has_effect( efftype_id( "grabbing" ) ) );

CHECK( base_dodge / 2 == dummy.get_dodge() );
}

SECTION( "2 grabs: 1/3 dodge" ) {
zed1->add_effect( efftype_id( "grabbing" ), 1_minutes );
zed2->add_effect( efftype_id( "grabbing" ), 1_minutes );
REQUIRE( zed1->has_effect( efftype_id( "grabbing" ) ) );
REQUIRE( zed2->has_effect( efftype_id( "grabbing" ) ) );

// effect_grabbed
// - dodge ability scaled by number of grabbers
CHECK( base_dodge / 3 == dummy.get_dodge() );
}

SECTION( "3 grabs: 1/4 dodge" ) {
zed1->add_effect( efftype_id( "grabbing" ), 1_minutes );
zed2->add_effect( efftype_id( "grabbing" ), 1_minutes );
zed3->add_effect( efftype_id( "grabbing" ), 1_minutes );
REQUIRE( zed1->has_effect( efftype_id( "grabbing" ) ) );
REQUIRE( zed2->has_effect( efftype_id( "grabbing" ) ) );
REQUIRE( zed3->has_effect( efftype_id( "grabbing" ) ) );

// Each dodge after the first subtracts 2 points of skill (?)
CHECK( base_dodge / 4 == dummy.get_dodge() );
}

// Speed below 100 linearly decreases dodge effectiveness
SECTION( "4 grabs: 1/5 dodge" ) {
zed1->add_effect( efftype_id( "grabbing" ), 1_minutes );
zed2->add_effect( efftype_id( "grabbing" ), 1_minutes );
zed3->add_effect( efftype_id( "grabbing" ), 1_minutes );
zed4->add_effect( efftype_id( "grabbing" ), 1_minutes );
REQUIRE( zed1->has_effect( efftype_id( "grabbing" ) ) );
REQUIRE( zed2->has_effect( efftype_id( "grabbing" ) ) );
REQUIRE( zed3->has_effect( efftype_id( "grabbing" ) ) );
REQUIRE( zed4->has_effect( efftype_id( "grabbing" ) ) );

CHECK( base_dodge / 5 == dummy.get_dodge() );
}
}
}

0 comments on commit 6134549

Please sign in to comment.