#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Bonus Spell Card"]
#Text["Try to capture it"]
#Background["./BG.txt"]
#Player[DEFAULT]
#BGM["./Shou.mp3"]
#System["./system/Default_System.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 idle = true;
let atk = false;
let fog = 0;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,0];
let phase = [0,0,0,0];
@Initialize
{
SetBoss(true);
SetPlayerLife(-1);
SetPlayerSpell(0);
}

@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(1750);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(53);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(true);
	}
	case(EV_REQUEST_IS_LAST_SPELL)
	{
		SetScriptResult(true);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(0,0,240);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy,10,7);
	Cutin("\"The Everlasting Vajra\"",15,"SHOU");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	}
//----------------------------------------------------

task TShot1{
	let ang = rand(0,360);
	maple(3);
	wait(120);
	PlaySound("Boon1",100,0);
	PlaySound("Laser2",100,90);
	ObjectionLaser(ang,0);
	ObjectionLaser(ang+180,1);
	wait(120);
	maple(3);
	wait(90);
	phase[0] = 1;
	wait(540);
	maple(3);
	wait(90);
	phase[1] = 1;
	wait(600);
	maple(3);
	wait(90);
	phase[2] = 1;
	wait(600);
	maple(3);
	wait(60);
	phase[3] = 1;
}

task ObjectionLaser(dir,type){
	let laser = PagodarLaser(GetEnemyX,GetEnemyY,dir,700,90,12000,"GREEN");
	let c = 0;
	let p = [0,0];
	let p2 = dir;
	let way = 1;
		while(!Obj_IsDeleted(laser)){
		ObjMove_SetAngle(laser,dir);
		dir+=0.4;
		c++;
				if(phase[0]==1 && c%45==0 && ObjEnemy_GetInfo(objBoss,INFO_LIFE)>10){
				PlaySound("BulletWave",95,0);
				p = GetLineBorderPoint(GetEnemyX, GetEnemyY, GetEnemyX+1000*cos(dir), GetEnemyY+1000*sin(dir));
					ascent(i in -4..5){
					let shot = ScalingBullet(p[0],p[1],0,getDotAngle(GetEnemyX,GetEnemyY,p[0],p[1])+i*30,377,68,0.8,0,12);
					ObjMove_AddPatternA2(shot,0,NO_CHANGE,NO_CHANGE,0.01,0,1.5);
					}
				}
				if(phase[1]==1 && c%10==type*5 && ObjEnemy_GetInfo(objBoss,INFO_LIFE)>10){
				p2 += 17;
				PlaySound("Shot6",95,0);
				ShotA2(GetEnemyX+60*cos(p2),GetEnemyY+60*sin(p2),0.5,p2,0.015,3,345,0,12);
				}
				if(phase[2]==1 && c%5==0 && ObjEnemy_GetInfo(objBoss,INFO_LIFE)>10){
				p = GetLineBorderPoint(GetEnemyX, GetEnemyY, GetEnemyX+1000*cos(dir), GetEnemyY+1000*sin(dir));
				PlaySound("Shot1",85,0);
				ShotA2(p[0],p[1],1,getDotAngle(GetPlayerX,GetPlayerY,p[0],p[1]),0.015,3,116,0,12);
				}
				if(phase[3]==1 && c%120==0 && ObjEnemy_GetInfo(objBoss,INFO_LIFE)>10){
					if(type==0){
					PlaySound("Laser2",100,0);
						ascent(i in 0..18){
						let curve = CurvyLaser(GetEnemyX,GetEnemyY,1,i*20+dir,8,25,510,0);
						ObjMove_AddPatternA2(curve,0,NO_CHANGE,NO_CHANGE,0.05,0.5*way,4);
						}
						way = -way;
					}
				}
		yield;
		}
}

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

task TRender
{
	DrawBoss;
}

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

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0)
		{
		AddScore(ObjEnemyBossScene_GetInfo(objScene,INFO_SPELL_SCORE));
		let dis = 0;
		let px = GetEnemyX;
		let py = GetEnemyY;
		StartSlow(TARGET_ALL,30);
		ClearBullet(90,10);
		TAccel(50,10,0.02,120);
		MapleExplode(180,1,2,5);
		PlaySound("enemoff",95,0);
		wait(105);
		StopSlow(TARGET_ALL);
		PlaySound("enemoff",100,0);
		MapleExplode(20,50,1,6);
		Obj_Delete(objBoss);
		wait(30);
		SetAutoDeleteObject(true);
		loop(240){yield;}
		}
		else{
		ClearBullet(90,10);
		Obj_Delete(objBoss);
		SetAutoDeleteObject(true);
		loop(120){yield;}
		}
		CloseScript(GetOwnScriptID());
		return;
	}