Skip to content

Commit

Permalink
Apply effects from passive enchantments (#43101)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fris0uman authored Aug 26, 2020
1 parent 27c72e7 commit a7dda48
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 10 deletions.
16 changes: 16 additions & 0 deletions data/mods/TEST_DATA/bionics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[
{
"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",
"included": true,
"//": "not actually included, this is a trick to not have to add an item version.",
"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" ]
}
]
10 changes: 0 additions & 10 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9414,16 +9414,6 @@ void item::process_relic( Character *carrier, const tripoint &pos )
active_enchantments.emplace_back( ench );
}
}

for( const enchantment &ench : active_enchantments ) {
ench.activate_passive( *carrier );
}

// Recalculate, as it might have changed (by mod_*_bonus above)
carrier->str_cur = carrier->get_str();
carrier->int_cur = carrier->get_int();
carrier->dex_cur = carrier->get_dex();
carrier->per_cur = carrier->get_per();
}

bool item::process_corpse( player *carrier, const tripoint &pos )
Expand Down
2 changes: 2 additions & 0 deletions src/suffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,8 @@ void Character::suffer()
suffer_without_sleep( sleep_deprivation );
suffer_from_tourniquet();
suffer_from_pain();
//Suffer from enchantments
enchantment_cache->activate_passive( *this );
}

bool Character::irradiate( float rads, bool bypass )
Expand Down
86 changes: 86 additions & 0 deletions tests/enchantments_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#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 );
clear_map();
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 &equiped_ring_strplus_one = p.i_add( item( "test_ring_strength_1" ) );
p.wear( equiped_ring_strplus_one, false );

// 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 a7dda48

Please sign in to comment.