
#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("Moon Sign \"Sunlight Reflector\"",20);
	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(13000);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(61);
	}
	case(EV_REQUEST_SPELL_SCORE) {
		SetScriptResult(62000);
	}
} 

@MainLoop {
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	
	// collision for the shots and player
	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,15);
	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;
	TEnd;
	overlay;
	yield;
} 

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

task movement {
	wait(180);
	FireRing;
	loop(1){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		DelayLaser(bossX,bossY,0,300,30,30,1003,40);
		wait(40);
		Laser(1);
		wait(300);
		DelayLaser(bossX,bossY,180,300,30,30,1003,40);
		wait(40);
		Laser2(-1);
		wait(300);
	}
	
	FireRing2;
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		DelayLaser(bossX,bossY,0,300,30,30,1003,40);
		wait(40);
		Laser(1);
		wait(300);
		DelayLaser(bossX,bossY,180,300,30,30,1003,40);
		wait(40);
		Laser2(-1);
		wait(300);
	}
}

task fire {
	let angleT = rand(0,360);
	loop(32){
		CreateShotA1(bossX+10*cos(angleT),bossY+10*sin(angleT),1,angleT, 23,30);
		angleT+=360/32;
	}
}

task Laser(dir){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		SE_Play(laser,40);
        let obj = CreateStraightLaserA1(bossX, bossY,270 + 105*dir, 412, 26, 240, 1003, 0);
        ascent(i in 0..180){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
            ObjStLaser_SetAngle(obj, 0*dir + 60/120*i * dir);
            yield;
        }
 }
task Laser2(dir){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		SE_Play(laser,40);
        let obj = CreateStraightLaserA1(bossX, bossY,270 + 105*dir, 412, 26, 240, 1003, 0);
        ascent(i in 0..180){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
            ObjStLaser_SetAngle(obj, 285 + 105*dir + 60/120*i * dir);
            yield;
        }
 }
	
task DelayLaser(x, y, ang, l, w, dt, graph, delay){ 
	let objlaser = CreateStraightLaserA1(x, y, ang, l, w, dt, graph, delay);
	ObjStLaser_SetSource(objlaser, false);
	loop(delay-1){//So that the graphic never enlarges. 
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0){
		Obj_Delete(objlaser); 
		return;
		}
	yield;
	}
	Obj_Delete(objlaser);
}

task FireRing{
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		fire;
		ShootDelay;
		wait(60);
	}
}

task fire2 {
	let angleT = rand(0,360);
	loop(16){
		 CreateLooseLaserA1(bossX,bossY, 3, angleT, 75, 18, 1019, 0);
		angleT+=360/16;
	}
}

task FireRing2 {
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		fire2;
		ShootDelay2;
		wait(30);
	}
}

task ShootDelay{
	wait(30);
	SE_Play(shoot,40);
}

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