Skip to content

Commit 6ac4e32

Browse files
authored
[magic_type]: Fix cannot_cast_message logic (#82497)
* Fix message logic * aaaaaastyle
1 parent b96da1f commit 6ac4e32

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/handle_action.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,17 +1886,17 @@ static void cast_spell( bool recast_spell = false )
18861886
return;
18871887
}
18881888

1889-
std::set<std::string> failure_messages = {};
1889+
std::map<magic_type_id, bool> success_tracker = {};
18901890
for( const spell_id &sp : spells ) {
18911891
spell &temp_spell = player_character.magic->get_spell( sp );
1892-
if( temp_spell.can_cast( player_character, failure_messages ) ) {
1893-
break;
1894-
}
1892+
temp_spell.can_cast( player_character, success_tracker );
18951893
}
18961894

1897-
for( const std::string &failure_message : failure_messages ) {
1898-
add_msg( game_message_params{ m_bad, gmf_bypass_cooldown },
1899-
failure_message );
1895+
for( auto const& [m_type, any_success] : success_tracker ) {
1896+
if( !any_success && m_type->cannot_cast_message.has_value() ) {
1897+
add_msg( game_message_params{ m_bad, gmf_bypass_cooldown },
1898+
m_type->cannot_cast_message.value() );
1899+
}
19001900
}
19011901

19021902
if( recast_spell && player_character.magic->last_spell.is_null() ) {

src/magic.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,16 +1265,22 @@ bool spell::can_cast( const Character &guy ) const
12651265
return guy.magic->has_enough_energy( guy, *this );
12661266
}
12671267

1268-
bool spell::can_cast( const Character &guy, std::set<std::string> &failure_messages )
1268+
bool spell::can_cast( const Character &guy, std::map<magic_type_id, bool> &success_tracker )
12691269
{
1270-
if( can_cast( guy ) ) {
1271-
return true;
1272-
} else if( type->magic_type.has_value() &&
1273-
type->magic_type.value()->cannot_cast_message.has_value() ) {
1274-
failure_messages.insert( type->magic_type.value()->cannot_cast_message.value() );
1275-
return false;
1270+
if( type->magic_type.has_value() &&
1271+
type->magic_type.value()->cannot_cast_message.has_value() ) {
1272+
// Insert first occurence of magic_type_id as false since only successful casts will be tracked.
1273+
if( success_tracker.count( type->magic_type.value() ) == 0 ) {
1274+
success_tracker[type->magic_type.value()] = false;
1275+
}
1276+
if( can_cast( guy ) ) {
1277+
success_tracker[type->magic_type.value()] = true;
1278+
return true;
1279+
} else {
1280+
return false;
1281+
}
12761282
} else {
1277-
return false;
1283+
return can_cast( guy );
12781284
}
12791285
}
12801286

src/magic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ class spell
579579
bool has_components() const;
580580
// can the Character cast this spell?
581581
bool can_cast( const Character &guy ) const;
582-
bool can_cast( const Character &guy, std::set<std::string> &failure_messages );
582+
bool can_cast( const Character &guy, std::map<magic_type_id, bool> &success_tracker );
583583
// can the Character learn this spell?
584584
bool can_learn( const Character &guy ) const;
585585
// if spell shoots more than one projectile

0 commit comments

Comments
 (0)