#include "./S04_01.dnh"
#include "./S04_02.dnh"

task missiles(){
  if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;} //Default kill to prevent (0,0) spawning
	//{
		let aux;
    
    real r = 0, o = 270, wvel = 0.4;
	//}

  showWarning();
  wait(60*2);
  async{
    PlaySFXV(SFX_CHARGE, 80); 
    loop(30){
      Concentration(bx, by, 60, 800, 5, 8, 9, BLEND_ADD_ARGB, 92, 0, 153, 1);
      wait(2);
    }
  }
  wait(60*1);
  primRect(60); purpwave(); ballCircs();
  while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
    loop(4){
      PlaySFXV(SFX_SHOT02, 43); 

      if(Obj_IsDeleted(objBoss)){return;}
      ascent(int i in 0..16){
        real a = r + 360/16*i;

        aux = CShotA1(bx + 40*cos(o), by + 40*sin(o), 4, a, SHOT_RICE_RED, 5);
        ObjMove_SetAngularVelocity(aux, wvel);
      } 
      
      wait(4);
    }

    wvel *= -1;
    r += 11; o += 360/18; o = NormalizeAngle(o);
    wait(11);
  }
}

task purpwave(){
  //{
		let aux; real r = 0, s = 1, sides;
	//}

  while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 1000){
    if(GetCommonData("Timer", 600) < 27){break;}

    PlaySFXV(SFX_MAGIC02, 55); 
    PlaySFXV(SFX_MAO01, 55); 

    ascent(int j in 0..3){
      ascent(int i in 0..40){
        real a = r + 360/40*i + 360/80*j;

        aux = CScaledShotA1(bx, by, 3.5 - j/1.25, a, SHOT_ORB_GREEN, 5, 1);
        ObjRender_SetBlendType(aux, BLEND_ALPHA_INV);
        Obj_SetRenderPriorityI(aux, 27); ObjShot_SetSpellResist(aux, true);
      }
    }

    r = rand(0,360);
    wait(60 * 4);
  }
  
  async{
    PlaySFXV(SFX_CHARGE, 80); 
    loop(30){
      Concentration(bx, by, 60, 200, 5, 8, 9, BLEND_ADD_ARGB, 208, 61, 245, 1);
      wait(2);
    }
  }

  helpp(); r = 90;
  while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
    
    loop(30){
      PlaySFXV(SFX_MAGIC02, 55); 
      PlaySFXV(SFX_MAO01, 55); 
      PlaySFXV(SFX_SHOT03, 55); 

      if(Obj_IsDeleted(objBoss)){return;}
      
      sides = bx + 120*s; r = posToPlayer(sides, 5);
      ascent(int i in 0..13){
        real a = r + 360/13*i;

        aux = CScaledShotA2(sides, 5, 4, a, 1/5.5, 7.5, SHOT_ORB_GREEN, 5, 1.75);
        ObjRender_SetBlendType(aux, BLEND_ALPHA_INV); Obj_SetRenderPriorityI(aux, 27); 
        ObjShot_SetSpellResist(aux, true); 

        aux = CustomCLaser(sides, 5, 4, a, SHOT_ORB_RED, [1.5, 5, 4, 5], BLEND_ADD_ARGB);
        ObjMove_SetAcceleration(aux, 1/5.5); ObjMove_SetMaxSpeed(aux, 7.5);
        Obj_SetValue(aux, "removable", true); 

      }

      s *= -1;
      wait(60 * 1.5);
    }

  }

}

task helpp(){
  //{
		let aux; real r = 0;
	//}
  
  while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){

    PlaySFXV(SFX_SHOT01, 35); 
    ascent(int i in 0..16){
      real a = r + 360/16*i;

      aux = CScaledShotA1(bx, by, 2.5, a, SHOT_ORB_PURPLE, 5, 1.2);
      Obj_SetRenderPriorityI(aux, 27); 
      ObjShot_SetSpellResist(aux, true);
    }

    r += 360/32 + rand(-11, 11);
    wait(60 * 1);
  }
}
