#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Shizuha Spell"]

#include"./../Functions/Cutin/Cutin.txt"
#include"./LoadGraphics.txt"

let bossObj;
let bossX;
let bossY;
let damage = 0;
let global = 0;

let card = GetCurrentScriptDirectory ~ "./../Sounds/se_cat00.wav";
let kira = GetCurrentScriptDirectory ~ "./../Sounds/se_kira02.wav";
let exp = GetCurrentScriptDirectory ~ "./../Sounds/se_noise.wav";
let sho = GetCurrentScriptDirectory ~ "./../Sounds/se_tan00b.wav";
#include"./DrawBoss.txt"

@Initialize{
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	LoadShotData;
	animateBossS;
	mainTask;
	TEnd;

	LoadSound(exp);
	LoadSound(sho);
	LoadSound(card);
	LoadSound(kira);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(600);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}
	case(EV_START_BOSS_SPELL){
		let path = GetCurrentScriptDirectory ~ "./../System/Minoriko_System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);yield;}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);

	if(damage==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(damage==1){ObjEnemy_SetDamageRate(bossObj, 15, 5);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);
	yield;}

@Finalize{}

task mainTask{wait(1);TEtama;PlaySE(card);
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY-120,5,3);
	ObjCutin_SetSpellcardS4("Autumn Breeze \"Momiji leaf-fall\"", cutin1, "KANAKO", 255, 64, 0);
	ObjCutin_LaunchS3("KANAKO", cutin1, "normal");
	TSpellBG;wait(120);damage=1;TBreeze;wait(240);
	animateBossSAura;
		TBossWind;SetCommonData("wind",1);}

task TBreeze{ PlaySE(sho);
		if(Obj_IsDeleted(bossObj)){break;} 
		ascent(i in 0..36){ascent(a in 0..6){
			let s = CreateShotA1(bossX,bossY,1+a,i*10+4,378,30);
			ObjShot_SetSpellResist(s,true);
			manage(s);}}

	task manage(obj){
		wait(120);
		if(!Obj_IsDeleted(obj)){ObjMove_SetSpeed(obj,0);PlaySE(kira);
		let s = CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),rand(0.4,1.4),rand(80,100),rand(371,373),30);
		ObjShot_SetSpellResist(s,true);
		wait(10);Obj_Delete(obj);
		let r = rand(-5,5);
		while(GetCommonData("wind",0) == 0){yield;}
		let angle = ObjMove_GetAngle(s); SetSpeed(s);
		while(!Obj_IsDeleted(bossObj)){
			ObjMove_SetAngle(s,angle);
			if(global==1){
				if(angle >= 120+r){angle = 120+r;}
				if(ObjMove_GetX(s) <= -5){ObjMove_SetX(s,389);}
				if(ObjMove_GetY(s) >= 453){ObjMove_SetY(s,-5);}
				angle+=1;}
			if(global==2){
				if(angle <= 60+r){angle = 60+r;}
				if(ObjMove_GetX(s) >= 389){ObjMove_SetX(s,-5);}
				if(ObjMove_GetY(s) >= 453){ObjMove_SetY(s,-5);}
				angle-=1;}
		yield;}}}
	task SetSpeed(obj){ loop(90){
		ObjMove_SetSpeed(obj,ObjMove_GetSpeed(obj)+0.02);
		yield;}}}

task se_wind{wait(30);PlaySE(exp);}

task TBossWind{ let y = 0;
	while(GetCommonData("wind",0) == 0){yield;}
	while(!Obj_IsDeleted(bossObj)){
	y = 0; global = 1;se_wind;
	loop(141){
		if(Obj_IsDeleted(bossObj)){break;}
		ObjMove_SetDestAtWeight(bossObj,bossX-550,bossY+y,1,20);
		if(ObjMove_GetX(bossObj) < -200){ObjMove_SetX(bossObj,584);}
	y+=0.1; yield;}
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY-120,1,5);
	wait(180);
	y = 0; global = 2;se_wind;
	loop(141){
		if(Obj_IsDeleted(bossObj)){break;}
		ObjMove_SetDestAtWeight(bossObj,bossX+550,bossY+y,1,20);
		if(ObjMove_GetX(bossObj) > 584){ObjMove_SetX(bossObj,-200);}
	y+=0.1; yield;}
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY-120,1,5);
	wait(180);}}