
#ScriptVersion[3]
#Title["Spell5"]
#Text["Spell5"]
#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 angleboss = 0;
let final = false;
@Initialize
{
	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);
	SetPlayerSpeed(4,2);
	angleboss += 1;
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(3500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(55);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(50000);
	}
}

//----------------------------------------------------
task mainTask{
	wait(60);
	ObjEnemy_SetDamageRate(objBoss,10,25);
	PlaySound("cardcall",100,0);
	ObjEnemyBossScene_StartSpell(objScene);
	Cutin("Medi","\"Madness Doll\"",15);
	wait(60);
	maple(3);
	wait(120);
	PlaySound("stars",100,0);
	TExplosionA(GetEnemyX, GetEnemyY, 4, 0.2);
	TExplosionA(GetEnemyX, GetEnemyY, 4, 0.35);
	TRapid;
	wait(240);
	maple(3);
	wait(120);
	TPoison;
	wait(1800);
	maple(3);
	wait(120);
	final = true;
	ObjEnemy_SetDamageRate(objBoss,70,25);
	}
//----------------------------------------------------

task BossMove{
	while(!Obj_IsDeleted(objBoss)){
	ObjMove_SetDestAtWeight(objBoss,stgx+90*cos(angleboss),(stgy-125)+30*sin(angleboss),10,1);
	yield;
	}
	}

task TRapid{
	let color = [PELLET_GREEN,PELLET_YELLOW,PELLET_PURPLE];
	let color2 = [LARGE_GREEN,LARGE_YELLOW,LARGE_PURPLE];
	let angle = [23,37,41];
	let result = 0;
	let r_result = 0;
	let s = 1;
	let dir = 0;
	let count = 0;
	ascent(n in 0..1000){
	PlaySound("Shot1",90,0);
	if(n%20==0){
	result = rand(0,2);
	r_result = round(result);
	dir = angle[r_result];
	s = -s;
	}
	if(n==150){ObjEnemy_SetDamageRate(objBoss,25,25);}
	if(n==300){ObjEnemy_SetDamageRate(objBoss,40,25);}
	if(n==450){ObjEnemy_SetDamageRate(objBoss,55,25);}
	if(n%30==0 && n>=150){
	PlaySound("BulletWave",95,0);
	ascent(i in 0..24){
	CreateShotOA1(objBoss,2.5,i*15+GetAngleToPlayer(objBoss),color2[count%3],20);
	count++;
	}
	}
	if(n%30==10 && n>=300){
	PlaySound("BulletWave",95,0);
	ascent(i in 0..24){
	CreateShotOA1(objBoss,2.5,i*15+GetAngleToPlayer(objBoss),color2[count%3],20);
	count++;
	}
	}
	if(n%30==20 && n>=450){
	PlaySound("BulletWave",95,0);
	ascent(i in 0..24){
	CreateShotOA1(objBoss,2.5,i*15+GetAngleToPlayer(objBoss),color2[count%3],20);
	count++;
	}
	}
	if(n%60==59){TMovement(35,10,5);}
	ascent(i in 0..6){
	CreateShotA1(GetEnemyX+40*cos(i*60+n*dir*s),GetEnemyY+40*sin(i*60+n*dir*s),2,i*60+n*dir*s,color[i%3],15);
	}
	wait(4);
	}
	}

task TPoison{
	ascent(n in 0..1000){
	poison(GetEnemyX,GetEnemyY,rand(2,3.5),n*37,0,0,0.7,150);
	wait(10);
	if(final == true){
	poison(GetEnemyX,GetEnemyY,rand(2,3.5),n*37+198,0,0,0.7,180);
	}
	}
	}

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

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;}
		StartSlow(TARGET_ALL,30);
		RemoveSound(MainSTG~"sound/Shot1.wav");
		RemoveSound(MainSTG~"sound/BulletWave.wav");
		loop(10){
		TExplosionA(GetEnemyX+rand(-50,50),GetEnemyY+rand(-50,50),10,0.6);
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		wait(10);
		}
		StopSlow(TARGET_ALL);
		PlaySound("enemoff",100,0);
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		Obj_Delete(objBoss);
		SetAutoDeleteObject(true);
		StopSlow(TARGET_ALL);
		loop(180){
			DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
			yield;
			}
		CloseScript(GetOwnScriptID());
		return;
	}
