From 3a0641e581d3ebbe7a6ac4f688efc08e36159165 Mon Sep 17 00:00:00 2001 From: Venera3 <72006894+Venera3@users.noreply.github.com> Date: Sun, 16 Jan 2022 06:55:53 +0100 Subject: [PATCH] Martial art tech effect custom messages, gate tech effects behind arbitrary character flags (#54414) --- data/json/mutations/mutation_techs.json | 11 +++++++++-- doc/MARTIALART_JSON.md | 4 +++- src/martialarts.cpp | 3 ++- src/martialarts.h | 6 ++++-- src/melee.cpp | 6 +++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/data/json/mutations/mutation_techs.json b/data/json/mutations/mutation_techs.json index b17b320ec9..dfa8b9c0c7 100644 --- a/data/json/mutations/mutation_techs.json +++ b/data/json/mutations/mutation_techs.json @@ -21,8 +21,15 @@ { "stat": "movecost", "scale": 40 } ], "tech_effects": [ - { "id": "bleed", "chance": 100, "duration": 2000, "permanent": true, "on_damage": false }, - { "id": "downed", "chance": 50, "duration": 2 } + { + "id": "bleed", + "chance": 100, + "duration": 2000, + "permanent": true, + "on_damage": false, + "message": "You bleed the %s dry!" + }, + { "id": "downed", "chance": 50, "duration": 2, "message": "You bonk the %s real good", "req_flag": "DREAMY" } ] } ] diff --git a/doc/MARTIALART_JSON.md b/doc/MARTIALART_JSON.md index 5555282ff3..34ae38a378 100644 --- a/doc/MARTIALART_JSON.md +++ b/doc/MARTIALART_JSON.md @@ -92,7 +92,9 @@ "chance": 100, // Percent chance to apply the effect on this attack "permanent": false, // If true the effect won't decay (default false) "duration": 15, // Duration of the effect in turns - "on_damage": true // If true the effect will only be applied if the attack succeeded in doing damage (default true) + "on_damage": true, // If true the effect will only be applied if the attack succeeded in doing damage (default true) + "req_flag": "ANY", // A single arbitrary character flag (from traits, bionics, effects, or bodyparts) required to apply this effect + "message": "Example" // The message to print if you succesfully apply the effect, %s can be substituted for the target's name } ] ``` diff --git a/src/martialarts.cpp b/src/martialarts.cpp index fa91abbe68..16ba6bb54e 100644 --- a/src/martialarts.cpp +++ b/src/martialarts.cpp @@ -170,7 +170,8 @@ tech_effect_data load_tech_effect_data( const JsonObject &e ) { return tech_effect_data( efftype_id( e.get_string( "id" ) ), e.get_int( "duration", 0 ), e.get_bool( "permanent", false ), e.get_bool( "on_damage", true ), - e.get_int( "chance", 100 ) ); + e.get_int( "chance", 100 ), e.get_string( "message", "" ), + json_character_flag( e.get_string( "req_flag", "NULL" ) ) ); } class tech_effect_reader : public generic_typed_reader diff --git a/src/martialarts.h b/src/martialarts.h index 4e82d62943..4b974bcd6b 100644 --- a/src/martialarts.h +++ b/src/martialarts.h @@ -108,11 +108,13 @@ struct tech_effect_data { bool permanent; bool on_damage; int chance; + std::string message; + json_character_flag req_flag; tech_effect_data( const efftype_id &nid, int dur, bool perm, bool ondmg, - int nchance ) : + int nchance, std::string message, json_character_flag req_flag ) : id( nid ), duration( dur ), permanent( perm ), on_damage( ondmg ), - chance( nchance ) {} + chance( nchance ), message( message ), req_flag( req_flag ) {} }; class ma_technique diff --git a/src/melee.cpp b/src/melee.cpp index fed1ea2be8..2f05dd579a 100644 --- a/src/melee.cpp +++ b/src/melee.cpp @@ -108,6 +108,7 @@ static const json_character_flag json_flag_CBQ_LEARN_BONUS( "CBQ_LEARN_BONUS" ); static const json_character_flag json_flag_HARDTOHIT( "HARDTOHIT" ); static const json_character_flag json_flag_HYPEROPIC( "HYPEROPIC" ); static const json_character_flag json_flag_NEED_ACTIVE_TO_MELEE( "NEED_ACTIVE_TO_MELEE" ); +static const json_character_flag json_flag_NULL( "NULL" ); static const json_character_flag json_flag_UNARMED_BONUS( "UNARMED_BONUS" ); static const limb_score_id limb_score_block( "block" ); @@ -1792,7 +1793,10 @@ void Character::perform_technique( const ma_technique &technique, Creature &t, d for( const tech_effect_data &eff : technique.tech_effects ) { // Add the tech's effects if it rolls the chance and either did damage or ignores it if( x_in_y( eff.chance, 100 ) && ( di.total_damage() != 0 || !eff.on_damage ) ) { - t.add_effect( eff.id, time_duration::from_turns( eff.duration ), eff.permanent ); + if( eff.req_flag == json_flag_NULL || has_flag( eff.req_flag ) ) { + t.add_effect( eff.id, time_duration::from_turns( eff.duration ), eff.permanent ); + add_msg_if_player( m_good, _( eff.message ), t.disp_name() ); + } } } } -- GitLab