#include "Monster.h" #include "MonsterStrategyHelpers.h" #include "DEFINES.h" #include "Crawler.h" #include "utils.h" #include "safemap.h" #include "Effect.h" #include "FallingDebris.h" INCLUDE_game INCLUDE_BULLET_LIST INCLUDE_ANIMATION_DATA INCLUDE_MONSTER_NAME_DATA typedef Attribute A; void Monster::STRATEGY::SLIMEKING(Monster&m,float fElapsedTime,int strategyNumber){ float bulletSpd=ConfigFloat("BulletSpd")/100*24; m.F(A::SHOOT_RING_TIMER)=std::max(0.f,m.F(A::SHOOT_RING_TIMER)-fElapsedTime); m.F(A::SHOOT_RING_DELAY)=std::max(0.f,m.F(A::SHOOT_RING_DELAY)-fElapsedTime); m.F(A::JUMP_LANDING_TIMER)=std::max(0.f,m.F(A::JUMP_LANDING_TIMER)-fElapsedTime); const auto ShootBulletRing=[&](float angleOffset){ int bulletCount=ConfigInt("Phase1.RingBulletCount"); for(int i=0;i(m.GetPos(),vf2d{cos(angle),sin(angle)}*bulletSpd,6,ConfigInt("ProjectileDamage"),m.OnUpperLevel(),false,YELLOW,vf2d{6,6})); } }; const auto Landed=[&ShootBulletRing,&m](int currentPhase){ if(currentPhase==1){ ShootBulletRing(m.F(A::SHOOT_RING_OFFSET)); } }; const auto TransitionPhase=[&](int newPhase){ const int MAX_ATTEMPTS=100; //Maximum number of tries to find a valid location. Player*player=game->GetPlayer(); const auto PositionInRangeOfPlayer=[&player](vf2d&pos,float radius){ return geom2d::line(player->GetPos(),pos).length()<=player->GetSizeMult()*12*2+radius; }; const auto SpawnMonsterFromConfig=[&](int phase){ std::string spawnMonster=ConfigStringArr("Phase"+std::to_string(phase)+".MonsterSpawnOnChange",0); int spawnCount=ConfigIntArr("Phase"+std::to_string(phase)+".MonsterSpawnOnChange",1); for(int i=0;iGetSizeMult()*12);attempts++){ randomAngle=util::random(2*PI); spawnPos=m.pos+vf2d{cos(randomAngle),sin(randomAngle)}*m.GetSizeMult()*12; } game->SpawnMonster(spawnPos,MONSTER_NAME_DATA[spawnMonster]); } }; switch(newPhase){ case 2:{ SpawnMonsterFromConfig(2); }break; case 3:{ SpawnMonsterFromConfig(3); }break; case 4:{ SpawnMonsterFromConfig(4); }break; case 5:{ }break; } }; const auto StartJump=[&](float jumpDuration,vf2d targetPos,float recoveryTime){ m.V(A::JUMP_ORIGINAL_POS)=m.GetPos(); m.F(A::JUMP_ORIGINAL_LANDING_TIMER)=m.F(A::JUMP_LANDING_TIMER)=jumpDuration; m.V(A::JUMP_TARGET_POS)=targetPos; m.F(A::RECOVERY_TIME)=recoveryTime; m.state=State::JUMP; }; if(m.state==State::RECOVERY){ m.F(A::RECOVERY_TIME)=std::max(0.f,m.F(A::RECOVERY_TIME)-fElapsedTime); if(m.F(A::RECOVERY_TIME)==0){ m.state=State::NORMAL; } return; } if(m.state==State::JUMP){ float jumpLandingTimerRatio=m.F(A::JUMP_LANDING_TIMER)/m.F(A::JUMP_ORIGINAL_LANDING_TIMER); if(m.GetPos().x>game->GetPlayer()->GetPos().x){ m.SetX(std::max(game->GetPlayer()->GetPos().x,m.GetPos().x-ConfigInt("JumpMoveSpd")*game->GetElapsedTime())); } else if(m.GetPos().xGetPlayer()->GetPos().x){ m.SetX(std::min(game->GetPlayer()->GetPos().x,m.GetPos().x+ConfigInt("JumpMoveSpd")*game->GetElapsedTime())); } if(m.GetPos().y>game->GetPlayer()->GetPos().y){ m.SetY(std::max(game->GetPlayer()->GetPos().y,m.GetPos().y-ConfigInt("JumpMoveSpd")*game->GetElapsedTime())); } else if(m.GetPos().yGetPlayer()->GetPos().y){ m.SetY(std::min(game->GetPlayer()->GetPos().y,m.GetPos().y+ConfigInt("JumpMoveSpd")*game->GetElapsedTime())); } if(m.F(A::JUMP_LANDING_TIMER)>=m.F(A::JUMP_ORIGINAL_LANDING_TIMER)/2){ m.SetZ(util::lerp(0,ConfigInt("JumpHeight"),1-jumpLandingTimerRatio)); }else{ m.SetZ(util::lerp(0,ConfigInt("JumpHeight"),jumpLandingTimerRatio*2)); } if(m.F(A::JUMP_LANDING_TIMER)==0){ m.state=State::RECOVERY; game->SetupWorldShake(0.6); geom2d::linelineToPlayer(m.GetPos(),game->GetPlayer()->GetPos()); float dist=lineToPlayer.length(); for(int i=0;i<200;i++){ float randomDir=util::random(2*PI); game->AddEffect(std::make_unique(m.GetPos()+vf2d{cos(randomDir),sin(randomDir)}*m.GetSizeMult()*8,util::random(1),"circle.png",m.OnUpperLevel(),vf2d{1,1},0.5,vf2d{cos(randomDir)*util::random(5),sin(randomDir)*-util::random(15)-5}*30,BLACK),true); } if(dist<12*m.GetSizeMult()){ game->GetPlayer()->Hurt(ConfigInt("JumpAttackDamage"),m.OnUpperLevel(),m.GetZ()); if(dist<0.001){ float randomDir=util::random(2*PI); lineToPlayer={m.GetPos(),m.GetPos()+vf2d{cos(randomDir),sin(randomDir)}*1}; } game->GetPlayer()->Knockback(lineToPlayer.vector().norm()*ConfigInt("JumpKnockbackFactor")); } Landed(m.phase); m.SetStrategyDrawFunction([](Crawler*game){}); } else if(m.F(A::JUMP_LANDING_TIMER)<=ConfigFloat("JumpWarningIndicatorTime")){ m.SetStrategyDrawFunction([&](Crawler*game){ Decal*dec=ANIMATION_DATA["range_indicator.png"].GetFrame(game->GetElapsedTime()).GetSourceImage()->Decal(); game->view.DrawRotatedDecal(m.GetPos(),dec,0,dec->sprite->Size()/2,vf2d{m.GetSizeMult(),m.GetSizeMult()},RED); }); } return; } switch(m.phase){ case 0:{ m.size=ConfigInt("Phase1.Size")/100; m.diesNormally=false; m.F(A::IFRAME_TIME_UPON_HIT)=0; m.iframe_timer=ConfigFloat("Phase5.IframeTimePerHit"); m.phase=1; }break; case 1:{ if(m.hp<=m.maxhp*ConfigFloat("Phase2.Change")/100){ m.phase=2; m.SetSize(ConfigFloat("Phase2.Size")/100,false); TransitionPhase(m.phase); return; } if(m.F(A::SHOOT_RING_TIMER)==0){ if(m.I(A::PATTERN_REPEAT_COUNT)>=ConfigInt("Phase1.JumpAfter")){ StartJump(ConfigFloat("Phase1.AirborneTime"),game->GetPlayer()->GetPos(),ConfigFloat("Phase1.LandingRecoveryTime")); m.I(A::PATTERN_REPEAT_COUNT)=0; return; } m.I(A::SHOOT_RING_COUNTER)=ConfigInt("Phase1.ShootRingCount")-1; m.F(A::SHOOT_RING_DELAY)=ConfigFloat("Phase1.ShootRingDelay"); ShootBulletRing(m.F(A::SHOOT_RING_OFFSET)); m.F(A::SHOOT_RING_TIMER)=ConfigFloat("Phase1.ShootRepeatTime"); m.B(A::SHOOT_RING_RIGHT)=bool(rand()%2); m.I(A::PATTERN_REPEAT_COUNT)++; } if(m.I(A::SHOOT_RING_COUNTER)>0){ if(m.F(A::SHOOT_RING_DELAY)==0){ m.I(A::SHOOT_RING_COUNTER)--; m.F(A::SHOOT_RING_DELAY)=ConfigFloat("Phase1.ShootRingDelay"); if(m.B(A::SHOOT_RING_RIGHT)){ m.F(A::SHOOT_RING_OFFSET)+=util::degToRad(ConfigFloat("Phase1.RingOffset")); }else{ m.F(A::SHOOT_RING_OFFSET)-=util::degToRad(ConfigFloat("Phase1.RingOffset")); } ShootBulletRing(m.F(A::SHOOT_RING_OFFSET)); } } }break; case 2:{ if(m.hp<=m.maxhp*ConfigFloat("Phase3.Change")/100){ m.phase=3; m.SetSize(ConfigFloat("Phase3.Size")/100,false); TransitionPhase(m.phase); return; } }break; case 3:{ if(m.hp<=m.maxhp*ConfigFloat("Phase4.Change")/100){ m.phase=4; m.SetSize(ConfigFloat("Phase4.Size")/100,false); TransitionPhase(m.phase); return; } }break; case 4:{ if(m.hp<=0){ m.phase=5; m.F(A::IFRAME_TIME_UPON_HIT)=1; TransitionPhase(m.phase); return; } }break; } }