# pragma region License
/*
License ( OLC - 3 )
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
Copyright 2024 Joshua Sigona < sigonasr2 @ gmail . com >
Redistribution and use in source and binary forms , with or without modification ,
are permitted provided that the following conditions are met :
1. Redistributions or derivations of source code must retain the above copyright
notice , this list of conditions and the following disclaimer .
2. Redistributions or derivative works in binary form must reproduce the above
copyright notice . This list of conditions and the following disclaimer must be
reproduced in the documentation and / or other materials provided with the distribution .
3. Neither the name of the copyright holder nor the names of its contributors may
be used to endorse or promote products derived from this software without specific
prior written permission .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS " AND ANY
EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED . IN NO EVENT
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT , INDIRECT ,
INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED
TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR
BUSINESS INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN
CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE .
Portions of this software are copyright <EFBFBD> 2024 The FreeType
Project ( www . freetype . org ) . Please see LICENSE_FT . txt for more information .
All rights reserved .
*/
# pragma endregion
# include "MonsterStrategyHelpers.h"
# include "util.h"
# include "AdventuresInLestoria.h"
# include "SoundEffect.h"
# include "BulletTypes.h"
# include "Arc.h"
using A = Attribute ;
INCLUDE_game
INCLUDE_MONSTER_LIST
INCLUDE_MONSTER_DATA
void Monster : : STRATEGY : : OCTOPUS_ARM ( Monster & m , float fElapsedTime , std : : string strategy ) {
enum PhaseName {
INIT ,
RISE_ANIMATION ,
SEARCH ,
PREPARE_ATTACK ,
ATTACK_ANIMATION ,
SUBMERGE ,
} ;
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 ) ;
m . SetStrategyDeathFunction ( [ bossDamageOnDeath = ConfigInt ( " Boss Damage On Death " ) ] ( GameEvent & event , Monster & m , const StrategyName & strategyName ) {
const std : : string GIANT_OCTOPUS_NAME { " Giant Octopus " } ;
const std : : string OCTOPUS_ARM_NAME { " Octopus Arm " } ;
if ( ! MONSTER_DATA . count ( GIANT_OCTOPUS_NAME ) ) ERR ( std : : format ( " WARNING! {} does not exist on the map! THIS SHOULD NOT BE HAPPENING! " , GIANT_OCTOPUS_NAME ) ) ;
auto boss { std : : find_if ( MONSTER_LIST . begin ( ) , MONSTER_LIST . end ( ) , [ & GIANT_OCTOPUS_NAME ] ( const std : : shared_ptr < Monster > & m ) {
return m - > GetName ( ) = = GIANT_OCTOPUS_NAME ;
} ) } ;
if ( boss ! = MONSTER_LIST . end ( ) ) {
Monster & bossMonster { * * boss } ;
bossMonster . Hurt ( bossDamageOnDeath , m . OnUpperLevel ( ) , m . GetZ ( ) ) ;
}
std : : for_each ( MONSTER_LIST . begin ( ) , MONSTER_LIST . end ( ) , [ & OCTOPUS_ARM_NAME , & strategyName ] ( const std : : shared_ptr < Monster > & m ) {
if ( m - > GetName ( ) = = OCTOPUS_ARM_NAME ) {
m - > PerformAnimation ( " SUBMERGE " ) ;
m - > SetPhase ( strategyName , SUBMERGE ) ;
m - > GetFloat ( A : : RECOVERY_TIME ) = m - > GetCurrentAnimation ( ) . GetTotalAnimationDuration ( ) ;
}
} ) ;
return false ;
} ) ;
} break ;
case RISE_ANIMATION : {
m . F ( A : : CASTING_TIMER ) - = fElapsedTime ;
if ( m . F ( A : : CASTING_TIMER ) < = 0.f ) {
m . PerformAnimation ( " IDLE " , game - > GetPlayer ( ) - > GetPos ( ) ) ;
SETPHASE ( SEARCH ) ;
}
} break ;
case SEARCH : {
if ( util : : distance ( m . GetPos ( ) , game - > GetPlayer ( ) - > GetPos ( ) ) < = ConfigFloat ( " Attack Radius " ) / 100.f * 24 ) {
SETPHASE ( PREPARE_ATTACK ) ;
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 , & 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 ) {
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 ;
case SUBMERGE : {
m . F ( A : : RECOVERY_TIME ) - = fElapsedTime ;
if ( m . F ( A : : RECOVERY_TIME ) < = 0.f ) {
m . PerformAnimation ( " RISE " ) ;
m . F ( A : : CASTING_TIMER ) = m . GetCurrentAnimation ( ) . GetTotalAnimationDuration ( ) ;
SETPHASE ( RISE_ANIMATION ) ;
}
} break ;
}
}