#“Œ•û’e–‹•—[Single]
#ScriptVersion[3]
#Title["Spell"]
#Text["Spell"]
#Background["./BG.txt"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Player["./MoF_Reimu/Reimu.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"script/Marisa/Shot/Default_ShotConst.txt"
#include"script/Default_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 s = 1;
let objScene=GetEnemyBossSceneObjectID();
let Nuclear = GCSD~"img/Nuclear.png";
@Initialize
{
SetBoss;
LoadTexture(Nuclear);
}

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

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,0.8,true);
	wait(45);
	Cutin("Light Sign\"Magic Grenade\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	ObjMove_SetDestAtWeight(objBoss,stgx,130,10,7);
	wait(90);
	Star;
	wait(120);
	ObjEnemy_SetDamageRate(objBoss,50,25);
	}
//----------------------------------------------------

task Star{
	let n = 0;
	while(!Obj_IsDeleted(objBoss)){
	PlaySound("Shot1",90,0);
	ascent(i in 0..6){
	let shot = ShotOA1(objBoss,2,i*60+n*5.5*s,251+n%8,0,12);
	//DelayShot(shot,0,2.5,0,12,0);
	Manage(shot,n%8);
	}
	if(n%70==18){
	Grenade(s,0);
	s=-s;
	}
	if(n%70==40){
	Grenade(s,1);
	s=-s;
	}
	if(n%70==62){
	Grenade(s,2);
	s=-s;
	}
	n++;
	wait(12);
	}
		task Manage(shot,num){
		wait(60);
			ascent(i in 0..2){
			let obj = ShotOA1(shot,1.5,ObjMove_GetAngle(shot)-5+i*10,131+num,0,6);
			//DelayShot(obj,131+num,3,10);
			}
			Obj_Delete(shot);
		}
	}

task Grenade(s,type){
		let shot;
		TMovement(50,5,5);
		if(type==0){
		maple(2);
		wait(50);
		ascent(n in 0..3){
		PlaySound("Shot6",95,0);
		if(s==1){shot = ShotA2(GetEnemyX,GetEnemyY,4,20+n*60,-4/60,0,215,0,8);}
		else{shot = ShotA2(GetEnemyX,GetEnemyY,4,160-n*60,-4/60,0,215,0,8);}
		Bomb(shot,n);
		wait(10);
		}
		}
		if(type==1){
		maple(2);
		wait(50);
		ascent(n in 0..4){
		PlaySound("Shot6",95,0);
		if(s==1){shot = ShotA2(GetEnemyX,GetEnemyY,5,-40+n*60,-5/60,0,215,0,8);}
		else{shot = ShotA2(GetEnemyX,GetEnemyY,5,220-n*60,-5/60,0,215,0,8);}
		Bomb(shot,n);
		wait(9);
		}
		}
		else if(type==2){
		maple(1);
		wait(100);
		ascent(n in 0..6){
		PlaySound("Shot6",95,0);
		if(s==1){shot = ShotA2(GetEnemyX,GetEnemyY,4,20+n*60,-4/60,0,215,0,8);}
		else{shot = ShotA2(GetEnemyX,GetEnemyY,4,160-n*60,-4/60,0,215,0,8);}
		Bomb(shot,n);
		wait(10);
		}
		}
	}
	
task Bomb(shot,num){
	ObjShot_SetSpellResist(shot,true);
	wait(60);
	BombEffect;
	task BombEffect{
		PlaySound("BulletWave",90,0);
		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
		let size = 0;
		let x = ObjRender_GetX(shot);
		let y = ObjRender_GetY(shot);
		ObjPrim_SetTexture(obj,Nuclear);
		ObjSprite2D_SetSourceRect(obj,0,256,256,512);
		ObjSprite2D_SetDestCenter(obj);
		ObjRender_SetScaleXYZ(obj,0,0,0);
		ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
		ObjRender_SetPosition(obj,x,y,0);
		Obj_SetRenderPriority(obj,0.21);
		Obj_Delete(shot);
		CheckBoss;
		ascent(i in 0..20){
		ShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),rand(0.5,1.5),i*18+num*7,155,0,8);
		}
		ascent(i in 0..10){
		ObjRender_SetScaleXYZ(obj,size,size,0);
		size += 0.02;
		yield;
		}
		ascent(i in 0..90){
		ObjRender_SetScaleXYZ(obj,size,size,0);
		size += 0.005;
		if(i==60){		
			ascent(i in 0..18){
			ShotA1(ObjRender_GetX(obj)+40*cos(i*20),ObjRender_GetY(obj)+40*sin(i*20),0.5,i*20,25,0,8);
			}
		}
		yield;
		}
		ascent(i in 0..60){
		ObjRender_SetScaleXYZ(obj,size,size,0);
		ObjRender_SetColor(obj,255-i*4.5,255-i*4.5,255-i*4.5);
		size += 0.0025;
		yield;
		}
		if(!Obj_IsDeleted(obj)){Obj_Delete(obj);}
		task CheckBoss{
		while(!Obj_IsDeleted(objBoss)){yield;}
		Obj_Delete(obj);
		}
		}
	}

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

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;
	}
