#include_function ".\bosslib\StbShotHelpers.dnh"
#include_function ".\bosslib\TimerHelpers.dnh"
#include_function ".\bosslib\SpeedManageHelpers.dnh"

// Call this in @Initialize
sub InitializeStbBoss {
  SetLife(65535);
  LoadGraphic(imgDelay);
  LoadGraphic(imgText);
  LoadGraphic(imgTimer);
  LoadGraphic(imgNiceShot);
  RunStbShotsManager;
  RunMovementManager;
  RunSelfDeleteManager;
  RunTimer;
}

// A task to check if the boss should be deleted due to player death
// or if the required shots are obtained, or if the boss should run.
task RunSelfDeleteManager {
  loop {
    if(GetPlayerEnabled == false){
      DeleteEnemyShot(ALL);
      VanishEnemy;
      return;
    }
    if(GetCurrentPicture == GetTargetShotCount){
      loop(35){ yield; }
      ascent(i in 0..length(StbShots)){
        ObjStbShot_FadeDelete(StbShots[i][0]);
      }
      loop(5){ yield; }
      CreateDeathEffect;
      SetGameSpeed(2);
      VanishEnemy;
    }
    if(Timer == 0){
      while(GetY>GetClipMinY){
        yield;
      }
      ascent(i in 0..length(StbShots)){
        ObjStbShot_FadeDelete(StbShots[i][0]);
      }
      VanishEnemy;
    }
    yield;
  }
}

sub CreateDeathEffect {
  CreateEnemyFromFile(GetCurrentScriptDirectory ~ "bosslib\DeathDummy.dnh", GetX, GetY, 0, 0, 0);
}