Skip to content

Commit

Permalink
[EoC] Update u_cast_spell and fix player_levels_spell event (CleverRa…
Browse files Browse the repository at this point in the history
…ven#68946)

* u_cast_spell update

* fix player_levels_spell
  • Loading branch information
lispcoc authored Oct 28, 2023
1 parent 1b23faf commit a4fc506
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion doc/EFFECT_ON_CONDITION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2754,7 +2754,8 @@ You or NPC cast a spell. The spell uses fake spell data (ignore `energy_cost`, `
| "message" | optional | string or [variable object](##variable-object) | part of `_cast_spell`; message to send when spell is casted |
| "npc_message" | optional | string or [variable object](##variable-object) | part of `_cast_spell`; message if npc uses |
| "min_level", "max_level" | optional | int, float or [variable object](##variable-object) | part of `_cast_spell`; level of the spell that would be casted (min level define what the actual spell level would be casted, adding max_level make EoC pick a random level between min and max) |
| "targeted" | optional | boolean | default false; if true, allow you to aim casted spell, otherwise cast it in random place, like `RANDOM_TARGET` spell flag was used |
| "targeted" | optional | boolean | default false; if true, allow you to aim casted spell, otherwise cast it in the location set by "loc" |
| "loc" | optional | [variable object](##variable-object) | Set target location of the spell. If not used, target to caster's location |
| "true_eocs" | optional | string, [variable object](##variable-object), `effect_on_condition` or range of all of them | if spell was casted successfully, all EoCs from this field would be triggered; |
| "false_eocs" | optional | string, [variable object](##variable-object), `effect_on_condition` or range of all of them | if spell was not casted successfully, all EoCs from this field would be triggered |

Expand Down
4 changes: 4 additions & 0 deletions src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,11 @@ void known_magic::set_spell_exp( const spell_id &sp, int new_exp, const Characte
} else {
if( new_exp >= 0 ) {
spell &temp_sp = get_spell( sp );
int old_level = temp_sp.get_level();
temp_sp.set_exp( new_exp );
if( guy->is_avatar() && old_level != temp_sp.get_level() ) {
get_event_bus().send<event_type::player_levels_spell>( guy->getID(), sp->id, temp_sp.get_level() );
}
} else {
get_event_bus().send<event_type::character_forgets_spell>( guy->getID(), sp->id );
spellbook.erase( sp );
Expand Down
10 changes: 8 additions & 2 deletions src/npctalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4131,7 +4131,11 @@ void talk_effect_fun_t::set_cast_spell( const JsonObject &jo, std::string_view m
if( jo.has_bool( "targeted" ) ) {
targeted = jo.get_bool( "targeted" );
}
function = [is_npc, fake, targeted, true_eocs, false_eocs]( dialogue const & d ) {
std::optional<var_info> loc_var;
if( jo.has_object( "loc" ) ) {
loc_var = read_var_info( jo.get_object( "loc" ) );
}
function = [is_npc, fake, targeted, loc_var, true_eocs, false_eocs]( dialogue const & d ) {
Creature *caster = d.actor( is_npc )->get_creature();
if( !caster ) {
debugmsg( "No valid caster for spell. %s", d.get_callstack() );
Expand All @@ -4150,7 +4154,9 @@ void talk_effect_fun_t::set_cast_spell( const JsonObject &jo, std::string_view m
caster->add_msg_if_player( fake.trigger_message );
}
} else {
sp.cast_all_effects( *caster, caster->pos() );
const tripoint target_pos = loc_var ?
get_map().getlocal( get_tripoint_from_var( loc_var, d ) ) : caster->pos();
sp.cast_all_effects( *caster, target_pos );
caster->add_msg_if_player( fake.trigger_message );
}
}
Expand Down

0 comments on commit a4fc506

Please sign in to comment.