File tree Expand file tree Collapse file tree 3 files changed +22
-16
lines changed Expand file tree Collapse file tree 3 files changed +22
-16
lines changed Original file line number Diff line number Diff line change @@ -1886,17 +1886,17 @@ static void cast_spell( bool recast_spell = false )
1886
1886
return ;
1887
1887
}
1888
1888
1889
- std::set<std::string> failure_messages = {};
1889
+ std::map<magic_type_id, bool > success_tracker = {};
1890
1890
for ( const spell_id &sp : spells ) {
1891
1891
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 );
1895
1893
}
1896
1894
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
+ }
1900
1900
}
1901
1901
1902
1902
if ( recast_spell && player_character.magic ->last_spell .is_null () ) {
Original file line number Diff line number Diff line change @@ -1265,16 +1265,22 @@ bool spell::can_cast( const Character &guy ) const
1265
1265
return guy.magic ->has_enough_energy ( guy, *this );
1266
1266
}
1267
1267
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 )
1269
1269
{
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
+ }
1276
1282
} else {
1277
- return false ;
1283
+ return can_cast ( guy ) ;
1278
1284
}
1279
1285
}
1280
1286
Original file line number Diff line number Diff line change @@ -579,7 +579,7 @@ class spell
579
579
bool has_components () const ;
580
580
// can the Character cast this spell?
581
581
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 );
583
583
// can the Character learn this spell?
584
584
bool can_learn ( const Character &guy ) const ;
585
585
// if spell shoots more than one projectile
You can’t perform that action at this time.
0 commit comments