Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

casting a spell casts the wrong spell #76137

Merged
merged 6 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/handle_action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1781,13 +1781,11 @@ static void cast_spell()
}
}

const int spell_index = player_character.magic->select_spell( player_character );
if( spell_index < 0 ) {
spell &sp = player_character.magic->select_spell( player_character );
// if no spell was selected
if( sp.id().is_null() ) {
return;
}

spell &sp = *player_character.magic->get_spells()[spell_index];

player_character.cast_spell( sp, false, std::nullopt );
}

Expand Down
11 changes: 7 additions & 4 deletions src/magic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2812,7 +2812,7 @@ int known_magic::get_invlet( const spell_id &sp, std::set<int> &used_invlets )
return 0;
}

int known_magic::select_spell( Character &guy )
spell &known_magic::select_spell( Character &guy )
{
std::vector<spell *> known_spells_sorted = get_spells();

Expand Down Expand Up @@ -2905,8 +2905,12 @@ int known_magic::select_spell( Character &guy )
spell_menu.query( true, 50, true );

casting_ignore = static_cast<spellcasting_callback *>( spell_menu.callback )->casting_ignore;

return spell_menu.ret;
if( spell_menu.ret < 0 ) {
static spell null_spell_reference( spell_id::NULL_ID() );
return null_spell_reference;
}
spell *selected_spell = known_spells_sorted[spell_menu.ret];
return *selected_spell;
}

void known_magic::on_mutation_gain( const trait_id &mid, Character &guy )
Expand Down Expand Up @@ -2963,7 +2967,6 @@ static std::string color_number( const float num )
return colorize( "0", c_white );
}
}

static void draw_spellbook_info( const spell_type &sp )
{
const spell fake_spell( sp.id );
Expand Down
4 changes: 2 additions & 2 deletions src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,8 +689,8 @@ class known_magic
// gets the spell associated with the spell_id to be edited
spell &get_spell( const spell_id &sp );
// opens up a ui that the Character can choose a spell from
// returns the index of the spell in the vector of spells
int select_spell( Character &guy );
// returns the selected spell
spell &select_spell( Character &guy );
// get all known spells
std::vector<spell *> get_spells();
// directly get the character known spells
Expand Down
Loading