//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["First non"]
#include "./../../ZUNShot/ZUNShot_Const.txt"
#include "./../sharedFuncDave.dnh"



let objBoss;
let width = 384;
let height = 448;
let life = 5800;
let scene = GetEnemyBossSceneObjectID();

@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(life);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(50);
    }
}


@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	SetCommonData("non1", "no");
	
	animNon( objBoss);
	TFinalizeNon(scene, objBoss);
	
	
    ObjMove_SetDestAtFrame(objBoss, width/2, 2*height/5, 60);
	Main;
}


@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 28);
    yield;
}



task Main{
    Name(1, objBoss);
    Indicator(objBoss, 1);
    takeDamage(objBoss, scene, life);
    ObjEnemy_SetDamageRate(objBoss, 0, 0);
	wait(120);
	ObjEnemy_SetDamageRate(objBoss, 20, 0);
    wait(60); 
	let shot1 = LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/ATTACK4.WAV", 60);
	let shot2 = LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/ATTACK5.WAV", 60);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
		ObjMove_SetDestAtFrame(objBoss, rand(3*width/10, 7*width/10), rand(0.25*height, 0.3*height), 60);
		wait(40);
		ObjEnemy_SetDamageRate(objBoss, 100, 50);
		ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/Charge.WAV", 80));
		wait(60);
		shotSound(shot1, 60, 60, 7, objBoss, false, 0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 6, GetAngleToPlayer(objBoss), 9, 1, 2, 300, 1, 0, 3, -0.02, -0.005, 1.5, 0, 0, 47, objBoss, 0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 6, GetAngleToPlayer(objBoss), 9, -1, 2, 300, 1, 0, 3, -0.02, -0.005, 1.5, 0, 0, 47, objBoss, 0);
		wait(60);
		shotSound(shot1, 240, 60, 4, objBoss, false, 0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 4, GetAngleToPlayer(objBoss)-45, 7, 2, 0, 240, 1, 0, 2.5, -0.005, -0.001, 1.2, 0, 0, 54, objBoss, 0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 4, GetAngleToPlayer(objBoss)-45, 7, -2, 0, 240, 1, 0, 2.5, -0.005, -0.001, 1.2, 0, 0, 54, objBoss, 0);

		wait(60);
		shotSound(shot2, 240, 60, 8, objBoss, false, 0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, GetAngleToPlayer(objBoss)-20, 8, -1, 0, 240, 1, 0, 1, 0, 0, 1, 0, 0, 289, objBoss, 0);
		spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, GetAngleToPlayer(objBoss)-20, 7, 1, 0, 240, 1, 0, 1, 0, 0, 1, 0, 0, 289, objBoss, 0);
		wait(240);
		
		let dir=1;
		if(rand(0,1)>1/2){dir=-1;}
		wait(60);
		ObjMove_SetDestAtFrame(objBoss, width/2 - dir*width/4 + dir* rand(0, 40), rand(height/5, 2*height/5), 60);
		wait(110);
		shotSound(shot1, 120, 60, 5, objBoss, false, 0);
		ascent(i in 0..3){
		    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
			spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3, 90-110*dir +30*dir*i, 4, 3*dir, 0, 120, 1, 0, 1.5, 0.001, 0.01, 2.5, 0, 0, 219 +4*i, objBoss, 0);
		}
		wait(150);
		shotSound(shot1, 120, 60, 5, objBoss, false, 0);
		ascent(i in 0..3){
		    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
			spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3, 90+110 *dir -dir*30*i, 4, -3*dir, 0, 120, 1, 0, 1.5, 0.001, 0.01, 2.5, 0, 0, 219 +4*i, objBoss, 0);
		}
		wait(150);
		}
	}