From a216f30459bb3d99e8a929433963c2a23d6e5c57 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:24:33 +0000 Subject: [PATCH 1/6] Spells that activate EoCs pass their target as a context val location variable "spell_location" --- src/magic_spell_effect.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/magic_spell_effect.cpp b/src/magic_spell_effect.cpp index 907d61002df36..0e013b6fc64e6 100644 --- a/src/magic_spell_effect.cpp +++ b/src/magic_spell_effect.cpp @@ -1894,6 +1894,9 @@ void spell_effect::effect_on_condition( const spell &sp, Creature &caster, } Creature *victim = creatures.creature_at( 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 ) { From 2ea0280fe986d84bbdc11aa9cc2e42d0b136bcee Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:31:40 +0000 Subject: [PATCH 2/6] Fix get_tripoint_from_var() always expecting a valid talker regardless of a var being provided --- src/condition.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/condition.cpp b/src/condition.cpp index 783438bf30148..9fdee0fd9fb43 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -383,14 +383,18 @@ str_translation_or_var get_str_translation_or_var( tripoint_abs_ms get_tripoint_from_var( std::optional 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 From b95cff2a96178366be381b34d15aa9af14ad5035 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:31:48 +0000 Subject: [PATCH 3/6] Documentation --- doc/MAGIC.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/MAGIC.md b/doc/MAGIC.md index df55a396966e1..938ec0c3dadc0 100644 --- a/doc/MAGIC.md +++ b/doc/MAGIC.md @@ -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. From 4381abc4e83ae25a8272fc0b53e710fd9a45c7b0 Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:32:04 +0000 Subject: [PATCH 4/6] Example usage --- .../paraclesians/arvore_mutation_spells.json | 22 +++++++++++++++++-- .../ter_transforms/arvore_ter_transforms.json | 5 +++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/data/mods/Xedra_Evolved/mutations/paraclesians/arvore_mutation_spells.json b/data/mods/Xedra_Evolved/mutations/paraclesians/arvore_mutation_spells.json index 4f7a281c51814..310517f48e5aa 100644 --- a/data/mods/Xedra_Evolved/mutations/paraclesians/arvore_mutation_spells.json +++ b/data/mods/Xedra_Evolved/mutations/paraclesians/arvore_mutation_spells.json @@ -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", diff --git a/data/mods/Xedra_Evolved/ter_transforms/arvore_ter_transforms.json b/data/mods/Xedra_Evolved/ter_transforms/arvore_ter_transforms.json index 1dad13e9ac4d4..ca5bb48f5fd5d 100644 --- a/data/mods/Xedra_Evolved/ter_transforms/arvore_ter_transforms.json +++ b/data/mods/Xedra_Evolved/ter_transforms/arvore_ter_transforms.json @@ -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", From 0ce6e7efbaed289825200e2d1dd0edc2d6efa4bc Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:33:41 +0000 Subject: [PATCH 5/6] Extra space --- src/condition.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/condition.cpp b/src/condition.cpp index 9fdee0fd9fb43..4cf138fa2e6b6 100644 --- a/src/condition.cpp +++ b/src/condition.cpp @@ -390,7 +390,7 @@ tripoint_abs_ms get_tripoint_from_var( std::optional var, dialogue con } } if( !d.has_actor( is_npc ) ) { - debugmsg( "Tried to access location of invalid %s talker. %s", is_npc ? "beta" : "alpha", + debugmsg( "Tried to access location of invalid %s talker. %s", is_npc ? "beta" : "alpha", d.get_callstack() ); return tripoint_abs_ms( tripoint_min ); } From f9311a2a3c1c1b9ad479e02eb4b847cba1a7b70a Mon Sep 17 00:00:00 2001 From: Procyonae <45432782+Procyonae@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:33:51 +0000 Subject: [PATCH 6/6] Extra doc --- doc/EFFECT_ON_CONDITION.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/EFFECT_ON_CONDITION.md b/doc/EFFECT_ON_CONDITION.md index 06553e8c0a0b8..ab5b1195b7f71 100644 --- a/doc/EFFECT_ON_CONDITION.md +++ b/doc/EFFECT_ON_CONDITION.md @@ -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) |