
#include "./default_system/AllStarShot_Const.txt"
#include"./functions.txt"
#include "./cutin.txt"
let objScene = GetEnemyBossSceneObjectID();
@Initialize {
	// define a boss in bossObj and register it
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	ObjEnemyBossScene_StartSpell(objScene);
	
	// move boss to desired x y location at desired speed
	ObjMove_SetDestAtSpeed(bossObj, 192,100,3);
	

	mainTask;	// run mainTask
	
} 

@Event { 
	// setting the boss timer and life
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(4000);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(46);
	}
	case(EV_REQUEST_SPELL_SCORE) {
		SetScriptResult(75000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
	SetScriptResult(true);
	}
} 

@MainLoop {
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	
	// collision for the shots and player
	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,10);
	yield;
} 

@Finalize {
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT)
        +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
		AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
	}

} 

task mainTask { 
	RenderBoss;
	movement;
	CutinA1("Fairy Sign \"Dazzling Gleam\"",20);
	setOverlay;
	TEnd;
	yield;
} 

//ObjMove_SetDestAtSpeed(bossObj,x,y,speed);		

task movement {
	wait(120);
	loop{
		loop(7){
			if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
			SE_Play(shoot,40);
			fireA;
			fireB;
			wait(30);
		}
		LoopA;
		
	}
}

task fireA {
	let angleT = rand(0,360);
	loop(20){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(bossX,bossY,2,angleT,rand(4,9),20);
			angleT+=360/20;
	}
}
task fireB {
	let angleT = rand(0,360);
	loop(30){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(bossX,bossY,3,angleT,rand(520,524),20);
			angleT+=360/30;
	}
}

task fireC {
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
	let angleT = 0;
	loop(30){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(bossX-10,bossY-10,1.5,angleT,rand(785,788),10);
			angleT+=360/30;
	}
} 



task LoopA{
	SE_Play(shoot2,55);
	loop(3){
			fireC;
			wait(15);
		}
}
