diff --git a/data/mods/TEST_DATA/bionics.json b/data/mods/TEST_DATA/bionics.json new file mode 100644 index 0000000000000..de8bad4968036 --- /dev/null +++ b/data/mods/TEST_DATA/bionics.json @@ -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 + } +] diff --git a/data/mods/TEST_DATA/enchantments.json b/data/mods/TEST_DATA/enchantments.json new file mode 100644 index 0000000000000..150617c6df896 --- /dev/null +++ b/data/mods/TEST_DATA/enchantments.json @@ -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 } ] + } +] diff --git a/data/mods/TEST_DATA/items.json b/data/mods/TEST_DATA/items.json index 85fb1df9127c2..014664292ae38 100644 --- a/data/mods/TEST_DATA/items.json +++ b/data/mods/TEST_DATA/items.json @@ -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", diff --git a/data/mods/TEST_DATA/mutations.json b/data/mods/TEST_DATA/mutations.json new file mode 100644 index 0000000000000..61ed54258f8b3 --- /dev/null +++ b/data/mods/TEST_DATA/mutations.json @@ -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" ] + } +] diff --git a/tests/enchantments_test.cpp b/tests/enchantments_test.cpp new file mode 100644 index 0000000000000..7fcfe48074de0 --- /dev/null +++ b/tests/enchantments_test.cpp @@ -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 ); +}