Skip to content

Commit

Permalink
Added three new martial art buff events (CleverRaven#30633)
Browse files Browse the repository at this point in the history
* Added new martial art buff events

Adds onmiss, oncrit and onkill buff events.
  • Loading branch information
Hymore246 authored and ZhilkinSerg committed May 24, 2019
1 parent a036fae commit 8403903
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
35 changes: 35 additions & 0 deletions data/json/martialarts.json
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,41 @@
]
}
],
"oncrit_buffs": [
{
"id": "debug_crit_buff",
"name": "Lightning Strike",
"description": "Lightning strikes twice. +Perception electric damage for 3 turns. Stacks 2 times.",
"unarmed_allowed": true,
"min_unarmed": 0,
"buff_duration": 3,
"max_stacks": 2,
"flat_bonuses": [ [ "damage", "electric", "per", 1.0 ] ]
}
],
"onmiss_buffs": [
{
"id": "debug_miss_buff",
"name": "Getting Angry",
"description": "When I get my hands on you... +2 bash damage for 2 turns. Stacks 5 times.",
"unarmed_allowed": true,
"min_unarmed": 0,
"buff_duration": 2,
"max_stacks": 5,
"flat_bonuses": [ [ "damage", "bash", 2.0 ] ]
}
],
"onkill_buffs": [
{
"id": "debug_kill_buff",
"name": "On Fire",
"description": "YOU ARE ON FIRE! +5 fire damage for 5 turns.",
"unarmed_allowed": true,
"min_unarmed": 0,
"buff_duration": 5,
"flat_bonuses": [ [ "damage", "heat", 5.0 ] ]
}
],
"techniques": [ "tec_debug_slow", "tec_debug_arpen" ]
},
{
Expand Down
33 changes: 33 additions & 0 deletions src/martialarts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ void martialart::load( JsonObject &jo, const std::string & )
optional( jo, was_loaded, "ondodge_buffs", ondodge_buffs, ma_buff_reader{} );
optional( jo, was_loaded, "onblock_buffs", onblock_buffs, ma_buff_reader{} );
optional( jo, was_loaded, "ongethit_buffs", ongethit_buffs, ma_buff_reader{} );
optional( jo, was_loaded, "onmiss_buffs", onmiss_buffs, ma_buff_reader{} );
optional( jo, was_loaded, "oncrit_buffs", oncrit_buffs, ma_buff_reader{} );
optional( jo, was_loaded, "onkill_buffs", onkill_buffs, ma_buff_reader{} );

optional( jo, was_loaded, "techniques", techniques, auto_flags_reader<matec_id> {} );
optional( jo, was_loaded, "weapons", weapons, auto_flags_reader<itype_id> {} );
Expand Down Expand Up @@ -633,6 +636,21 @@ void martialart::apply_ongethit_buffs( player &u ) const
simultaneous_add( u, ongethit_buffs );
}

void martialart::apply_onmiss_buffs( player &u ) const
{
simultaneous_add( u, onmiss_buffs );
}

void martialart::apply_oncrit_buffs( player &u ) const
{
simultaneous_add( u, oncrit_buffs );
}

void martialart::apply_onkill_buffs( player &u ) const
{
simultaneous_add( u, onkill_buffs );
}

bool martialart::has_technique( const player &u, const matec_id &tec_id ) const
{
for( const auto &elem : techniques ) {
Expand Down Expand Up @@ -781,6 +799,18 @@ void player::ma_ongethit_effects()
{
style_selected.obj().apply_ongethit_buffs( *this );
}
void player::ma_onmiss_effects()
{
style_selected.obj().apply_onmiss_buffs( *this );
}
void player::ma_oncrit_effects()
{
style_selected.obj().apply_oncrit_buffs( *this );
}
void player::ma_onkill_effects()
{
style_selected.obj().apply_onkill_buffs( *this );
}

template<typename C, typename F>
static void accumulate_ma_buff_effects( const C &container, F f )
Expand Down Expand Up @@ -1074,7 +1104,10 @@ bool ma_style_callback::key( const input_context &ctxt, const input_event &event
buff_desc( _( "Passive" ), ma.static_buffs, true );
buff_desc( _( "Move" ), ma.onmove_buffs );
buff_desc( _( "Hit" ), ma.onhit_buffs );
buff_desc( _( "Miss" ), ma.onmiss_buffs );
buff_desc( _( "Attack" ), ma.onattack_buffs );
buff_desc( _( "Crit" ), ma.oncrit_buffs );
buff_desc( _( "Kill" ), ma.onkill_buffs );
buff_desc( _( "Dodge" ), ma.ondodge_buffs );
buff_desc( _( "Block" ), ma.onblock_buffs );
buff_desc( _( "Get hit" ), ma.ongethit_buffs );
Expand Down
9 changes: 9 additions & 0 deletions src/martialarts.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ class martialart

void apply_ongethit_buffs( player &u ) const;

void apply_onmiss_buffs( player &u ) const;

void apply_oncrit_buffs( player &u ) const;

void apply_onkill_buffs( player &u ) const;

// determines if a technique is valid or not for this style
bool has_technique( const player &u, const matec_id &tech ) const;
// determines if a weapon is valid for this style
Expand Down Expand Up @@ -235,6 +241,9 @@ class martialart
std::vector<mabuff_id> ondodge_buffs;
std::vector<mabuff_id> onblock_buffs;
std::vector<mabuff_id> ongethit_buffs;
std::vector<mabuff_id> onmiss_buffs;
std::vector<mabuff_id> oncrit_buffs;
std::vector<mabuff_id> onkill_buffs;
};

class ma_style_callback : public uilist_callback
Expand Down
11 changes: 11 additions & 0 deletions src/melee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ void player::melee_attack( Creature &t, bool allow_special, const matec_id &forc
if( has_miss_recovery_tec( cur_weapon ) ) {
move_cost /= 2;
}

ma_onmiss_effects(); // trigger martial arts on-miss effects
} else {
// Remember if we see the monster at start - it may change
const bool seen = g->u.sees( t );
Expand Down Expand Up @@ -503,9 +505,18 @@ void player::melee_attack( Creature &t, bool allow_special, const matec_id &forc
if( !specialmsg.empty() ) {
add_msg_if_player( m_neutral, specialmsg );
}

if( critical_hit ) {
ma_oncrit_effects(); // trigger martial arts on-crit effects
}

}

t.check_dead_state();

if( t.is_dead_state() ) {
ma_onkill_effects(); // trigger martial arts on-kill effects
}
}

const int melee = get_skill_level( skill_melee );
Expand Down
6 changes: 6 additions & 0 deletions src/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ class player : public Character
void ma_onblock_effects();
/** Fires all get hit-triggered martial arts events */
void ma_ongethit_effects();
/** Fires all miss-triggered martial arts events */
void ma_onmiss_effects();
/** Fires all crit-triggered martial arts events */
void ma_oncrit_effects();
/** Fires all kill-triggered martial arts events */
void ma_onkill_effects();

/** Returns true if the player has any martial arts buffs attached */
bool has_mabuff( const mabuff_id &buff_id ) const;
Expand Down

0 comments on commit 8403903

Please sign in to comment.