diff --git a/data/mods/Magiclysm/items/enchanted.json b/data/mods/Magiclysm/items/enchanted.json index 692046477a6c1..30f09660939ba 100644 --- a/data/mods/Magiclysm/items/enchanted.json +++ b/data/mods/Magiclysm/items/enchanted.json @@ -58,5 +58,22 @@ "passive_effects": [ { "has": "WORN", "condition": "ALWAYS", "values": [ { "value": "REGEN_MANA", "multiply": 1 } ] } ] }, "flags": [ "VARSIZE" ] + }, + { + "id": "debug_fireball_hammer", + "type": "GENERIC", + "name": "fireball hammer", + "copy-from": "magi_staff_minor", + "description": "Use with caution! Flammable! Explosive!", + "relic_data": { + "passive_effects": [ + { + "has": "WIELD", + "condition": "ALWAYS", + "hit_you_effect": [ { "id": "fireball" } ], + "hit_me_effect": [ { "id": "light_healing" } ] + } + ] + } } ] diff --git a/src/character.cpp b/src/character.cpp index 6fe9f231d5d5d..ed84c034d6568 100644 --- a/src/character.cpp +++ b/src/character.cpp @@ -4540,3 +4540,13 @@ float Character::bionic_armor_bonus( body_part bp, damage_type dt ) const return result; } +void Character::did_hit( Creature &target ) +{ + enchantment_cache.cast_hit_you( *this, target.pos() ); +} + +void Character::on_hit( Creature * /*source*/, body_part /*bp_hit*/, + float /*difficulty*/, dealt_projectile_attack const *const /*proj*/ ) +{ + enchantment_cache.cast_hit_me( *this ); +} diff --git a/src/character.h b/src/character.h index 5a652bb8486e8..b8eac8cdd35fa 100644 --- a/src/character.h +++ b/src/character.h @@ -401,6 +401,11 @@ class Character : public Creature, public visitable */ void check_item_encumbrance_flag(); + // any side effects that might happen when the Character is hit + void on_hit( Creature *source, body_part /*bp_hit*/, + float /*difficulty*/, dealt_projectile_attack const *const /*proj*/ ) override; + // any side effects that might happen when the Character hits a Creature + void did_hit( Creature &target ); /** * Check for relevant passive, non-clothing that can absorb damage, and reduce by specified diff --git a/src/magic_enchantment.cpp b/src/magic_enchantment.cpp index e96c3283a25cf..3fab89e767ba3 100644 --- a/src/magic_enchantment.cpp +++ b/src/magic_enchantment.cpp @@ -381,3 +381,17 @@ void enchantment::activate_passive( Character &guy ) const guy.mod_speed_bonus( get_value_add( mod::SPEED ) ); guy.mod_speed_bonus( mult_bonus( mod::SPEED, guy.get_speed_base() ) ); } + +void enchantment::cast_hit_you( Character &caster, const tripoint &target ) const +{ + for( const fake_spell &sp : hit_you_effect ) { + sp.get_spell( sp.level ).cast_all_effects( caster, target ); + } +} + +void enchantment::cast_hit_me( Character &caster ) const +{ + for( const fake_spell &sp : hit_me_effect ) { + sp.get_spell( sp.level ).cast_all_effects( caster, caster.pos() ); + } +} diff --git a/src/magic_enchantment.h b/src/magic_enchantment.h index 7a9cec93c2aa2..d5f738a099020 100644 --- a/src/magic_enchantment.h +++ b/src/magic_enchantment.h @@ -132,6 +132,11 @@ class enchantment bool was_loaded; void serialize( JsonOut &jsout ) const; + + // casts all the hit_you_effects on the target + void cast_hit_you( Character &caster, const tripoint &target ) const; + // casts all the hit_me_effects on self + void cast_hit_me( Character &caster ) const; private: // values that add to the base value std::map values_add; diff --git a/src/melee.cpp b/src/melee.cpp index ce0ee2b7d128e..7d971e58a96ee 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -53,6 +53,7 @@ #include "material.h" #include "type_id.h" #include "point.h" +#include "projectile.h" #include "vehicle.h" #include "vpart_position.h" #include "mapdata.h" @@ -563,6 +564,11 @@ void player::melee_attack( Creature &t, bool allow_special, const matec_id &forc ma_onattack_effects(); // trigger martial arts on-attack effects // some things (shattering weapons) can harm the attacking creature. check_dead_state(); + did_hit( t ); + if( t.as_character() ) { + dealt_projectile_attack &dp = dealt_projectile_attack(); + t.as_character()->on_hit( this, body_part::num_bp, 0.0f, &dp ); + } return; } diff --git a/src/player.cpp b/src/player.cpp index a886d4f5eae67..0a2d858195ad2 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -2793,6 +2793,7 @@ void player::on_hit( Creature *source, body_part bp_hit, add_effect( effect_downed, 2_turns ); } } + Character::on_hit( source, bp_hit, 0.0f, proj ); } int player::get_lift_assist() const