#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["yy_s2"]

#include"./shot/ZUNShot_Const.txt"
#include"./function/index.txt"

//----------------------------------------------------
//global variables
//----------------------------------------------------
let objBoss;
let objScene = GetEnemyBossSceneObjectID();
let circles = [];


@Event {

	alternative(GetEventType())
	case(EV_REQUEST_LIFE) {
		SetScriptResult(3750);
	}
	
	case(EV_REQUEST_TIMER){
		SetScriptResult(35)
	}
	
	case(EV_REQUEST_SPELL_SCORE) {
		SetScriptResult(50000);
	}
	
}

@Initialize {
	TMainTask();
}

@MainLoop {
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 24);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 26);
	
	yield;
}

task TMainTask () {
	objBoss = TDrawBoss();
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	ObjMove_SetDestAtWeight(objBoss, halfStageFrameWidth, GetStgFrameHeight() / 3, 10, 15);
	
	while (IsPlayerSpellActive == true || ObjMove_GetSpeed(objBoss) > 0) { yield; }
	
	TCharge01(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), "MAGENTA", "ROSE", "BRIGHT", 6);
	FWait(60);
	ObjMove_SetDestAtWeight(objBoss, halfStageFrameWidth, GetStgFrameHeight() / 4, 10, 15);
	ObjEnemyBossScene_StartSpell(objScene);
	TDrawCutin01(objBoss, "Boundary Sign \"Border of Zone and Apathy\"");
	TEnd();
	FWait(120);
	TShoot01();
	FWait(60);
	ObjEnemy_SetDamageRate(objBoss, 100, 100);
}

task TShoot01 () {
	let spin = 0;
	let waitTime = 3;
	let dir = 1;
	let count = 0;
	let loopTimes = 180 / waitTime;
	
	while (ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0) {
		TCharge01(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), "YELLOW", "LIME", "BRIGHT", 6);
		FWait(60);
		FBreakIfFalse(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0);
		
		loop (loopTimes) {
		
			let angle = 0;
			while (angle < 360) {
				let sum = angle + (spin * 4.73 * dir);
				
				ascent (i in 0..5) {
					let obj = CreateShotA2(ObjMove_GetX(objBoss) + 75 * cos(sum), ObjMove_GetY(objBoss) + 75 * sin(sum), 8, sum, -(8 / 15), 0, A_PELLET_YELLOW, 5);
					ObjMove_AddPatternA1(obj, 15, (i / 4) + 2, NO_CHANGE);
				}
				
				angle += 360 / 3;
			}
			
			FPlaySoundDelay(objBoss, "script/yukari_yakumo_fuchsia/se/tan00.wav", 5);
			spin += waitTime;
			count ++;
			
			if (count % (loopTimes / 4) == 0) {
				SMovement(3.75, 10);
			}
			
			if (count % (loopTimes / 10) == 0) {
				let randResult = rand(0, 360 / 12);
				
				let angle = 0;
				while (angle < 360) {
					CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3.625, angle + randResult, A_LARGE_ORANGE, 15);
					angle += 360 / 20;
				}
				
				FPlaySoundDelay(objBoss, "script/yukari_yakumo_fuchsia/se/tan02.wav", 15);
			}
			
			FWait(waitTime);
			FBreakIfFalse(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0);
		}
		
		dir = -dir;
		ObjMove_SetDestAtWeight(objBoss, halfStageFrameWidth, GetStgFrameHeight() / 3, 15, 5);
		FWait(60);
		FBreakIfFalse(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0);
		SetCommonData("bossAtkAnim", true);
		TCharge01(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), "BLUE", "INDIGO", "BRIGHT", 6);
		FWait(60);
		FBreakIfFalse(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0);
		
		loop (60) {
			
			let angle = -45;
			while (angle <= 45) {
				FGravityShot(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(2, 8) / 2.25, angle + rand(0, 90 / 4) - 90 - 11.25, 0.025, GetAngleToPlayer(objBoss), PELLET_BLUE, 5);
				angle += 90 / 4;
			}
			
			FPlaySoundDelay(objBoss, "script/yukari_yakumo_fuchsia/se/don20.wav", 5);
		}
		
		FBreakIfFalse(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0);
		ObjMove_SetDestAtWeight(objBoss, halfStageFrameWidth, GetStgFrameHeight() / 4, 15, 5);
		FWait(195);
		FBreakIfFalse(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0);
		SetCommonData("bossAtkAnim", false);
	}
	
}

task SMovement (weight, speed) {
	let resultx = rand(0, 1);
	resultx = round(resultx);
	let resulty = rand(0, 1);
	resulty = round(resulty);
	let posx = rand(150, -150);
	
	if (posx < 75 && posx > -75) {
	
		if (resultx == 1) {
			SetCommonData("toRight", GetCommonData("toRight", 0) + 1);
			
			if (GetCommonData("toRight", 0) % 4 == 0) {
				posx = -75;
			} else {
				SetCommonData("countForRight", GetCommonData("countForRight", 0) + 1);
				posx = 75;
				
				if (GetCommonData("countForRight", 0) % 2 == 0 || GetCommonData("countForRight", 0) % 7 == 0) {
					posx = -75;
				}
				
			}
			
		} else {
			posx = -75;
		}
		
	}
	
	if ((ObjMove_GetX(objBoss) + posx) <= 50 || (ObjMove_GetX(objBoss) + posx) >= (GetStgFrameWidth() - 50)) {
		posx= - posx;
	}
	
	let posy = rand(25, -25);
	
	if (posy < 25 && posy > -25) {
	
		if (resulty == 1) {
			SetCommonData("toDown", GetCommonData("toDown", 0) + 1);
			
			if (GetCommonData("toRight", 0) % 4 == 0) {
				posy = -15;
			} else {
				SetCommonData("countForDown", GetCommonData("countForDown", 0) + 1);
				posy = 15;
				
				if (GetCommonData("countForDown", 0) % 2 == 0 || GetCommonData("countForDown", 0) % 6 == 0) {
					posy = -15;
				}
				
			}
		
		}
		
	}
	
	if ((ObjMove_GetY(objBoss) + posy) <= 32 || (ObjMove_GetY(objBoss) + posy) >= GetStgFrameHeight() / 3) {
		posy = -posy;
	}
	
	ObjMove_SetDestAtWeight(objBoss, ObjMove_GetX(objBoss) + posx, ObjMove_GetY(objBoss) + posy, weight, speed);
}

task TEnd () {

	while (ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0) { yield; }
	
	SetCommonData("bossAtkAnim", false);
	TExplosionA(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 10, 0.5);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(objBoss);
	
	loop (60) {
		yield;
		DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
	}
	
	CloseScript(GetOwnScriptID());
	return;
}



	
	
	
	
	
	
	
	
	
	
	
	
	
	




