Skip to content

Commit 1f38c9b

Browse files
authored
Magic Infrastructure: Make magic_type spell fail chance still affected by spell specific flags (#79506)
* Make spell fail chance still affected by spell specific flags * astyle * skip auto fail / suceed if magic type defined
1 parent 99ffd7c commit 1f38c9b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/magic.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,11 +1343,6 @@ float spell::spell_fail( const Character &guy ) const
13431343
if( has_flag( spell_flag::NO_FAIL ) ) {
13441344
return 0.0f;
13451345
}
1346-
if( type->magic_type.has_value() &&
1347-
type->magic_type.value()->failure_chance_formula_id.has_value() ) {
1348-
const_dialogue d( get_const_talker_for( guy ), nullptr );
1349-
return type->magic_type.value()->failure_chance_formula_id.value()->eval( d );
1350-
}
13511346

13521347
const bool is_psi = has_flag( spell_flag::PSIONIC );
13531348

@@ -1390,15 +1385,26 @@ float spell::spell_fail( const Character &guy ) const
13901385
static_cast<float>( 45 ) );
13911386
}
13921387
}
1388+
bool has_type_fail_chance = type->magic_type.has_value() &&
1389+
type->magic_type.value()->failure_chance_formula_id.has_value();
13931390
// add an if statement in here because sufficiently large numbers will definitely overflow because of exponents
1394-
if( ( effective_skill > 30.0f && !is_psi ) || ( psi_effective_skill > 40.0f && is_psi ) ) {
1395-
return 0.0f;
1396-
} else if( ( effective_skill < 0.0f && !is_psi ) || ( psi_effective_skill < 0.0f && is_psi ) ) {
1397-
return 1.0f;
1391+
if( !has_type_fail_chance ) {
1392+
if( ( effective_skill > 30.0f && !is_psi ) || ( psi_effective_skill > 40.0f && is_psi ) ) {
1393+
return 0.0f;
1394+
} else if( ( effective_skill < 0.0f && !is_psi ) || ( psi_effective_skill < 0.0f && is_psi ) ) {
1395+
return 1.0f;
1396+
}
13981397
}
13991398

1400-
float fail_chance = std::pow( ( effective_skill - 30.0f ) / 30.0f, 2 );
1401-
float psi_fail_chance = std::pow( ( psi_effective_skill - 40.0f ) / 40.0f, 2 );
1399+
float fail_chance = 0;
1400+
if( has_type_fail_chance ) {
1401+
const_dialogue d( get_const_talker_for( guy ), nullptr );
1402+
fail_chance = type->magic_type.value()->failure_chance_formula_id.value()->eval( d );
1403+
} else if( is_psi ) {
1404+
fail_chance = std::pow( ( psi_effective_skill - 40.0f ) / 40.0f, 2 );
1405+
} else {
1406+
fail_chance = std::pow( ( effective_skill - 30.0f ) / 30.0f, 2 );
1407+
}
14021408

14031409
if( !is_psi ) {
14041410
if( has_flag( spell_flag::SOMATIC ) &&
@@ -1429,10 +1435,9 @@ float spell::spell_fail( const Character &guy ) const
14291435
return 1.0f;
14301436
}
14311437
fail_chance /= 1.0f - concentration_loss;
1432-
psi_fail_chance /= 1.0f - concentration_loss;
14331438
}
14341439

1435-
return clamp( is_psi ? psi_fail_chance : fail_chance, 0.0f, 1.0f );
1440+
return clamp( fail_chance, 0.0f, 1.0f );
14361441
}
14371442

14381443
std::string spell::colorized_fail_percent( const Character &guy ) const

0 commit comments

Comments
 (0)