#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell 3 - Ofuda Dragonfly \"Overwhelming Luck\""]
#Text[""]
#Background["./../BG.txt"]
#Player["./../player/DT_PLAYERS/Reimu/TypeB/Reimu.txt", "./../player/DT_PLAYERS/Marisa/TypeA/Marisa.txt", "./../player/DT_PLAYERS/Sakuya/TypeB/Sakuya.txt", "./../player/gt_medicine/PracticeP.txt"]
#System["./../system/Default_System.dnh"]

#include "./../LibRefs.dnh"
#include "./../lib/Cutin/Cutin.txt"
#include "./task_folder/S03.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_SPELL_SCORE){
   SetScriptResult(1000000);
  }
}

@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-110, 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/cuts01.png";

	ObjCutin_SetSpellcardS4("Ofuda Dragonfly \"Overwhelming Luck\"", cut, "C_YOUMU", 21, 209, 65);
	ObjCutin_LaunchS3("C_YOUMU", cut, "Hard");

  SetCommonData("objScene", objScene);
}

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

  //nue
	missiles(); 
}

task TDrawLoop{
  renderHinaMoF(objBoss); renderHinaAura(objBoss);
  EnMarikin(objBoss);
  ObjRender_SetScaleXYZ(objBoss, 1.15, 1.1, 0);
  DrawName(objBoss, "Hina Kagiyama", [240, 117, 166], [170, 9, 9], [104, 30]);
}

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, 1); //0 = life; 1 = spell
		AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
  }
  else{NotifyEventAll(EV_USER_SYSTEM + 1, false);}
	
  Delete(); SetAutoDeleteObject(true);

  CloseScript(GetOwnScriptID());
  return;
}