# 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 ,
ATTACK_RECOVERY ,
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 ( ) ) {
game - > DrawShadowStringDecal ( { 100 , 100 } , std : : format ( " Stored Arc Active: {} " , std : : any_cast < Arc > ( m . ANY ( A : : STORED_ARC ) ) . pos . str ( ) ) ) ;
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 ( ) ;
}
fElapsedTime * = m . F ( A : : ATTACK_ANIMATION_SPEED ) ;
switch ( PHASE ( ) ) {
case INIT : {
m . I ( A : : SUBMERGE_STRAT_ID ) = SUBMERGE ;
m . F ( A : : ATTACK_ANIMATION_SPEED ) = 1.f ;
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 ( [ deathFadeTime = ConfigFloat ( " Death Fade Time " ) , bossDamageOnDeath = ConfigInt ( " Boss Damage On Death " ) , armHealAmtOnDeath = ConfigInt ( " Arm Heal Amount On Death " ) , reemergeWaitTime = ConfigFloat ( " Re-Emerge Wait Time " ) , delayTimeIncreasePerArm = ConfigFloat ( " Delay Time Increase Per Arm " ) , armAttackBuffOnDeath = ConfigFloat ( " Arm Attack Buff On Death " ) , bossAttackBuffOnDeath = ConfigFloat ( " Boss Attack Buff On Death " ) ] ( GameEvent & event , Monster & m , const StrategyName & strategyName ) {
m . SetStrategyDrawFunction ( [ ] ( AiL * game , Monster & monster , const std : : string & strategy ) { } ) ;
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 . _DealTrueDamage ( bossDamageOnDeath ) ;
}
float delayTimePerArm { 0.f } ;
std : : for_each ( MONSTER_LIST . begin ( ) , MONSTER_LIST . end ( ) , [ & OCTOPUS_ARM_NAME , & GIANT_OCTOPUS_NAME , & strategyName , & armHealAmtOnDeath , & reemergeWaitTime , & delayTimeIncreasePerArm , & delayTimePerArm , & armAttackBuffOnDeath , & bossAttackBuffOnDeath ] ( const std : : shared_ptr < Monster > & m ) {
if ( m - > GetName ( ) = = OCTOPUS_ARM_NAME ) {
m - > PerformAnimation ( " SUBMERGE " ) ;
m - > SetPhase ( strategyName , SUBMERGE ) ;
m - > V ( A : : JUMP_TARGET_POS ) = m - > GetPos ( ) ;
m - > SetCollisionRadius ( 0.f ) ;
if ( ! m - > IsDead ( ) ) m - > Heal ( armHealAmtOnDeath , true ) ;
m - > GetFloat ( A : : RECOVERY_TIME ) = reemergeWaitTime + delayTimePerArm ;
m - > SetStrategyDrawFunction ( [ ] ( AiL * game , Monster & monster , const std : : string & strategy ) { } ) ;
if ( m - > HasBuff ( BuffType : : STAT_UP ) ) {
bool found { false } ;
for ( Buff & b : m - > EditBuffs ( BuffType : : STAT_UP ) ) {
for ( const ItemAttribute & attr : b . attr ) {
if ( attr . ActualName ( ) = = " Attack % " ) {
found = true ;
b . intensity + = armAttackBuffOnDeath / 100.f ;
}
}
}
if ( ! found ) m - > AddBuff ( BuffType : : STAT_UP , INFINITE , armAttackBuffOnDeath / 100.f , { " Attack % " } ) ;
} else m - > AddBuff ( BuffType : : STAT_UP , INFINITE , armAttackBuffOnDeath / 100.f , { " Attack % " } ) ;
delayTimePerArm + = delayTimeIncreasePerArm ;
} else if ( m - > GetName ( ) = = GIANT_OCTOPUS_NAME ) {
if ( m - > HasBuff ( BuffType : : STAT_UP ) ) {
bool found { false } ;
for ( Buff & b : m - > EditBuffs ( BuffType : : STAT_UP ) ) {
for ( const ItemAttribute & attr : b . attr ) {
if ( attr . ActualName ( ) = = " Attack % " ) {
found = true ;
b . intensity + = bossAttackBuffOnDeath / 100.f ;
}
}
}
if ( ! found ) m - > AddBuff ( BuffType : : STAT_UP , INFINITE , bossAttackBuffOnDeath / 100.f , { " Attack % " } ) ;
} else m - > AddBuff ( BuffType : : STAT_UP , INFINITE , bossAttackBuffOnDeath / 100.f , { " Attack % " } ) ;
}
} ) ;
m . SetLifetime ( deathFadeTime ) ;
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 ( ) ) ;
m . SetCollisionRadius ( m . GetOriginalCollisionRadius ( ) ) ;
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 ( [ arc = 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 { float ( std : : fmod ( game - > GetRunTime ( ) , 2.f ) ) } ;
uint8_t alpha { util : : lerp ( uint8_t ( 0 ) , uint8_t ( 128 ) , alphaTimer ) } ;
if ( alphaTimer > 1.f ) alpha = util : : lerp ( 0 , 128 , 1 - ( alphaTimer - 1 ) ) ;
const_cast < Arc & > ( arc ) . Draw ( game , { 0 , 0 , 128 , uint8_t ( alpha ) } ) ;
if ( storedArc . has_value ( ) ) {
const uint8_t effectAlpha { util : : lerp ( uint8_t ( 0 ) , uint8_t ( 128 ) , 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 ) {
SETPHASE ( ATTACK_ANIMATION ) ;
m . PerformAnimation ( " ATTACKING " ) ;
m . F ( A : : ENVIRONMENT_TIMER ) = m . F ( A : : RECOVERY_TIME ) = ConfigFloat ( " Attack Effect Time " ) ;
m . F ( A : : SWING_OCCURRED ) = ConfigFloat ( " Attack Swing Damage Wait Time " ) ;
}
} break ;
case ATTACK_ANIMATION : {
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 ) ;
m . SetStrategyDrawFunction ( [ & storedArc = m . ANY ( A : : STORED_ARC ) , attackEffectTime = ConfigFloat ( " Attack Effect Time " ) ] ( AiL * game , Monster & monster , const std : : string & strategy ) {
const float alphaTimer { float ( std : : fmod ( game - > GetRunTime ( ) , 2.f ) ) } ;
if ( storedArc . has_value ( ) ) {
const uint8_t effectAlpha { util : : lerp ( uint8_t ( 0 ) , uint8_t ( 255 ) , alphaTimer / attackEffectTime ) } ;
std : : any_cast < Arc > ( storedArc ) . Draw ( game , { 255 , 255 , 255 , effectAlpha } ) ;
}
} ) ;
SETPHASE ( ATTACK_RECOVERY ) ;
}
} break ;
case ATTACK_RECOVERY : {
m . F ( A : : RECOVERY_TIME ) - = fElapsedTime ;
if ( m . F ( A : : RECOVERY_TIME ) < = 0.f ) {
m . PerformAnimation ( " SUBMERGE " ) ;
SETPHASE ( SUBMERGE ) ;
m . GetFloat ( A : : RECOVERY_TIME ) = m . GetCurrentAnimation ( ) . GetTotalAnimationDuration ( ) * util : : random_range ( 1.f , 2.f ) ;
m . SetCollisionRadius ( 0.f ) ;
m . V ( A : : JUMP_TARGET_POS ) = m . GetPos ( ) ;
m . SetStrategyDrawFunction ( [ ] ( AiL * game , Monster & monster , const std : : string & strategy ) { } ) ;
}
} break ;
case SUBMERGE : {
m . F ( A : : RECOVERY_TIME ) - = fElapsedTime ;
if ( m . F ( A : : RECOVERY_TIME ) < = 0.f ) {
m . PerformAnimation ( " RISE " ) ;
m . SetPos ( m . V ( A : : JUMP_TARGET_POS ) ) ;
m . F ( A : : CASTING_TIMER ) = m . GetCurrentAnimation ( ) . GetTotalAnimationDuration ( ) ;
SETPHASE ( RISE_ANIMATION ) ;
}
} break ;
}
}