#“Œ•û’e–‹•—[Single]
#ScriptVersion[3]
#Title["Spell5"]
#Text["Spell5"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]

#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"script/Marisa/Shot/Default_ShotConst.txt"
#include"script/Default_system/Default_Effect.Txt"
#Player["./MoF_Reimu/Reimu.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 way = 1;
let s = 1;
let objScene=GetEnemyBossSceneObjectID();
let arr = [1,6,4,2,3,5,0,7];
let shotarr = [31,32,33,34,35,37,38];
let shotnum = 2;

@Initialize
{
SetBoss;
}

@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(2222);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(50);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(3000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,0.8,true);
	wait(45);
	Cutin("Star Sign\"Orreries Kaleidoscope\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy,10,7);
	wait(60);
	TFamiliar;
	wait(360);
	TProtect;
	}
//----------------------------------------------------

task TProtect{
	let n = 0;
	while(!Obj_IsDeleted(objBoss)){
		PlaySound("Shot6",90,0);
		ascent(i in 0..72){
		let shot = ShotA2(GetEnemyX,GetEnemyY,4,i*5,-4/35,0.6,21+n%8,0,8);
		DelayDelete(shot);
		}
		wait(120);
		n++;
	}
		task DelayDelete(shot){
		wait(30);
			descent(i in 0..60){
			if(i<30){ObjShot_SetIntersectionEnable(shot,false);}
			ObjRender_SetColor(shot,i*4,i*4,i*4);
			yield;
			}
			Obj_Delete(shot);
		}
	}
	
task TShot1{
	let n = 0;
	maple(2);
	wait(55);
	ObjEnemy_SetDamageRate(objBoss,20,0);
	while(!Obj_IsDeleted(objBoss)){
		PlaySound("BulletWave",90,0);
		ascent(i in 0..8){
		let shot = ShotA2(GetEnemyX,GetEnemyY,0,i*45-n*8,0.015,2,131+n%8,0,8);
		}
		wait(13);
		n++;
	}	
	}
	
task TShot2{
	let n = 0;
	maple(2);
	wait(55);
	ObjEnemy_SetDamageRate(objBoss,30,0);
	while(!Obj_IsDeleted(objBoss)){
		PlaySound("Eff1",95,0);
		ascent(i in 0..8){
		ascent(j in 0..3){
		let shot = ShotA2(GetEnemyX,GetEnemyY,4,i*45+j*3-n*19,-0.075,0.75,251+n%8,211+n%8,8);
		//ObjRender_SetBlendType(shot,BLEND_ADD_ARGB);
		}
		}
		wait(120);
		n++;
	}	
	}
	
task TShot3{
	let n = 0;
	maple(2);
	wait(55);
	ObjEnemy_SetDamageRate(objBoss,50,0);
	while(!Obj_IsDeleted(objBoss)){
		PlaySound("Shot1",90,0);
		ascent(i in 0..18){
		let shot = ShotA2(GetEnemyX,GetEnemyY,3,i*20-n*9,-0.05,0.8,171+n%8,0,8);
		}
		wait(60);
		n++;
	}	
	}

task TFamiliar{
	let n = 0;
	let larr = [141,142,143,144,145,147,148];
	maple(3);
	wait(110);
		PlaySound("Eff5",100,0);
	ascent(i in 0..6){
	let enemy = fam(GetEnemyX,GetEnemyY,200,arr[i],false);
	Control(enemy,75,i,n%2);
	enemy = fam(GetEnemyX,GetEnemyY,200,arr[i],false);
	Control(enemy,180,i,n%2);
	n++;
	}
	wait(210);
	TShot1;
	wait(480);
	TShot2;
	wait(600);
	TShot3;
		task Control(enemy,maxr,num,type){
		let r = 0;
		let c = 0;
		let acc_c = 0;
		let u = maxr/75;
		let u2 = 0.5;
			descent(n in 0..90){
			if(r<maxr){r += u;}
			ObjMove_SetDestAtWeight(enemy,GetEnemyX+r*cos(num*360/6+c),GetEnemyY+r*sin(num*360/6+c),10,10);
			c-= n/8;
			yield;
			}
			FLaser(type);
			PlaySound("Laser5",100,0);
			wait(90);
			loop(3600){
			ObjMove_SetPosition(enemy,GetEnemyX+r*cos(num*360/6+c),GetEnemyY+r*sin(num*360/6+c));
			c+= acc_c*way;
			if(acc_c<0.4){acc_c+=0.004;}
			yield;
			}
			
				task FLaser(type){
				let dir = 0;
				let obj = CreateStraightLaserA1(ObjMove_GetX(enemy),ObjMove_GetY(enemy),dir,0,20,9900,larr[num],80);
				let value = 0;
				let c = 0;
					while(!Obj_IsDeleted(obj)){
						if(c%2==0){
						let dummy = ShotOA1(enemy,0,0,larr[num]-120,0,4);
						ObjShot_SetSpellResist(dummy,true);
						ObjShot_SetDeleteFrame(dummy,0);
						}
						ObjMove_SetPosition(obj,ObjMove_GetX(enemy),ObjMove_GetY(enemy));
						dir = CheckDir(obj,maxr,type);
						ObjStLaser_SetAngle(obj,dir);
						if(type==1){value = 150;}
						if(type==0){value = 110;}
						if(ObjLaser_GetLength(obj)<value){ObjLaser_SetLength(obj,ObjLaser_GetLength(obj)+2);}
						c++;
						yield;
					}
			}
			
		}
	}
	
		function CheckDir(obj,maxr,type){
						let dir = 0;
						if(maxr==180){
						if(type==0){dir = getAtanAngle(obj,objBoss)}
						if(type==1){dir = getAtanAngle(obj,objBoss)+180}
						}
						else{
						if(type==0){dir = getAtanAngle(obj,objBoss)+180}
						if(type==1){dir = getAtanAngle(obj,objBoss)}
						}
				return dir;
			}

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

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));}
		EndBoss(1);
		wait(60);
		CloseScript(GetOwnScriptID());
		return;
	}
	*/
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);
		SetAutoDeleteObject(true);
		loop(10){
		TExplosionA(GetEnemyX+rand(-50,50),GetEnemyY+rand(-50,50),10,0.6);
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		wait(10);
		}
		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(60){
		let arr = GetShotIdInCircleA2(stgx,stgy,1000,TARGET_ENEMY);
		ascent(i in 0..length(arr)){
			if(!Obj_IsDeleted(arr[i]) && GetDistance(ObjMove_GetX(arr[i]),ObjMove_GetY(arr[i]),px,py) <dis && IsPlayerSpellActive == false){
			let grr = GetShotDataInfoA1(ObjShot_GetImageID(arr[i]),TARGET_ENEMY,INFO_DELAY_COLOR);
			//effbreak(arr[i],10);
			Obj_Delete(arr[i]);
			}
		}
		dis += 20;
		yield;
			}
		loop(120){yield;}
		CloseScript(GetOwnScriptID());
		return;
	}