Skip to content

Commit

Permalink
Add tests for enchantments
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman committed Aug 22, 2020
1 parent d30c9c1 commit 4ef713e
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
14 changes: 14 additions & 0 deletions data/mods/TEST_DATA/bionics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"id": "test_bio_night",
"type": "bionic",
"name": { "str": "Artificial Night Generator" },
"description": "When active, this bionic eliminates all light within a 2 tile radius through destructive interference.",
"occupied_bodyparts": [ [ "torso", 16 ] ],
"flags": [ "BIONIC_TOGGLED" ],
"enchantments": [ "TEST_ENCH" ],
"act_cost": "9 kJ",
"react_cost": "9 kJ",
"time": 1
}
]
18 changes: 18 additions & 0 deletions data/mods/TEST_DATA/enchantments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"type": "enchantment",
"id": "TEST_ENCH",
"condition": "ALWAYS",
"emitter": "emit_shadow_field",
"values": [ { "value": "STRENGTH", "multiply": 2, "add": 25 } ],
"hit_me_effect": [
{
"id": "generic_blinding_spray_1",
"hit_self": false,
"message": "Your ink glands spray some ink into %2$s's eyes.",
"npc_message": "%1$s's ink glands spay some ink into %2$s's eyes."
}
],
"ench_effects": [ { "effect": "invisibility", "intensity": 1 } ]
}
]
18 changes: 18 additions & 0 deletions data/mods/TEST_DATA/items.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@
"effects": [ "NEVER_MISFIRES", "NON-FOULING", "RECOVER_80" ],
"qualities": [ [ "HAMMER", 1 ] ]
},
{
"type": "TOOL_ARMOR",
"id": "test_ring_strength_1",
"weight": "4 g",
"volume": "1 ml",
"price": 5000,
"material": [ "copper" ],
"symbol": "[",
"color": "light_red",
"covers": [ "hand_l", "hand_r" ],
"sided": true,
"coverage": 0,
"warmth": 0,
"flags": [ "WATER_FRIENDLY", "ALLOWS_NATURAL_ATTACKS", "FANCY", "ONLY_ONE", "SKINTIGHT" ],
"name": { "str": "ring of strength +1", "str_pl": "rings of strength +1" },
"description": "A copper ring that makes you a little stronger when you wear it.",
"relic_data": { "passive_effects": [ { "has": "WORN", "condition": "ALWAYS", "values": [ { "value": "STRENGTH", "add": 1 } ] } ] }
},
{
"id": "test_rag",
"type": "TOOL",
Expand Down
13 changes: 13 additions & 0 deletions data/mods/TEST_DATA/mutations.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"type": "mutation",
"id": "TEST_INK_GLANDS",
"name": "Ink glands",
"points": 1,
"visibility": 1,
"ugliness": 1,
"description": "Several ink glands have grown onto your torso. They can be used to spray defensive ink and blind an attacker in an emergency, as long as the torso isn't covered.",
"enchantments": [ "TEST_ENCH" ],
"category": [ "CEPHALOPOD" ]
}
]
85 changes: 85 additions & 0 deletions tests/enchantments_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "catch/catch.hpp"

#include "avatar.h"
#include "bionics.h"
#include "character.h"
#include "field.h"
#include "map.h"
#include "map_helpers.h"
#include "monster.h"
#include "mutation.h"
#include "player_helpers.h"
#include "item.h"



static void test_generic_ench( avatar &p, int str_before )
{
// wait a turn for the effect to kick in
p.process_turn();

CHECK( p.get_str() == str_before + p.get_str_base() * 2 + 25 );

CHECK( p.has_effect( efftype_id( "invisibility" ) ) );

const field &fields_here = get_map().field_at( p.pos() );
CHECK( fields_here.find_field( field_type_id( "fd_shadow" ) ) != nullptr );

// place a zombie next to the avatar
const tripoint spot( 61, 60, 0 );
monster &zombie = spawn_test_monster( "mon_zombie", spot );

p.on_hit( &zombie, bodypart_id( "torso" ), 0.0, nullptr );

CHECK( zombie.has_effect( efftype_id( "blind" ) ) );
}

TEST_CASE( "worn enchantments", "[enchantments][worn][items]" )
{
avatar p;
clear_character( p );

int str_before = p.get_str();

// put on the ring
item ring_strplus_one( "test_ring_strength_1" );
p.wear( ring_strplus_one );

// wait a turn for the effect to kick in
p.recalculate_enchantment_cache();
p.process_turn();

CHECK( p.get_str() == str_before + 1 );

}

TEST_CASE( "bionic enchantments", "[enchantments][bionics]" )
{
avatar p;
clear_character( p );

int str_before = p.get_str();

p.set_max_power_level( 100_kJ );
p.set_power_level( 100_kJ );

give_and_activate_bionic( p, bionic_id( "test_bio_night" ) );

test_generic_ench( p, str_before );
}

TEST_CASE( "mutation enchantments", "[enchantments][mutations]" )
{
avatar p;
clear_character( p );

const trait_id test_ink( "TEST_INK_GLANDS" );
int str_before = p.get_str();

p.toggle_trait( test_ink );
REQUIRE( p.has_trait( test_ink ) );

p.recalculate_enchantment_cache();

test_generic_ench( p, str_before );
}

0 comments on commit 4ef713e

Please sign in to comment.