
#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);
	CutinWait;
	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(99*99*99*99);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(61);
	}
	case(EV_REQUEST_SPELL_SCORE) {
		SetScriptResult(70000);
	}
	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;
	setOverlay;
	TFinalize;
	yield;
} 
task movement{
	wait(120);
	loop(15){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		SunnyDay;
		waitS(1);
	}
	solarBeamALoop;
	
	solarLaserLoop;
	loop(15){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		SunnyDay;
		wait(60);
	}
	FairyWind;
	RainDance;
	loop(20){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		SunnyDay;
		wait(60);
	}
	loop(10){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		SunnyDay;
		waitS(1);
	}
}
//ObjMove_SetDestAtSpeed(bossObj,x,y,speed);		
task CutinWait{
	CutinA1("Fire Sign \"Sunny Day\"",15);
	waitS(15);
	SE_Play(spellcard,80);
	CutinA2("Grass Sign \"Solarbeam\"",15);
	waitS(15);
	SE_Play(spellcard,80);
	CutinA3("Water Sign \"Rain Dance\"",15);
	waitS(20);
	SE_Play(spellcard,80);
	CutinA4("Fairy Sign \"Fairy Wind\"",15);
}

task SunnyDay{
	let angleT = rand(0,360);
	SE_Play(shoot2,45);
	loop(20){
		CreateLooseLaserA1(GetCenterX,0,2.5,angleT,50,20,1019,30);
		angleT+=360/20;
		}
}
task solarBeamA{
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
	let angleT=270;
	loop(1){
		 let obj = CreateShotA1(bossX,bossY,2,angleT,788,0);
		}
		angleT+=180/1;
}

task solarBeamALoop{
	loop(40){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		solarBeamA;
		wait(10);
	}
	loop{
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		solarBeamB;
		wait(5);
	}
}
task solarBeamB{
	let angleT=270;
	loop(1){
	if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		 let obj = CreateShotA1(bossX,bossY,2,angleT,788,0);
		 BulletReflectAll(obj);
		}
		angleT+=180/1;
}

task SolarLaser{
	let angleT = angleToPlayer;
	CreateStraightLaserA1(bossX, bossY, angleT, 512, 30, 60, 1011, 60);
	CreateStraightLaserA1(bossX, bossY, angleT-180, 512, 30, 60, 1011, 60);
}
task laserWait{
	wait(60);
	SE_Play(laserSFX,40);
}
task solarLaserLoop{
	waitS(8);
	loop{
		if(ObjEnemy_GetInfo(bossObj,INFO_LIFE) <=0) {return;}
		laserWait;
		SolarLaser;
		wait(120);
	}
}
task FairyWind{
	waitS(20);
	loop{
		SE_Play(shoot,30);
		if(ObjEnemy_GetInfo(bossObj,INFO_LIFE) <=0) {return;}
		CreateShotA1(0,rand(0,GetStgFrameHeight),rand(1,2),rand(0,10)-rand(20,-10),52,30);
		wait(10);
	}
}
task BulletReflectAll(obj){
	while(ObjMove_GetX(obj)>0&&ObjMove_GetX(obj) < GetStgFrameWidth&&ObjMove_GetY(obj) >0) {yield;}
	if (ObjMove_GetX(obj) <=  0){
		ObjMove_SetX(obj, 0);
		ObjMove_SetAngle(obj, rand(0,90));
	} 
	else if (ObjMove_GetX(obj) >= GetStgFrameWidth){
		ObjMove_SetX(obj, GetStgFrameWidth);
		ObjMove_SetAngle(obj, rand(90,180));
	} else if(ObjMove_GetY(obj)<=0) {
		ObjMove_SetY(obj, 0);
		ObjMove_SetAngle(obj, rand(-182,-358));
	}
	wait(10);
	ObjShot_SetGraphic(obj,27);
}
task RainDance{
	loop{
		SE_Play(shoot2,40);
		if (ObjEnemy_GetInfo(bossObj,INFO_LIFE) <= 0){return;}
		CreateShotA1(rand(0,GetStgFrameWidth),10,rand(2,3),rand(88,92),55,120);
		wait(10);
	}
}


