#“Œ•û’e–‹•—[Single]
#ScriptVersion[3]
#Title["Bonus Spell Card"]
#Text["A spell card that not for the contest.Made it for fun,though"]
#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 slash = 1;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,0];
@Initialize
{
SetBoss(false);
}

@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(4000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(62);
	}
}

//----------------------------------------------------
task mainTask{
	SetCommonData("Difficulty",4);
	SetPlayerLife(0);
	SetPlayerSpell(0);
	Sound(Sound(GCSD~"Cutting.mp3"));
	DamageRateAtFrame(0,0,60);
	magiccircle(objBoss,0.8,true);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("Youmu Sign\"Extra Slash\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TSlash;
	}
//----------------------------------------------------

task TSlash{
	let obj;
	maple(2);
	wait(55);
	let p = rand(0,45);
	ascent(i in 0..36){
	ascent(a in 0..9){
	ShotA2(GetEnemyX+60*cos(i*10+p),GetEnemyY+60*sin(i*10+p),0,i*10+60+p,0.005+a/200,6,261,0,8);
	ShotA2(GetEnemyX+30*cos(i*10+p),GetEnemyY+30*sin(i*10+p),0,i*10-60+p,0.005+a/200,6,267,0,8);
	}
	}
	wait(180);
	maple(3);
	wait(60);
	StartCharge(60);
	wait(60);
	SetCommonData("petal",0.25);
	StopSlow(TARGET_ALL);
		ascent(i in 0..9){
		PlaySound("byoro07",95,0);
		let obj = CreateStraightLaserA1(stgx*2+32,stgy*2/8*i-stgy*2/8,165,0,15,120,155,60);
		Manage(obj);
		wait(5);
		}
	wait(270);
	TAccel(35,5,0.1,60);
	ascent(n in 0..24){
		PlaySound("Shot6",90,0);
		ascent(i in 0..5){
			ShotOA1(objBoss,0.5+n/6,i*72+n*12,266,0,8);
			ShotOA1(objBoss,0.5+n/6,i*72-n*8,264,0,8);
		}
		wait(5);
	}
	wait(105);
	maple(1);
	wait(60);
	StartCharge(60);
	wait(60);
	SetCommonData("petal",0.25);
	StopSlow(TARGET_ALL);
	PlaySound("byoro07",95,0);
	obj = CreateStraightLaserA1(stgx-150,-30,60,0,15,120,152,75);
	Manage2(obj,55);
	obj = CreateStraightLaserA1(-3,stgy,-15,0,15,120,152,75);
	Manage2(obj,55+240);
	wait(180);
	AccelMove(objBoss,stgx,30,0.1,30);
	wait(180);
	maple(2);
	StartCharge(60);
	wait(60);
	SetCommonData("petal",0.25);
	StopSlow(TARGET_ALL);
	PlaySound("Eff3",95,0);
	CreateStraightLaserA1(GetEnemyX,GetEnemyY,90,500,20,120,152,60);
	CreateStraightLaserA1(GetEnemyX+10,GetEnemyY+50,85,500,20,120,152,60);
	CreateStraightLaserA1(GetEnemyX-10,GetEnemyY+50,95,500,20,120,152,60);
	ObjMove_SetPosition(objBoss,stgx,400);
	wait(60);
	ascent(n in 0..12){
		PlaySound("Shot6",95,0);
		ascent(a in 0..7){
		ShotA1(stgx,n*37,0.5+a/3,180+rand(-2,2),61+round(a/2),0,12);
		ShotA1(stgx,n*37,0.5+a/3,rand(-2,2),61+round(a/2),0,12);
		}
	}
	PlaySound("Eff2",95,0);
	ascent(i in 0..12){
		ascent(a in 0..7){
		ShotA2(i*35,stgy*0,0,90+rand(-2,2),0.005+a/150,6,91+round(a/2),0,12);
		ShotA2(i*35,stgy*0,0,270+rand(-2,2),0.005+a/150,6,91+round(a/2),0,12);
		}
	}
	wait(120);
	attack(60,120,1);
	wait(60);
	PlaySound("Eff3",95,0);
	CreateStraightLaserA1(GetEnemyX,GetEnemyY,270,500,20,120,152,60);
	CreateStraightLaserA1(GetEnemyX+10,GetEnemyY+50,270-5,500,20,120,152,60);
	CreateStraightLaserA1(GetEnemyX-10,GetEnemyY+50,270+5,500,20,120,152,60);
	ObjMove_SetPosition(objBoss,stgx,30);
	wait(60);
	ascent(n in 0..12){
		ascent(a in 0..7){
		ShotA1(stgx,n*37,0.5+a/3,180+rand(-2,2),61+round(a/2),0,12);
		ShotA1(stgx,n*37,0.5+a/3,rand(-2,2),61+round(a/2),0,12);
		}
	}
	PlaySound("Eff2",95,0);
	ascent(i in 0..12){
		ascent(a in 0..7){
		ShotA2(i*35,stgy*2,0,90+rand(-2,2),0.005+a/150,6,91+round(a/2),0,12);
		ShotA2(i*35,stgy*2,0,270+rand(-2,2),0.005+a/150,6,91+round(a/2),0,12);
		}
	}
	wait(90);
	AccelMove(objBoss,stgx+50,120,0.1,60);
	ascent(n in 0..3){
	ascent(j in 0..12){
		ascent(i in 0..5){
		ShotOA1(objBoss,0.5+j/4,angleToPlayer-40+i*20,268,0,12);
		}
	}
	wait(30);
	}
	wait(45);
	AccelMove(objBoss,stgx-100,120,0.1,60);
	wait(60);
	maple(1);
	wait(60);
	StartCharge(60);
	wait(60);
	SetCommonData("petal",0.25);
	StopSlow(TARGET_ALL);
	PlaySound("byoro07",95,0);
	obj = CreateStraightLaserA1(stgx+150,-30,120,0,15,120,152,75);
	Manage2(obj,55);
	obj = CreateStraightLaserA1(stgx*2+3,stgy,195,0,15,120,152,75);
	Manage2(obj,55+240);
	wait(120);
	AccelMove(objBoss,stgx-175,60,0.1,60);
	wait(120);
	maple(2);
	StartCharge(60);
	wait(60);
	SetCommonData("petal",0.25);
	StopSlow(TARGET_ALL);
	PlaySound("Eff3",95,0);
	PlaySound("Eff3",95,20);
	PlaySound("Eff3",95,40);
	PlaySound("Eff3",95,60);
	let laser = CreateStraightLaserA1(stgx-175,60,90,340,15,60,157,90);
	Spawn(laser,90);
	ObjMove_SetPosition(objBoss,stgx-175,400); // W shape
	wait(20);
	laser = CreateStraightLaserA1(stgx-175,400,300,450,15,60,157,70);
	Spawn(laser,70);
	ObjMove_SetPosition(objBoss,stgx,60);
	wait(20);
	laser = CreateStraightLaserA1(stgx,60,60,450,15,60,157,50);
	Spawn(laser,50);
	ObjMove_SetPosition(objBoss,stgx+175,400);
	wait(20);
	laser = CreateStraightLaserA1(stgx+175,400,270,340,15,60,157,30);
	Spawn(laser,30);
	ObjMove_SetPosition(objBoss,stgx+175,60);
	wait(30);
	PlaySound("Laser4",95,0);
		ascent(i in 0..12){
			ascent(a in 0..5){
			ShotA1(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),0.5+a/3,i*30+a*6,227,0,8);
			}
		}
	AccelMove(objBoss,stgx,150,0.1,60);
	wait(180);
	PlaySound("Charge5",100,0);
	PlaySound("Charge4",100,60);
	ascent(n in 0..18){
	SCharge01(objBoss,2.5+n/9,30,0,255,255);
	loop(5){
	etama(250,10,0,0,1);
	Explode(GetEnemyX,GetEnemyY,rand(1,8),rand(0,360),rand(1,2));
	}
	wait(5);
	}
	NCharge01(objBoss,4.5,30,0,255,255);
	let v = 2;
	let c = 0;
	let r = 120;
	wait(30);
		loop(10){
		Explode(GetEnemyX,GetEnemyY,rand(1,8),rand(0,360),rand(1,2));
		}
		while(r>0){
		r-= 1;
		PlaySound("Shot4",90,0);
		ascent(i in 0..5){
			ascent(j in 0..2){
			ShotA1(GetEnemyX+r*cos(i*72-c*13),GetEnemyY+r*sin(i*72-c*13),v,i*72+j*180+c*13,266,0,12);
			}
		}
		if(c>60){
		ascent(i in 0..5){
			ascent(j in 0..2){
			ShotA1(GetEnemyX+r*cos(i*72+c*13),GetEnemyY+r*sin(i*72+c*13),v+1,i*72+j*180-c*13,261,0,12);
			}
		}
		}
		c++;
		wait(5);
		}
		PlaySound("Eff2",100,0);
		ascent(i in 0..24){
		ascent(a in 0..9){
		ShotA2(GetEnemyX,GetEnemyY,0,i*15+a,0.005+a/200,6,263,0,12);
		ShotA2(GetEnemyX,GetEnemyY,0,i*15-a,0.005+a/200,6,263,0,12);
		}
		}
		wait(180);
		ObjEnemy_SetLife(objBoss,0);
		task Spawn(obj,delay){
		wait(delay);
		ascent(i in 0..9){
			ascent(a in 0..5){
			ShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0.5+a/3,i*40+a*8,227,0,8);
			ShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),0.5+a/3,i*40-a*8,227,0,8);
			}
		}
		Obj_Delete(obj);
		}
		task Manage2(obj,t){
				let s = 1;
				let ang = ObjStLaser_GetAngle(obj);
				let color = 172;
				let r = rand(0,29);
				if(t==295){color = 174;}
				ascent(p in 0..20){
				ObjLaser_SetLength(obj,p*30);
				yield;
				}
				wait(40);
				ascent(n in 0..20){
					PlaySound("Shot6",95,0);
					ascent(i in 0..12){
					let shot = ShotA2(ObjMove_GetX(obj)+n*30*cos(ang),ObjMove_GetY(obj)+n*30*sin(ang),3.5,i*30+n*13*s+r,0,0,color+i%2,0,8);
					ObjMove_SetAngularVelocity(shot,4);
					ObjMove_AddPatternA2(shot,90,NO_CHANGE,NO_CHANGE,-0.05,0,0.5+n/20);
					}
					s = s;
				wait(2);
				}
		}
		task Manage(obj){
			let ang = ObjStLaser_GetAngle(obj);
			ascent(i in 0..15){
			ObjLaser_SetLength(obj,i*35);
			yield;
			}
			wait(45);
			ascent(i in 0..20){
			PlaySound("Shot6",95,0);
			PlaySound("BulletWave",95,90);
			let maxv = 0.75+(i%3)/3;
				ascent(j in 0..2){
				let shot = ShotA2(ObjMove_GetX(obj)+i*25*cos(ang),ObjMove_GetY(obj)+i*25*sin(ang),0,ang+90+j*180,0,0,94+j,0,6);
				ObjMove_AddPatternA2(shot,0,0,NO_CHANGE,0.002,rand(-0.05,0.05),maxv);
				ObjMove_AddPatternA2(shot,90,NO_CHANGE,NO_CHANGE,0.0075,0,maxv);
				DelayShot(shot,174+j,2,128,12,90);
				}
				wait(1);
			}
		}
	}

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

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(100){
		Explode(GetEnemyX,GetEnemyY,rand(4,7),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;
	}