#include "./BossInclude.dnh"

@Event{
	let LIFE_VALUE = 2200;
	let TIME_VALUE = 35;
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){
		SetScriptResult(LIFE_VALUE);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(TIME_VALUE);
	}
}

@Initialize{
	Boundary = [64,64,64,64];
	MAIN_Initialize;
	BOSS_Initialize("CHAR_SEIJA");
	NORMAL_Finalize;
	//----------//
	ObjEnemy_SetCollision(objBoss,32,16);
	ObjEnemy_SetDamageRate(objBoss,0,0);
	ObjMove_SetDestAtBrake(objBoss,CenX,CenY-64,90);
	ObjAnim_SetActionA1(objBoss,ACT_MOVE,90);
	//----------//
	MainThread_Standard;
}

task ObjBoss_SetStepChargeA1(let objTarget){
	PlaySoundA1(SE_CHARGE_NORM);
	ascent(let i in 0..6){
		let wtTime = 90-12*i;
		SetChargeEffectA2(objTarget,[0,-24],3,SHOT_ARGB,[RED,BLUE][i%2],wtTime);
		wait(10);
		if(!ObjEnemy_IsAlive(objTarget)){ return; }
	}
}

task MainThread_Standard{
	wait(90);
	ObjAnim_SetActionA1(objBoss,ACT_SHOT_B,180);
	ObjBoss_SetStepChargeA1(objBoss);
	ObjEnemy_WaitDamageRate(objBoss,100,67.5,60);
	wait(60);
	let rValue = GetInverser;
	while(ObjEnemy_IsAlive(objBoss)){
		local{
			SubTask_SetAttackA1(rand_deg,rValue);
			wait(45);
			if(!ObjEnemy_IsAlive(objBoss)){ return; }
			SubTask_SetAttackA2(rand_deg,-rValue);
			task SubTask_SetAttackA1(let setAngle, let rMod){
				let dMax = 16;
				descent(let d in 0..dMax){
					PlaySoundA1(SE_SHOT_MAIN);
					PlaySoundO1(objBoss,SE_WAVE_NEW,45);
					PlaySoundO1(objBoss,SE_WAVE_SET,45+45);
					let decLength = d*96/(dMax-1);
					ascent(let iWay in 0..12){
						let wayAngle = setAngle+iWay*(360/12);
						let sX = GetGapX(GetBossX,decLength,wayAngle);
						let sY = GetGapY(GetBossY-24,decLength,wayAngle);
						let objLoc = CreateShotS2(sX,sY,1.5,wayAngle,-1.5/60,0,REV_RICE_BLUE,12,BLUE);
						ObjShot_SetReverseShotA1(objLoc,45,RICE_BLUE);
					}
					setAngle += 18.75*rMod;
					wait(2);
					if(!ObjEnemy_IsAlive(objBoss)){ return; }
				}
			}
			task SubTask_SetAttackA2(let setAngle, let rMod){
				let dMax = 16;
				let wtTime = 45;
				descent(let d in 0..dMax){
					PlaySoundA1(SE_SHOT_MAIN);
					PlaySoundO1(objBoss,SE_WAVE_NEW,wtTime);
					PlaySoundO1(objBoss,SE_WAVE_SET,wtTime+45);
					let decLength = d*72/(dMax-1);
					ascent(let iWay in 0..16){
						let wayAngle = setAngle+iWay*(360/16);
						let sX = GetGapX(GetBossX,decLength,wayAngle);
						let sY = GetGapY(GetBossY-24,decLength,wayAngle);
						let objLoc = CreateShotS2(sX,sY,2,wayAngle,-2/60,0,REV_ELLIPSE_RED,12,RED);
						let newAngle = wayAngle+d*(90/(dMax-1))*rMod;
						ObjShot_SetReverseShotA2(objLoc,wtTime,newAngle,ELLIPSE_RED);
					}
					wtTime -= 1;
					setAngle += 2.25*rMod;
					wait(4);
					if(!ObjEnemy_IsAlive(objBoss)){ return; }
				}
			}
			task ObjShot_SetReverseShotA1(let objTarget, let wtTime, let revGraph){
				let iniGraph = ObjShot_GetImageID(objTarget);
				let iniColor = ObjVar_GetColorValue(objTarget);
				let getAngle = ObjMove_GetAngle(objTarget);
				wait(wtTime);
				if(Obj_IsDeleted(objTarget)){ return; }
				let oX = ObjMove_GetX(objTarget);
				let oY = ObjMove_GetY(objTarget);
				ObjVar_DisableBreak(objTarget);
				Obj_WaitDelete(objTarget,1);
				// Transition --------------------
				let obj1 = CreateShotD2(oX,oY,2,2,getAngle,1/30,3,revGraph,12,iniColor);
				wait(45);
				if(Obj_IsDeleted(obj1)){ return; }
				oX = ObjMove_GetX(obj1);
				oY = ObjMove_GetY(obj1);
				ObjVar_DisableBreak(obj1);
				Obj_WaitDelete(obj1,1);
				// Ending ------------------------
				CreateShotD2(oX,oY,3,3,getAngle,-2/30,1,iniGraph,12,iniColor);
			}
			task ObjShot_SetReverseShotA2(let objTarget, let wtTime, let newAngle, let revGraph){
				let iniGraph = ObjShot_GetImageID(objTarget);
				let iniColor = ObjVar_GetColorValue(objTarget);
				wait(wtTime);
				if(Obj_IsDeleted(objTarget)){ return; }
				let oX = ObjMove_GetX(objTarget);
				let oY = ObjMove_GetY(objTarget);
				ObjVar_DisableBreak(objTarget);
				Obj_WaitDelete(objTarget,1);
				// Transition --------------------
				let obj1 = CreateShotD2(oX,oY,2,2,newAngle,3/30,5,revGraph,12,iniColor);
				wait(45);
				if(Obj_IsDeleted(obj1)){ return; }
				oX = ObjMove_GetX(obj1);
				oY = ObjMove_GetY(obj1);
				ObjVar_DisableBreak(obj1);
				Obj_WaitDelete(obj1,1);
				// Ending ------------------------
				CreateShotD2(oX,oY,3,3,newAngle,-2/30,1,iniGraph,12,iniColor);
			}
		}
		wait(90);
		if(!ObjEnemy_IsAlive(objBoss)){ return; }
		let LTRB = [MinX+80,CenY-64,MaxX-80,CenY-32];
		ObjAnim_SetActionA1(objBoss,ACT_MOVE,45);
		ObjAnim_SetActionA2(objBoss,60,ACT_SHOT_B,180);
		ObjBoss_SetStepChargeA1(objBoss);
		ObjMove_SetDestAtRand(objBoss,rand(32,48),rand(0,32),LTRB,45);
		wait(75);
		rValue = -rValue;
	}
}