
#ScriptVersion[3]
#Title["Spell1"]
#Text["Spell1"]
#Background["./Background.txt"]
#BGM[DEFAULT]
#Player[DEFAULT]

#include"./Functions/Index.txt"
#include"script/Letty/shot/ZUNShot_Const.txt"
#include"script/Default_system/Default_Effect.Txt"

let objBoss;
let enemy;
let bSpell=false;
let GCSD=GetCurrentScriptDirectory~"";
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let objScene=GetEnemyBossSceneObjectID();
@Initialize
{
	LoadTexture(GCSD~"shot/ZUNShot.png");
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjEnemy_SetDamageRate(objBoss,0,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,7);
	mainTask;
	TRender;
	TEnd;
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);//出現と同時に敵弾を全て削除	
}

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

//----------------------------------------------------
task mainTask{
	wait(60);
	ObjEnemy_SetDamageRate(objBoss,50,25);
	PlaySound("cardcall",100,0);
	Cutin("Medi","Cold Sign\"Unreasonable Hailstone\"",15);
	ObjEnemyBossScene_StartSpell(objScene);
	wait(60);
	TTest;
	}
//----------------------------------------------------

task TTest{
	let s = 1;
	while(!Obj_IsDeleted(objBoss)){
	ascent(n in 0..26){
	ascent(i in 0..3){
	ascent(a in 0..4){
	let obj = ShotA2(GetEnemyX+90*cos(i*120+n*7),GetEnemyY+90*sin(i*120+n*7),5,-i*48+a*360/4+n*20,-0.1,1.25,PELLET_BLUE,12);
	}
	}
	if(n%20==5){
	TSnow(s);
	s = -s;
	}
	PlaySound("Shot1",98,0);
	wait(10);
	}
	wait(180);
	s = -s;
	ascent(n in 0..26){
	ascent(i in 0..3){
	ascent(a in 0..4){
	let obj = ShotA2(GetEnemyX+90*cos(i*120-n*7),GetEnemyY+90*sin(i*120-n*7),5,-i*48+a*360/4-n*20,-0.1,1.25,PELLET_BLUE,12);
	}
	}
	if(n%20==5){
	TSnow(s);
	s = -s;
	}
	PlaySound("Shot1",98,0);
	wait(10);
	}
	wait(120);
	}
	}

task TSnow(s){
	maple(1);
	wait(120);
	attack(90);
	if(s==1){
	ascent(i in 0..36){
	PlaySound("BulletWave",95,0);
	let obj = snow(GetEnemyX+210*cos(i*10),GetEnemyY+90*sin(i*10),0.1,rand(0,359),3,30,0);
	Manage(obj,s);
	wait(4);
	}
	}
	if(s==-1){
	descent(i in 0..36){
	PlaySound("BulletWave",95,0);
	let obj = snow(GetEnemyX+210*cos(i*10),GetEnemyY+90*sin(i*10),0.1,rand(0,359),3,30,0);
	Manage(obj,s);
	wait(4);
	}
	}
	TMovement(35,5,5);
	}

task Manage(obj,s){
	let shot;
	let shot2;
	wait(120);
	let x = ObjMove_GetX(obj)+rand(-5,5);
	let y = ObjMove_GetY(obj)+rand(-5,5);
	Obj_Delete(obj);
	ascent(i in 0..1){
	PlaySound("Shot1",100,0);
	ascent(a in 0..1){
	if(s==1){
	shot = ShotA2(x,y,5,90,-0.2,0,LARGE_BLUE,20);
	Manage2(shot,0);
	shot = ShotA2(x,y,5,270,-0.2,0,LARGE_BLUE,20);
	Manage2(shot,0);
	}
	}
	if(s==-1){
	shot = ShotA2(x,y,0,90,-0.2,0,LARGE_AQUA,20);
	ObjMove_SetAngle(shot,GetAngleToPlayer(shot)+rand(-2.5,2.5));
	Manage2(shot,1);
	}
	wait(5);
	}
	}

task Manage2(obj,type){
	wait(60);
	if(type==0){
	 ascent(a in 0..2){
	 ShotOA1(obj,1+a/5,90,DOT_BLUE,12);
	 }
	}
	if(type==1){
	 ascent(a in 0..2){
	 ShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),0,getAtanAngle(obj,objPlayer),0.01+a/100,5,SMALL_AQUA,12);
	 }
	}
	Obj_Delete(obj);
	}

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

task TRender
{
	magiccircle(objBoss,1.75,true);
	let imgMiko = GetCurrentScriptDirectory~"img/boss.png";
	let f = 0;
	let t = 0;
	ObjPrim_SetTexture(objBoss, imgMiko);
	ObjRender_SetScaleXYZ(objBoss,1.05,1.05,1);
	while(!Obj_IsDeleted(objBoss))
	{
		let angle = ObjMove_GetAngle(objBoss);
		let speed = ObjMove_GetSpeed(objBoss);
		if(speed == 0 && idle == true){
		ObjRender_SetAngleY(objBoss,180);
		if(f<8){ObjSprite2D_SetSourceRect(objBoss, 0, 0, 48, 64);}
		if(f>=8 && f<16){ObjSprite2D_SetSourceRect(objBoss, 48, 0, 96, 64);}
		if(f>=16 && f<24){ObjSprite2D_SetSourceRect(objBoss, 96, 0, 144, 64);}
		if(f>=24 && f<32){ObjSprite2D_SetSourceRect(objBoss, 144, 0, 192, 64);}
		if(f>=32){f=0;}
		f++;
		t = 0;
		}
		else if(cos(angle) > 0 || cos(angle) < 0 && t == 0){
		if(cos(angle)<0){ObjRender_SetAngleY(objBoss,0);}
		else{ObjRender_SetAngleY(objBoss,180);}
		manageSprite;
		t = 1;
		}
		ObjSprite2D_SetDestCenter(objBoss);
		yield;
	}
}

//----------------------------------------------------
task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		//TExplosionA(GetEnemyX,GetEnemyY,10,0.6);
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		Obj_Delete(objBoss);
		SetAutoDeleteObject(true);
		loop(10){
			DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
			yield;
			}
		CloseScript(GetOwnScriptID());
		return;
	}
