2023-06-11 20:26:41 -05:00
#include "Monster.h"
2023-06-12 00:37:55 -05:00
#include "DamageNumber.h"
2023-06-15 23:44:34 -05:00
#include "Crawler.h"
2023-06-16 01:41:38 -05:00
#include "Bullet.h"
2023-06-30 15:44:41 -07:00
#include "BulletTypes.h"
2023-06-15 04:53:57 -05:00
#include "DEFINES.h"
2023-08-06 19:00:09 -05:00
#include "safemap.h"
2023-09-19 03:38:09 -05:00
#include "MonsterStrategyHelpers.h"
#include "utils.h"
2023-09-23 15:28:21 -05:00
#include "MonsterAttribute.h"
2023-06-11 20:26:41 -05:00
2023-06-15 04:53:57 -05:00
INCLUDE_ANIMATION_DATA
INCLUDE_MONSTER_DATA
INCLUDE_MONSTER_LIST
INCLUDE_DAMAGENUMBER_LIST
2023-06-15 23:44:34 -05:00
INCLUDE_game
2023-06-16 01:41:38 -05:00
INCLUDE_BULLET_LIST
2023-08-06 19:00:09 -05:00
INCLUDE_DATA
INCLUDE_STRATEGY_DATA
2023-09-16 07:00:38 -05:00
INCLUDE_GFX
2023-08-06 19:00:09 -05:00
2023-08-13 02:12:19 -05:00
safemap < std :: string , int > STRATEGY_DATA ;
2023-09-07 01:35:23 -05:00
safemap < int , std :: string > STRATEGY_ID_DATA ;
2023-08-13 02:12:19 -05:00
std :: map < int , Renderable *> MonsterData :: imgs ;
2023-06-11 20:44:51 -05:00
2023-07-10 19:22:33 -05:00
Monster :: Monster ( vf2d pos , MonsterData data , bool upperLevel ) :
2023-09-07 20:20:21 +00:00
pos ( pos ), hp ( data . GetHealth ()), maxhp ( data . GetHealth ()), atk ( data . GetAttack ()), moveSpd ( data . GetMoveSpdMult ()), size ( data . GetSizeMult ()), targetSize ( data . GetSizeMult ()), strategy ( data . GetAIStrategy ()), id ( data . GetID ()), upperLevel ( upperLevel ){
2023-06-11 21:19:45 -05:00
bool firstAnimation = true ;
2023-08-06 19:00:09 -05:00
for ( std :: string & anim : data . GetAnimations ()){
2023-06-11 21:19:45 -05:00
animation . AddState ( anim , ANIMATION_DATA [ anim ]);
if ( firstAnimation ){
animation . ChangeState ( internal_animState , anim );
firstAnimation = false ;
}
}
2023-06-11 21:54:51 -05:00
randomFrameOffset = ( rand () % 1000 ) / 1000.f ;
2023-06-11 20:26:41 -05:00
}
vf2d & Monster :: GetPos (){
return pos ;
}
int Monster :: GetHealth (){
return hp ;
}
int Monster :: GetAttack (){
2023-06-19 03:25:01 -05:00
float mod_atk = atk ;
for ( Buff & b : GetBuffs ( ATTACK_UP )){
mod_atk += atk * b . intensity ;
}
return int ( mod_atk );
2023-06-11 20:26:41 -05:00
}
float Monster :: GetMoveSpdMult (){
2023-06-19 03:25:01 -05:00
float mod_moveSpd = moveSpd ;
for ( Buff & b : GetBuffs ( SLOWDOWN )){
mod_moveSpd -= moveSpd * b . intensity ;
}
return mod_moveSpd ;
2023-06-11 20:26:41 -05:00
}
float Monster :: GetSizeMult (){
return size ;
2023-06-11 21:19:45 -05:00
}
2023-06-11 21:54:51 -05:00
Animate2D :: Frame Monster :: GetFrame (){
return animation . GetFrame ( internal_animState );
}
2023-08-06 19:00:09 -05:00
void Monster :: UpdateAnimation ( std :: string state ){
2023-06-11 21:19:45 -05:00
animation . ChangeState ( internal_animState , state );
}
2023-06-16 01:10:40 -05:00
void Monster :: PerformJumpAnimation (){
2023-08-13 02:12:19 -05:00
animation . ChangeState ( internal_animState , MONSTER_DATA [ id ]. GetJumpAnimation ());
2023-06-16 01:10:40 -05:00
}
2023-06-16 01:41:38 -05:00
void Monster :: PerformShootAnimation (){
2023-08-13 02:12:19 -05:00
animation . ChangeState ( internal_animState , MONSTER_DATA [ id ]. GetShootAnimation ());
}
void Monster :: PerformIdleAnimation (){
animation . ChangeState ( internal_animState , MONSTER_DATA [ id ]. GetIdleAnimation ());
2023-06-16 01:41:38 -05:00
}
2023-06-24 01:18:21 -07:00
bool Monster :: SetX ( float x ){
2023-06-24 00:00:14 -07:00
vf2d newPos = { x , pos . y };
vi2d tilePos = vi2d ( newPos / 24 ) * 24 ;
2023-07-06 14:59:21 -05:00
geom2d :: rect < int > collisionRect = game -> GetTileCollision ( game -> GetCurrentLevel (), newPos , upperLevel );
2023-06-24 00:00:14 -07:00
if ( collisionRect . pos == vi2d { 0 , 0 } && collisionRect . size == vi2d { 1 , 1 }){
pos . x = std :: clamp ( x , 12.f * GetSizeMult (), float ( game -> WORLD_SIZE . x * 24 - 12 * GetSizeMult ()));
2023-07-07 06:42:49 -05:00
Moved ();
2023-06-24 01:18:21 -07:00
return true ;
2023-06-16 01:10:40 -05:00
} else {
2023-06-24 00:00:14 -07:00
geom2d :: rect < float > collision = { collisionRect . pos , collisionRect . size };
collision . pos += tilePos ;
2023-09-23 15:10:59 -05:00
if ( ! geom2d :: overlaps ( geom2d :: circle < float > ( newPos , 12 * GetSizeMult ()), collision )){
2023-06-24 00:00:14 -07:00
pos . x = std :: clamp ( x , 12.f * GetSizeMult (), float ( game -> WORLD_SIZE . x * 24 - 12 * GetSizeMult ()));
2023-07-07 06:42:49 -05:00
Moved ();
2023-06-24 01:18:21 -07:00
return true ;
2023-06-24 00:00:14 -07:00
}
2023-06-16 01:10:40 -05:00
}
2023-06-24 01:18:21 -07:00
return false ;
2023-06-16 01:10:40 -05:00
}
2023-06-24 01:18:21 -07:00
bool Monster :: SetY ( float y ){
2023-06-24 00:00:14 -07:00
vf2d newPos = { pos . x , y };
vi2d tilePos = vi2d ( newPos / 24 ) * 24 ;
2023-07-06 14:59:21 -05:00
geom2d :: rect < int > collisionRect = game -> GetTileCollision ( game -> GetCurrentLevel (), newPos , upperLevel );
2023-06-24 00:00:14 -07:00
if ( collisionRect . pos == vi2d { 0 , 0 } && collisionRect . size == vi2d { 1 , 1 }){
pos . y = std :: clamp ( y , 12.f * GetSizeMult (), float ( game -> WORLD_SIZE . y * 24 - 12 * GetSizeMult ()));
2023-07-07 06:42:49 -05:00
Moved ();
2023-06-24 01:18:21 -07:00
return true ;
2023-06-16 01:10:40 -05:00
} else {
2023-06-24 00:00:14 -07:00
geom2d :: rect < float > collision = { collisionRect . pos , collisionRect . size };
collision . pos += tilePos ;
2023-09-23 15:10:59 -05:00
if ( ! geom2d :: overlaps ( geom2d :: circle < float > ( newPos , 12 * GetSizeMult ()), collision )){
2023-06-24 00:00:14 -07:00
pos . y = std :: clamp ( y , 12.f * GetSizeMult (), float ( game -> WORLD_SIZE . y * 24 - 12 * GetSizeMult ()));
2023-07-07 06:42:49 -05:00
Moved ();
2023-06-24 01:18:21 -07:00
return true ;
2023-06-24 00:00:14 -07:00
}
2023-06-16 01:10:40 -05:00
}
2023-06-24 01:18:21 -07:00
return false ;
2023-06-16 01:10:40 -05:00
}
2023-06-11 22:57:43 -05:00
bool Monster :: Update ( float fElapsedTime ){
2023-07-25 19:48:24 -05:00
lastHitTimer = std :: max ( 0.f , lastHitTimer - fElapsedTime );
2023-09-07 01:35:23 -05:00
iframe_timer = std :: max ( 0.f , iframe_timer - fElapsedTime );
2023-09-07 20:20:21 +00:00
if ( size != targetSize ){
if ( size > targetSize ){
size = std :: max ( targetSize , size - Crawler :: SIZE_CHANGE_SPEED * fElapsedTime );
} else {
size = std :: min ( targetSize , size + Crawler :: SIZE_CHANGE_SPEED * fElapsedTime );
}
}
2023-06-15 23:44:34 -05:00
if ( IsAlive ()){
2023-06-19 03:25:01 -05:00
for ( std :: vector < Buff >:: iterator it = buffList . begin (); it != buffList . end (); ++ it ){
Buff & b =* it ;
b . duration -= fElapsedTime ;
if ( b . duration <= 0 ){
it = buffList . erase ( it );
if ( it == buffList . end ()) break ;
}
}
2023-08-13 22:32:04 -05:00
if ( ! HasIframes ()){
for ( Monster & m : MONSTER_LIST ){
if ( & m == this ) continue ;
2023-09-09 07:10:31 -05:00
if ( ! m . HasIframes () && OnUpperLevel () == m . OnUpperLevel () && abs ( m . GetZ () - GetZ ()) <= 1 && geom2d :: overlaps ( geom2d :: circle ( pos , 12 * size / 2 ), geom2d :: circle ( m . GetPos (), 12 * m . GetSizeMult () / 2 ))){
2023-08-13 22:32:04 -05:00
m . Collision ( * this );
geom2d :: line line ( pos , m . GetPos ());
float dist = line . length ();
2023-09-09 07:10:31 -05:00
m . SetPos ( line . rpoint ( dist * 1.1 ));
2023-08-13 22:32:04 -05:00
if ( m . IsAlive ()){
vel = line . vector (). norm () *- 128 ;
}
2023-06-15 23:44:34 -05:00
}
}
2023-09-16 07:00:38 -05:00
if ( ! game -> GetPlayer () -> HasIframes () && abs ( game -> GetPlayer () -> GetZ () - GetZ ()) <= 1 && game -> GetPlayer () -> OnUpperLevel () == OnUpperLevel () && geom2d :: overlaps ( geom2d :: circle ( pos , 12 * size / 2 ), geom2d :: circle ( game -> GetPlayer () -> GetPos (), 12 * game -> GetPlayer () -> GetSizeMult () / 2 ))){
2023-08-13 22:32:04 -05:00
geom2d :: line line ( pos , game -> GetPlayer () -> GetPos ());
float dist = line . length ();
2023-09-09 07:10:31 -05:00
SetPos ( line . rpoint ( - 0.1 ));
2023-08-13 22:32:04 -05:00
vel = line . vector (). norm () *- 128 ;
}
2023-06-15 23:44:34 -05:00
}
2023-07-29 10:21:53 -05:00
if ( GetState () == State :: NORMAL ){
2023-07-13 20:24:47 +00:00
if ( game -> GetPlayer () -> GetX () > pos . x ){
2023-06-15 23:44:34 -05:00
facingDirection = RIGHT ;
} else {
facingDirection = LEFT ;
}
}
2023-08-13 02:12:19 -05:00
Monster :: STRATEGY :: RUN_STRATEGY ( * this , fElapsedTime );
2023-06-15 23:44:34 -05:00
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 );
}
2023-06-24 00:00:14 -07:00
if ( vel != vf2d { 0 , 0 }){
SetX ( pos . x + vel . x * fElapsedTime );
SetY ( pos . y + vel . y * fElapsedTime );
}
2023-06-11 21:19:45 -05:00
}
2023-09-07 01:35:23 -05:00
if ( ! IsAlive ()){
2023-06-11 22:57:43 -05:00
deathTimer += fElapsedTime ;
if ( deathTimer > 3 ){
return false ;
}
}
2023-06-11 21:54:51 -05:00
animation . UpdateState ( internal_animState , randomFrameOffset + fElapsedTime );
randomFrameOffset = 0 ;
2023-06-11 22:57:43 -05:00
return true ;
}
2023-06-15 23:44:34 -05:00
Key Monster :: GetFacingDirection (){
return facingDirection ;
}
void Monster :: Draw (){
2023-08-13 23:01:23 -05:00
if ( GetZ () > 0 ){
vf2d shadowScale = vf2d { 8 * GetSizeMult () / 3.f , 1 } / std :: max ( 1.f , GetZ () / 24 );
2023-09-16 07:00:38 -05:00
game -> view . DrawDecal ( GetPos () - vf2d { 3 , 3 } * shadowScale / 2 + vf2d { 0 , 6 * GetSizeMult ()}, GFX [ "circle.png" ]. Decal (), shadowScale , BLACK );
2023-08-13 23:01:23 -05:00
}
2023-09-16 04:38:38 -05:00
game -> view . DrawPartialRotatedDecal ( GetPos () - vf2d { 0 , GetZ ()}, GetFrame (). GetSourceImage () -> Decal (), 0 , GetFrame (). GetSourceRect (). size / 2 , GetFrame (). GetSourceRect (). pos , GetFrame (). GetSourceRect (). size , vf2d ( GetSizeMult () * ( GetFacingDirection () == RIGHT ?- 1 : 1 ), GetSizeMult ()), GetBuffs ( BuffType :: SLOWDOWN ). size () > 0 ? Pixel { uint8_t ( 255 * abs ( sin ( 1.4 * GetBuffs ( BuffType :: SLOWDOWN )[ 0 ]. duration ))), uint8_t ( 255 * abs ( sin ( 1.4 * GetBuffs ( BuffType :: SLOWDOWN )[ 0 ]. duration ))), uint8_t ( 128 + 127 * abs ( sin ( 1.4 * GetBuffs ( BuffType :: SLOWDOWN )[ 0 ]. duration )))} : WHITE );
}
void Monster :: DrawReflection ( float drawRatioX , float multiplierX ){
game -> SetDecalMode ( DecalMode :: ADDITIVE );
game -> view . DrawPartialRotatedDecal ( GetPos () + vf2d { drawRatioX * GetFrame (). GetSourceRect (). size . x , GetZ () + ( GetFrame (). GetSourceRect (). size . y - 16 ) * GetSizeMult ()}, GetFrame (). GetSourceImage () -> Decal (), 0 , GetFrame (). GetSourceRect (). size / 2 , GetFrame (). GetSourceRect (). pos , GetFrame (). GetSourceRect (). size , vf2d ( GetSizeMult () * ( GetFacingDirection () == RIGHT ?- 1 : 1 ) * multiplierX , GetSizeMult () *- 1 ), GetBuffs ( BuffType :: SLOWDOWN ). size () > 0 ? Pixel { uint8_t ( 255 * abs ( sin ( 1.4 * GetBuffs ( BuffType :: SLOWDOWN )[ 0 ]. duration ))), uint8_t ( 255 * abs ( sin ( 1.4 * GetBuffs ( BuffType :: SLOWDOWN )[ 0 ]. duration ))), uint8_t ( 128 + 127 * abs ( sin ( 1.4 * GetBuffs ( BuffType :: SLOWDOWN )[ 0 ]. duration )))} : WHITE );
game -> SetDecalMode ( DecalMode :: NORMAL );
2023-06-15 23:44:34 -05:00
}
2023-07-14 15:44:17 +00:00
void Monster :: Collision ( Player * p ){
2023-08-13 02:12:19 -05:00
if ( MONSTER_DATA [ id ]. GetCollisionDmg () > 0 &&! hasHitPlayer ){
2023-09-11 05:27:36 -05:00
if ( p -> Hurt ( MONSTER_DATA [ id ]. GetCollisionDmg (), OnUpperLevel (), GetZ ())){
hasHitPlayer = true ;
}
2023-06-16 01:10:40 -05:00
}
2023-06-15 23:44:34 -05:00
Collision ();
}
void Monster :: Collision ( Monster & m ){
Collision ();
}
void Monster :: Collision (){
2023-09-19 03:38:09 -05:00
if ( strategy == 0 && GetState () == State :: MOVE_TOWARDS && util :: random ( Monster :: STRATEGY :: _GetInt ( * this , "BumpStopChance" , strategy )) < 1 ){ //The run towards strategy causes state to return to normal upon a collision.
2023-09-09 07:10:31 -05:00
SetState ( State :: NORMAL );
2023-06-15 23:44:34 -05:00
}
}
void Monster :: SetVelocity ( vf2d vel ){
this -> vel = vel ;
}
2023-09-09 07:10:31 -05:00
bool Monster :: SetPos ( vf2d pos ){
2023-07-06 14:24:43 -05:00
bool resultX = SetX ( pos . x );
bool resultY = SetY ( pos . y );
if ( resultY &&! resultX ){
resultX = SetX ( pos . x );
}
return resultX | resultY ;
2023-06-15 23:44:34 -05:00
}
2023-07-07 06:42:49 -05:00
void Monster :: Moved (){
ZoneData & zoneData = game -> GetZoneData ( game -> GetCurrentLevel ());
for ( geom2d :: rect < int >& upperLevelZone : zoneData [ "UpperZone" ]){
if ( geom2d :: overlaps ( upperLevelZone , pos )){
upperLevel = true ;
}
}
for ( geom2d :: rect < int >& lowerLevelZone : zoneData [ "LowerZone" ]){
if ( geom2d :: overlaps ( lowerLevelZone , pos )){
upperLevel = false ;
}
}
}
2023-08-06 19:00:09 -05:00
std :: string Monster :: GetDeathAnimationName (){
2023-08-13 02:12:19 -05:00
return MONSTER_DATA [ id ]. GetDeathAnimation ();
2023-06-16 09:52:49 -05:00
}
2023-09-11 05:27:36 -05:00
bool Monster :: Hurt ( int damage , bool onUpperLevel , float z ){
if ( ! IsAlive () || onUpperLevel != OnUpperLevel () || HasIframes () || abs ( GetZ () - z ) > 1 ) return false ;
2023-06-19 03:25:01 -05:00
float mod_dmg = damage ;
for ( Buff & b : GetBuffs ( BuffType :: DAMAGE_REDUCTION )){
mod_dmg -= damage * b . intensity ;
}
hp = std :: max ( 0 , hp - int ( mod_dmg ));
2023-07-25 19:48:24 -05:00
if ( lastHitTimer > 0 ){
damageNumberPtr . get () -> damage += int ( mod_dmg );
damageNumberPtr . get () -> pauseTime = 0.4 ;
} else {
2023-09-25 23:51:56 -05:00
damageNumberPtr = std :: make_shared < DamageNumber > ( pos , int ( mod_dmg ));
DAMAGENUMBER_LIST . push_back ( damageNumberPtr );
2023-07-25 19:48:24 -05:00
}
lastHitTimer = 0.05 ;
2023-09-07 01:35:23 -05:00
if ( ! IsAlive ()){
2023-06-11 22:57:43 -05:00
animation . ChangeState ( internal_animState , GetDeathAnimationName ());
2023-09-23 16:27:10 -05:00
} else {
hp = std :: max ( 1 , hp ); //Make sure it stays alive if it's supposed to be alive...
2023-06-11 22:57:43 -05:00
}
2023-09-23 16:27:10 -05:00
GetInt ( Attribute :: HITS_UNTIL_DEATH ) = std :: max ( 0 , GetInt ( Attribute :: HITS_UNTIL_DEATH ) - 1 );
2023-09-08 16:00:07 +00:00
iframe_timer = GetFloat ( Attribute :: IFRAME_TIME_UPON_HIT );
2023-06-15 00:47:11 -05:00
return true ;
2023-06-11 21:19:45 -05:00
}
2023-06-12 00:37:55 -05:00
bool Monster :: IsAlive (){
2023-09-07 01:35:23 -05:00
return hp > 0 ||! diesNormally ;
2023-06-12 00:37:55 -05:00
}
2023-06-15 23:44:34 -05:00
vf2d & Monster :: GetTargetPos (){
return target ;
}
2023-06-12 00:37:55 -05:00
2023-06-11 21:19:45 -05:00
MonsterSpawner :: MonsterSpawner (){}
2023-09-26 05:22:04 -05:00
MonsterSpawner :: MonsterSpawner ( vf2d pos , vf2d range , std :: vector < std :: pair < int , vf2d >> monsters , bool upperLevel , std :: string bossNameDisplay )
: pos ( pos ), range ( range ), monsters ( monsters ), upperLevel ( upperLevel ), bossNameDisplay ( bossNameDisplay ){
2023-06-11 21:19:45 -05:00
}
bool MonsterSpawner :: SpawnTriggered (){
return triggered ;
}
2023-06-22 17:44:51 -07:00
vf2d MonsterSpawner :: GetRange (){
2023-06-11 21:19:45 -05:00
return range ;
}
vf2d MonsterSpawner :: GetPos (){
return pos ;
}
2023-09-07 20:20:21 +00:00
2023-06-11 21:54:51 -05:00
void MonsterSpawner :: SetTriggered ( bool trigger , bool spawnMonsters ){
2023-06-11 21:19:45 -05:00
triggered = trigger ;
2023-06-11 21:54:51 -05:00
if ( spawnMonsters ){
2023-08-13 02:12:19 -05:00
for ( std :: pair < int , vf2d >& monsterInfo : monsters ){
2023-09-19 03:30:18 -05:00
game -> SpawnMonster ( pos + monsterInfo . second , & MONSTER_DATA [ monsterInfo . first ], DoesUpperLevelSpawning ());
2023-06-11 21:54:51 -05:00
}
2023-09-26 05:22:04 -05:00
if ( bossNameDisplay != "" ){
game -> SetBossNameDisplay ( bossNameDisplay );
}
2023-06-11 21:54:51 -05:00
}
2023-06-19 03:25:01 -05:00
}
2023-07-10 19:22:33 -05:00
bool MonsterSpawner :: DoesUpperLevelSpawning (){
return upperLevel ;
}
2023-07-07 04:49:26 -05:00
bool Monster :: OnUpperLevel (){
return upperLevel ;
}
2023-06-19 03:25:01 -05:00
void Monster :: AddBuff ( BuffType type , float duration , float intensity ){
buffList . push_back ( Buff { type , duration , intensity });
}
2023-07-10 18:40:51 +00:00
void Monster :: StartPathfinding ( float pathingTime ){
2023-09-09 07:10:31 -05:00
SetState ( State :: PATH_AROUND );
2023-07-10 18:40:51 +00:00
path = game -> pathfinder . Solve_AStar ( pos , target , 12 , OnUpperLevel ());
if ( path . size () > 0 ){
pathIndex = 0 ;
//We gives this mob 5 seconds to figure out a path to the target.
targetAcquireTimer = pathingTime ;
}
}
void Monster :: PathAroundBehavior ( float fElapsedTime ){
if ( path . size () > 0 ){
//Move towards the new path.
geom2d :: line moveTowardsLine = geom2d :: line ( pos , path [ pathIndex ] * 24 );
if ( moveTowardsLine . length () > 2 ){
2023-09-09 07:10:31 -05:00
SetPos ( pos + moveTowardsLine . vector (). norm () * 100 * fElapsedTime * GetMoveSpdMult ());
2023-07-10 18:40:51 +00:00
if ( moveTowardsLine . vector (). x > 0 ){
facingDirection = RIGHT ;
} else {
facingDirection = LEFT ;
}
} else {
if ( pathIndex + 1 >= path . size ()){
//We have reached the end of the path!
targetAcquireTimer = 0 ;
} else {
pathIndex ++ ;
}
}
} else {
//We actually can't do anything so just quit.
targetAcquireTimer = 0 ;
}
}
2023-06-19 03:25:01 -05:00
std :: vector < Buff > Monster :: GetBuffs ( BuffType buff ){
std :: vector < Buff > filteredBuffs ;
std :: copy_if ( buffList . begin (), buffList . end (), std :: back_inserter ( filteredBuffs ),[ buff ]( Buff & b ){ return b . type == buff ;});
return filteredBuffs ;
2023-07-29 10:21:53 -05:00
}
2023-09-09 07:10:31 -05:00
State :: State Monster :: GetState (){
2023-07-29 10:21:53 -05:00
return state ;
}
2023-09-09 07:10:31 -05:00
void Monster :: SetState ( State :: State newState ){
2023-07-29 10:21:53 -05:00
state = newState ;
2023-08-06 19:00:09 -05:00
}
void Monster :: InitializeStrategies (){
int readCounter = 0 ;
while ( DATA [ "MonsterStrategy" ]. HasProperty ( std :: to_string ( readCounter ))){
2023-09-07 01:35:23 -05:00
std :: string strategyName = DATA [ "MonsterStrategy" ][ std :: to_string ( readCounter )][ "Name" ]. GetString ();
STRATEGY_DATA [ strategyName ] = readCounter ;
STRATEGY_ID_DATA [ readCounter ] = strategyName ;
2023-08-06 19:00:09 -05:00
readCounter ++ ;
}
STRATEGY_DATA . SetInitialized ();
2023-09-07 01:35:23 -05:00
STRATEGY_ID_DATA . SetInitialized ();
2023-08-13 22:32:04 -05:00
}
bool Monster :: HasIframes (){
return iframe_timer > 0 ;
2023-08-13 23:01:23 -05:00
}
float Monster :: GetZ (){
return z ;
2023-09-07 01:35:23 -05:00
}
std :: string Monster :: GetStrategy (){
return STRATEGY_ID_DATA [ strategy ];
2023-09-07 20:20:21 +00:00
}
void Monster :: SetSize ( float newSize , bool immediate ){
if ( immediate ){
size = targetSize = newSize ;
} else {
targetSize = newSize ;
}
2023-09-08 14:36:31 +00:00
}
2023-09-23 13:12:00 -05:00
float & Monster :: GetFloat ( Attribute a ){
if ( attributes . count ( a ) == 0 ){
attributes [ a ] = 0.f ;
}
return std :: get < float > ( attributes [ a ]);
}
int & Monster :: GetInt ( Attribute a ){
if ( attributes . count ( a ) == 0 ){
attributes [ a ] = 0 ;
}
return std :: get < int > ( attributes [ a ]);
}
std :: string & Monster :: GetString ( Attribute a ){
if ( attributes . count ( a ) == 0 ){
attributes [ a ] = "" ;
}
return std :: get < std :: string > ( attributes [ a ]);
}
bool & Monster :: GetBool ( Attribute a ){
if ( attributes . count ( a ) == 0 ){
attributes [ a ] = false ;
}
return std :: get < bool > ( attributes [ a ]);
}
vf2d & Monster :: GetVf2d ( Attribute a ){
if ( attributes . count ( a ) == 0 ){
attributes [ a ] = vf2d {};
}
return std :: get < vf2d > ( attributes [ a ]);
}
2023-09-09 07:10:31 -05:00
void Monster :: SetZ ( float z ){
this -> z = z ;
}
void Monster :: SetStrategyDrawFunction ( std :: function < void ( Crawler * ) > func ){
strategyDraw = func ;
2023-06-11 20:26:41 -05:00
}