#include "./BossInclude.dnh"

@Event{
	let LIFE_VALUE = 2500;
	let TIME_VALUE = 40;
	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-80,90);
	ObjAnim_SetActionA1(objBoss,ACT_MOVE,90);
	//----------//
	MainThread_Standard;
}

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

task MainThread_Standard{
	wait(90);
	ObjAnim_SetActionA1(objBoss,ACT_SHOT_B,60*99);
	ObjBoss_SetStepChargeA1(objBoss);
	ObjEnemy_WaitDamageRate(objBoss,100,75,60);
	wait(60);
	SubTask_SetPatternA1(GetInverser);
	wait(120);
	while(ObjEnemy_IsAlive(objBoss)){
		PlaySoundA1(SE_WAVE_NEW);
		let randAngle = rand_deg;
		let pX = GetGapX(GetBossX,64,randAngle);
		let pY = GetGapY(GetBossY-8,64,randAngle);
		let toPlayer = GetAngleToPlayer2(pX,pY);
		let arcWide = rand_int(30,60);
		ascent(let iWide in 0..3){
			let arcAngle = toPlayer-(arcWide/2)+iWide*(arcWide/2);
			let objLoc = CreateShotD2(pX,pY,0,0,arcAngle,3/45,3,FIRE_PURPLE,-12,PURPLE);
		}
		wait(15);
	}
	
	task SubTask_SetPatternA1(let rMod){
		while(ObjEnemy_IsAlive(objBoss)){
			let setAngle = rand_deg;
			let wtTime = 5;
			let iValue = 0;
			let dMax = 9+15;
			VarTask_ControlLoop;
			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*80/(dMax-1);
				ascent(let iWay in 0..20){
					let wayAngle = setAngle+iWay*(360/20);
					let sX = GetGapX(GetBossX,decLength,wayAngle);
					let sY = GetGapY(GetBossY-24,decLength,wayAngle);
					let objLoc = CreateShotS2(sX,sY,2,wayAngle,-2/60,0,[REV_RICE_RED,REV_RICE_BLUE][iValue],12,[RED,BLUE][iValue]);
					ObjShot_SetReverseShotA2(objLoc,45,[RICE_RED,RICE_BLUE][iValue]);
				}
				wait(wtTime);
				if(!ObjEnemy_IsAlive(objBoss)){ return; }
			}
			task VarTask_ControlLoop{
				ascent(let i in 0..9){
					wait(5);
					if(i < 8){
						setAngle += 1.75*rMod;
					}
				}
				wtTime = 3;
				iValue++;
				loop(15){
					wait(3);
					setAngle -= 2.25*rMod;
				}
			}
			task ObjShot_SetReverseShotA2(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,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,getAngle,-2/30,1,iniGraph,12,iniColor);
			}
			rMod = -rMod;
			wait(105);
		}
	}
}