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

#include"./Functions/Index.txt"
#include"script/Medicine/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();
let s = 1;
@Initialize
{
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjEnemy_SetDamageRate(objBoss,0,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,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);
	SetPlayerSpeed(4,2);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(2000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(50);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);
	}
}

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

task TFam{
	let dir = 0;
	let spd = 0;
	ascent(n in 0..100){
	dir = rand(90,270);
	spd = rand(4,5);
	enemy = fam(GetEnemyX,GetEnemyY,spd,dir,-0.2,0.5,100);
	Control(enemy,1,PELLET_GREEN);
	enemy = fam(GetEnemyX,GetEnemyY,spd,dir+120,-0.2,0.5,100);
	Control(enemy,-1,PELLET_GREEN);
	enemy = fam(GetEnemyX,GetEnemyY,spd,dir+240,-0.2,0.5,100);
	Control(enemy,-1,PELLET_GREEN);
	wait(180);
	if(n==0){TFire;}
	dir = rand(120,240);
	spd = rand(4,5);
	enemy = fam(GetEnemyX,GetEnemyY,spd,dir,-0.2,0.5,100);
	Control(enemy,1,PELLET_YELLOW);
	enemy = fam(GetEnemyX,GetEnemyY,spd,dir+120,-0.2,0.5,100);
	Control(enemy,-1,PELLET_YELLOW);
	enemy = fam(GetEnemyX,GetEnemyY,spd,dir+240,-0.2,0.5,100);
	Control(enemy,-1,PELLET_YELLOW);
	if(n>=1){TFire2;}
	wait(90);
	TMovement(35,10,5);
	wait(90);
	if(n>=1){TFire2;}
	s = -s;
	}
	}

task TFire{
	let n = 0;
	while(!Obj_IsDeleted(objBoss)){
	ascent(i in 0..4){
	CreateShotOA1(objBoss,1.75,i*90+n*8.3*s,PELLET_RED,12);
	}
	n++;
	wait(4);
	}
	}

task TFire2{
	PlaySound("Shot5",100,0);
	ascent(i in 0..18){
	ascent(a in 0..4){
	CreateShotOA1(objBoss,1.5+a,i*20,LARGE_PURPLE,12);
	}
	}
	}

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

task Control(obj,dir,color){
	deadpoison;
	wait(60);
	ascent(n in 0..13){
	 PlaySound("Shot1",90,0);
	 ascent(i in 0..15){
	  ascent(a in 0..1){
	  CreateShotOA1(obj,1.5,i*24+a*2+n*11*dir,color,12);
	  }
	 }
	 wait(25);
	}
	 task deadpoison{
	 let x;
	 let y;
	 while(ObjEnemy_GetInfo(obj,INFO_LIFE)>0){
	 x = ObjMove_GetX(obj);
	 y = ObjMove_GetY(obj);
	 yield;
	 }
	  let angle = rand(0,39);
	  ascent(i in 0..9){
	  spoison(x,y,1,i*40+angle,0,0,0.5,60);
	  }
	 }
	}

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

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){
		if(f<8){ObjSprite2D_SetSourceRect(objBoss, 0, 0, 64, 64);}
		if(f>=8 && f<16){ObjSprite2D_SetSourceRect(objBoss, 64, 0, 128, 64);}
		if(f>=16 && f<24){ObjSprite2D_SetSourceRect(objBoss, 128, 0, 192, 64);}
		if(f>=24 && f<32){ObjSprite2D_SetSourceRect(objBoss, 192, 0, 256, 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;
	}
