# 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 © 2024 The FreeType
Project ( www . freetype . org ) . Please see LICENSE_FT . txt for more information .
All rights reserved .
*/
# pragma endregion
# include "Monster.h"
# include "Player.h"
# include "AdventuresInLestoria.h"
# include "DamageNumber.h"
# include "Bullet.h"
# include "BulletTypes.h"
# include "DEFINES.h"
# include "safemap.h"
# include "util.h"
# include "Key.h"
# include "Menu.h"
# include "GameState.h"
# include "MenuComponent.h"
# include "config.h"
# include <string_view>
# include "SoundEffect.h"
# include "olcPGEX_Gamepad.h"
# include "ProgressBar.h"
# include "MenuLabel.h"
# include "GameSettings.h"
# include "Unlock.h"
# include "Tutorial.h"
# include <ranges>
# ifndef __EMSCRIPTEN__
# include "steam/isteamuserstats.h"
# endif
INCLUDE_MONSTER_DATA
INCLUDE_MONSTER_LIST
INCLUDE_ANIMATION_DATA
INCLUDE_SPAWNER_LIST
INCLUDE_BULLET_LIST
INCLUDE_DAMAGENUMBER_LIST
INCLUDE_game
INCLUDE_DATA
std : : vector < std : : reference_wrapper < Ability > > Player : : ABILITY_LIST ;
float Player : : GROUND_SLAM_SPIN_TIME = 0.6f ;
const bool Player : : INVERTED = true ;
const bool Player : : USE_WALK_DIR = true ;
InputGroup Player : : KEY_ABILITY1 ;
InputGroup Player : : KEY_ABILITY2 ;
InputGroup Player : : KEY_ABILITY3 ;
InputGroup Player : : KEY_ABILITY4 ;
InputGroup Player : : KEY_DEFENSIVE ;
InputGroup Player : : KEY_ITEM1 ;
InputGroup Player : : KEY_ITEM2 ;
InputGroup Player : : KEY_ITEM3 ;
std : : vector < std : : weak_ptr < MenuComponent > > Player : : moneyListeners ;
Player : : Player ( )
: facingDirection ( DOWN ) , state ( State : : NORMAL ) {
Initialize ( ) ;
}
Player : : Player ( Player * player )
: pos ( player - > GetPos ( ) ) , vel ( player - > GetVelocity ( ) ) , iframe_time ( player - > iframe_time ) ,
facingDirection ( DOWN ) , state ( State : : NORMAL ) {
Initialize ( ) ;
}
void Player : : Initialize ( ) {
Player : : GROUND_SLAM_SPIN_TIME = " Warrior.Ability 2.SpinTime " _F ;
SetBaseStat ( " Health " , " Warrior.BaseHealth " _I ) ;
SetBaseStat ( " Mana " , " Player.BaseMana " _I ) ;
SetBaseStat ( " Defense " , 0 ) ;
SetBaseStat ( " Attack " , " Warrior.BaseAtk " _I ) ;
SetBaseStat ( " Move Spd % " , 100 ) ;
SetBaseStat ( " CDR " , 0 ) ;
SetBaseStat ( " Crit Rate " , " Player.Crit Rate " _F ) ;
SetBaseStat ( " Crit Dmg " , " Player.Crit Dmg " _F ) ;
SetBaseStat ( " Health % " , 0 ) ;
SetBaseStat ( " HP6 Recovery % " , 0 ) ;
SetBaseStat ( " HP4 Recovery % " , 0 ) ;
SetBaseStat ( " HP Recovery % " , 0 ) ;
SetBaseStat ( " Damage Reduction " , 0 ) ;
SetBaseStat ( " Attack Spd " , 0 ) ;
cooldownSoundInstance = Audio : : Engine ( ) . LoadSound ( " spell_cast.ogg " _SFX , MiniAudio : : SFX ) ;
afterImage . Create ( 24 , 24 ) ;
for ( Pixel & p : afterImage . Sprite ( ) - > pColData ) {
p . a = 0 ;
}
afterImage . Decal ( ) - > Update ( ) ;
playerOutline . Create ( 24 , 24 ) ;
shield . reserve ( SHIELD_CAPACITY ) ;
DeactivateCatForm ( ) ;
}
void Player : : OnLevelStart ( ) {
AddTimer ( PlayerTimerType : : PLAYER_OUTLINE_TIMER , Timer { " Player Outline Update Timer " , 0.05f , [ & ] ( ) { UpdatePlayerOutline ( ) ; } , Timer : : REPEAT } ) ;
AddTimer ( PlayerTimerType : : OPPORTUNITY_SHOT_RANDOM_SPECIAL_MARK , Timer { " Opportunity Shot " , " Opportunity Shot " _ENC [ " MARK TIME " ] , [ & ] ( ) {
if ( HasEnchant ( " Opportunity Shot " ) ) {
std : : vector < std : : weak_ptr < Monster > > onScreenMonsters ;
std : : copy_if ( MONSTER_LIST . begin ( ) , MONSTER_LIST . end ( ) , std : : back_inserter ( onScreenMonsters ) , [ ] ( const std : : shared_ptr < Monster > & monster ) {
geom2d : : rect < float > gameView { game - > camera . GetViewPosition ( ) , game - > camera . GetViewSize ( ) } ;
return geom2d : : overlaps ( gameView , geom2d : : circle < float > ( monster - > GetPos ( ) , monster - > GetCollisionRadius ( ) ) ) ;
} ) ;
if ( onScreenMonsters . size ( ) > 0 ) {
uint8_t randomChoice { uint8_t ( util : : random ( ) % onScreenMonsters . size ( ) ) } ;
onScreenMonsters [ randomChoice ] . lock ( ) - > ApplySpecialMark ( " Trapper.Ability 1.Duration " _F , 1U ) ;
}
}
} , Timer : : TimerType : : REPEAT } ) ;
}
void Player : : InitializeMinimapImage ( ) {
# pragma region Setup Minimap Image
minimapImg . Create ( " Player.Minimap Image Size " _i [ 0 ] , " Player.Minimap Image Size " _i [ 1 ] ) ;
game - > SetDrawTarget ( minimapImg . Sprite ( ) ) ;
game - > SetPixelMode ( Pixel : : Mode : : ALPHA ) ;
game - > Clear ( BLANK ) ;
for ( int y = 0 ; y < " Player.Minimap Image Size " _i [ 1 ] ; y + + ) {
for ( int x = 0 ; x < " Player.Minimap Image Size " _i [ 0 ] ; x + + ) {
const int radius = " Player.Minimap Image Size " _i [ 0 ] / 2 ;
const vi2d center = vi2d { " Player.Minimap Image Offset " _i [ 0 ] , " Player.Minimap Image Offset " _i [ 1 ] } ;
vi2d imgOffset = vi2d { - " Player.Minimap Image Size " _i [ 0 ] / 2 , - " Player.Minimap Image Size " _i [ 1 ] / 2 } + vi2d { " Player.Minimap Image Offset " _i [ 0 ] , " Player.Minimap Image Offset " _i [ 1 ] } ;
float dist = geom2d : : line < float > { imgOffset + vi2d { x , y } , center } . length ( ) ;
if ( dist > radius ) continue ;
std : : string className = GetWalkSAnimation ( ) ;
Animate2D : : FrameSequence sequence = ANIMATION_DATA . at ( className ) ;
Animate2D : : Frame frame = sequence . GetFrame ( 0.f ) ;
const Renderable * temp = frame . GetSourceImage ( ) ;
Pixel col = temp - > Sprite ( ) - > GetPixel ( imgOffset + vi2d { x , y } ) ;
minimapImg . Sprite ( ) - > SetPixel ( { x , y } , col ) ;
}
}
game - > SetDrawTarget ( nullptr ) ;
game - > SetPixelMode ( Pixel : : Mode : : NORMAL ) ;
minimapImg . Decal ( ) - > Update ( ) ;
# pragma endregion
}
void Player : : ForceSetPos ( vf2d pos ) {
this - > pos = pos ;
Moved ( ) ;
}
bool Player : : _SetX ( float x , MoveFlag : : MoveFlag flags , const bool playerInvoked ) {
vf2d newPos = { x , pos . y } ;
vi2d tilePos = vi2d ( newPos / float ( game - > GetCurrentMapData ( ) . tilewidth ) ) * game - > GetCurrentMapData ( ) . tilewidth ;
geom2d : : rect < float > collisionRect = game - > GetTileCollision ( game - > GetCurrentLevel ( ) , newPos , upperLevel ) ;
# pragma region lambdas
auto NoTileCollisionExistsHere = [ & ] ( ) { return collisionRect = = game - > NO_COLLISION ; } ;
# pragma endregion
if ( NoTileCollisionExistsHere ( ) ) {
pos . x = std : : clamp ( x , game - > GetCurrentMapData ( ) . tilewidth / 2.f * GetSizeMult ( ) , float ( game - > GetCurrentMapData ( ) . width * game - > GetCurrentMapData ( ) . tilewidth - game - > GetCurrentMapData ( ) . tilewidth / 2.f * GetSizeMult ( ) ) ) ;
Moved ( flags ) ;
return true ;
} else {
geom2d : : rect < float > collision = { collisionRect . pos , collisionRect . size } ;
# pragma region lambdas
auto NoPlayerCollisionWithTile = [ & ] ( ) { return ! geom2d : : overlaps ( geom2d : : circle < float > ( newPos , 4 ) , collision ) ; } ;
# pragma endregion
collision . pos + = tilePos ;
if ( NoPlayerCollisionWithTile ( ) ) {
pos . x = std : : clamp ( x , game - > GetCurrentMapData ( ) . tilewidth / 2.f * GetSizeMult ( ) , float ( game - > GetCurrentMapData ( ) . width * game - > GetCurrentMapData ( ) . tilewidth - game - > GetCurrentMapData ( ) . tilewidth / 2.f * GetSizeMult ( ) ) ) ;
Moved ( flags ) ;
return true ;
} else
if ( playerInvoked ) { //If player invoked, we'll try the smart move system.
vf2d pushDir = vf2d { 1.f , util : : random ( 2 * PI ) } . cart ( ) ;
if ( collision . middle ( ) ! = pos ) pushDir = geom2d : : line < float > ( collision . middle ( ) , pos ) . vector ( ) . norm ( ) ;
newPos = { newPos . x , pos . y + pushDir . y * 12 } ;
if ( NoPlayerCollisionWithTile ( ) ) {
return _SetY ( pos . y + pushDir . y * game - > GetElapsedTime ( ) * 12 , flags , false ) ;
}
}
}
return false ;
} ;
bool Player : : _SetY ( float y , MoveFlag : : MoveFlag flags , const bool playerInvoked ) {
vf2d newPos = { pos . x , y } ;
vi2d tilePos = vi2d ( newPos / float ( game - > GetCurrentMapData ( ) . tilewidth ) ) * game - > GetCurrentMapData ( ) . tilewidth ;
geom2d : : rect < float > collisionRect = game - > GetTileCollision ( game - > GetCurrentLevel ( ) , newPos , upperLevel ) ;
# pragma region lambdas
auto NoTileCollisionExistsHere = [ & ] ( ) { return collisionRect = = game - > NO_COLLISION ; } ;
# pragma endregion
if ( NoTileCollisionExistsHere ( ) ) {
pos . y = std : : clamp ( y , game - > GetCurrentMapData ( ) . tilewidth / 2.f * GetSizeMult ( ) , float ( game - > GetCurrentMapData ( ) . height * game - > GetCurrentMapData ( ) . tilewidth - game - > GetCurrentMapData ( ) . tilewidth / 2.f * GetSizeMult ( ) ) ) ;
Moved ( flags ) ;
return true ;
} else {
geom2d : : rect < float > collision = { collisionRect . pos , collisionRect . size } ;
# pragma region lambdas
auto NoPlayerCollisionWithTile = [ & ] ( ) { return ! geom2d : : overlaps ( geom2d : : circle < float > ( newPos , 4 ) , collision ) ; } ;
# pragma endregion
collision . pos + = tilePos ;
if ( NoPlayerCollisionWithTile ( ) ) {
pos . y = std : : clamp ( y , game - > GetCurrentMapData ( ) . tilewidth / 2.f * GetSizeMult ( ) , float ( game - > GetCurrentMapData ( ) . height * game - > GetCurrentMapData ( ) . tilewidth - game - > GetCurrentMapData ( ) . tilewidth / 2.f * GetSizeMult ( ) ) ) ;
Moved ( flags ) ;
return true ;
} else
if ( playerInvoked ) { //If player invoked, we'll try the smart move system.{
vf2d pushDir = vf2d { 1.f , util : : random ( 2 * PI ) } . cart ( ) ;
if ( collision . middle ( ) ! = pos ) geom2d : : line < float > ( collision . middle ( ) , pos ) . vector ( ) . norm ( ) ;
newPos = { pos . x + pushDir . x * 12 , newPos . y } ;
if ( NoPlayerCollisionWithTile ( ) ) {
return _SetX ( pos . x + pushDir . x * game - > GetElapsedTime ( ) * 12 , flags , false ) ;
}
}
}
return false ;
}
bool Player : : SetX ( float x , MoveFlag : : MoveFlag flags ) {
return _SetX ( x , flags ) ;
}
bool Player : : SetY ( float y , MoveFlag : : MoveFlag flags ) {
return _SetY ( y , flags ) ;
}
void Player : : SetZ ( float z ) {
this - > z = z ;
}
bool Player : : SetPos ( vf2d pos , MoveFlag : : MoveFlag flags ) {
bool resultX = SetX ( pos . x , flags ) ;
bool resultY = SetY ( pos . y , flags ) ;
if ( resultY & & ! resultX ) {
resultX = SetX ( pos . x , flags ) ;
}
return resultX | | resultY ;
}
const vf2d & Player : : GetPos ( ) const {
return pos ;
}
float Player : : GetX ( ) {
return pos . x ;
}
float Player : : GetY ( ) {
return pos . y ;
}
float Player : : GetZ ( ) {
return z ;
}
const int Player : : GetHealth ( ) const {
return hp ;
}
const int Player : : GetMaxHealth ( ) const {
return int ( GetModdedStatBonuses ( " Health " ) ) ;
}
const int Player : : GetMana ( ) const {
return mana ;
}
const int Player : : GetMaxMana ( ) const {
return GetEquipStat ( " Mana " ) ;
}
const int Player : : GetAttack ( ) const {
const int originalAtk { int ( round ( GetModdedStatBonuses ( " Attack " ) ) ) } ;
int finalAtk { originalAtk } ;
finalAtk + = LastReserveEnchantConditionsMet ( ) ? round ( GetBaseStat ( " Attack " ) * " Last Reserve " _ENC [ " ATTACK PCT " ] / 100.f ) : 0 ;
if ( GetBuffs ( BuffType : : ADRENALINE_RUSH ) . size ( ) > 0 ) finalAtk + = " Bloodlust " _ENC [ " ATTACK BUFF PCT INCREASE " ] / 100.f * originalAtk * int ( GetBuffs ( ADRENALINE_RUSH ) [ 0 ] . intensity ) ;
return finalAtk ;
}
const int Player : : GetDefense ( ) const {
return int ( GetModdedStatBonuses ( " Defense " ) ) ;
}
float Player : : GetMoveSpdMult ( ) {
float moveSpdPct = GetEquipStat ( " Move Spd % " ) / 100.f ;
float mod_moveSpd = moveSpdPct ;
for ( const Buff & b : GetBuffs ( BuffType : : SLOWDOWN ) ) {
mod_moveSpd - = moveSpdPct * b . intensity ;
}
for ( const Buff & b : GetBuffs ( BuffType : : BLOCK_SLOWDOWN ) ) {
mod_moveSpd - = moveSpdPct * b . intensity ;
}
for ( const Buff & b : GetBuffs ( LOCKON_SPEEDBOOST ) ) {
mod_moveSpd + = moveSpdPct * b . intensity ;
}
for ( const Buff & b : GetBuffs ( SPEEDBOOST ) ) {
mod_moveSpd + = moveSpdPct * b . intensity ;
}
for ( const Buff & b : GetStatBuffs ( { " Move Spd % " } ) ) {
mod_moveSpd + = moveSpdPct * b . intensity ;
}
for ( const Buff & b : GetBuffs ( BuffType : : ADRENALINE_RUSH ) ) {
mod_moveSpd + = moveSpdPct * " Thief.Ability 3.Movement Speed Increase " _F / 100.f ;
}
return mod_moveSpd ;
}
float Player : : GetSizeMult ( ) const {
return size ;
}
float Player : : GetAttackRange ( ) {
float finalAttackRange { base_attack_range } ;
if ( HasEnchant ( " Adrenaline Stim " ) & & GetBuffs ( BuffType : : ADRENALINE_RUSH ) . size ( ) > 0 ) finalAttackRange + = base_attack_range * " Adrenaline Stim " _ENC [ " ATTACK RANGE INCREASE PCT " ] / 100.f ;
if ( GetBuffs ( BuffType : : SWORD_ENCHANTMENT ) . size ( ) > 0 ) finalAttackRange + = base_attack_range * " Sword Enchantment " _ENC [ " AUTO RANGE INCREASE " ] / 100.f ;
finalAttackRange * = GetSizeMult ( ) ;
return finalAttackRange ;
}
float Player : : GetSpinAngle ( ) {
return spin_angle ;
}
State : : State Player : : GetState ( ) {
return state ;
}
void Player : : Knockback ( vf2d vel ) {
//A new angle will be applied, but will be constrained by whichever applied velocity is strongest (either the current velocity, or the new one). This prevents continuous uncapped velocities to knockbacks applied.
if ( vel = = vf2d { } ) return ;
float maxVelThreshold ;
if ( GetState ( ) = = State : : BLOCK ) vel * = 1 - ( " Warrior.Right Click Ability.Knockback Reduction " _I / 100.f ) ;
if ( this - > vel = = vf2d { } ) maxVelThreshold = vel . mag ( ) ;
else maxVelThreshold = std : : max ( vel . mag ( ) , this - > vel . mag ( ) ) ;
this - > vel + = vel ;
float newVelAngle = this - > vel . polar ( ) . y ;
this - > vel = vf2d { maxVelThreshold , newVelAngle } . cart ( ) ;
}
void Player : : Update ( float fElapsedTime ) {
Ability & rightClickAbility = GetRightClickAbility ( ) ,
& ability = GetAbility1 ( ) ,
& ability2 = GetAbility2 ( ) ,
& ability3 = GetAbility3 ( ) ,
& ability4 = GetAbility4 ( ) ,
& item1 = useItem1 ,
& item2 = useItem2 ,
& item3 = useItem3 ;
attack_cooldown_timer = std : : max ( 0.f , attack_cooldown_timer - fElapsedTime ) ;
iframe_time = std : : max ( 0.f , iframe_time - fElapsedTime ) ;
notEnoughManaDisplay . second = std : : max ( 0.f , notEnoughManaDisplay . second - fElapsedTime ) ;
notificationDisplay . second = std : : max ( 0.f , notificationDisplay . second - fElapsedTime ) ;
lastHitTimer = std : : max ( 0.f , lastHitTimer - fElapsedTime ) ;
lastDotTimer = std : : max ( 0.f , lastDotTimer - fElapsedTime ) ;
lastPathfindingCooldown = std : : max ( 0.f , lastPathfindingCooldown - fElapsedTime ) ;
lowHealthSoundPlayedTimer = std : : max ( 0.f , lowHealthSoundPlayedTimer - fElapsedTime ) ;
poisonArrowReadyTimer = std : : max ( 0.f , poisonArrowReadyTimer - fElapsedTime ) ;
poisonArrowLastParticleTimer = std : : max ( 0.f , poisonArrowLastParticleTimer - fElapsedTime ) ;
if ( hurtRumbleTime > 0.f ) {
hurtRumbleTime = std : : max ( 0.f , hurtRumbleTime - fElapsedTime ) ;
if ( hurtRumbleTime = = 0.f ) {
Input : : StopVibration ( ) ;
}
}
blockTimer = std : : max ( 0.f , blockTimer - fElapsedTime ) ;
lastCombatTime = lastCombatTime + fElapsedTime ;
manaTickTimer - = fElapsedTime ;
hpRecoveryTimer = std : : max ( 0.f , hpRecoveryTimer - fElapsedTime ) ;
hp6RecoveryTimer = std : : max ( 0.f , hp6RecoveryTimer - fElapsedTime ) ;
hp4RecoveryTimer = std : : max ( 0.f , hp4RecoveryTimer - fElapsedTime ) ;
RunTimers ( ) ;
PerformHPRecovery ( ) ;
CheckEndZoneCollision ( ) ;
if ( state = = State : : CASTING ) {
if ( ! Audio : : Engine ( ) . IsPlaying ( cooldownSoundInstance ) ) {
Audio : : Engine ( ) . SetVolume ( cooldownSoundInstance , Audio : : GetCalculatedSFXVolume ( " Audio.Casting Sound Volume " _F / 100.f ) ) ;
Audio : : Engine ( ) . Play ( cooldownSoundInstance , true ) ;
}
castInfo . castTimer - = fElapsedTime ;
if ( castInfo . castTimer < = 0 ) {
bool allowed = castPrepAbility - > actionPerformedDuringCast ;
SetState ( State : : NORMAL ) ;
if ( ! allowed & & castPrepAbility - > action ( this , castInfo . castPos ) ) allowed = true ;
if ( allowed ) {
if ( castPrepAbility - > cooldown = = 0.f ) castPrepAbility - > cooldown = castPrepAbility - > GetCooldownTime ( ) ;
castPrepAbility - > charges - - ;
ConsumeMana ( castPrepAbility - > manaCost ) ;
OnAbilityUse ( ability ) ;
}
castInfo . castTimer = 0 ;
}
} else {
Audio : : Engine ( ) . Stop ( cooldownSoundInstance ) ;
}
while ( manaTickTimer < = 0 ) {
manaTickTimer + = 0.2f ;
RestoreMana ( 1 , true ) ;
}
std : : for_each ( buffList . begin ( ) , buffList . end ( ) , [ & ] ( Buff & b ) { b . Update ( game , fElapsedTime ) ; } ) ;
std : : erase_if ( buffList , [ ] ( Buff & b ) {
if ( b . duration < = 0.f ) {
if ( ! std : : holds_alternative < Player * > ( b . attachedTarget ) ) ERR ( std : : format ( " WARNING! Somehow removed buff of type {} is inside the player buff list but is not attached to the Player? THIS SHOULD NOT BE HAPPENING! " , int ( b . type ) ) ) ;
if ( b . playerBuffCallbackFunc ) b . playerBuffCallbackFunc ( std : : get < Player * > ( b . attachedTarget ) , b ) ;
return true ;
}
return false ;
} ) ;
//Class-specific update events.
OnUpdate ( fElapsedTime ) ;
switch ( state ) {
case State : : SPIN : {
switch ( facingDirection ) {
case UP : {
if ( lastAnimationFlip = = 0 ) {
lastAnimationFlip = 0.03f ;
facingDirection = DOWN ;
UpdateAnimation ( " WARRIOR_WALK_S " ) ;
}
} break ;
case DOWN : {
if ( lastAnimationFlip = = 0 ) {
lastAnimationFlip = 0.03f ;
facingDirection = UP ;
UpdateAnimation ( " WARRIOR_WALK_N " ) ;
}
} break ;
}
if ( facingDirection = = RIGHT ) {
spin_angle + = spin_spd * fElapsedTime ;
} else {
spin_angle - = spin_spd * fElapsedTime ;
}
if ( spin_attack_timer > 0 ) {
z = float ( " Warrior.Ability 2.SpinMaxHeight " _I ) * sin ( 3.3f * ( GROUND_SLAM_SPIN_TIME - spin_attack_timer ) / GROUND_SLAM_SPIN_TIME ) ;
spin_attack_timer = std : : max ( 0.f , spin_attack_timer - fElapsedTime ) ;
} else {
SetState ( State : : NORMAL ) ;
spin_angle = 0 ;
z = 0 ;
float numb = 4 ;
float groundSlamVisualRange { " Warrior.Ability 2.Range " _F / 300 * 1.33f } ;
float groundSlamRange { " Warrior.Ability 2.Range " _F / 100 * 12 } ;
int groundSlamDamage { int ( GetAttack ( ) * " Warrior.Ability 2.DamageMult " _F ) } ;
if ( HasEnchant ( " Improved Ground Slam " ) ) {
groundSlamVisualRange + = groundSlamVisualRange * " Improved Ground Slam " _ENC [ " GROUND SLAM RADIUS INCREASE " ] / 100.f ;
groundSlamRange + = groundSlamRange * " Improved Ground Slam " _ENC [ " GROUND SLAM RADIUS INCREASE " ] / 100.f ;
groundSlamDamage + = GetDefense ( ) * " Improved Ground Slam " _ENC [ " DEFENSE DAMAGE " ] / 100.f ;
}
const HurtList & hitEnemies = game - > Hurt ( pos , groundSlamRange , groundSlamDamage , OnUpperLevel ( ) , 0 , HurtType : : MONSTER , HurtFlag : : PLAYER_ABILITY ) ;
# pragma region Knockback effect
for ( auto & [ targetPtr , wasHurt ] : hitEnemies ) {
if ( ! std : : holds_alternative < Monster * > ( targetPtr ) ) ERR ( " WARNING! A hurt request list was expecting only monster pointers, but got another type instead! THIS SHOULD NOT BE HAPPENING! " ) ;
Monster * monsterPtr = std : : get < Monster * > ( targetPtr ) ;
float knockbackDir = 0 ;
float knockbackAmt = 0 ;
if ( HasEnchant ( " Slam Shock " ) ) monsterPtr - > Stun ( " Slam Shock " _ENC [ " STUN DURATION " ] ) ;
if ( geom2d : : line < float > ( GetPos ( ) , monsterPtr - > GetPos ( ) ) . length ( ) < = 0.001f ) {
knockbackDir = util : : random ( 2 * PI ) ;
knockbackAmt = " Warrior.Ability 2.KnockbackAmt " _F ;
} else {
knockbackDir = geom2d : : line < float > ( GetPos ( ) , monsterPtr - > GetPos ( ) ) . vector ( ) . norm ( ) . polar ( ) . y ;
knockbackAmt = std : : clamp ( " Warrior.Ability 2.KnockbackAmt " _F - geom2d : : line < float > ( GetPos ( ) , monsterPtr - > GetPos ( ) ) . length ( ) * " Warrior.Ability 2.KnockbackReduction " _F , 1.f , " Warrior.Ability 2.KnockbackAmt " _F ) ;
}
knockbackAmt = std : : max ( 1.f , knockbackAmt - " Warrior.Ability 2.KnockbackWeightFactor " _F * ( monsterPtr - > GetSizeMult ( ) - 1.f ) ) ;
monsterPtr - > Knockback ( vf2d { knockbackAmt , knockbackDir } . cart ( ) ) ;
}
# pragma endregion
game - > AddEffect ( std : : make_unique < Effect > ( GetPos ( ) , " Warrior.Ability 2.EffectLifetime " _F , " ground-slam-attack-front.png " , upperLevel , groundSlamVisualRange , " Warrior.Ability 2.EffectFadetime " _F ) , std : : make_unique < Effect > ( GetPos ( ) , " Warrior.Ability 2.EffectLifetime " _F , " ground-slam-attack-back.png " , upperLevel , groundSlamVisualRange , " Warrior.Ability 2.EffectFadetime " _F ) ) ;
SoundEffect : : PlaySFX ( " Warrior Ground Slam " , SoundEffect : : CENTERED ) ;
}
if ( lastAnimationFlip > 0 ) {
lastAnimationFlip = std : : max ( 0.f , lastAnimationFlip - fElapsedTime ) ;
}
UpdateAnimationStates ( ) ;
} break ;
case State : : BLOCK : {
if ( blockTimer < = 0 ) {
SetState ( State : : NORMAL ) ;
}
} break ;
case State : : SWING_SONIC_SWORD : {
if ( ability3 . GetCooldownTime ( ) - ability3 . cooldown > 0.5 ) {
SetState ( State : : NORMAL ) ;
switch ( facingDirection ) {
case DOWN : {
UpdateAnimation ( " WARRIOR_IDLE_S " ) ;
} break ;
case RIGHT : {
UpdateAnimation ( " WARRIOR_IDLE_E " ) ;
} break ;
case LEFT : {
UpdateAnimation ( " WARRIOR_IDLE_W " ) ;
} break ;
case UP : {
UpdateAnimation ( " WARRIOR_IDLE_N " ) ;
} break ;
}
}
UpdateAnimationStates ( ) ;
} break ;
case State : : TELEPORT : {
teleportAnimationTimer = std : : max ( 0.f , teleportAnimationTimer - fElapsedTime ) ;
if ( teleportAnimationTimer < = 0 ) {
ForceSetPos ( teleportTarget ) ;
SetState ( State : : NORMAL ) ;
}
UpdateAnimationStates ( ) ;
} break ;
case State : : ROLL : {
footstepTimer - = fElapsedTime ;
if ( facingDirection = = RIGHT ) spin_angle + = util : : degToRad ( " Thief.Right Click Ability.Roll Rotation Speed " _F ) * fElapsedTime ;
else spin_angle - = util : : degToRad ( " Thief.Right Click Ability.Roll Rotation Speed " _F ) * fElapsedTime ;
ySquishFactor = 0.5f * sin ( ( PI * fElapsedTime ) / " Thief.Right Click Ability.Bounce Period Time " _F ) + 0.5f ;
if ( rolling_timer < = 0.f ) {
SetState ( State : : NORMAL ) ;
}
if ( footstepTimer < = 0.f ) {
game - > PlayFootstepSound ( ) ;
footstepTimer = 0.05f ;
}
} break ;
case State : : DEADLYDASH : {
deadlyDashWaitTimer - = fElapsedTime ;
deadlyDashAdditiveBlendingToggleTimer - = fElapsedTime ;
if ( deadlyDashWaitTimer < = 0.f ) {
deadlyDashWaitTimer = INFINITY ;
} else
if ( deadlyDashAdditiveBlendingToggleTimer < = 0.f ) {
deadlyDashAdditiveBlendingToggleTimer = 0.05f ;
SetAdditiveBlending ( ! IsUsingAdditiveBlending ( ) ) ;
}
if ( deadlyDashAfterDashTimer < = 0.f ) {
geom2d : : line mouseDir { GetPos ( ) , GetWorldAimingLocation ( Player : : USE_WALK_DIR ) } ;
vf2d clampedMousePolarDir { util : : pointTo ( GetPos ( ) , GetWorldAimingLocation ( Player : : USE_WALK_DIR ) ) . polar ( ) } ;
clampedMousePolarDir . x = std : : clamp ( mouseDir . length ( ) , 24.f , " Thief.Ability 2.Range " _F * 24.f / 100 ) ;
const vf2d originalPos { GetPos ( ) } ;
deadlyDashEndingPos = GetPos ( ) + clampedMousePolarDir . cart ( ) ;
SoundEffect : : PlaySFX ( " Deadly Dash " , GetPos ( ) ) ;
SetPos ( MoveUsingPathfinding ( deadlyDashEndingPos ) ) ;
SetAnimationBasedOnTargetingDirection ( " DEADLYDASH " , util : : angleTo ( originalPos , GetPos ( ) ) ) ;
CreateBullet ( DeadlyDash ) ( originalPos , GetPos ( ) , " Thief.Ability 2.Hit Radius " _F , " Thief.Ability 2.Deadly Dash After Images Lingering Time " _F , GetAttack ( ) * " Thief.Ability 2.Damage " _F , " Thief.Ability 2.Knockback Amount " _F , OnUpperLevel ( ) , true , 5.f , animation . currentStateName , WHITE ) EndBullet ;
SetState ( State : : NORMAL ) ;
SetAdditiveBlending ( false ) ;
game - > SetupWorldShake ( 0.3f ) ;
}
} break ;
case State : : LEAP : {
leapTimer - = fElapsedTime ;
if ( leapTimer < = 0.f ) {
SetState ( State : : NORMAL ) ;
SetupAfterImage ( ) ;
afterImagePos = GetPos ( ) ;
SetZ ( 0.f ) ;
break ;
}
SetZ ( ( sin ( ( 1.f / totalLeapTime ) * PI * leapTimer ) / 2.f ) * " Witch.Right Click Ability.Leap Max Z " _F ) ;
SetVelocity ( vf2d { " Witch.Right Click Ability.Leap Velocity " _F / 100.f * 24 , transformTargetDir } . cart ( ) ) ;
UpdateAnimationStates ( ) ;
} break ;
default : {
//Update animations normally.
UpdateAnimationStates ( ) ;
}
}
# pragma region Reset certain state variables after timers expire.
if ( deadlyDashAfterDashTimer < = 0.f ) {
deadlyDashAfterDashTimer = INFINITY ;
SetAdditiveBlending ( false ) ;
game - > SetWorldZoom ( 1.f ) ;
}
if ( rolling_timer < = 0.f ) {
rolling_timer = INFINITY ;
spin_angle = 0.f ;
ySquishFactor = 1.f ;
}
rolling_timer - = fElapsedTime ;
deadlyDashAfterDashTimer - = fElapsedTime ;
# pragma endregion
float cooldownMultiplier ;
if ( game - > GetPlayer ( ) - > GetCooldownReductionPct ( ) > = 1.0f ) {
cooldownMultiplier = 999999 ;
} else {
cooldownMultiplier = 1 / ( 1 - game - > GetPlayer ( ) - > GetCooldownReductionPct ( ) ) ;
}
const std : : vector < std : : reference_wrapper < Ability > > playerAbilities { GetAbilities ( ) } ;
std : : for_each ( playerAbilities . begin ( ) , playerAbilities . end ( ) , [ & fElapsedTime , & cooldownMultiplier ] ( std : : reference_wrapper < Ability > a ) {
//NOTE: We have to compare to the max cooldown time when reducing cooldowns since it's possible when we equip/unequip items that the cooldown remaining is longer than the max cooldown, so we will immediately set the cooldown to that value if necessary.
if ( a . get ( ) . itemAbility ) a . get ( ) . cooldown = std : : min ( a . get ( ) . GetCooldownTime ( ) , a . get ( ) . cooldown - fElapsedTime ) ; //Item abilities are not affected by CDR.
else if ( a . get ( ) . charges > = a . get ( ) . MAX_CHARGES ) a . get ( ) . cooldown = 0.f ; //We got in a state where we probably unequipped something and no longer need to be on cooldown.
else a . get ( ) . cooldown = std : : min ( a . get ( ) . GetCooldownTime ( ) , a . get ( ) . cooldown - fElapsedTime * cooldownMultiplier ) ;
if ( a . get ( ) . cooldown < = 0.f ) {
a . get ( ) . charges = std : : min ( a . get ( ) . MAX_CHARGES , uint8_t ( a . get ( ) . charges + 1 ) ) ;
if ( a . get ( ) . charges < a . get ( ) . MAX_CHARGES ) a . get ( ) . cooldown = a . get ( ) . GetCooldownTime ( ) ;
else a . get ( ) . cooldown = 0.f ;
}
} ) ;
for ( std : : shared_ptr < Monster > & m : MONSTER_LIST ) {
const float playerRadius { 12 * GetSizeMult ( ) / 2 } ;
const float monsterRadius { m - > GetCollisionRadius ( ) } ;
if ( ! HasIframes ( ) & & abs ( m - > GetZ ( ) - GetZ ( ) ) < = 1 & & OnUpperLevel ( ) = = m - > OnUpperLevel ( ) & & geom2d : : overlaps ( geom2d : : circle ( pos , playerRadius ) , geom2d : : circle ( m - > GetPos ( ) , monsterRadius ) ) ) {
if ( m - > IsAlive ( ) ) {
m - > Collision ( this ) ;
}
geom2d : : line line ( pos , m - > GetPos ( ) ) ;
float dist = line . length ( ) ;
while ( dist < = 0.001 ) {
line = { pos + vf2d { util : : random ( 0.2f ) - 0.1f , util : : random ( 0.2f ) - 0.1f } , m - > GetPos ( ) } ;
dist = line . length ( ) ;
}
const float displacementDist = ( playerRadius + monsterRadius ) - dist ;
if ( ! m - > IsSolid ( ) ) {
m - > SetPos ( line . rpoint ( dist * 1.1f ) ) ;
}
if ( m - > IsAlive ( ) & & ! m - > IsNPC ( ) ) { //Don't set the knockback if this monster is actually an NPC. Let's just push them around.
if ( ! m - > IsSolid ( ) ) {
float knockbackStrength = 1.f ;
std : : vector < Buff > knockbackBuffs = m - > GetBuffs ( COLLISION_KNOCKBACK_STRENGTH ) ;
for ( Buff & b : knockbackBuffs ) {
knockbackStrength + = b . intensity ;
}
m - > Knockback ( line . vector ( ) . norm ( ) * 128.f ) ;
Knockback ( line . vector ( ) . norm ( ) * - 128.f * knockbackStrength ) ;
} else {
SetPos ( line . rpoint ( - displacementDist ) ) ;
}
}
}
}
if ( ! std : : isfinite ( vel . x ) | | ! std : : isfinite ( vel . y ) ) {
ERR ( std : : format ( " WARNING! The velocity vector for the player is NOT normal! Current vel:{} . Attempting manual resetting of velocity. " , vel . str ( ) ) ) ;
vel = { } ;
}
vf2d finalWindSpd = game - > GetWindSpeed ( ) ;
if ( GetState ( ) = = State : : BLOCK ) finalWindSpd * = 1 - ( " Warrior.Right Click Ability.Knockback Reduction " _F / 100.f ) ;
game - > GetPlayer ( ) - > SetPos ( game - > GetPlayer ( ) - > GetPos ( ) + finalWindSpd * game - > GetElapsedTime ( ) , MoveFlag : : PREVENT_CAST_CANCELLING ) ;
if ( vel ! = vf2d { 0 , 0 } ) {
float newX = pos . x + vel . x * fElapsedTime ;
float newY = pos . y + vel . y * fElapsedTime ;
SetX ( newX ) ;
SetY ( newY ) ;
if ( vel . x > 0 ) {
vel . x = std : : max ( 0.f , vel . x - friction * fElapsedTime ) ;
} else {
vel . x = std : : min ( 0.f , vel . x + friction * fElapsedTime ) ;
}
if ( vel . y > 0 ) {
vel . y = std : : max ( 0.f , vel . y - friction * fElapsedTime ) ;
} else {
vel . y = std : : min ( 0.f , vel . y + friction * fElapsedTime ) ;
}
}
if ( Menu : : stack . empty ( ) ) {
if ( CanAct ( ) & & attack_cooldown_timer = = 0 & & AiL : : KEY_ATTACK . Held ( ) ) {
Tutorial : : GetTask ( TutorialTaskName : : USE_ATTACK ) . I ( A : : ATTACK_COUNT ) + + ;
AutoAttack ( ) ;
}
CheckAndPerformAbility ( rightClickAbility , Player : : KEY_DEFENSIVE ) ;
CheckAndPerformAbility ( ability , Player : : KEY_ABILITY1 ) ;
CheckAndPerformAbility ( ability2 , Player : : KEY_ABILITY2 ) ;
CheckAndPerformAbility ( ability3 , Player : : KEY_ABILITY3 ) ;
CheckAndPerformAbility ( ability4 , Player : : KEY_ABILITY4 ) ;
CheckAndPerformAbility ( item1 , Player : : KEY_ITEM1 ) ;
CheckAndPerformAbility ( item2 , Player : : KEY_ITEM2 ) ;
CheckAndPerformAbility ( item3 , Player : : KEY_ITEM3 ) ;
if ( GetState ( ) = = State : : PREP_CAST ) {
# define CheckAbilityKeyReleasedAndCastSpell(ability,releaseState) \
if ( & ability = = castPrepAbility & & releaseState ) { CastSpell ( ability ) ; }
CheckAbilityKeyReleasedAndCastSpell ( rightClickAbility , Player : : KEY_DEFENSIVE . Released ( ) )
else
CheckAbilityKeyReleasedAndCastSpell ( ability , Player : : KEY_ABILITY1 . Released ( ) )
else
CheckAbilityKeyReleasedAndCastSpell ( ability2 , Player : : KEY_ABILITY2 . Released ( ) )
else
CheckAbilityKeyReleasedAndCastSpell ( ability3 , Player : : KEY_ABILITY3 . Released ( ) )
else
CheckAbilityKeyReleasedAndCastSpell ( ability4 , Player : : KEY_ABILITY4 . Released ( ) )
else
CheckAbilityKeyReleasedAndCastSpell ( item1 , Player : : KEY_ITEM1 . Released ( ) )
else
CheckAbilityKeyReleasedAndCastSpell ( item2 , Player : : KEY_ITEM2 . Released ( ) )
else
CheckAbilityKeyReleasedAndCastSpell ( item3 , Player : : KEY_ITEM3 . Released ( ) )
}
}
# pragma region Warrior
switch ( GetState ( ) ) {
case State : : SWING_SWORD : {
SetSwordSwingTimer ( GetSwordSwingTimer ( ) - fElapsedTime ) ;
if ( GetSwordSwingTimer ( ) < = 0 ) {
SetSwordSwingTimer ( 0 ) ;
SetState ( State : : NORMAL ) ;
}
} break ;
}
# pragma endregion
# pragma region Ranger
if ( GetState ( ) = = State : : SHOOT_ARROW ) {
if ( rangerShootAnimationTimer > 0.f ) {
rangerShootAnimationTimer = std : : max ( 0.f , rangerShootAnimationTimer - fElapsedTime ) ;
} else
if ( attack_cooldown_timer < = ARROW_ATTACK_COOLDOWN - 0.3 ) {
SetState ( State : : NORMAL ) ;
}
}
if ( retreatTimer > 0 ) {
SetZ ( 6 * sin ( PI / RETREAT_TIME * retreatTimer ) ) ;
retreatTimer - = fElapsedTime ;
if ( retreatTimer < = 0 ) {
SetVelocity ( { } ) ;
SetZ ( 0 ) ;
SetState ( State : : NORMAL ) ;
}
}
if ( ghostRemoveTimer > 0 ) {
ghostRemoveTimer - = fElapsedTime ;
if ( ghostRemoveTimer < = 0 ) {
if ( ghostPositions . size ( ) > 0 ) {
ghostPositions . erase ( ghostPositions . begin ( ) ) ;
if ( ghostPositions . size ( ) > 0 ) {
ghostRemoveTimer = RETREAT_GHOST_FRAME_DELAY ;
}
}
}
}
if ( ghostFrameTimer > 0 ) {
ghostFrameTimer - = fElapsedTime ;
if ( ghostFrameTimer < = 0 & & GetState ( ) = = State : : RETREAT ) {
ghostPositions . push_back ( GetPos ( ) + vf2d { 0 , - GetZ ( ) } ) ;
ghostFrameTimer = RETREAT_GHOST_FRAME_DELAY ;
}
}
if ( rapidFireTimer > 0 ) {
rapidFireTimer - = fElapsedTime ;
if ( rapidFireTimer < = 0 ) {
if ( remainingRapidFireShots > 0 ) {
remainingRapidFireShots - - ;
geom2d : : line pointTowardsCursor ( GetPos ( ) , GetWorldAimingLocation ( ) ) ;
vf2d extendedLine = pointTowardsCursor . upoint ( 1.1f ) ;
float angleToCursor = atan2 ( extendedLine . y - GetPos ( ) . y , extendedLine . x - GetPos ( ) . x ) ;
attack_cooldown_timer = ARROW_ATTACK_COOLDOWN ;
BULLET_LIST . push_back ( std : : make_unique < Arrow > ( Arrow ( GetPos ( ) , extendedLine , vf2d { cos ( angleToCursor ) * " Ranger.Ability 1.ArrowSpd " _F , float ( sin ( angleToCursor ) * " Ranger.Ability 1.ArrowSpd " _F - PI / 8 * " Ranger.Ability 1.ArrowSpd " _F ) } + movementVelocity / 1.5f , 12 * " Ranger.Ability 1.ArrowRadius " _F / 100 , int ( GetAttack ( ) * " Ranger.Ability 1.DamageMult " _F ) , OnUpperLevel ( ) , true ) ) ) ;
if ( GetClass ( ) & ( RANGER | TRAPPER ) ) SetAnimationBasedOnTargetingDirection ( " SHOOT " , angleToCursor ) ;
rapidFireTimer = RAPID_FIRE_SHOOT_DELAY ;
} else {
SetState ( State : : NORMAL ) ;
}
}
}
# pragma endregion
# pragma region Thief
if ( daggerThrowWaitTimer - fElapsedTime < = 0.f ) {
daggerThrowWaitTimer = INFINITY ;
float angleToCursor = atan2 ( GetWorldAimingLocation ( Player : : USE_WALK_DIR ) . y - GetPos ( ) . y , GetWorldAimingLocation ( Player : : USE_WALK_DIR ) . x - GetPos ( ) . x ) ;
const float daggerLifetime { " Thief.Ability 1.Dagger Range " _F / " Thief.Ability 1.Dagger Speed " _F } ;
if ( HasEnchant ( " Triple Toss " ) ) {
CreateBullet ( Bullet ) ( GetPos ( ) , vf2d { " Thief.Ability 1.Dagger Speed " _F , angleToCursor + util : : degToRad ( " Triple Toss " _ENC [ " SPREAD ANGLE " ] ) } . cart ( ) , " Thief.Ability 1.Dagger Radius " _F , GetAttack ( ) * " Thief.Ability 1.Damage " _I , " dagger.png " , OnUpperLevel ( ) , false , daggerLifetime , true , true , WHITE , { 1.f , 1.f } , 0.f , " Dagger Hit " ) EndBullet ;
CreateBullet ( Bullet ) ( GetPos ( ) , vf2d { " Thief.Ability 1.Dagger Speed " _F , angleToCursor - util : : degToRad ( " Triple Toss " _ENC [ " SPREAD ANGLE " ] ) } . cart ( ) , " Thief.Ability 1.Dagger Radius " _F , GetAttack ( ) * " Thief.Ability 1.Damage " _I , " dagger.png " , OnUpperLevel ( ) , false , daggerLifetime , true , true , WHITE , { 1.f , 1.f } , 0.f , " Dagger Hit " ) EndBullet ;
}
CreateBullet ( Bullet ) ( GetPos ( ) , vf2d { " Thief.Ability 1.Dagger Speed " _F , angleToCursor } . cart ( ) , " Thief.Ability 1.Dagger Radius " _F , GetAttack ( ) * " Thief.Ability 1.Damage " _I , " dagger.png " , OnUpperLevel ( ) , false , daggerLifetime , true , true , WHITE , { 1.f , 1.f } , 0.f , " Dagger Hit " ) EndBullet ;
}
daggerThrowWaitTimer - = fElapsedTime ;
# pragma endregion
# pragma region Witch
const auto RemoveScanLine = [ & ] ( uint8_t scanLine ) {
for ( int x : std : : ranges : : iota_view ( 0 , afterImage . Sprite ( ) - > width ) ) {
afterImage . Sprite ( ) - > SetPixel ( { x , scanLine } , BLANK ) ;
}
afterImage . Decal ( ) - > Update ( ) ;
} ;
//Scan Line goes through 1-23 (odd numbers) first, then 0-22.
const bool ScanLineFinished { scanLine = = 24U } ;
if ( ! ScanLineFinished ) {
removeLineTimer - = fElapsedTime ;
if ( removeLineTimer < = 0.f ) {
removeLineTimer = TIME_BETWEEN_LINE_REMOVALS ;
RemoveScanLine ( scanLine ) ;
scanLine + = 2 ;
if ( scanLine > 23 & & scanLine % 2 = = 1 ) {
scanLine = 0 ;
}
}
}
# pragma endregion
# pragma region Handle knockup timers
if ( knockUpTimer > 0.f ) {
knockUpTimer = std : : max ( 0.f , knockUpTimer - fElapsedTime ) ;
if ( knockUpTimer = = 0.f ) {
totalKnockupTime = 0.f ;
knockUpZAmt = 0.f ;
SetZ ( 0.f ) ;
} else {
SetZ ( util : : lerp ( 0.f , 1.f , - ( pow ( ( knockUpTimer - totalKnockupTime / 2 ) / ( totalKnockupTime / 2 ) , 2 ) ) + 1 ) * knockUpZAmt ) ;
}
}
# pragma endregion
}
float Player : : GetSwordSwingTimer ( ) {
return swordSwingTimer ;
}
void Player : : SetSwordSwingTimer ( float val ) {
swordSwingTimer = val ;
}
void Player : : SetState ( State : : State newState ) {
if ( GetState ( ) = = State : : BLOCK ) {
RemoveAllBuffs ( BuffType : : BLOCK_SLOWDOWN ) ;
}
state = newState ;
}
vf2d Player : : GetVelocity ( ) {
return vel ;
}
bool Player : : CanMove ( ) {
const bool DeadlyDashExpiringOnThisFrame { deadlyDashAfterDashTimer - game - > GetElapsedTime ( ) < = 0.f } ;
return knockUpTimer = = 0.f & & state ! = State : : ANIMATION_LOCK & & ( DeadlyDashExpiringOnThisFrame | | state ! = State : : DEADLYDASH ) & & ( state ! = State : : CASTING | | ( castInfo . castTotalTime - castInfo . castTimer > 0.2f ) ) ;
}
bool Player : : CanAct ( ) {
Ability dummyAbility ;
return CanAct ( dummyAbility ) ;
}
const bool Player : : CanAct ( const Ability & ability ) {
return knockUpTimer = = 0 & & ! ability . waitForRelease & & ( ability . canCancelCast | | state ! = State : : CASTING ) & & state ! = State : : ANIMATION_LOCK & & state ! = State : : DEADLYDASH & & state ! = State : : RETREAT & &
( GameState : : STATE = = GameState : : states [ States : : GAME_RUN ]
| | GameState : : STATE = = GameState : : states [ States : : GAME_HUB ] & & ! ability . itemAbility ) ;
}
bool Player : : HasIframes ( ) {
return iframe_time > 0 ;
}
bool Player : : Hurt ( HurtDamageInfo damageData ) {
return Hurt ( damageData . damage , damageData . onUpperLevel , damageData . z , damageData . damageRule , damageData . hurtFlags ) ;
}
bool Player : : Hurt ( int damage , bool onUpperLevel , float z , HurtFlag : : HurtFlag hurtFlags ) {
return Hurt ( damage , onUpperLevel , z , TrueDamageFlag : : NORMAL_DAMAGE , hurtFlags ) ;
}
bool Player : : Hurt ( int damage , bool onUpperLevel , float z , const TrueDamageFlag damageRule , HurtFlag : : HurtFlag hurtFlags ) {
const bool IsDOT { bool ( hurtFlags & HurtFlag : : DOT ) } ;
const bool TrueDamage { damageRule = = TrueDamageFlag : : IGNORE_DAMAGE_RULES } ;
const bool NormalDamageCalculationRequired { ! IsDOT & & ! TrueDamage } ;
const bool PlayHitSoundEffect { ! IsDOT } ;
if ( ! TrueDamage & & ! IsDOT & & ( ! IsAlive ( ) | | HasIframes ( ) | | OnUpperLevel ( ) ! = onUpperLevel | | abs ( GetZ ( ) - z ) > 1 ) ) return false ;
float mod_dmg = float ( damage ) ;
if ( NormalDamageCalculationRequired ) {
if ( GetState ( ) = = State : : BLOCK ) {
mod_dmg = 0 ;
SoundEffect : : PlaySFX ( " Warrior Block Hit " , SoundEffect : : CENTERED ) ;
} else {
float otherDmgTaken = 1 - GetDamageReductionFromBuffs ( ) ;
float armorDmgTaken = 1 - GetDefenseDamageReductionLookup ( ) ;
lastCombatTime = 0 ;
float finalPctDmgTaken = armorDmgTaken * otherDmgTaken ;
if ( finalPctDmgTaken < = 6. _Pct ) {
LOG ( " WARNING! Damage Reduction has somehow ended up below 6%, which is over the cap! " ) ;
}
finalPctDmgTaken = std : : max ( 6.25 _Pct , finalPctDmgTaken ) ; //Apply Damage Cap.
float minPctDmgReduction = 0.05 _Pct * GetDefense ( ) ;
float finalPctDmgReduction = 1 - finalPctDmgTaken ;
float pctDmgReductionDiff = finalPctDmgReduction - minPctDmgReduction ;
float dmgRoll = minPctDmgReduction + util : : random ( pctDmgReductionDiff ) ;
mod_dmg * = 1 - dmgRoll ;
}
}
mod_dmg * = GetDamageAmplificationMult ( ) ;
mod_dmg = std : : ceil ( mod_dmg ) ;
if ( Menu : : IsMenuOpen ( ) & & mod_dmg > 0 ) Menu : : CloseAllMenus ( ) ;
const bool tookLethalDamage { int ( mod_dmg ) > = hp } ;
bool survivedHitDueToDefiance { false } ;
if ( tookLethalDamage & & game - > GetPlayer ( ) - > HasEnchant ( " Death Defiance " ) ) survivedHitDueToDefiance = util : : random ( 1.f ) < = " Death Defiance " _ENC [ " LETHAL DAMAGE AVOID CHANCE " ] / 100.f ;
if ( ! IsDOT & & mod_dmg > 0 ) {
Pixel vignetteOverlayCol { " Interface.Vignette Color " _Pixel } ;
if ( tookLethalDamage & & survivedHitDueToDefiance ) vignetteOverlayCol = " Interface.Vignette Death Defiance Color " _Pixel ;
game - > ShowDamageVignetteOverlay ( vignetteOverlayCol ) ;
}
bool tookShieldDamage { false } ;
if ( tookLethalDamage & & survivedHitDueToDefiance ) ApplyIframes ( " Death Defiance " _ENC [ " LETHAL DAMAGE SURVIVE IFRAME TIME " ] ) ;
else {
if ( CatFormActive ( ) ) {
tookShieldDamage = true ;
if ( PlayHitSoundEffect ) SoundEffect : : PlaySFX ( " Warrior Block Hit " , SoundEffect : : CENTERED ) ;
DeactivateCatForm ( ) ;
} else if ( GetShield ( ) > 0 ) {
tookShieldDamage = true ;
if ( PlayHitSoundEffect ) SoundEffect : : PlaySFX ( " Warrior Block Hit " , SoundEffect : : CENTERED ) ;
SubtractShield ( mod_dmg ) ;
}
else {
if ( PlayHitSoundEffect ) SoundEffect : : PlaySFX ( " Player Hit " , SoundEffect : : CENTERED ) ;
hp = std : : max ( 0 , hp - int ( mod_dmg ) ) ;
}
}
if ( ! IsAlive ( ) & & GameState : : STATE ! = GameState : : states [ States : : DEATH ] ) GameState : : ChangeState ( States : : DEATH ) ;
hurtRumbleTime = " Player.Hurt Rumble Time " _F ;
Input : : StartVibration ( ) ;
Input : : SetLightbar ( PixelLerp ( DARK_RED , GREEN , GetHealthRatio ( ) ) ) ;
if ( IsDOT ) {
if ( lastDotTimer > 0 ) {
dotNumberPtr . get ( ) - > AddDamage ( int ( mod_dmg ) ) ;
} else {
dotNumberPtr = std : : make_shared < DamageNumber > ( pos + vf2d { 0 , 8.f } , int ( mod_dmg ) , false , DamageNumberType : : DOT ) ;
DAMAGENUMBER_LIST . push_back ( dotNumberPtr ) ;
}
lastDotTimer = 0.05f ;
} else {
if ( lastHitTimer > 0 ) {
damageNumberPtr . get ( ) - > AddDamage ( int ( mod_dmg ) ) ;
if ( tookShieldDamage ) damageNumberPtr - > SetType ( DamageNumberType : : SHIELD_LOSS ) ;
damageNumberPtr . get ( ) - > SetPauseTimer ( 0.4f ) ;
} else {
damageNumberPtr = std : : make_shared < DamageNumber > ( pos , int ( mod_dmg ) , true ) ;
if ( tookShieldDamage ) damageNumberPtr - > SetType ( DamageNumberType : : SHIELD_LOSS ) ;
DAMAGENUMBER_LIST . push_back ( damageNumberPtr ) ;
}
lastHitTimer = 0.05f ;
}
if ( ! lowHealthSoundPlayed & & lowHealthSoundPlayedTimer = = 0.f & & GetHealthRatio ( ) < = " Player.Health Warning Pct " _F / 100.f ) {
SoundEffect : : PlaySFX ( " Health Warning " , SoundEffect : : CENTERED ) ;
lowHealthSoundPlayed = true ;
lowHealthSoundPlayedTimer = " Player.Health Warning Cooldown " _F ;
}
if ( game - > GetPlayer ( ) - > GetHealth ( ) < game - > GetPlayer ( ) - > GetMaxHealth ( ) * 0.5f & & ! Tutorial : : TaskIsComplete ( TutorialTaskName : : USE_RECOVERY_ITEMS ) ) {
Tutorial : : SetNextTask ( TutorialTaskName : : USE_RECOVERY_ITEMS ) ;
}
if ( GameSettings : : AutoPauseEnabled ( ) & & ! Menu : : IsMenuOpen ( ) & & GameState : : STATE = = GameState : : states [ States : : GAME_RUN ] & & ! game - > IsFocused ( ) ) {
Menu : : OpenMenu ( MenuType : : PAUSE ) ;
}
return true ;
}
void Player : : AddAnimation ( std : : string state ) {
animation . AddState ( state , ANIMATION_DATA . at ( state ) ) ;
}
void Player : : UpdateAnimation ( std : : string animState , int specificClass , const float frameMult ) {
if ( specificClass = = ANY | | specificClass & GetClass ( ) ) {
animation . ChangeState ( internal_animState , animState , frameMult ) ;
animation . ChangeState ( internal_catAnimState , std : : format ( " WITCH_CAT_WALK_{} " , animState [ animState . length ( ) - 1 ] ) , frameMult ) ;
}
}
const Animate2D : : Frame & Player : : GetFrame ( ) const {
return animation . GetFrame ( internal_animState ) ;
}
const Animate2D : : Frame & Player : : GetCatFrame ( ) const {
return animation . GetFrame ( internal_catAnimState ) ;
}
void Player : : SetFacingDirection ( Key direction ) {
facingDirection = direction ;
}
Key Player : : GetFacingDirection ( ) const {
return facingDirection ;
}
void Player : : CancelCast ( ) {
bool wasCasting = castInfo . castTimer > 0 ;
castInfo = { " " , 0 } ;
std : : erase_if ( buffList , [ ] ( Buff & b ) { return b . type = = OVER_TIME_DURING_CAST ; } ) ; //Remove all buffs that would be applied during a cast, as we got interrupted.
if ( wasCasting ) {
DAMAGENUMBER_LIST . push_back ( std : : make_shared < DamageNumber > ( GetPos ( ) , 0 , true , DamageNumberType : : INTERRUPT ) ) ;
}
if ( state = = State : : CASTING ) {
state = State : : NORMAL ;
castPrepAbility - > waitForRelease = true ;
}
}
void Player : : Moved ( MoveFlag : : MoveFlag flags ) {
if ( ! ( flags & MoveFlag : : PREVENT_CAST_CANCELLING ) & & state = = State : : CASTING ) {
state = State : : NORMAL ;
castPrepAbility - > waitForRelease = true ;
CancelCast ( ) ;
}
for ( auto & [ spawnerID , spawner ] : SPAWNER_LIST ) {
if ( ! spawner . SpawnTriggered ( ) & & spawner . DoesUpperLevelSpawning ( ) = = OnUpperLevel ( ) & & geom2d : : contains ( geom2d : : rect < float > { spawner . GetPos ( ) , spawner . GetRange ( ) } , pos ) ) {
if ( GameState : : STATE = = GameState : : states [ States : : GAME_RUN ] ) {
if ( ! Tutorial : : TaskIsComplete ( TutorialTaskName : : USE_ATTACK ) ) {
Tutorial : : SetNextTask ( TutorialTaskName : : USE_ATTACK ) ;
} else
if ( ! Tutorial : : TaskIsComplete ( TutorialTaskName : : USE_ABILITIES ) ) {
Tutorial : : SetNextTask ( TutorialTaskName : : USE_ABILITIES ) ;
} else
if ( game - > GetPlayer ( ) - > GetHealth ( ) < game - > GetPlayer ( ) - > GetMaxHealth ( ) * 0.8f & & ! Tutorial : : TaskIsComplete ( TutorialTaskName : : USE_DEFENSIVE ) ) {
Tutorial : : SetNextTask ( TutorialTaskName : : USE_DEFENSIVE ) ;
}
}
spawner . SetTriggered ( true ) ;
}
}
const std : : map < std : : string , std : : vector < ZoneData > > & zoneData = game - > GetZones ( game - > GetCurrentLevel ( ) ) ;
if ( zoneData . count ( " UpperZone " ) ) {
for ( const ZoneData & upperLevelZone : zoneData . at ( " UpperZone " ) ) {
if ( geom2d : : overlaps ( upperLevelZone . zone , pos ) ) {
upperLevel = true ;
}
}
} else if ( ! game - > TestingModeEnabled ( ) ) ERR ( std : : format ( " WARNING! Map { } is missing Upper Zones ! THIS SHOULD NOT BE HAPPENING ! " ,game->GetCurrentMapDisplayName()));
if ( zoneData . count ( " LowerZone " ) ) {
for ( const ZoneData & lowerLevelZone : zoneData . at ( " LowerZone " ) ) {
if ( geom2d : : overlaps ( lowerLevelZone . zone , pos ) ) {
upperLevel = false ;
}
}
} else if ( ! game - > TestingModeEnabled ( ) ) ERR ( std : : format ( " WARNING! Map { } is missing Lower Zones ! THIS SHOULD NOT BE HAPPENING ! " ,game->GetCurrentMapDisplayName()));
EnvironmentalAudio : : UpdateEnvironmentalAudio ( ) ;
if ( ! std : : isfinite ( pos . x ) ) {
ERR ( std : : format ( " WARNING! Player X position is {}...Trying to recover. THIS SHOULD NOT BE HAPPENING! " , pos . x ) ) ;
ForceSetPos ( { float ( game - > GetCurrentMapData ( ) . playerSpawnLocation . x ) , pos . y } ) ;
}
if ( ! std : : isfinite ( pos . y ) ) {
ERR ( std : : format ( " WARNING! Player Y position is {}...Trying to recover. THIS SHOULD NOT BE HAPPENING! " , pos . y ) ) ;
ForceSetPos ( { pos . x , float ( game - > GetCurrentMapData ( ) . playerSpawnLocation . y ) } ) ;
}
game - > minimap . UpdateChunk ( game - > GetCurrentMapName ( ) , GetPos ( ) / game - > GetCurrentMapData ( ) . tilewidth / " Minimap.Chunk Size " _I , InitialLoad : : NO ) ;
}
void Player : : Spin ( float duration , float spinSpd ) {
SetState ( State : : SPIN ) ;
spin_attack_timer = duration ;
spin_spd = spinSpd ;
spin_angle = 0 ;
}
void Player : : UpdateWalkingAnimation ( Key direction , const float frameMult ) {
std : : string anim ;
switch ( direction ) {
case UP : anim = GetWalkNAnimation ( ) ; break ;
case RIGHT : anim = GetWalkEAnimation ( ) ; break ;
case DOWN : anim = GetWalkSAnimation ( ) ; break ;
case LEFT : anim = GetWalkWAnimation ( ) ; break ;
}
SetFacingDirection ( direction ) ;
UpdateAnimation ( anim , 0 , frameMult ) ;
}
void Player : : UpdateIdleAnimation ( Key direction ) {
std : : string anim ;
switch ( direction ) {
case UP : anim = GetIdleNAnimation ( ) ; break ;
case RIGHT : anim = GetIdleEAnimation ( ) ; break ;
case DOWN : anim = GetIdleSAnimation ( ) ; break ;
case LEFT : anim = GetIdleWAnimation ( ) ; break ;
}
SetFacingDirection ( direction ) ;
UpdateAnimation ( anim ) ;
animation . ChangeState ( internal_catAnimState , std : : format ( " WITCH_CAT_WALK_{} " , anim [ anim . length ( ) - 1 ] ) , 0.f ) ;
}
void Player : : AddBuff ( BuffType type , float duration , float intensity ) {
Buff & newBuff { buffList . emplace_back ( this , type , duration , intensity ) } ;
OnBuffAdd ( newBuff ) ;
}
void Player : : AddBuff ( BuffType type , float duration , float intensity , Buff : : PlayerBuffExpireCallbackFunction expireCallbackFunc ) {
Buff & newBuff { buffList . emplace_back ( this , type , duration , intensity , expireCallbackFunc ) } ;
OnBuffAdd ( newBuff ) ;
}
void Player : : AddBuff ( BuffType type , float duration , float intensity , std : : set < ItemAttribute > attr ) {
if ( type = = STAT_UP ) std : : for_each ( attr . begin ( ) , attr . end ( ) , [ ] ( const ItemAttribute & attr ) { if ( attr . ActualName ( ) ! = " Health " & & attr . ActualName ( ) ! = " Health % " & & attr . ActualName ( ) ! = " Attack " & & attr . ActualName ( ) ! = " Attack % " & & attr . ActualName ( ) ! = " Defense " & & attr . ActualName ( ) ! = " Defense % " & & attr . ActualName ( ) ! = " CDR " & & attr . ActualName ( ) ! = " Move Spd % " ) ERR ( std : : format ( " WARNING! Stat Up Attribute type {} is NOT IMPLEMENTED! " , attr . ActualName ( ) ) ) ; } ) ;
Buff & newBuff { buffList . emplace_back ( this , type , duration , intensity , attr ) } ;
OnBuffAdd ( newBuff ) ;
}
void Player : : AddBuff ( BuffType type , float duration , float intensity , std : : set < std : : string > attr ) {
if ( type = = STAT_UP ) std : : for_each ( attr . begin ( ) , attr . end ( ) , [ ] ( const std : : string & attr ) { if ( attr ! = " Health " & & attr ! = " Health % " & & attr ! = " Attack " & & attr ! = " Attack % " & & attr ! = " Defense " & & attr ! = " Defense % " & & attr ! = " CDR " & & attr ! = " Move Spd % " ) ERR ( std : : format ( " WARNING! Stat Up Attribute type {} is NOT IMPLEMENTED! " , attr ) ) ; } ) ;
Buff & newBuff { buffList . emplace_back ( this , type , duration , intensity , attr ) } ;
OnBuffAdd ( newBuff ) ;
}
void Player : : AddBuff ( BuffRestorationType type , BuffOverTimeType : : BuffOverTimeType overTimeType , float duration , float intensity , float timeBetweenTicks ) {
Buff & newBuff { buffList . emplace_back ( this , type , overTimeType , duration , intensity , timeBetweenTicks ) } ;
OnBuffAdd ( newBuff ) ;
}
void Player : : AddBuff ( BuffRestorationType type , BuffOverTimeType : : BuffOverTimeType overTimeType , float duration , float intensity , float timeBetweenTicks , Buff : : PlayerBuffExpireCallbackFunction expireCallbackFunc ) {
Buff & newBuff { buffList . emplace_back ( this , type , overTimeType , duration , intensity , timeBetweenTicks , expireCallbackFunc ) } ;
OnBuffAdd ( newBuff ) ;
}
void Player : : AddBuff ( BuffType type , BuffRestorationType restorationType , BuffOverTimeType : : BuffOverTimeType overTimeType , float duration , float intensity , float timeBetweenTicks ) {
Buff & newBuff { buffList . emplace_back ( this , type , restorationType , overTimeType , duration , intensity , timeBetweenTicks ) } ;
OnBuffAdd ( newBuff ) ;
}
void Player : : AddBuff ( BuffType type , BuffRestorationType restorationType , BuffOverTimeType : : BuffOverTimeType overTimeType , float duration , float intensity , float timeBetweenTicks , Buff : : PlayerBuffExpireCallbackFunction expireCallbackFunc ) {
Buff & newBuff { buffList . emplace_back ( this , type , restorationType , overTimeType , duration , intensity , timeBetweenTicks , expireCallbackFunc ) } ;
OnBuffAdd ( newBuff ) ;
}
bool Player : : OnUpperLevel ( ) {
return upperLevel ;
}
const std : : vector < Buff > Player : : GetBuffs ( BuffType buff ) const {
std : : vector < Buff > filteredBuffs ;
std : : copy_if ( buffList . begin ( ) , buffList . end ( ) , std : : back_inserter ( filteredBuffs ) , [ & buff ] ( const Buff & b ) { return b . type = = buff ; } ) ;
return filteredBuffs ;
}
void Player : : RemoveBuff ( BuffType buff ) {
for ( auto it = buffList . begin ( ) ; it ! = buffList . end ( ) ; + + it ) {
Buff & b = * it ;
if ( b . type = = buff ) {
buffList . erase ( it ) ;
return ;
}
}
}
Buff & Player : : GetOrAddBuff ( BuffType buff , std : : pair < BuffDuration , BuffIntensity > newBuff ) {
if ( GetBuffs ( buff ) . size ( ) > 0 ) return EditBuff ( buff , 0 ) ;
else return buffList . emplace_back ( this , buff , newBuff . first , newBuff . second ) ;
}
Buff & Player : : EditBuff ( BuffType buff , size_t buffInd ) {
return EditBuffs ( buff ) [ buffInd ] ;
}
std : : vector < std : : reference_wrapper < Buff > > Player : : EditBuffs ( BuffType buff ) {
std : : vector < std : : reference_wrapper < Buff > > filteredBuffs ;
std : : copy_if ( buffList . begin ( ) , buffList . end ( ) , std : : back_inserter ( filteredBuffs ) , [ & buff ] ( const Buff & b ) { return b . type = = buff ; } ) ;
return filteredBuffs ;
}
void Player : : RemoveAllBuffs ( BuffType buff ) {
std : : erase_if ( buffList , [ & ] ( Buff & b ) { return b . type = = buff ; } ) ;
}
void Player : : RemoveAllBuffs ( ) {
buffList . clear ( ) ;
}
void Player : : CastSpell ( Ability & ability ) {
vf2d castPosition = GetWorldAimingLocation ( ) ;
if ( testAimingLoc ) castPosition = testAimingLoc . value ( ) ;
float distance = float ( sqrt ( pow ( GetX ( ) - castPosition . x , 2 ) + pow ( GetY ( ) - castPosition . y , 2 ) ) ) ;
if ( distance > ability . precastInfo . range ) { //Clamp the distance.
vf2d pointToCursor = { castPosition . x - GetX ( ) , castPosition . y - GetY ( ) } ;
pointToCursor = pointToCursor . norm ( ) * ability . precastInfo . range ;
castPosition = GetPos ( ) + pointToCursor ;
}
castInfo = { ability . name , ability . precastInfo . castTime , ability . precastInfo . castTime , castPosition } ;
if ( ability . actionPerformedDuringCast ) { ability . action ( this , castPosition ) ; OnAbilityUse ( ability ) ; }
SetState ( State : : CASTING ) ;
}
CastInfo & Player : : GetCastInfo ( ) {
return castInfo ;
}
bool Player : : CanPathfindTo ( vf2d pos , vf2d targetPos , float range ) {
if ( game - > TestingModeEnabled ( ) ) return true ;
range * = ( 24 / game - > pathfinder . gridSpacing . x ) ;
if ( targetPos . x < 0 | | targetPos . y < 0 | | targetPos . x > game - > GetCurrentMapData ( ) . width * game - > GetCurrentMapData ( ) . tilewidth | | targetPos . y > game - > GetCurrentMapData ( ) . height * game - > GetCurrentMapData ( ) . tileheight ) return false ;
std : : vector < vf2d > pathing = game - > pathfinder . Solve_AStar ( pos , targetPos , range , upperLevel ) ;
return pathing . size ( ) > 0 & & pathing . size ( ) < range ; //We'll say 7 tiles or less is close enough to 650 range. Have a little bit of wiggle room.
}
void Player : : PrepareCast ( Ability & ability ) {
castPrepAbility = & ability ;
if ( ability . precastInfo . range > 0 ) {
SetState ( State : : PREP_CAST ) ;
} else {
CastSpell ( ability ) ;
}
}
void Player : : SetVelocity ( vf2d vel ) {
this - > vel = vel ;
}
void Player : : SetAnimationBasedOnTarget ( const std : : string_view animation_name , const vf2d & target ) {
SetAnimationBasedOnTargetingDirection ( animation_name , util : : pointTo ( GetPos ( ) , target ) . polar ( ) . y ) ;
}
void Player : : SetAnimationBasedOnTargetingDirection ( const std : : string_view animation_name , float targetDirection ) {
while ( targetDirection < - PI ) targetDirection + = 2 * PI ;
while ( targetDirection > PI ) targetDirection - = 2 * PI ;
auto FacingEast = [ & ] ( ) { return targetDirection < = PI / 4 & & targetDirection > - PI / 4 ; } ;
auto FacingWest = [ & ] ( ) { return targetDirection > = 3 * PI / 4 | | targetDirection < - 3 * PI / 4 ; } ;
auto FacingSouth = [ & ] ( ) { return targetDirection < = 3 * PI / 4 & & targetDirection > PI / 4 ; } ;
//Assume facing North.
char facingChar { ' N ' } ;
Key facingKey { UP } ;
auto Capitalize = [ ] ( const std : : string_view str ) {
std : : string newStr ;
newStr . resize ( str . length ( ) ) ;
for ( int i = 0 ; const char & c : str ) newStr [ i + + ] = toupper ( c ) ; \
return newStr ;
} ;
if ( FacingSouth ( ) ) {
facingChar = ' S ' ;
facingKey = DOWN ;
}
if ( FacingEast ( ) ) {
facingChar = ' E ' ;
facingKey = RIGHT ;
}
if ( FacingWest ( ) ) {
facingChar = ' W ' ;
facingKey = LEFT ;
}
SetFacingDirection ( facingKey ) ;
std : : string newAnimState { std : : format ( " {}_{}_{} " , Capitalize ( GetClassName ( ) ) , animation_name , facingChar ) } ;
if ( animation . HasState ( newAnimState ) ) UpdateAnimation ( newAnimState ) ;
}
void Player : : ApplyIframes ( float duration ) {
iframe_time = std : : max ( iframe_time , duration ) ;
}
void Player : : _SetIframes ( float duration ) {
iframe_time = duration ;
}
bool Player : : Heal ( int damage , bool suppressDamageNumber ) {
hp = std : : clamp ( hp + damage , 0 , int ( GetMaxHealth ( ) ) ) ;
if ( ! suppressDamageNumber & & damage > 0 ) {
DAMAGENUMBER_LIST . push_back ( std : : make_shared < DamageNumber > ( GetPos ( ) , damage , true , DamageNumberType : : HEALTH_GAIN ) ) ;
}
Input : : SetLightbar ( PixelLerp ( DARK_RED , GREEN , GetHealthRatio ( ) ) ) ;
return true ;
}
void Player : : RestoreMana ( int amt , bool suppressDamageNumber ) {
mana = std : : clamp ( mana + amt , 0 , GetMaxMana ( ) ) ;
if ( amt > 0 & & ! suppressDamageNumber ) {
DAMAGENUMBER_LIST . push_back ( std : : make_shared < DamageNumber > ( GetPos ( ) , amt , true , DamageNumberType : : MANA_GAIN ) ) ;
}
}
void Player : : ConsumeMana ( int amt ) {
mana = std : : clamp ( mana - amt , 0 , GetMaxMana ( ) ) ;
}
void Player : : SetSizeMult ( float size ) {
this - > size = size ;
}
void Player : : ResetLastCombatTime ( ) {
lastCombatTime = 0 ;
}
bool Player : : IsOutOfCombat ( ) {
return lastCombatTime > = " Player.Out of Combat Time " _F ;
}
float Player : : GetEndZoneStandTime ( ) {
return endZoneStandTime ;
}
void Player : : CheckEndZoneCollision ( ) {
auto HasZoneData = [ & ] ( ) {
return game - > GetZones ( ) . count ( " EndZone " ) ;
} ;
if ( IsOutOfCombat ( ) & & HasZoneData ( ) ) {
for ( const ZoneData & zone : game - > GetZones ( ) . at ( " EndZone " ) ) {
if ( zone . isUpper = = upperLevel & & geom2d : : overlaps ( GetPos ( ) , zone . zone ) ) {
endZoneStandTime + = game - > GetElapsedTime ( ) ;
if ( endZoneStandTime > = " Player.End Zone Wait Time " _F ) {
Component < MenuLabel > ( LEVEL_COMPLETE , " Stage Complete Label " ) - > SetLabel ( " Stage Completed " ) ;
game - > SetCompletedStageFlag ( ) ;
Component < MenuComponent > ( LEVEL_COMPLETE , " Level Details Outline " ) - > SetLabel ( " Complete Bonus \n +10% XP " ) ;
if ( Unlock : : IsUnlocked ( " STORY_1_1 " ) ) {
Component < MenuComponent > ( LEVEL_COMPLETE , " Next Button " ) - > Enable ( ) ;
} else {
Component < MenuComponent > ( LEVEL_COMPLETE , " Next Button " ) - > Disable ( ) ;
}
GameState : : ChangeState ( States : : LEVEL_COMPLETE ) ;
}
return ;
}
}
}
endZoneStandTime = 0 ;
}
void Player : : SetItem1UseFunc ( Ability a ) {
useItem1 = a ;
} ;
void Player : : SetItem2UseFunc ( Ability a ) {
useItem2 = a ;
} ;
void Player : : SetItem3UseFunc ( Ability a ) {
useItem3 = a ;
} ;
const float & Player : : GetEquipStat ( std : : string_view a ) const {
return GetEquipStat ( ItemAttribute : : Get ( a ) ) ;
}
const float & Player : : GetEquipStat ( ItemAttribute a ) const {
return stats . GetEquipStat ( a ) ;
}
const float & Player : : GetBaseStat ( std : : string_view a ) const {
return GetBaseStat ( ItemAttribute : : Get ( a ) ) ;
}
const float & Player : : GetBaseStat ( ItemAttribute a ) const {
return stats . GetBaseStat ( a ) ;
}
void EntityStats : : RecalculateEquipStats ( ) {
baseStats . copyTo ( equipStats ) ;
for ( int i = int ( EquipSlot : : HELMET ) ; i < = int ( EquipSlot : : RING2 ) ; i < < = 1 ) {
EquipSlot slot = EquipSlot ( i ) ;
std : : weak_ptr < Item > equip = Inventory : : GetEquip ( slot ) ;
if ( ISBLANK ( equip ) ) continue ;
for ( auto & [ key , size ] : ItemAttribute : : attributes ) {
equipStats . A ( key ) + = equip . lock ( ) - > GetStats ( ) . A_Read ( key ) ;
equipStats . A ( key ) + = equip . lock ( ) - > RandomStats ( ) . A_Read ( key ) ;
if ( slot & EquipSlot : : RING2 & & equip . lock ( ) - > HasEnchant ( ) ) { //Special doubling-up ring logic.
const bool IsNonCommonEnchant { equip . lock ( ) - > HasEnchant ( ) & & equip . lock ( ) - > GetEnchant ( ) . value ( ) . Category ( ) ! = ItemEnchantInfo : : ItemEnchantCategory : : GENERAL } ;
const bool Slot1HasSameEnchant { ! ISBLANK ( Inventory : : GetEquip ( EquipSlot : : RING1 ) ) & & Inventory : : GetEquip ( EquipSlot : : RING1 ) . lock ( ) - > HasEnchant ( ) & & Inventory : : GetEquip ( EquipSlot : : RING1 ) . lock ( ) - > GetEnchant ( ) . value ( ) . Name ( ) = = equip . lock ( ) - > GetEnchant ( ) . value ( ) . Name ( ) } ;
if ( ! IsNonCommonEnchant | | ! Slot1HasSameEnchant ) equipStats . A ( key ) + = equip . lock ( ) - > GetEnchant ( ) . value ( ) . GetAttribute ( key ) ;
} else if ( equip . lock ( ) - > HasEnchant ( ) ) equipStats . A ( key ) + = equip . lock ( ) - > GetEnchant ( ) . value ( ) . GetAttribute ( key ) ;
}
}
const std : : map < ItemSet , int > & setCounts = Inventory : : GetEquippedItemSets ( ) ;
for ( const auto & [ set , equipCount ] : setCounts ) {
const Stats & setStats = set [ equipCount ] ;
for ( auto & [ key , size ] : ItemAttribute : : attributes ) {
equipStats . A ( key ) + = setStats . A_Read ( key ) ;
}
}
game - > GetPlayer ( ) - > UpdateHealthAndMana ( ) ;
for ( std : : weak_ptr < MenuComponent > component : Menu : : equipStatListeners ) {
component . lock ( ) - > OnEquipStatsUpdate ( ) ;
}
}
const float & EntityStats : : GetEquipStat ( ItemAttribute stat ) const {
return equipStats . A_Read ( stat ) ;
}
const float & EntityStats : : GetEquipStat ( std : : string_view stat ) const {
return equipStats . A_Read ( stat ) ;
}
const float & EntityStats : : GetBaseStat ( ItemAttribute stat ) const {
return baseStats . A_Read ( stat ) ;
}
const float & EntityStats : : GetBaseStat ( std : : string_view stat ) const {
return baseStats . A_Read ( stat ) ;
}
void EntityStats : : SetBaseStat ( ItemAttribute stat , float val ) {
baseStats . A ( stat ) = val ;
RecalculateEquipStats ( ) ;
}
void EntityStats : : SetBaseStat ( std : : string_view stat , float val ) {
SetBaseStat ( ItemAttribute : : Get ( stat ) , val ) ;
}
void Player : : SetBaseStat ( std : : string_view a , float val ) {
stats . SetBaseStat ( ItemAttribute : : Get ( a ) , val ) ;
}
void Player : : SetBaseStat ( ItemAttribute a , float val ) {
stats . SetBaseStat ( a , val ) ;
}
const std : : string & ItemSet : : GetSetName ( ) const {
return name ;
}
uint32_t Player : : GetMoney ( ) const {
return money ;
}
void Player : : SetMoney ( uint32_t newMoney ) {
money = newMoney ;
for ( auto & component : moneyListeners ) {
component . lock ( ) - > OnPlayerMoneyUpdate ( newMoney ) ;
}
}
void Player : : AddMoneyListener ( std : : weak_ptr < MenuComponent > component ) {
if ( std : : find_if ( moneyListeners . begin ( ) , moneyListeners . end ( ) , [ & ] ( auto & ptr ) { return & * ptr . lock ( ) = = & * component . lock ( ) ; } ) ! = moneyListeners . end ( ) ) {
ERR ( " WARNING! Component " < < component . lock ( ) - > GetName ( ) < < " has already been added to the Chapter listener list! There should not be any duplicates!! " )
}
moneyListeners . push_back ( component ) ;
}
const float Player : : GetDamageReductionFromBuffs ( ) const {
float dmgReduction = 0 ;
for ( const Buff & b : GetBuffs ( BuffType : : DAMAGE_REDUCTION ) ) {
dmgReduction + = b . intensity ;
}
dmgReduction + = GetEquipStat ( " Damage Reduction " ) / 100.f ;
if ( LastReserveEnchantConditionsMet ( ) ) dmgReduction + = " Last Reserve " _ENC [ " DAMAGE REDUCTION PCT " ] / 100.f ;
return std : : min ( 0.75f , dmgReduction ) ;
} ;
const float Player : : GetDefenseDamageReductionLookup ( ) const {
float dmgReduction = 0 ;
dmgReduction + = Stats : : GetDamageReductionPct ( GetDefense ( ) ) ;
return std : : min ( 0.75f , dmgReduction ) ;
} ;
void Player : : RecalculateEquipStats ( ) {
stats . RecalculateEquipStats ( ) ;
enchantList . clear ( ) ;
enchantAbilityList . clear ( ) ;
const auto EquipSlotHasEnchant = [ ] ( const EquipSlot slot , const std : : string_view enchantToCheck ) { return ! Inventory : : GetEquip ( slot ) . expired ( ) & & Inventory : : GetEquip ( slot ) . lock ( ) - > GetEnchant ( ) . has_value ( ) & & Inventory : : GetEquip ( slot ) . lock ( ) - > GetEnchant ( ) . value ( ) . Name ( ) = = enchantToCheck ; } ;
for ( int i = int ( EquipSlot : : RING2 ) ; i > = int ( EquipSlot : : HELMET ) ; i > > = 1 ) { //I'm inverting the order of this equip slot check because typically the player will have enchants in the ring slots, so check those earlier to terminate the loop quicker.
EquipSlot slot = EquipSlot ( i ) ;
if ( ! ISBLANK ( Inventory : : GetEquip ( slot ) ) & & Inventory : : GetEquip ( slot ) . lock ( ) - > GetEnchant ( ) . has_value ( ) ) {
const ItemEnchant enchant { * Inventory : : GetEquip ( slot ) . lock ( ) - > GetEnchant ( ) } ;
enchantList . insert ( enchant . Name ( ) ) ;
if ( enchant . Ability ( ) ) enchantAbilityList . insert ( ( * enchant . Ability ( ) ) . get ( ) . name ) ;
}
}
# pragma region Reset Abilities before Enchant Modifications
Warrior : : ResetToOriginalAbilities ( ) ;
Ranger : : ResetToOriginalAbilities ( ) ;
Wizard : : ResetToOriginalAbilities ( ) ;
Thief : : ResetToOriginalAbilities ( ) ;
Trapper : : ResetToOriginalAbilities ( ) ;
Witch : : ResetToOriginalAbilities ( ) ;
# pragma endregion
if ( GetClass ( ) & RANGER ) {
if ( HasEnchant ( " Mega Charged Shot " ) ) GetAbility2 ( ) . precastInfo . castTime + = " Mega Charged Shot " _ENC [ " CAST TIME INCREASE " ] ;
if ( HasEnchant ( " Multi-Multishot " ) ) {
GetAbility3 ( ) . MAX_CHARGES = " Multi-Multishot " _ENC [ " EXTRA CHARGE COUNT " ] ;
GetAbility3 ( ) . COOLDOWN_TIME - = GetAbility3 ( ) . COOLDOWN_TIME * " Multi-Multishot " _ENC [ " COOLDOWN REDUCTION PCT " ] / 100.f ;
}
}
if ( GetClass ( ) & TRAPPER ) {
if ( HasEnchant ( " Trap Collector " ) ) {
GetAbility2 ( ) . MAX_CHARGES = " Trap Collector " _ENC [ " CHARGE COUNT " ] ;
GetAbility3 ( ) . MAX_CHARGES = " Trap Collector " _ENC [ " CHARGE COUNT " ] ;
}
}
if ( GetClass ( ) & WARRIOR ) {
if ( HasEnchant ( " Sonic Upgrade " ) ) {
GetAbility3 ( ) . COOLDOWN_TIME - = GetAbility3 ( ) . COOLDOWN_TIME * " Sonic Upgrade " _ENC [ " REDUCTION PCT " ] / 100.f ;
GetAbility3 ( ) . manaCost - = GetAbility3 ( ) . manaCost * " Sonic Upgrade " _ENC [ " REDUCTION PCT " ] / 100.f ;
}
}
if ( GetClass ( ) & WITCH ) {
if ( HasEnchant ( " Nine Lives " ) ) GetRightClickAbility ( ) . COOLDOWN_TIME = " Nine Lives " _ENC [ " TRANSFORM COOLDOWN " ] ;
}
if ( GetClass ( ) & WIZARD ) {
if ( HasEnchant ( " Blink Portal " ) ) GetRightClickAbility ( ) . COOLDOWN_TIME = " Blink Portal " _ENC [ " COOLDOWN " ] ;
if ( HasEnchant ( " Summon Comet " ) ) {
float castTimeDiff { _GetOriginalAbility3 ( ) . precastInfo . castTime - " Summon Comet " _ENC [ " METEOR CAST TIME " ] } ;
GetAbility3 ( ) . precastInfo . castTime - = castTimeDiff ;
GetAbility3 ( ) . COOLDOWN_TIME + = " Summon Comet " _ENC [ " COOLDOWN REDUCTION " ] ; //This is not a typo, we add because the cooldown reduction in the config is NEGATIVE!
}
if ( HasEnchant ( " Solar Flare " ) ) {
float castTimeDiff { _GetOriginalAbility3 ( ) . precastInfo . castTime - " Solar Flare " _ENC [ " METEOR CAST TIME " ] } ;
GetAbility3 ( ) . precastInfo . castTime - = castTimeDiff ;
GetAbility3 ( ) . COOLDOWN_TIME + = " Solar Flare " _ENC [ " COOLDOWN INCREASE " ] ;
}
}
for ( const std : : reference_wrapper < Ability > & a : GetAbilities ( ) ) {
if ( a . get ( ) . itemAbility ) continue ;
if ( a . get ( ) . charges < a . get ( ) . MAX_CHARGES & & a . get ( ) . cooldown = = 0.f ) a . get ( ) . cooldown = a . get ( ) . GetCooldownTime ( ) ;
}
}
const std : : vector < Buff > Player : : GetStatBuffs ( const std : : vector < std : : string > & attr ) const {
std : : vector < Buff > statUpBuffs ;
std : : copy_if ( buffList . begin ( ) , buffList . end ( ) , std : : back_inserter ( statUpBuffs ) , [ & ] ( const Buff b ) {
return b . type = = STAT_UP & & std : : find_if ( attr . begin ( ) , attr . end ( ) , [ & ] ( const std : : string & attr ) { return b . attr . count ( ItemAttribute : : Get ( attr ) ) ; } ) ! = attr . end ( ) ;
} ) ;
return statUpBuffs ;
}
const ItemAttributable & EntityStats : : GetStats ( ) const {
return equipStats ;
}
const ItemAttributable & Player : : GetStats ( ) const {
return stats . GetStats ( ) ;
} ;
const ItemAttributable & EntityStats : : GetBaseStats ( ) const {
return baseStats ;
} ;
const ItemAttributable & Player : : GetBaseStats ( ) const {
return stats . GetBaseStats ( ) ;
} ;
const ItemAttribute & Player : : GetBonusStat ( std : : string_view attr ) const {
return ItemAttribute : : Get ( attr , const_cast < Player * > ( this ) ) ;
}
const float Player : : GetCooldownReductionPct ( ) const {
float modCDRPct = 0 ;
const std : : vector < Buff > & buffs = GetStatBuffs ( { " CDR " } ) ;
for ( const Buff & b : buffs ) {
modCDRPct + = b . intensity ;
}
modCDRPct + = GetEquipStat ( " CDR " ) / 100 ;
modCDRPct + = LastReserveEnchantConditionsMet ( ) ? " Last Reserve " _ENC [ " COOLDOWN REDUCTION PCT " ] / 100.f : 0.f ;
return modCDRPct ;
}
const float Player : : GetCritRatePct ( ) const {
float modCritRatePct = 0 ;
modCritRatePct + = GetEquipStat ( " Crit Rate " ) / 100 ;
return modCritRatePct ;
}
const float Player : : GetCritDmgPct ( ) const {
float modCritDmgPct = 0 ;
modCritDmgPct + = GetEquipStat ( " Crit Dmg " ) / 100 ;
return modCritDmgPct ;
}
const float Player : : GetHPRecoveryPct ( ) const {
float modHPRecoveryPct = 0 ;
modHPRecoveryPct + = GetEquipStat ( " HP Recovery % " ) / 100 ;
if ( HasEnchant ( " Second Wind " ) & & GetHealthRatio ( ) < = " Second Wind " _ENC [ " HP BELOW THRESHOLD " ] / 100.f ) modHPRecoveryPct + = " Second Wind " _ENC [ " HP RECOVERY PCT " ] / 100.f ;
return modHPRecoveryPct ;
}
const float Player : : GetHP6RecoveryPct ( ) const {
float modHPRecoveryPct = 0 ;
modHPRecoveryPct + = GetEquipStat ( " HP6 Recovery % " ) / 100 ;
# pragma region Emergency Recovery Enchant Bonuses
const bool UseHP4RecoveryInstead { GetHealthRatio ( ) < = " Emergency Recovery " _ENC [ " FOUR SECOND HP THRESHOLD " ] / 100.f } ;
if ( HasEnchant ( " Emergency Recovery " ) & & ! UseHP4RecoveryInstead ) {
const float missingHealthRatio { std : : ceil ( ( ( 1 - GetHealthRatio ( ) ) * 100 ) ) / 100 } ;
const float effectBonusBasedOnMissingHealth { " Emergency Recovery " _ENC [ " GAIN AMOUNT PCT " ] / 100.f * int ( missingHealthRatio / ( " Emergency Recovery " _ENC [ " MISSING HEALTH BONUS PCT " ] / 100.f ) ) } ;
modHPRecoveryPct + = " Emergency Recovery " _ENC [ " HP RECOVERY PCT " ] / 100.f ;
modHPRecoveryPct + = effectBonusBasedOnMissingHealth ;
}
# pragma endregion
return modHPRecoveryPct ;
}
const float Player : : GetHP4RecoveryPct ( ) const {
float modHPRecoveryPct = 0 ;
modHPRecoveryPct + = GetEquipStat ( " HP4 Recovery % " ) / 100 ;
# pragma region Emergency Recovery Enchant Bonuses
const bool UseHP4RecoveryInstead { GetHealthRatio ( ) < = " Emergency Recovery " _ENC [ " FOUR SECOND HP THRESHOLD " ] / 100.f } ;
if ( HasEnchant ( " Emergency Recovery " ) & & UseHP4RecoveryInstead ) {
const float missingHealthRatio { std : : ceil ( ( ( 1 - GetHealthRatio ( ) ) * 100 ) ) / 100 } ;
const float effectBonusBasedOnMissingHealth { " Emergency Recovery " _ENC [ " GAIN AMOUNT PCT " ] / 100.f * int ( missingHealthRatio / ( " Emergency Recovery " _ENC [ " MISSING HEALTH BONUS PCT " ] / 100.f ) ) } ;
modHPRecoveryPct + = " Emergency Recovery " _ENC [ " HP RECOVERY PCT " ] / 100.f ;
modHPRecoveryPct + = effectBonusBasedOnMissingHealth ;
}
# pragma endregion
return modHPRecoveryPct ;
}
void Player : : PerformHPRecovery ( ) {
int hpRecoveryAmt = 0 ;
if ( hpRecoveryTimer = = 0 ) {
if ( float ( GetHPRecoveryPct ( ) * GetMaxHealth ( ) ) > 0.1 _Pct ) {
hpRecoveryAmt + = std : : ceil ( GetHPRecoveryPct ( ) * GetMaxHealth ( ) ) ;
}
hpRecoveryTimer = 1 ;
}
if ( hp4RecoveryTimer = = 0 ) {
if ( float ( GetHP4RecoveryPct ( ) * GetMaxHealth ( ) ) > 0.1 _Pct ) {
hpRecoveryAmt + = std : : ceil ( GetHP4RecoveryPct ( ) * GetMaxHealth ( ) ) ;
}
hp4RecoveryTimer = 4 ;
}
if ( hp6RecoveryTimer = = 0 ) {
if ( float ( GetHP6RecoveryPct ( ) * GetMaxHealth ( ) ) > 0.1 _Pct ) {
hpRecoveryAmt + = std : : ceil ( GetHP6RecoveryPct ( ) * GetMaxHealth ( ) ) ;
}
hp6RecoveryTimer = 6 ;
}
if ( GetHealth ( ) < GetMaxHealth ( ) ) {
Heal ( hpRecoveryAmt ) ;
}
if ( GetHealthRatio ( ) > " Player.Health Warning Pct " _F / 100.f ) {
lowHealthSoundPlayed = false ;
}
}
void Player : : AddXP ( const uint64_t xpGain ) {
currentLevelXP + = xpGain ;
totalXPEarned + = xpGain ;
if ( Level ( ) < LevelCap ( ) ) {
while ( currentLevelXP > = NextLevelXPRequired ( ) ) {
currentLevelXP - = NextLevelXPRequired ( ) ;
SetLevel ( Level ( ) + 1 ) ;
OnLevelUp ( ) ;
}
}
Component < ProgressBar > ( MenuType : : CHARACTER_MENU , " XP Bar " ) - > ResetProgressBar ( game - > GetPlayer ( ) - > CurrentXP ( ) , game - > GetPlayer ( ) - > NextLevelXPRequired ( ) ) ;
}
void Player : : SetXP ( const uint64_t xp ) {
currentLevelXP = xp ;
Component < ProgressBar > ( MenuType : : CHARACTER_MENU , " XP Bar " ) - > ResetProgressBar ( game - > GetPlayer ( ) - > CurrentXP ( ) , game - > GetPlayer ( ) - > NextLevelXPRequired ( ) ) ;
}
void Player : : SetTotalXPEarned ( const uint64_t totalXP ) {
totalXPEarned = totalXP ;
}
void Player : : OnLevelUp ( ) {
stats . SetBaseStat ( " Health " , GetBaseStat ( " Health " ) + hpGrowthRate ) ;
stats . SetBaseStat ( " Attack " , GetBaseStat ( " Attack " ) + atkGrowthRate ) ;
Heal ( GetBaseStat ( " Health " ) ) ;
STEAMUSERSTATS (
for ( auto & [ key , size ] : DATA . GetProperty ( " Achievement.Class Unlocks " ) ) {
datafile & unlock = DATA . GetProperty ( std : : format ( " Achievement.Class Unlocks.{} " , key ) ) ;
if ( classutils : : StringToClass ( unlock [ " Class Requirement " ] . GetString ( ) ) = = GetClass ( ) & &
Level ( ) - 1 < unlock [ " Level Requirement " ] . GetInt ( ) & &
Level ( ) = = unlock [ " Level Requirement " ] . GetInt ( ) ) {
SteamUserStats ( ) - > SetAchievement ( unlock [ " API Name " ] . GetString ( ) . c_str ( ) ) ;
SteamUserStats ( ) - > StoreStats ( ) ;
}
}
)
}
const uint8_t Player : : LevelCap ( ) const {
return levelCap ;
}
const uint8_t Player : : Level ( ) const {
return level ;
}
void Player : : SetLevel ( uint8_t newLevel ) {
level = newLevel ;
Component < MenuLabel > ( CHARACTER_MENU , " Level Class Display " ) - > SetLabel ( std : : format ( " Lv{} {} " , game - > GetPlayer ( ) - > Level ( ) , game - > GetPlayer ( ) - > GetClassName ( ) ) ) ;
Component < MenuLabel > ( LEVEL_COMPLETE , " Level Display " ) - > SetLabel ( std : : format ( " Lv{} " , game - > GetPlayer ( ) - > Level ( ) ) ) ;
}
const uint64_t Player : : CurrentXP ( ) const {
return currentLevelXP ;
}
const uint64_t Player : : TotalXP ( ) const {
return totalXPEarned ;
}
const uint64_t Player : : NextLevelXPRequired ( ) const {
if ( Level ( ) < LevelCap ( ) ) {
return DATA . GetProperty ( std : : format ( " PlayerXP.LEVEL[{}] " , Level ( ) + 1 ) ) . GetBigInt ( ) ;
}
return 0 ;
}
void Player : : ResetAccumulatedXP ( ) {
accumulatedXP = 0 ;
}
void Player : : AddAccumulatedXP ( const uint64_t xpGain ) {
accumulatedXP + = xpGain ;
}
const uint64_t Player : : GetAccumulatedXP ( ) const {
return accumulatedXP ;
}
const float Player : : GetAttackRecoveryRateReduction ( ) const {
float attackSpd { GetModdedStatBonuses ( " Attack Spd " ) } ;
for ( const Buff & b : GetBuffs ( BuffType : : ADRENALINE_RUSH ) ) {
attackSpd + = ATTACK_COOLDOWN * " Thief.Ability 3.Attack Speed Increase " _F / 100.f ;
}
for ( const Buff & b : GetBuffs ( BuffType : : LETHAL_TEMPO ) ) {
attackSpd + = ATTACK_COOLDOWN * " Lethal Tempo " _ENC [ " ATTACK SPEED INCREASE " ] / 100.f * b . intensity ;
}
return attackSpd ;
}
void EntityStats : : Reset ( ) {
equipStats . clear ( ) ;
baseStats . clear ( ) ;
}
geom2d : : circle < float > Player : : Hitbox ( ) {
return { GetPos ( ) , 12 * GetSizeMult ( ) / 2 } ;
}
void Player : : Knockup ( float duration ) {
if ( GetState ( ) = = State : : BLOCK ) duration * = 1 - ( " Warrior.Right Click Ability.Knockup Reduction " _I / 100.f ) ;
knockUpTimer + = duration ;
totalKnockupTime + = duration ;
knockUpZAmt + = 32 * pow ( duration , 2 ) ;
}
const vf2d Player : : GetWorldAimingLocation ( bool useWalkDir , bool invert ) {
vf2d screenAimingLoc { game - > view . ScreenToWorld ( GetAimingLocation ( useWalkDir , invert ) ) } ;
if ( game - > TestingModeEnabled ( ) ) screenAimingLoc = testAimingLoc . value_or ( GetPos ( ) + vf2d { } ) ;
if ( screenAimingLoc = = GetPos ( ) ) return GetPos ( ) + vf2d { 0 , - 1.f } ;
else return screenAimingLoc ;
}
const vf2d Player : : GetAimingLocation ( bool useWalkDir , bool invert ) {
if ( UsingAutoAim ( ) ) {
float xAxis = 0.f , yAxis = 0.f ;
# pragma region Manual Aiming
STEAMINPUT (
if ( fabs ( game - > KEY_SCROLLHORZ_R . Analog ( ) ) > 0.f ) {
xAxis = game - > KEY_SCROLLHORZ_R . Analog ( ) ;
}
if ( fabs ( game - > KEY_SCROLLVERT_R . Analog ( ) ) > 0.f ) {
yAxis = game - > KEY_SCROLLVERT_R . Analog ( ) ;
}
) else {
for ( GamePad * gamepad : GamePad : : getGamepads ( ) ) {
if ( gamepad - > stillConnected ) {
if ( fabs ( gamepad - > getAxis ( GPAxes : : RX ) ) > 0.f ) {
xAxis = gamepad - > getAxis ( GPAxes : : RX ) ;
}
if ( fabs ( gamepad - > getAxis ( GPAxes : : RY ) ) > 0.f ) {
yAxis = gamepad - > getAxis ( GPAxes : : RY ) ;
}
if ( xAxis ! = 0.f | | yAxis ! = 0.f ) break ; //Found a controller, so we're good to break.
}
}
}
# pragma endregion
if ( xAxis ! = 0.f | | yAxis ! = 0.f ) {
return { ( game - > ScreenWidth ( ) * xAxis ) / 2 + game - > ScreenWidth ( ) / 2 , ( game - > ScreenHeight ( ) * yAxis ) / 2 + game - > ScreenHeight ( ) / 2 } ;
} else {
if ( useWalkDir & & movementVelocity ! = vf2d { 0 , 0 } ) {
xAxis = aimingAngle . cart ( ) . x ;
yAxis = aimingAngle . cart ( ) . y ;
}
const vf2d MAX { std : : numeric_limits < float > : : max ( ) , std : : numeric_limits < float > : : max ( ) } ;
if ( xAxis ! = 0.f | | yAxis ! = 0.f ) {
return { ( game - > ScreenWidth ( ) * xAxis ) / 2 + game - > ScreenWidth ( ) / 2 , ( game - > ScreenHeight ( ) * yAxis ) / 2 + game - > ScreenHeight ( ) / 2 } ;
} else {
//Find the closest monster target. Provide a "Generic" target in case a target that is invulnerable is the only target that is available (and alive).
std : : optional < vf2d > closestPoint ;
std : : optional < vf2d > closestGenericPoint ; //Even if the monster is invulnerable, it might be worth targeting if a normal target is not found.
for ( std : : shared_ptr < Monster > & m : MONSTER_LIST ) {
geom2d : : line < float > aimingLine = geom2d : : line < float > ( GetPos ( ) , m - > GetPos ( ) ) ;
float distToMonster = aimingLine . length ( ) ;
float distToClosestPoint = geom2d : : line < float > ( GetPos ( ) , closestPoint . value_or ( MAX ) ) . length ( ) ;
float distToClosestGenericPoint = geom2d : : line < float > ( GetPos ( ) , closestGenericPoint . value_or ( MAX ) ) . length ( ) ;
if ( ! m - > InUndamageableState ( OnUpperLevel ( ) , GetZ ( ) ) ) {
if ( distToClosestPoint > distToMonster & & distToMonster < = operator " " _Pixels ( " Player.Auto Aim Detection Distance " _F ) ) {
closestPoint = m - > GetPos ( ) ;
}
}
if ( m - > IsAlive ( ) & & distToClosestGenericPoint > distToMonster & & distToMonster < = operator " " _Pixels ( " Player.Auto Aim Detection Distance " _F ) ) {
closestGenericPoint = m - > GetPos ( ) ;
}
}
std : : optional < geom2d : : line < float > > aimingLine ;
if ( closestPoint . has_value ( ) ) {
aimingLine = geom2d : : line < float > ( GetPos ( ) , closestPoint . value ( ) ) ;
} else
if ( closestGenericPoint . has_value ( ) ) {
aimingLine = geom2d : : line < float > ( GetPos ( ) , closestGenericPoint . value ( ) ) ;
}
if ( aimingLine . has_value ( ) ) {
vf2d aimingPoint = aimingLine . value ( ) . rpoint ( invert ? ( - operator " " _Pixels ( " Player.Aiming Cursor Max Distance " _F ) ) : std : : min ( aimingLine . value ( ) . length ( ) + 24.f , float ( operator " " _Pixels ( " Player.Aiming Cursor Max Distance " _F ) ) ) ) ;
return game - > GetScreenSize ( ) / 2 + aimingPoint - GetPos ( ) ;
} else return game - > GetScreenSize ( ) / 2 + vf2d { float ( operator " " _Pixels ( " Player.Aiming Cursor Max Distance " _F ) ) , aimingAngle . y } . cart ( ) ;
}
}
} else {
return game - > GetMousePos ( ) ;
}
}
const bool Player : : UsingAutoAim ( ) const {
return ( GameSettings : : KeyboardAutoAimEnabled ( ) & & game - > LastMouseMovement ( ) > = 2.f ) | | Input : : UsingGamepad ( ) ;
}
void Player : : UpdateHealthAndMana ( ) {
//Perform a check to make sure stats are initialized before they can be used.
if ( game - > GameInitialized ( ) ) {
hp = std : : min ( hp , int ( GetMaxHealth ( ) ) ) ;
mana = std : : min ( mana , GetMaxMana ( ) ) ;
}
}
void Player : : SetInvisible ( const bool invisibleState ) {
invisibility = invisibleState ;
}
const bool Player : : IsInvisible ( ) const {
return invisibility ;
}
void Player : : ResetVelocity ( ) {
vel = { } ;
}
const float Player : : GetHealthGrowthRate ( ) const {
return hpGrowthRate ;
}
const float Player : : GetAtkGrowthRate ( ) const {
return atkGrowthRate ;
}
const float Player : : GetIframeTime ( ) const {
return iframe_time ;
}
const Renderable & Player : : GetMinimapImage ( ) const {
return minimapImg ;
}
void Player : : ProximityKnockback ( const vf2d centerPoint , const float knockbackFactor ) {
geom2d : : line < float > lineToPlayer ( centerPoint , game - > GetPlayer ( ) - > GetPos ( ) ) ;
float dist = lineToPlayer . length ( ) ;
if ( dist < 0.001f ) {
float randomDir = util : : random ( 2 * PI ) ;
lineToPlayer = { centerPoint , centerPoint + vf2d { cos ( randomDir ) , sin ( randomDir ) } * 1 } ;
}
game - > GetPlayer ( ) - > Knockback ( lineToPlayer . vector ( ) . norm ( ) * knockbackFactor ) ;
}
void Player : : AddVelocity ( vf2d vel ) {
this - > vel + = vel * game - > GetElapsedTime ( ) ;
}
const float Player : : GetHealthRatio ( ) const {
return GetHealth ( ) / float ( GetMaxHealth ( ) ) ;
}
const bool Player : : IsAlive ( ) const {
return GetHealth ( ) > 0 ;
}
void Player : : CheckAndPerformAbility ( Ability & ability , InputGroup key ) {
if ( key . Released ( ) ) ability . keyReleaseRequiredToReactivate = false ;
const bool AllowedToCast = ! ability . precastInfo . precastTargetingRequired & & GetState ( ) ! = State : : ANIMATION_LOCK & & ( game - > TestingModeEnabled ( ) | | ! ability . keyReleaseRequiredToReactivate ) ;
const bool HasEnoughOfItem = ! ability . itemAbility | |
& ability = = & useItem1 & & game - > GetLoadoutItem ( 0 ) . lock ( ) - > Amt ( ) > 0 | |
& ability = = & useItem2 & & game - > GetLoadoutItem ( 1 ) . lock ( ) - > Amt ( ) > 0 | |
& ability = = & useItem3 & & game - > GetLoadoutItem ( 2 ) . lock ( ) - > Amt ( ) > 0 ;
if ( ability . name ! = " ??? " ) {
if ( CanAct ( ability ) ) {
if ( ability . charges > = 1 & & GetMana ( ) > = ability . manaCost ) {
if ( key . Held ( ) | | key . Released ( ) & & & ability = = castPrepAbility & & GetState ( ) = = State : : PREP_CAST ) {
# pragma region Tutorial Defensive / Use Ability Tasks
if ( & ability = = & GetRightClickAbility ( ) ) {
Tutorial : : GetTask ( TutorialTaskName : : USE_DEFENSIVE ) . I ( A : : DEFENSIVE_COUNT ) + + ;
} else {
Tutorial : : GetTask ( TutorialTaskName : : USE_ABILITIES ) . I ( A : : ABILITY_COUNT ) + + ;
}
# pragma endregion
if ( AllowedToCast & & ability . action ( this , { } ) ) {
bool allowed = ability . actionPerformedDuringCast ;
if ( ability . cooldown = = 0.f ) ability . cooldown = ability . GetCooldownTime ( ) ;
ability . charges - - ;
CancelCast ( ) ;
ConsumeMana ( ability . manaCost ) ;
ability . keyReleaseRequiredToReactivate = true ;
OnAbilityUse ( ability ) ;
} else
if ( ability . precastInfo . precastTargetingRequired & & GetState ( ) = = State : : NORMAL & & HasEnoughOfItem ) {
PrepareCast ( ability ) ;
}
}
} else
if ( ability . cooldown = = 0 & & GetMana ( ) < ability . manaCost & & key . Pressed ( ) ) {
NotEnoughManaDisplay ( ability . name , 1.f ) ;
}
} else
if ( key . Released ( ) | | ! key . Held ( ) ) ability . waitForRelease = false ;
}
}
const float Player : : GetModdedStatBonuses ( std : : string_view stat ) const {
if ( ItemAttribute : : Get ( stat ) . DisplayAsPercent ( ) ) ERR ( std : : format ( " WARNING! Stat {} was provided. A percentage-based stat should not be supplied here! GetModdedStatBonuses() is supposed to calculate using a BASE stat and includes the percentage modifier already! Please fix this! " , stat ) )
float flatBonuses { GetEquipStat ( stat ) + GetBonusStat ( stat ) } ;
float pctBonusSum { } ;
for ( const auto & [ attrName , attr ] : ItemAttribute : : attributes ) {
if ( stat = = attrName ) continue ; //Ignore self.
if ( attr . Modifies ( ) = = stat ) {
pctBonusSum + = stats . GetStats ( ) . A_Read ( attrName ) ;
}
}
for ( const Buff & buff : GetBuffs ( BuffType : : STAT_UP ) ) {
for ( const ItemAttribute & attr : buff . attr ) {
if ( attr . Modifies ( ) = = stat ) {
if ( attr . DisplayAsPercent ( ) ) {
pctBonusSum + = buff . intensity * 100.f ;
}
}
}
}
return flatBonuses + flatBonuses * pctBonusSum / 100.f ;
}
const float Player : : GetModdedStatBonuses ( ItemAttribute stat ) const {
return GetModdedStatBonuses ( stat . ActualName ( ) ) ;
}
void Player : : SetAdditiveBlending ( const bool additiveBlending ) {
renderedSpriteUsesAdditiveBlending = additiveBlending ;
}
const bool Player : : IsUsingAdditiveBlending ( ) const {
return renderedSpriteUsesAdditiveBlending ;
}
vf2d Player : : MoveUsingPathfinding ( vf2d targetPos ) {
float pointMouseDirection = atan2 ( targetPos . y - GetPos ( ) . y , targetPos . x - GetPos ( ) . x ) ;
vf2d pointTowardsMouse = { cos ( pointMouseDirection ) , sin ( pointMouseDirection ) } ;
float dist { geom2d : : line < float > { GetPos ( ) , targetPos } . length ( ) } ;
vf2d teleportPoint = GetPos ( ) + pointTowardsMouse * dist ;
while ( dist > 0 ) {
vi2d tilePos = vi2d ( teleportPoint / float ( game - > GetCurrentMapData ( ) . tilewidth ) ) * game - > GetCurrentMapData ( ) . tilewidth ;
geom2d : : rect < float > collisionRect = game - > GetTileCollision ( game - > GetCurrentLevel ( ) , teleportPoint , OnUpperLevel ( ) ) ;
collisionRect . pos + = tilePos ;
# pragma region lambdas
auto NoTileCollisionExistsHere = [ & ] ( ) { return collisionRect = = game - > NO_COLLISION ; } ;
# pragma endregion
# pragma region lambdas
auto NoPlayerCollisionWithTile = [ & ] ( ) { return ! geom2d : : overlaps ( geom2d : : circle < float > ( teleportPoint , 4 ) , collisionRect ) ; } ;
# pragma endregion
if ( CanPathfindTo ( GetPos ( ) , teleportPoint , 12 )
& & ( NoTileCollisionExistsHere ( ) | | NoPlayerCollisionWithTile ( ) ) ) {
return teleportPoint ;
}
dist - = 4 ;
teleportPoint = GetPos ( ) + pointTowardsMouse * dist ;
}
return GetPos ( ) ;
}
const std : : unordered_set < std : : string > & Player : : GetMyClass ( ) const {
return myClass ;
}
void Player : : SetupAfterImage ( ) {
game - > SetDrawTarget ( afterImage . Sprite ( ) ) ;
game - > Clear ( BLANK ) ;
game - > DrawPartialSprite ( { } , animation . GetFrame ( internal_animState ) . GetSourceImage ( ) - > Sprite ( ) , animation . GetFrame ( internal_animState ) . GetSourceRect ( ) . pos , animation . GetFrame ( internal_animState ) . GetSourceRect ( ) . size , 1U , 0U , { 255 , 255 , 254 } ) ; //Off-white so that the sprite is rendered completely in white.
game - > SetDrawTarget ( nullptr ) ;
afterImage . Decal ( ) - > Update ( ) ;
removeLineTimer = TIME_BETWEEN_LINE_REMOVALS ;
scanLine = 1U ;
}
void Player : : ApplyDot ( float duration , int damage , float timeBetweenTicks , Buff : : PlayerBuffExpireCallbackFunction expireCallbackFunc ) {
AddBuff ( BuffRestorationType : : OVER_TIME , BuffOverTimeType : : HP_DAMAGE_OVER_TIME , duration , damage , timeBetweenTicks , expireCallbackFunc ) ;
}
const float Player : : GetDamageAmplificationMult ( ) const {
float damageAmpMult { 1.f } ;
const std : : vector < Buff > & buffList { GetBuffs ( BuffType : : DAMAGE_AMPLIFICATION ) } ;
for ( const Buff & buff : buffList ) {
damageAmpMult + = buff . intensity ;
}
return damageAmpMult ;
}
const bool Player : : HasEnchant ( const std : : string_view enchantName ) const {
if ( ! ItemEnchantInfo : : GetEnchants ( ) . count ( std : : string ( enchantName ) ) ) ERR ( std : : format ( " WARNING! Enchantment {} does not exist in enchantment database! " , enchantName ) ) ;
return enchantList . count ( std : : string ( enchantName ) ) ;
}
void Player : : OnAbilityUse ( const Ability & ability ) {
if ( ability . itemAbility ) return ;
const auto UsedAbility = [ & ability ] ( const std : : string_view abilityName ) { return ability . name = = abilityName ; } ;
if ( HasEnchant ( " Wizard's Soul " ) & & ability . name ! = GetRightClickAbility ( ) . name ) {
const auto ReduceCooldown = [ this , & ability ] ( Ability & a ) {
if ( ability . name = = a . name ) return ;
a . cooldown - = " Wizard's Soul " _ENC [ " ABILITY COOLDOWN AMOUNT " ] ;
} ;
ReduceCooldown ( GetAbility1 ( ) ) ;
ReduceCooldown ( GetAbility2 ( ) ) ;
ReduceCooldown ( GetAbility3 ( ) ) ;
ReduceCooldown ( GetAbility4 ( ) ) ;
}
if ( UsedAbility ( " Deadly Dash " ) ) {
const bool IsFirstDash { Thief : : ability2 . manaCost ! = 0.f } ;
if ( HasEnchant ( " Deadly Mirage " ) & & IsFirstDash ) {
Thief : : ability2 . charges + + ;
Thief : : ability2 . manaCost = 0 ;
Thief : : ability2 . cooldown = 0.f ;
AddTimer ( PlayerTimerType : : DEADLY_MIRAGE_SECOND_CAST , Timer { " Deadly Mirage Second Cast " , " Deadly Mirage " _ENC [ " REACTIVATE TIMING WINDOW " ] , [ ] ( ) {
Thief : : ability2 . manaCost = " Thief.Ability 2.Mana Cost " _I ;
Thief : : ability2 . cooldown = " Thief.Ability 2.Cooldown " _F ;
Thief : : ability2 . charges - - ;
} , Timer : : MANUAL } ) ;
}
if ( ! IsFirstDash ) {
Thief : : ability2 . manaCost = " Thief.Ability 2.Mana Cost " _I ;
Thief : : ability2 . cooldown = " Thief.Ability 2.Cooldown " _F ;
CancelTimer ( PlayerTimerType : : DEADLY_MIRAGE_SECOND_CAST ) ;
}
}
if ( UsedAbility ( " Transform " ) & & HasEnchant ( " Nine Lives " ) ) {
if ( HasTimer ( PlayerTimerType : : CAT_FORM_ALREADY_ACTIVE ) & & GetTimer ( PlayerTimerType : : CAT_FORM_ALREADY_ACTIVE ) . IsRunning ( ) ) Witch : : rightClickAbility . cooldown = " Witch.Right Click Ability.Cooldown " _F ;
}
if ( UsedAbility ( " Teleport " ) & & HasEnchant ( " Blink Portal " ) ) {
const bool IsPortalTeleport { Wizard : : rightClickAbility . manaCost ! = 0.f } ;
if ( IsPortalTeleport ) {
Wizard : : rightClickAbility . charges + + ;
Wizard : : rightClickAbility . manaCost = 0 ;
Wizard : : rightClickAbility . cooldown = 0.f ;
AddTimer ( PlayerTimerType : : BLINK_PORTAL_SECOND_CAST , Timer { " Blink Portal Second Cast " , " Blink Portal " _ENC [ " REACTIVATION TIME " ] , [ ] ( ) {
Wizard : : rightClickAbility . manaCost = " Wizard.Right Click Ability.Mana Cost " _I ;
Wizard : : rightClickAbility . cooldown = " Blink Portal " _ENC [ " COOLDOWN " ] ;
Wizard : : rightClickAbility . charges - - ;
} , Timer : : MANUAL } ) ;
} else {
Wizard : : rightClickAbility . manaCost = " Wizard.Right Click Ability.Mana Cost " _I ;
Wizard : : rightClickAbility . cooldown = " Blink Portal " _ENC [ " COOLDOWN " ] ;
CancelTimer ( PlayerTimerType : : BLINK_PORTAL_SECOND_CAST ) ;
}
}
}
Ability & Player : : GetItem1 ( ) {
return useItem1 ;
}
Ability & Player : : GetItem2 ( ) {
return useItem2 ;
}
Ability & Player : : GetItem3 ( ) {
return useItem3 ;
}
const bool Player : : LastReserveEnchantConditionsMet ( ) const {
return HasEnchant ( " Last Reserve " ) & & GetHealthRatio ( ) < = " Last Reserve " _ENC [ " HP BELOW THRESHOLD " ] / 100.f ;
}
void Player : : ReduceAutoAttackTimer ( const float reduceAmt ) {
if ( reduceAmt < 0.f ) ERR ( std : : format ( " WARNING! Provided a negative number ({}) to reduce the player's auto attack number by. This is likely an error!! " , reduceAmt ) ) ;
attack_cooldown_timer = std : : max ( 0.f , attack_cooldown_timer - reduceAmt ) ;
}
const float & Player : : GetAutoAttackTimer ( ) const {
return attack_cooldown_timer ;
}
const bool Player : : PoisonArrowAutoAttackReady ( ) const {
return HasEnchant ( " Poisonous Arrow " ) & & poisonArrowReadyTimer = = 0.f ;
}
const vf2d Player : : GetFacingDirVector ( ) const {
switch ( GetFacingDirection ( ) ) {
case UP : {
return { 0 , - 1 } ;
} break ;
case DOWN : {
return { 0 , 1 } ;
} break ;
case LEFT : {
return { - 1 , 0 } ;
} break ;
case RIGHT : {
return { 1 , 0 } ;
} break ;
default : {
ERR ( std : : format ( " WARNING! Somehow got an invalid facing direction: {}. THIS SHOULD NOT BE HAPPENING! " , int ( GetFacingDirection ( ) ) ) ) ;
return { } ;
}
}
}
const int Player : : RemainingRapidFireShots ( ) const {
return remainingRapidFireShots ;
}
const std : : vector < std : : reference_wrapper < Ability > > Player : : GetAbilities ( ) {
return { GetRightClickAbility ( ) , GetAbility1 ( ) , GetAbility2 ( ) , GetAbility3 ( ) , GetAbility4 ( ) , GetItem1 ( ) , GetItem2 ( ) , GetItem3 ( ) } ;
}
const bool Player : : HasEnchantWithAbilityAffected ( const std : : string_view abilityName ) const {
return enchantAbilityList . count ( std : : string ( abilityName ) ) ;
}
Timer & Player : : AddTimer ( const PlayerTimerType type , const Timer & timer ) {
auto timerReturnResult { timers . insert ( { type , timer } ) } ;
Timer & newTimer { ( * ( timerReturnResult . first ) ) . second } ;
newTimer = timer ;
return newTimer ;
}
const bool Player : : HasTimer ( const PlayerTimerType type ) const {
return timers . count ( type ) ;
}
Timer & Player : : GetTimer ( const PlayerTimerType type ) {
return timers . at ( type ) ;
}
void Player : : CancelTimer ( const PlayerTimerType type ) {
GetTimer ( type ) . Cancel ( ) ;
}
void Player : : RunTimers ( ) {
for ( auto & [ type , timer ] : timers ) {
timer . Update ( game - > GetElapsedTime ( ) ) ;
}
}
void Player : : ResetTimers ( ) {
timers . clear ( ) ;
}
void Player : : UpdatePlayerOutline ( ) {
if ( GetBuffs ( BuffType : : DAMAGE_REDUCTION ) . size ( ) > 0 ) {
game - > SetDrawTarget ( playerOutline . Sprite ( ) ) ;
game - > Clear ( BLANK ) ;
for ( int32_t y : std : : ranges : : iota_view ( 0 , game - > GetDrawTargetHeight ( ) ) ) {
for ( int32_t x : std : : ranges : : iota_view ( 0 , game - > GetDrawTargetWidth ( ) ) ) {
if ( animation . GetFrame ( internal_animState ) . GetSourceImage ( ) - > Sprite ( ) - > GetPixel ( x , y ) ! = BLANK ) game - > GetDrawTarget ( ) - > SetPixel ( x , y , WHITE ) ;
}
}
playerOutline . Decal ( ) - > Update ( ) ;
game - > SetDrawTarget ( nullptr ) ;
}
}
void Player : : OnBuffAdd ( Buff & newBuff ) {
if ( newBuff . type = = DAMAGE_REDUCTION ) UpdatePlayerOutline ( ) ;
}
void Player : : _ForceCastSpell ( Ability & ability ) {
if ( game - > TestingModeEnabled ( ) ) {
PrepareCast ( ability ) ;
CastSpell ( ability ) ;
}
}
uint32_t Player : : GetShield ( ) const {
return std : : accumulate ( shield . begin ( ) , shield . end ( ) , 0U , [ ] ( const uint32_t shieldTotal , const std : : pair < PlayerTimerType , ShieldAmount > & shieldData ) { return shieldTotal + shieldData . second ; } ) ;
}
//NOTE: Shields of the same type will override each other! Create a timer type for each unique shield!
void Player : : AddShield ( const ShieldAmount shieldAmt , const float shieldTimer , const PlayerTimerType shieldType ) {
if ( HasTimer ( shieldType ) ) {
auto shieldIt { std : : find_if ( shield . begin ( ) , shield . end ( ) , [ & shieldType ] ( const std : : pair < PlayerTimerType , ShieldAmount > & shieldData ) { return shieldData . first = = shieldType ; } ) } ;
if ( shieldIt ! = shield . end ( ) ) {
std : : pair < PlayerTimerType , ShieldAmount > & shieldData { * shieldIt } ;
shieldData . second = std : : max ( shieldData . second , shieldAmt ) ;
AddTimer ( shieldType , Timer { std : : format ( " Shield Type {} " , int ( shieldType ) ) , shieldTimer , [ & shieldData , this ] ( ) { shieldData . second = 0U ; } } ) ;
} else ERR ( std : : format ( " WARNING! The shield type {} does not have a corresponding entry! All shields when generated should have made one! THIS SHOULD NOT BE HAPPENING! " , int ( shieldType ) ) ) ;
} else {
std : : pair < PlayerTimerType , ShieldAmount > & newShield { shield . emplace_back ( std : : pair < PlayerTimerType , ShieldAmount > { shieldType , shieldAmt } ) } ;
if ( shield . capacity ( ) > SHIELD_CAPACITY ) ERR ( std : : format ( " WARNING! Shield capacity limit has been reached! If you need more than {} shields, please expand the SHIELD_CAPACITY property of player! " , SHIELD_CAPACITY ) ) ;
AddTimer ( shieldType , Timer { std : : format ( " Shield Type {} " , int ( shieldType ) ) , shieldTimer , [ & newShield , this ] ( ) { newShield . second = 0U ; } } ) ;
}
}
Player : : ShieldAmount Player : : SubtractShield ( const ShieldAmount shieldDamage ) {
ShieldAmount leftoverShieldDamage { shieldDamage } ;
std : : for_each ( shield . begin ( ) , shield . end ( ) , [ & leftoverShieldDamage ] ( std : : pair < PlayerTimerType , ShieldAmount > & shieldData ) {
if ( leftoverShieldDamage = = 0U ) return ;
ShieldAmount currentShieldDamage { leftoverShieldDamage } ;
if ( shieldData . second < leftoverShieldDamage ) {
leftoverShieldDamage - = shieldData . second ;
shieldData . second = 0U ;
} else {
shieldData . second - = leftoverShieldDamage ;
leftoverShieldDamage = 0U ;
}
} ) ;
return leftoverShieldDamage ;
}
const float Player : : GetManaRatio ( ) const {
return GetMana ( ) / float ( GetMaxMana ( ) ) ;
}
void Player : : NotEnoughManaDisplay ( const std : : string_view text , const float displayTime ) {
notEnoughManaDisplay = std : : pair < std : : string , float > { text , displayTime } ;
}
void Player : : NotificationDisplay ( const std : : string_view text , const float displayTime ) {
notificationDisplay = std : : pair < std : : string , float > { text , displayTime } ;
}
void Player : : DeactivateCatForm ( ) {
catForm = false ;
}
void Player : : ActivateCatForm ( ) {
catForm = true ;
}
const bool Player : : CatFormActive ( ) const {
return catForm ;
}
void Player : : UpdateAnimationStates ( ) {
animation . UpdateState ( internal_animState , game - > GetElapsedTime ( ) ) ;
animation . UpdateState ( internal_catAnimState , game - > GetElapsedTime ( ) ) ;
}
void Player : : SetTestScreenAimingLocation ( vf2d forcedAimingLoc ) {
testAimingLoc = forcedAimingLoc ;
}
void Player : : SetAbility4 ( const Ability & ability ) {
}
void Player : : RemoveMoney ( const uint32_t moneyCost ) {
if ( moneyCost > GetMoney ( ) ) ERR ( std : : format ( " WARNING! Trying to spend more money than we actually have! THIS SHOULD NOT BE HAPPENING! Current Money: {} Trying to spend: {} " , GetMoney ( ) , moneyCost ) ) ;
SetMoney ( GetMoney ( ) - moneyCost ) ;
}
void Player : : AddMoney ( const uint32_t moneyCost ) {
SetMoney ( GetMoney ( ) + moneyCost ) ;
}