Skip to content

Commit

Permalink
Merge pull request #77656 from Procyonae/SpellEocsPassTarget
Browse files Browse the repository at this point in the history
Spell activated EoCs are passed the target as a context val
  • Loading branch information
Night-Pryanik authored Nov 8, 2024
2 parents a0591f1 + f9311a2 commit 8704e24
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,31 @@
"skill": "deduction",
"max_level": 20,
"difficulty": 6,
"effect": "ter_transform",
"effect_str": "ter_arvore_wood_wall",
"effect": "effect_on_condition",
"effect_str": "EOC_GROWING_WOOD_WALLS_WALL",
"shape": "blast",
"min_range": 1,
"max_range": 4,
"range_increment": 0.25
},
{
"type": "effect_on_condition",
"id": "EOC_GROWING_WOOD_WALLS_WALL",
"eoc_type": "ACTIVATION",
"effect": [
{
"npc_transform_radius": 0,
"ter_furn_transform": "ter_arvore_wood_wall",
"target_var": { "context_val": "spell_location" }
},
{ "location_variable_adjust": { "context_val": "spell_location" }, "z_adjust": 1 },
{
"npc_transform_radius": 0,
"ter_furn_transform": "ter_arvore_wood_wall_top",
"target_var": { "context_val": "spell_location" }
}
]
},
{
"id": "arvore_growing_wood_walls_floor",
"type": "SPELL",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
}
]
},
{
"type": "ter_furn_transform",
"id": "ter_arvore_wood_wall_top",
"terrain": [ { "result": [ "t_barkfloor_no_roof" ], "valid_terrain": [ "t_open_air" ] } ]
},
{
"type": "ter_furn_transform",
"id": "ter_arvore_wood_floor",
Expand Down
2 changes: 1 addition & 1 deletion doc/EFFECT_ON_CONDITION.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ For example, `{ "npc_has_effect": "Shadow_Reveal" }`, used by shadow lieutenant,
| Talk with monster | player (Avatar) | monster (monster) |
| Use computer | player (Avatar) | computer (Furniture) |
| furniture: "examine_action" | player (Avatar) | NONE |
| SPELL: "effect": "effect_on_condition" | target (Character, Monster) | spell caster (Character, Monster) |
| SPELL: "effect": "effect_on_condition" | target (Character, Monster) | spell caster (Character, Monster) | `spell_location`, location variable, location of target for use primarily when the target isn't a creature
| monster_attack: "eoc" | attacker ( Monster) | victim (Creature) | `damage`, int, damage dealt by attack
| use_action: "type": "effect_on_conditions" | user (Character) | item (item) | `id`, string, stores item id
| tick_action: "type": "effect_on_conditions" | carrier (Character) | item (item) |
Expand Down
2 changes: 1 addition & 1 deletion doc/MAGIC.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ Effect | Description
`charm_monster` | Charms a monster that has less hp than damage() for approximately duration().
`dash` | Dashes forward up to range and hits targets in a cone at the target.
`directed_push` | Pushes `valid_targets` in aoe away from the target location, with a distance of damage(). Negative values pull instead.
`effect_on_condition` | Runs the `effect_on_condition` from `effect_str` on all valid targets. The EOC will be centered on the player, with the NPC as caster.
`effect_on_condition` | Runs the `effect_on_condition` from `effect_str` on all valid targets. The EOC will be centered on the player, with the NPC as caster and a context val location variable `spell_location` for the target primarily useful if the target isn't a creature.
`emit` | Causes an `emit` at the target.
`explosion` | Causes an explosion centered on the target. Uses damage() for power and factor aoe()/10.
`flashbang` | Causes a flashbang effect is centered on the target. Uses damage() for power and factor aoe()/10.
Expand Down
10 changes: 7 additions & 3 deletions src/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,18 @@ str_translation_or_var get_str_translation_or_var(

tripoint_abs_ms get_tripoint_from_var( std::optional<var_info> var, dialogue const &d, bool is_npc )
{
tripoint_abs_ms target_pos = get_map().getglobal( d.actor( is_npc )->pos() );
if( var.has_value() ) {
std::string value = read_var_value( var.value(), d );
if( !value.empty() ) {
target_pos = tripoint_abs_ms( tripoint::from_string( value ) );
return tripoint_abs_ms( tripoint::from_string( value ) );
}
}
return target_pos;
if( !d.has_actor( is_npc ) ) {
debugmsg( "Tried to access location of invalid %s talker. %s", is_npc ? "beta" : "alpha",
d.get_callstack() );
return tripoint_abs_ms( tripoint_min );
}
return get_map().getglobal( d.actor( is_npc )->pos() );
}

template<class T>
Expand Down
3 changes: 3 additions & 0 deletions src/magic_spell_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,9 @@ void spell_effect::effect_on_condition( const spell &sp, Creature &caster,
}
Creature *victim = creatures.creature_at<Creature>( potential_target );
dialogue d( victim ? get_talker_for( victim ) : nullptr, get_talker_for( caster ) );
const tripoint_abs_ms target_abs = get_map().getglobal( potential_target );
write_var_value( var_type::context, "npctalk_var_spell_location", &d,
target_abs.to_string() );
d.amend_callstack( string_format( "Spell: %s Caster: %s", sp.id().c_str(), caster.disp_name() ) );
effect_on_condition_id eoc = effect_on_condition_id( sp.effect_data() );
if( eoc->type == eoc_type::ACTIVATION ) {
Expand Down

0 comments on commit 8704e24

Please sign in to comment.