
#include "./default_system/Default_Effect.txt"
#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);
	Cutin("Night Sign \"Moon\"",20);
	ObjEnemyBossScene_StartSpell(objScene);
	// move boss to desired x y location at desired speed
	ObjMove_SetDestAtSpeed(bossObj, GetStgFrameWidth/2,GetStgFrameHeight/2,3);
	mainTask;	// run mainTask
	
} 

@Event { 
	// setting the boss timer and life
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(99*99*99*99);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(61);
	}
	case(EV_REQUEST_SPELL_SCORE) {
		SetScriptResult(100000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
	SetScriptResult(true);
	}
} 

@MainLoop {
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	yield;
} 

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

task mainTask { 
	RenderBossFade;
	movement;
	TEnd;
	overlay;
	overlayMoon;
	yield;
} 

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

task movement {
	wait(180);
		loop(5){
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
			FireA;
			FireB;
			wait(80);
		}
		loop(5){
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
			FireA;
			FireB;
			wait(40);
			FireC;
			wait(40);
		}
		loop(5){
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
			FireA;
			FireB;
			wait(40);
			FireC;
			wait(20);
			LaserPoint;
			wait(20);
		}
		loop(5){
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
			FireA;
			FireB;
			wait(20);
			FireD;
			wait(20);
			FireC;
			wait(20);
			LaserPoint;
			wait(20);
		}
		loop(5){
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
			wait(40);
			FireC;
			wait(40);
			FireE;
			yield;
		}
		loop(5){
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
			wait(40);
			FireC;
			wait(40);
			FireE;
			FireD;
			yield;
		}
		loop(5){
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
			wait(40);
			FireC;
			FireB;
			wait(40);
			FireE;
			FireD;
			yield;
		}
		loop{
			if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
			wait(40);
			FireC;
			FireB;
			wait(40);
			FireA;
			FireE;
			FireD;
			LaserPoint;
			yield;
		}
	
	
}
task FireA{
	let angleT = angleToPlayer;
	SE_Play(shoot2,40);
	loop(8){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		 CreateLooseLaserA1(bossX,bossY, 3, angleT, 75, 18, 1022, 0);
		angleT+=360/8;
	}
}
task FireB{
	let angleT = angleToPlayer-25;
	SE_Play(shoot2,40);
	loop(8){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		 CreateLooseLaserA1(bossX,bossY,1.5 , angleT, 75, 18, 1022, 0);
		angleT+=360/8;
	}
}
task FireC{
	let angleT = 0;
	loop(32){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		 CreateShotA1(bossX,bossY, 2, angleT,32, 0);
		 SE_Play(shoot,20);
		 wait(5);
		angleT+=360/32;
	}
}
task FireE{
	let angleT = 0;
	loop(32){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		 CreateShotA1(bossX,bossY, 2, angleT,32, 0);
		 wait(5);
		angleT+=360/32;
	}
}

task LaserPoint {
	let angleT = angleToPlayer;
	if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
	SE_Play(laser,40);
		let obj = CreateStraightLaserA1(bossX, bossY, angleT, 512, 20, 20, 1001, 60);
		ObjStLaser_SetSource(obj, true); 
		let obj2 = CreateStraightLaserA1(bossX, bossY, angleT-180, 512, 20, 20, 1001, 60);
		ObjStLaser_SetSource(obj2, true); 
}

task FireD {
	let angleT = rand(0,360);
	loop(20){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		ShootDelay;
	ascent(i in 1..3){
		CreateShotA1(bossX+40*cos(angleT),bossY+40*sin(angleT),i,angleT, 214,30);
	}
		angleT+=360/20
	}
}

task ShootDelay{
	wait(30);
	SE_Play(shoot2,50);
}