@ -53,29 +53,23 @@ void Monster::STRATEGY::OCTOPUS_ARM(Monster&m,float fElapsedTime,std::string str
RISE_ANIMATION ,
SEARCH ,
PREPARE_ATTACK ,
ATTACK_ANIMATION ,
} ;
const auto GetAttackArc = [ ] ( const Monster & m ) {
float arcAngle { } ;
switch ( m . GetFacingDirection ( ) ) {
case Direction : : NORTH : {
arcAngle = - PI / 2 ;
} break ;
case Direction : : EAST : {
arcAngle = 0.f ;
} break ;
case Direction : : WEST : {
arcAngle = PI ;
} break ;
case Direction : : SOUTH : {
arcAngle = PI / 2 ;
} break ;
}
return Arc { m . GetPos ( ) , " Attack Radius " _F / 100.f * 24 , arcAngle , util : : degToRad ( " Attack Arc " _F ) } ;
const auto GetAttackArc = [ attackRadius = ConfigFloat ( " Attack Radius " ) , attackArc = ConfigFloat ( " Attack Arc " ) ] ( const Monster & m ) {
return Arc { m . GetPos ( ) , attackRadius / 100.f * 24 , util : : dirToAngle ( m . GetFacingDirection ( ) ) , util : : degToRad ( attackArc ) } ;
} ;
if ( m . ANY ( A : : STORED_ARC ) . has_value ( ) ) {
const float growthRate = ( ( ConfigFloat ( " Attack Radius " ) / 100.f * 24 ) / ConfigFloat ( " Attack Effect Time " ) ) * fElapsedTime ;
std : : any_cast < Arc > ( m . ANY ( A : : STORED_ARC ) ) . GrowRadius ( growthRate ) ;
m . F ( A : : ENVIRONMENT_TIMER ) - = fElapsedTime ;
if ( m . F ( A : : ENVIRONMENT_TIMER ) < = 0.f ) m . ANY ( A : : STORED_ARC ) . reset ( ) ;
}
switch ( PHASE ( ) ) {
case INIT : {
if ( ConfigFloat ( " Attack Swing Damage Wait Time " ) > m . GetAnimation ( " ATTACKING " ) . GetTotalAnimationDuration ( ) ) ERR ( std : : format ( " The Attack Swing Damage Wait Time ({}s) should not be greater than the total attack time animation duration! ({}s) " , ConfigFloat ( " Attack Swing Damage Wait Time " ) , m . GetAnimation ( " ATTACKING " ) . GetTotalAnimationDuration ( ) ) ) ;
m . PerformAnimation ( " RISE " , game - > GetPlayer ( ) - > GetPos ( ) ) ;
m . F ( A : : CASTING_TIMER ) = m . GetCurrentAnimation ( ) . GetTotalAnimationDuration ( ) ;
SETPHASE ( RISE_ANIMATION ) ;
@ -88,30 +82,52 @@ void Monster::STRATEGY::OCTOPUS_ARM(Monster&m,float fElapsedTime,std::string str
}
} break ;
case SEARCH : {
if ( util : : distance ( m . GetPos ( ) , game - > GetPlayer ( ) - > GetPos ( ) ) < = " Attack Radius " _F / 100.f * 24 ) {
if ( util : : distance ( m . GetPos ( ) , game - > GetPlayer ( ) - > GetPos ( ) ) < = ConfigFloat ( " Attack Radius " ) / 100.f * 24 ) {
SETPHASE ( PREPARE_ATTACK ) ;
m . F ( A : : ATTACK_COOLDOWN ) = " Attack Wiggle Time Range " _FRange ;
m . PerformAnimation ( " ATTACKING " , game - > GetPlayer ( ) - > GetPos ( ) ) ;
m . F ( A : : ATTACK_COOLDOWN ) = util : : random_range ( ConfigFloatArr ( " Attack Wiggle Time Range " , 0 ) , ConfigFloatArr ( " Attack Wiggle Time Range " , 1 ) ) ;
m . PerformAnimation ( " ATTACK " , game - > GetPlayer ( ) - > GetPos ( ) ) ;
Arc attackArc { GetAttackArc ( m ) } ;
m . SetStrategyDrawFunction ( [ & attackArc ] ( AiL * game , Monster & monster , const std : : string & strategy ) {
m . SetStrategyDrawFunction ( [ & attackArc , & storedArc = m . ANY ( A : : STORED_ARC ) , & alphaTimer = m . F ( A : : ENVIRONMENT_TIMER ) , attackEffectTime = ConfigFloat ( " Attack Effect Time " ) ] ( AiL * game , Monster & monster , const std : : string & strategy ) {
const float alphaTimer { std : : fmod ( game - > GetRunTime ( ) , 2.f ) } ;
uint8_t alpha { util : : lerp ( 0 , 255 , alphaTimer ) } ;
if ( alphaTimer > 1.f ) alpha = util : : lerp ( 0 , 255 , 1 - ( alphaTimer - 1 ) ) ;
attackArc . Draw ( game , { 0 , 0 , 255 , uint8_t ( alpha ) } ) ;
if ( storedArc . has_value ( ) ) {
const uint8_t effectAlpha { util : : lerp ( 0 , 255 , alphaTimer / attackEffectTime ) } ;
std : : any_cast < Arc > ( storedArc ) . Draw ( game , { 255 , 255 , 255 , effectAlpha } ) ;
}
} ) ;
}
} break ;
case PREPARE_ATTACK : {
m . F ( A : : ATTACK_COOLDOWN ) - = fElapsedTime ;
if ( m . F ( A : : ATTACK_COOLDOWN ) < = 0.f ) {
Arc attackArc { GetAttackArc ( m ) } ;
if ( attackArc . overlaps ( game - > GetPlayer ( ) - > GetPos ( ) ) ) {
game - > GetPlayer ( ) - > Knockback ( util : : pointTo ( m . GetPos ( ) , game - > GetPlayer ( ) - > GetPos ( ) ) * " Attack Knockback " _F ) ;
game - > GetPlayer ( ) - > Hurt ( m . GetAttack ( ) , m . OnUpperLevel ( ) , m . GetZ ( ) ) ;
m . PerformAnimation ( " ATTACKING " ) ;
m . F ( A : : ENVIRONMENT_TIMER ) = ConfigFloat ( " Attack Effect Time " ) ;
m . F ( A : : SWING_OCCURRED ) = ConfigFloat ( " Attack Swing Damage Wait Time " ) ;
}
} break ;
case ATTACK_ANIMATION : {
m . F ( A : : RECOVERY_TIME ) - = fElapsedTime ;
if ( m . F ( A : : SWING_OCCURRED ) > 0.f ) {
m . F ( A : : SWING_OCCURRED ) - = fElapsedTime ;
if ( m . F ( A : : SWING_OCCURRED ) < = 0.f ) {
Arc attackArc { GetAttackArc ( m ) } ;
if ( attackArc . overlaps ( game - > GetPlayer ( ) - > GetPos ( ) ) ) {
game - > GetPlayer ( ) - > Knockback ( util : : pointTo ( m . GetPos ( ) , game - > GetPlayer ( ) - > GetPos ( ) ) * ConfigFloat ( " Attack Knockback " ) ) ;
game - > GetPlayer ( ) - > Hurt ( m . GetAttack ( ) , m . OnUpperLevel ( ) , m . GetZ ( ) ) ;
}
m . F ( A : : RECOVERY_TIME ) = m . GetCurrentAnimation ( ) . GetTotalAnimationDuration ( ) ;
m . ANY ( A : : STORED_ARC ) = GetAttackArc ( m ) ;
}
}
if ( m . F ( A : : RECOVERY_TIME ) < = 0.f ) {
m . PerformIdleAnimation ( ) ;
SETPHASE ( SEARCH ) ;
}
} break ;
}
}