#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell 2 - Monotony \"Sloth's Barrage\""]
#Text[""]
#Background["./../BG.txt"]
#Player["./../TrickyPlayer/Tricky.dnh"]
#System["./../system/Default_System.dnh"]

#include "./../LibRefs.dnh"
#include "./../lib/Cutin/Cutin.txt"
#include "./task_folder/S02.dnh"

let objBoss;
let count = 0;
let objScene = GetEnemyBossSceneObjectID();

@Event{
  alternative(GetEventType())
  case(EV_REQUEST_LIFE){
    SetScriptResult(2000);
  }
  case(EV_REQUEST_TIMER){
    SetScriptResult(57);
  }
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(false);
	}
  case(EV_REQUEST_SPELL_SCORE){
   SetScriptResult(10000000);
  }
}

@Initialize{
  objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS); 
  ObjEnemy_Regist(objBoss); 
	
  //if(!GetCommonData("music", false)){BGM_Play("Harvest the Tres", 68, [0, 60*2 + 38.25]); SetCommonData("music", true);}

  ObjMove_SetDestAtFrameWeight(objBoss, gx, gy-100, 60); 
	StartSpell;
	TDrawLoop;
  TFinalize;
}

@MainLoop{
  ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
  ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);

  if(count == 0){
    phases;
    count = 0;
  } 
    
  count++;
  yield;
}

task StartSpell{
	wait(50); ObjEnemyBossScene_StartSpell(objScene); wait(30);
	let cut = GetCurrentScriptDirectory() ~ "../img/heci.png";

	ObjCutin_SetSpellcardS4("Monotony \"Sloth's Barrage\"", cut, "C_YOUMU", 223, 7, 7);
	//ObjCutin_SetSpellcardS4("Oh my God, they have it! \"S Q U A R E S\"", cut, "C_YOUMU", 223, 7, 7);
	ObjCutin_LaunchS3("C_YOUMU", cut, "Hard");

  SetCommonData("objScene", objScene); 

  /*
  ascent(i in 0..5){
    NotifyEventAll(EV_USER_SYSTEM + 3, Interpolate_Linear(255, 100, i/4)); wait(2);
  }
  */
}

task phases{
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	wait(60*4); 

  //nue
	missiles(); 
}

task TDrawLoop{
  renderKagerouDDC(objBoss); renderSeigaAura(objBoss);
  EnMarikin(objBoss);
  DrawName(objBoss, "Drekareen", [199, 5, 5], [102, 0, 0], [102, 36]);
}

task Delete(){ 
  Obj_Delete(objBoss);
}

task TFinalize {
  while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;} NotifyEventAll(EV_USER_SYSTEM + 2, NULL);
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) + ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
		NotifyEventAll(EV_USER_SYSTEM + 1, true, 0); //0 = life; 1 = spell
		AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
  }
  else{NotifyEventAll(EV_USER_SYSTEM + 1, false);}
	
  Delete(); SetAutoDeleteObject(true);

  CloseScript(GetOwnScriptID());
  return;
}