
#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("Embargo \"Prisoner of The Night\"",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(7000);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(41);
	}
	case(EV_REQUEST_SPELL_SCORE) {
		SetScriptResult(80000);
	}
	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,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);
	loop{
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		LaserLine;
		LaserLineR;
		wait(120);
		ObjMove_SetDestAtSpeed(bossObj,50,100,4);
		CircleRun;
		wait(120);
		LaserLine;
		LaserLineR;
		wait(120);
		ObjMove_SetDestAtSpeed(bossObj,300,100,4);
		CircleRun;
		wait(120);
		
	}
}

task CircleFast {
	let angleT = angleToPlayer;
	SE_Play(shoot,40);
	loop(24){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		CreateShotA1(bossX,bossY,3,angleT,23,0);
		angleT+= 360/24
	}
	
}


task Laserdelay{
	wait(60);
	SE_Play(laser,40);
}
task LaserLine{
	let angleT = 90;
	Laserdelay;
	ascent(i in 0..40){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		CreateStraightLaserA1(bossX+40+i*36, bossY, angleT, 512, 20, 60, 1001, 60);
	}
}
task LaserLineR{
	let angleT = 90;
	Laserdelay;
	ascent(i in 0..40){
		CreateStraightLaserA1(bossX-40-i*36, bossY, angleT, 512, 20, 60, 1001, 60);
	}
}

task LaserShot{
	
		let angleT = 90;
		let obj = CreateStraightLaserA1(bossX, bossY, angleT, 512, 20, 60, 1001, 60);
		ObjStLaser_SetSource(obj, true); //Do not show the laser source
		ObjLaser_SetGrazeInvalidFrame(obj, 5); //Allows for up to 1 graze each 5 frames
		ObjLaser_SetInvalidLength(obj, 5, 5); //5 percent of each end of the laser is safe
}

task CircleRun{
	loop(12){
		if(ObjEnemy_GetInfo(bossObj, INFO_LIFE) <= 0 ){return;}
		CircleFast;
		wait(10);
	}
}