#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["\"Every coin has two sides [Normal]\""]
#Text["Spell3N"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System2.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/ZUNShot_Const.txt"
#include"./system/Default_Effect.Txt"


let objBoss;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let fog = 0;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,0];
let xis = 0;
let yis = 0;
let change = false;
let phase = 1;
@Initialize
{
SetBoss(true);
}

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

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(2000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(50,0,180);
	DamageRateAtFrame(75,0,1380);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("\"Every coin has two sides [Normal]\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(60);
	TShot1;
	wait(120);
	TChange;
	}
//----------------------------------------------------

task TShot1{
	let c = 0;
	maple(3);
	wait(110);
	while(!Obj_IsDeleted(objBoss)){
		let r1 = rand(-25,25);
		PlaySound("Shot1",90,0);
		ascent(i in 0..7){
				let dir = i*360/7+r1;
				if(phase==1){
				let shot = ShotA1(GetEnemyX+0*cos(dir),GetEnemyY+0*sin(dir),2.5,dir,243,0,8);
				Manage(shot);
				}
				if(phase==2){
				let shot = ShotA1(GetEnemyX+30*cos(dir),GetEnemyY+30*sin(dir),2.5,dir,294,0,8);
				Manage(shot);
				}
		}
		c++;
			if(c%16==0 && c>16){
				PlaySound("Shot2",90,0);
				ascent(i in 0..60){
						if(phase==1){
						let shot = ShotA1(GetEnemyX,GetEnemyY,1.25,i*6+angleToPlayer,294,0,8);
						Manage(shot);
						}
						if(phase==2){
						let shot = ShotA1(GetEnemyX,GetEnemyY,1.25,i*6+angleToPlayer,243,0,8);
						Manage(shot);
						}
				}
			}
			if(c%16==0){
				PlaySound("BulletWave",98,0);
				ascent(i in -4..5){
						if(phase==1){
						let shot = ShotA2(GetEnemyX,GetEnemyY,4,i*4+angleToPlayer,-4/60,1,293,0,8);
						Manage(shot);
						}
						if(phase==2){
						let shot = ShotA2(GetEnemyX,GetEnemyY,4,i*4+angleToPlayer,-4/60,1,76,0,8);
						Manage(shot);
						}
				}
			}
		wait(8);
	}
}

task TChange{
	while(!Obj_IsDeleted(objBoss)){
	wait(120);
	TMovement(35,5,2);
	wait(120);
	maple(2);
	wait(60);
	PlaySound("Boon1",100,0);
	change = true;
	yield;
	change = false;
	phase = 2;
	wait(120);
	TMovement(35,5,2);
	wait(120);
	maple(2);
	wait(60);
	PlaySound("Boon1",100,0);
	change = true;
	yield;
	change = false;
	phase = 1;
	}
}

task Manage(shot){
	let t = 0;
	while(!Obj_IsDeleted(shot)){
		if(change== true && t==0){
		t=1;
		ReverseY;
		}
		yield;
	}
	task ReverseY{
		let graphic = ObjShot_GetImageID(shot);
				ascent(i in 0..91){
				ObjRender_SetAngleY(shot,i*2);
				if(i==45){
					ObjShot_SetIntersectionEnable(shot,false);
					if(graphic == 243){
					ObjShot_SetGraphic(shot,294);
					}
					if(graphic == 294){
					ObjShot_SetGraphic(shot,243);
					}
					if(graphic == 76){
					ObjShot_SetGraphic(shot,293);
					}
					if(graphic == 293){
					ObjShot_SetGraphic(shot,76);
					}
				}
				yield;
				}
				ObjShot_SetIntersectionEnable(shot,true);
				t = 0;
			}
	}

//----------------------------------------------------

task TRender
{
	DrawBoss;
}

//----------------------------------------------------

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		EndBoss(1);
		yield;
		CloseScript(GetOwnScriptID());
	}