Skip to content

Commit

Permalink
weakpoints also can use effect_on_conditions now
Browse files Browse the repository at this point in the history
  • Loading branch information
GuardianDll committed Aug 25, 2024
1 parent 35bd9cf commit acc0852
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/EFFECT_ON_CONDITION.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ For example, `{ "npc_has_effect": "Shadow_Reveal" }`, used by shadow lieutenant,
| mutation: "deactivated_eocs" | character (Character) | NONE |
| mutation: "processed_eocs" | character (Character) | NONE |
| recipe: "result_eocs" | crafter (Character) | NONE |
| monster weakpoint: "effect_on_conditions" | attacker (Creature) | victim (Creature) |
| monster death: "death_function" | killer (Creature, if exists, otherwise NONE)| victim (Creature) | Note that if monster was killed without a killer (falling anvil, explosion of a bomb etc), EoC would be built without alpha talker, so using EoC referencing `u_` would result in error. Use `has_alpha` condition before manipulating with alpha talker
| ammo_effect: "eoc" | shooter (Creature) | victim (if exist, otherwise NONE) (Creature) | `proj_damage`, int, amount of damage projectile dealt. Detonation via SPECIAL_COOKOFF ammo effect return `proj_damage` as 1. Note that if projectile miss the target, EoC would be built without beta talker, so using EoC referencing `npc_` or `n_` would result in error. Use `has_beta` condition before manipulating with npc

Expand Down
1 change: 1 addition & 0 deletions doc/MONSTERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ The `effects` field is a list of objects with the following subfields:
Field | Description
--- | ---
`effect` | The effect type.
`effect_on_conditions` | Array of EoCs that would be run. `u_` is attacker, `npc_` is victim. See EFFECT_ON_CONDITION.md for more information
`chance` | The probability of causing the effect.
`duration` | The duration of the effect. Either a (min, max) pair or a single value.
`permanent` | Whether the effect is permanent.
Expand Down
22 changes: 17 additions & 5 deletions src/weakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "creature.h"
#include "damage.h"
#include "debug.h"
#include "effect_on_condition.h"
#include "effect_source.h"
#include "enums.h"
#include "generic_factory.h"
Expand Down Expand Up @@ -277,9 +278,16 @@ void weakpoint_effect::apply_to( Creature &target, int total_damage,
if( !( rng_float( 0.0f, 100.f ) < chance ) ) {
return;
}
target.add_effect( effect_source( attack.source ), effect,
time_duration::from_turns( rng( duration.first, duration.second ) ),
permanent, rng( intensity.first, intensity.second ) );
if( effect && !effect.is_empty() ) {
target.add_effect( effect_source( attack.source ), effect,
time_duration::from_turns( rng( duration.first, duration.second ) ),
permanent, rng( intensity.first, intensity.second ) );
}

for( const effect_on_condition_id &eoc : effect_on_conditions ) {
dialogue d( get_talker_for( *attack.source ), get_talker_for( target ) );
eoc->activate( d );
}

if( !get_message().empty() && attack.source != nullptr && attack.source->is_avatar() ) {
add_msg_if_player_sees( target, m_good, get_message(), target.get_name() );
Expand All @@ -288,8 +296,12 @@ void weakpoint_effect::apply_to( Creature &target, int total_damage,

void weakpoint_effect::load( const JsonObject &jo )
{
assign( jo, "effect", effect );

if( jo.has_string( "effect" ) ) {
assign( jo, "effect", effect );
}
if( jo.has_array( "effect_on_conditions" ) ) {
assign( jo, "effect_on_conditions", effect_on_conditions );
}
if( jo.has_float( "chance" ) ) {
assign( jo, "chance", chance, false, 0.0f, 100.0f );
}
Expand Down
2 changes: 2 additions & 0 deletions src/weakpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ struct weakpoint_attack {
struct weakpoint_effect {
// The type of the effect.
efftype_id effect;
// Effect on condition, that would be run.
std::vector<effect_on_condition_id> effect_on_conditions;
// The percent chance of causing the effect.
float chance;
// Whether the effect is permanent.
Expand Down

0 comments on commit acc0852

Please sign in to comment.