
#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(55000);
	}
	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("Water Sign \"Water Pulse\"",20);
	setOverlay;
	TEnd;
	yield;
} 

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

task movement {
	wait(120);
	loop{
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		loop(40){
			SE_Play(shoot2,60);
			SE_Play(shoot,40);
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		waterA;
		wait(5);
		}
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		wait(30);
		laserCircle;
		wait(30);
	}
}



task waterA{
	CreateShotX1(bossX,bossY,rand(0.5,2),rand(0,360),rand(0,-360),rand(5,360),23,20);
	CreateShotX1(bossX,bossY,rand(0.25,2),rand(0,360),rand(0,-360),rand(0,360),214,30);
	CreateShotX1(bossX,bossY,rand(0.5,3),rand(0,360),rand(0,-360),rand(0,360),257,10);
	CreateShotX1(bossX,bossY,rand(1,3),rand(0,360),rand(0,-360),rand(0,360),39,5);
}
task CreateShotX1(let x,let y, let speed,let angle,let neg, let pos,let graphic,let delay){
	CreateShotA1(x,y,speed,angle,graphic,delay);
	CreateShotA1(x,y,speed,angle-neg,graphic,delay);
	CreateShotA1(x,y,speed,angle-pos,graphic,delay);
}
task laserCircle{
	let angleT = angleToPlayer;
	laserDelay;
	loop(8){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateStraightLaserA1(bossX, bossY, angleT, 512, 20, 20, 1007, 60);
		angleT+=360/8
	}
}
task laserDelay{
	wait(60);
	SE_Play(laserSFX,40);
}