Skip to content

Commit

Permalink
hit_you_effect and hit_me_effect (#34631)
Browse files Browse the repository at this point in the history
  • Loading branch information
KorGgenT authored and kevingranade committed Oct 11, 2019
1 parent b08601d commit 7fcaf47
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 0 deletions.
17 changes: 17 additions & 0 deletions data/mods/Magiclysm/items/enchanted.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" } ]
}
]
}
}
]
10 changes: 10 additions & 0 deletions src/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
5 changes: 5 additions & 0 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,11 @@ class Character : public Creature, public visitable<Character>
*/
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
Expand Down
14 changes: 14 additions & 0 deletions src/magic_enchantment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
}
5 changes: 5 additions & 0 deletions src/magic_enchantment.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<mod, int> values_add;
Expand Down
6 changes: 6 additions & 0 deletions src/melee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7fcaf47

Please sign in to comment.