task missiles(){
  if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0){return;} //Default kill to prevent (0,0) spawning
	//{
		let aux; let scale;
    
    let r = -90; let rain = 0;
    let numBullets = 10; let z = [3.125, -6.25];
	//}
	
  for(let i = 0; i <= 30; i++){
    PlaySFXV(SFX_SHOT03, 76);
    ascent(j in -3..4){
      let a = r + Interpolate_Smooth(0, 40, i/30)*j;

      CShotA1(bx, by, 4, a, ICE_RED, 5);
    }

    wait(3);
  }

  circles(); Obj_SetValue(objBoss, "cast", 2); waves();
  while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
    loop(7){
      if(Obj_IsDeleted(objBoss)){break;}

      PlaySFXV(SFX_SHOT03, 76);
      ascent(i in -3..4){
        let a = r + 40*i;

        aux = CShotA1(bx, by, 4, a, ICE_RED, 5); ObjShot_SetSpellResist(aux, true);
        rotateRandom(aux, rand(6, 11)); wallBang(aux);
      }

      r += 0.6;
      wait(4);
    }

    r += 11;
    wait(8);
  }
}

task waves(){
  //{
		let aux = []; let pos;
    
    let r = -90; let n = 1;
    let wvel = -0.5; let z;
	//}

  while(ObjEnemyBossScene_GetInfo(GetCommonData("objScene", ID_INVALID), INFO_TIMER) > 25){yield;}

  while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
    if(Obj_IsDeleted(objBoss)){break;}

    pos = [px, py];
    loop(15){
      PlaySFXVDelay(SFX_LASER00, 40, 30);
      aux = CreateDuoSTLaser(pos[0], pos[1] + rand(-15, 15), rand(-6, 6)+90, 90, 20, 60, ST_LASER_ANIMATED_GREEN, [36, 50]);
      for each(let dad : aux){
        the_baddest(dad, 800, 36);
      }

      wait(7);
    }
    wait(60);

    pos = [px, py];
    loop(15){
      PlaySFXVDelay(SFX_LASER00, 40, 30);
      aux = CreateDuoSTLaser(pos[0] + rand(-15, 15), pos[1], rand(-6, 6), 90, 20, 60, ST_LASER_ANIMATED_MINT, [36, 50]);
      for each(let dad : aux){
        the_baddest(dad, 800, 36);
      }

      wait(7);
    }

    wait(60);
  }
}

task circles(){
  //{
		let aux; let scale;
    
    let r = -90; let n = 1;
    let wvel = -0.5; let z;
	//}

  while(ObjEnemyBossScene_GetInfo(GetCommonData("objScene", ID_INVALID), INFO_TIMER) > 40){yield;}

  while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
    if(Obj_IsDeleted(objBoss)){break;}

    PlaySFXV(SFX_THICK, 78);
    z = rand(0, 360);
    ascent(i in 0..11){
      let a = r + 360/11*i;

      aux = CShotA1(bx, by, 3, a, LARGE_CRYSTAL_AQUA, 20); ObjShot_SetSpellResist(aux, true); ObjMove_SetAngularVelocity(aux, wvel);
      aux = CustomFlowerA1(bx, by, 3, a, CRYSTAL_INV_AQUA, [2, z, 1, 8*n, 15, 15, 1.2], BLEND_ALPHA); ObjMove_SetAngularVelocity(aux, wvel);

      n *= -1;
    } 

    r += 360/22 + rand(-5,5); r = NormalizeAngle(r);

    wvel *= -1;
    wait(40);
  }
}

//----------------------------------------------------------------------------------------------------
task rotateRandom(obj, vol){
  let angz = ObjRender_GetAngleZ(obj);
  loop{
    if(Obj_IsDeleted(obj)){break;}

    ObjRender_SetAngleZ(obj, angz); angz += vol; angz = NormalizeAngle(angz);
    yield;
  }
}

task wallBang(obj){
  while(getx(obj) > 0 && getx(obj) < stgw){yield;}
  if(Obj_IsDeleted(obj)){return;}

  if(getx(obj) <= 0){setx(obj, 0); seta(obj, 180-geta(obj));}
  else if(getx(obj) >= 0){setx(obj, stgw); seta(obj, 180-geta(obj));}
  ObjMove_AddPatternA3(obj, 5, NO_CHANGE, NO_CHANGE, -1/20, 0, 3, ICE_INV_RED);

}