
#ScriptVersion[3]
#Title["Spell2H"]
#Text["Spell2H"]
#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(2225);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	SetShotAutoDeleteClip(32,32,32,32);
	DamageRateAtFrame(50,25,225);
	DamageRateAtFrame(75,25,225+900);
	magiccircle(objBoss,0.8,true);
	wait(45);
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,7);
	Cutin("Human Sign\"Pyrophoric Slash\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	wait(90);
	}
//----------------------------------------------------

task TShot1{
	let p = 0;
	while(!Obj_IsDeleted(objBoss)){
	attack(55,120,1);
	StartSlow(TARGET_ALL,30);
	ManageSpeed(55);
	SetCommonData("petal",1);
	maple(2);
	wait(55);
	SetCommonData("petal",0.25);
	StopSlow(TARGET_ALL);
	ascent(i in 0..36+p){
	RLaser(GetEnemyX,GetEnemyY,i*25,130,5,1);
	yield;
	}
	wait(135);
	TAccel(30,10,0.05,60);
	wait(120);
	/*
	attack(55,120,1);
	StartSlow(TARGET_ALL,30);
	ManageSpeed(55);
	SetCommonData("petal",1);
	maple(2);
	wait(55);
	SetCommonData("petal",0.25);
	StopSlow(TARGET_ALL);
	ascent(i in 0..15+p){
	RLaser(384/(15+p)*i,448,210+i*4,130,5,1);
	wait(4);
	}
	wait(135);
	TAccel(30,10,0.05,60);
	wait(120);
	*/
	p+=1;
	attack(55,120,1);
	StartSlow(TARGET_ALL,30);
	ManageSpeed(55);
	SetCommonData("petal",1);
	maple(2);
	wait(55);
	SetCommonData("petal",0.25);
	StopSlow(TARGET_ALL);
	ascent(i in 0..36+p){
	RLaser(GetEnemyX,GetEnemyY,-i*25,130,5,-1);
	yield;
	}
	wait(135);
	TAccel(30,10,0.05,60);
	wait(120);
	/*
	attack(55,120,1);
	StartSlow(TARGET_ALL,30);
	ManageSpeed(55);
	SetCommonData("petal",1);
	maple(2);
	wait(55);
	SetCommonData("petal",0.25);
	StopSlow(TARGET_ALL);
	descent(i in 0..15+p){
	RLaser(384/(15+p)*i,448,270+i*4,130,5,-1);
	wait(4);
	}
	wait(135);
	TAccel(30,10,0.05,60);
	wait(120);
	*/
	p+=1;	
	}
	task Slash(way){
	descent(n in 0..18){
	ascent(i in 0..6){
	let px = GetEnemyX+n*8*cos(i*60-n*3*way);
	let py = GetEnemyY+n*8*sin(i*60-n*3*way);
		ascent(j in 0..6){
		let shot = ShotA2(px,py,4,j*60+n*27*way+i*7,0,0,171+n%7,0,12);
		ObjMove_SetAngularVelocity(shot,-5*way);
		ObjMove_AddPatternA2(shot,72,0.5+n/12,NO_CHANGE,0,0,0);
		}
	}
	wait(2);
	}
	}
		task RLaser(px,py,dir,length,num,way){
		let color = 0;
		if(way==1){color = 151;}
		else{color = 157;}
		PlaySound("Eff4",90,0);
		let obj = CreateStraightLaserA1(px,py,dir,length,10,30,color,45);
		ObjLaser_SetInvalidLength(obj,0.01,50);
		let x = px+length/2*cos(dir);
		let y = py+length/2*sin(dir);
		if(length<175){
		Bullet(1);
		}
		else{
		Bullet(17);
		}
			if(num>0){
			wait(5);
			RLaser(x,y,dir+10*way,length,num-1,way);
			}
			task Bullet(multi){
			wait(30);
					if(multi==1){
						ascent(i in 0..3){
						let shot = ShotA2(px,py,0,i*120+dir*multi,0.005,1,color,0,8);
						ObjMove_AddPatternA2(shot,45,0,NO_CHANGE,0.01,0,2.5);
						DelayShot(shot,color-100,2,128,10,10);
						}
					}
					else{
						ascent(i in 0..4){
						let shot = ShotA2(px,py,0,i*90+dir*multi,0.005,1,color,0,8);
						ObjMove_AddPatternA2(shot,45,0,NO_CHANGE,0.005,0,2);
						DelayShot(shot,color-100,2,128,10,10);
						}
					}
				}
			}
		
	}

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

task TRender
{
	DrawBoss;
}

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

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