
#ScriptVersion[3]
#Title["Spell3L"]
#Text["Spell3L"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Player["./MoF_Reimu/Reimu.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/Default_ShotConst.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];
@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(1750);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	DamageRateAtFrame(30,10,135);
	magiccircle(objBoss,0.8,true);
	wait(45);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("Six Realms Sword\"Soul-Shattering Slash\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	Pentagram(1);
	//TShot1;
	}
//----------------------------------------------------

task TShot1{
		let c = 0;
		let count = 0;
		let s = 1;
		while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>200){
			PlaySound("Shot6",90,0);
			ascent(i in 0..2){
				ascent(a in 0..4){
				let ang = i*180+c*23*s;
				let shot = ShotA1(GetEnemyX+30*cos(ang),GetEnemyY+30*sin(ang),1+a/3,ang+a*3*s,173+i,0,8);
				ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
				}
			}
		c++;
		if(c%33==17){
		Slash(count%2+1);
		count++;
		s = -s;
		}
		if(c%33==0){
		TAccel(35,5,0.05,90);
		}
		wait(10);
		}
		wait(30);
		ClearBullet(0);
		AccelMove(objBoss,stgx,135,0.1,60);
		DamageRateAtFrame(0,0,300);
		wait(90);
		Pentagram(2);
	}

task Slash(type){
		attack(50,60,2);
		maple(2);
		wait(55);
			if(type==1){
				ascent(i in 0..5){
				RealSlash(stgx*2/5*i+stgx*2/5,type);
				wait(5);
				}
				}
			if(type==2){
				descent(i in 0..5){
				RealSlash(stgx*2/5*i,type);
				wait(5);
				}
			}
		}
	

			task RealSlash(px,type){
			PlaySound("Eff3",90,0);
			PlaySound("Eff2",95,45);
			if(type==1){
			let ang = 255;
			let obj = CreateStraightLaserA1(px+20,stgy*2,ang,500,10,60,211,45);
			ascent(p in 0..11){
			ObjLaser_SetLength(obj,p*50);
			yield;
			}
			wait(34);
				ascent(i in 0..40){
				if(!Obj_IsDeleted(obj)){
				let shot = ShotA2(ObjMove_GetX(obj)+i*13*cos(ang),ObjMove_GetY(obj)+i*13*sin(ang),0,ang+180,0,0,151,0,6);
				ObjMove_AddPatternA2(shot,0,0,NO_CHANGE,0.015,rand(-1,1),rand(1.25,1.75));
				ObjMove_AddPatternA2(shot,15,NO_CHANGE,NO_CHANGE,0.015,0,rand(1.25,1.75));
				DelayShot(shot,51,2,128,12,15);
				wait(i%2);
				}
				}
			}
			if(type==2){
			let ang = 285;
			let obj = CreateStraightLaserA1(px-10,stgy*2,ang,500,10,60,211,45);
			ascent(p in 0..11){
			ObjLaser_SetLength(obj,p*50);
			yield;
			}
			wait(34);
				ascent(i in 0..40){
				if(!Obj_IsDeleted(obj)){
				let shot = ShotA2(ObjMove_GetX(obj)+i*13*cos(ang),ObjMove_GetY(obj)+i*13*sin(ang),0,ang+180,0,0,151,0,6);
				ObjMove_AddPatternA2(shot,0,0,NO_CHANGE,0.015,rand(-1,1),rand(1.25,1.75));
				ObjMove_AddPatternA2(shot,15,NO_CHANGE,NO_CHANGE,0.015,0,rand(1.25,1.75));
				DelayShot(shot,51,2,128,12,15);
				wait(i%2);
				}
				}
			}
		}

task Pentagram(type){
	let s = 1;
	attack(50,120,1);
	StartSlow(TARGET_ALL,30);
	ManageSpeed(50);
	SetCommonData("petal",1);
	maple(2);
	wait(50);
	SetCommonData("petal",0);
	StopSlow(TARGET_ALL);
	if(type==1){
	ascent(i in 0..5){
	PlaySound("Eff3",90,0);
	let px = stgx+200*cos(i*72-17);
	let py = stgy+50+200*sin(i*72-17);
	let dir = 126+i*72-17;
	let obj = CreateStraightLaserA1(px,py,dir,238,10,30,147,50-i*5);
	Manage(obj,i*5);
	wait(5);
	}
	wait(150);
	TShot1;
	}
	if(type==2){
	ascent(i in 0..5){
	PlaySound("Eff3",90,0);
	let px = stgx+200*cos(i*72-17);
	let py = stgy+25+200*sin(i*72-17);
	let dir = 126+i*72-17;
	let obj = CreateStraightLaserA1(px,py,dir,238,10,30,147,50-i*5);
	Manage(obj,i*5);
	px = stgx+200*cos(i*72-17+180);
	py = stgy+25+200*sin(i*72-17+180);
	dir = 126+i*72-17+180;
	obj = CreateStraightLaserA1(px,py,dir,238,10,30,147,50-i*5);
	Manage(obj,i*5);
	wait(5);
	}
	wait(240);
	DamageRateAtFrame(100,0,0);
	wait(150);
	ObjEnemy_SetLife(objBoss,0);
	}
		task Manage(obj,num){
			let srand = rand(0,30);
			TExplosionA(ObjMove_GetX(obj),ObjMove_GetY(obj),10,0.1);
			wait(50-num);
			PlaySound("Eff2",95,0);
			let ang = ObjStLaser_GetAngle(obj);
				ascent(i in 0..15){
					ascent(a in 0..7){
					ShotA1(ObjMove_GetX(obj)+i*16*cos(ang),ObjMove_GetY(obj)+i*16*sin(ang),0.5+a,ang-90+rand(-3,3),157,0,6);
						if(a%2==0){
						if(type==1){ShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0.5+a/5,i*24+srand,57,0,8);}
						if(type==2){ShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0.5+a/7,i*24+srand,57,0,8);}
						}
					}
				}
		}
	}

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

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(1);
		SetAutoDeleteObject(true);
		TAccel(20,10,0.01,80);
		loop(80){
		Explode(GetEnemyX,GetEnemyY,rand(4,6),rand(0,360),rand(1,2));
		wait(1);
		}
		StopSlow(TARGET_ALL);
		MapleExplode;
		PlaySound("enemoff",100,0);
		TExplosionA(GetEnemyX, GetEnemyY, 5, 0.1);
		TExplosionA(GetEnemyX, GetEnemyY, 5, 0.2);
		TExplosionA(GetEnemyX, GetEnemyY, 5, 0.35);
		Obj_Delete(objBoss);
		loop(150){yield;}
		CloseScript(GetOwnScriptID());
		return;
	}