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



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

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


@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);
	SetForbidPlayerShot(false);
	wait(120);
	ObjEnemy_SetDamageRate(objBoss, 20, 0);
	let shot = LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/ATTACK5.WAV", 60);
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/POWER UP.WAV", 80));
	wait(120);
	ObjEnemy_SetDamageRate(objBoss, 100, 50);
    let dir= 1; if(rand(0,1)>1/2){dir=-1;}
	circles;
	movement;
	missiles;
	let twinkle = LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/TWINKLE2.WAV", 80);
	spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 6, GetAngleToPlayer(objBoss)-45, 10, -dir*2, 10, 200, 1, 60, 2.5, -0.05, -0.01, 1.2, 0, 0, 231, objBoss, 0);
	sound(twinkle);
	while (ObjEnemy_GetInfo(objBoss, INFO_LIFE)>life/3){
	    shotSound(twinkle, 200, 40, 6, objBoss, false, life/3);
	    spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 6, GetAngleToPlayer(objBoss)-45, 5, dir*2, 10, 200, 1, 60, 3.5, -0.05, -0.01, 2, 0, 0, 227, objBoss, 0);
	    spiral(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 6, GetAngleToPlayer(objBoss)-45, 5, -dir*2, 10, 200, 1, 60, 3.5, -0.05, -0.01, 2, 0, 0, 231, objBoss, 0);
		wait(300);
	}
	let col = rand(193, 200);
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/ATTACK3.WAV", 100));
	DeleteShotAll(TYPE_ALL, TYPE_FADE);
	shotSound(shot, -1, 60, 4, objBoss, false, 0); let i=0; let num;
	while (ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    num = 5; if(i%2 ==0){num=6;}
	    loop(4){if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;} CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3, rand(140,400), col, 0);}
		loop(num-4){if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;} CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3, rand(0,180), col, 0);}
		yield; i++;
	}
}

task sound(twinkle){
    let t=0; ObjSound_SetRestartEnable(twinkle, true);
	while(t<200){if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;} ObjSound_Play(twinkle); wait(6); t+=6;}
}


task circles{
    wait(300);
	let shot = LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/ATTACK4.WAV", 70);
    while (ObjEnemy_GetInfo(objBoss, INFO_LIFE)>life/2){
	    ObjSound_Play(shot);
	    ascent(i in 0..22){
		    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
			CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 2, GetAngleToPlayer(objBoss)+i*360/22, 0.05, 5, 318, 0);
		}
		wait(20);
		ObjSound_Play(shot);
		ascent(i in 0..22){
		    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
			CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 2, GetAngleToPlayer(objBoss)+ 7+i*360/22, 0.05, 5, 318, 0);
		}
		wait(60);
	}
	while (ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    ObjSound_Play(shot);
	    ascent(i in 0..32){
		    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
			CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 2, GetAngleToPlayer(objBoss)+i*360/32, 0.05, 4, 318, 0);
		}
		wait(40);
	}
}

task movement{
    move(width/5, 4*width/5, height/5, 2*height/5, 230, 30, 300, objBoss, life/3);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>life/3){yield;}
    move(2*width/5, 4*width/5, height/5, 3*height/10, 0, 30, 60, objBoss, 0);
}

task missiles{
    let shot = LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/ATTACK5.WAV", 55);
	let t=0; let col = rand(193, 200);
	while(t<260){
	    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
	    ObjSound_Play(shot);
	    ascent(i in 0..2){CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, 90+ 25 + 72*i +rand(-5,5), col, 0);}
		ascent(i in 0..2){CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, 90- 97 + 72*i +rand(-5,5), col, 0);}
		wait(4); t+=4;
	}
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>life/3){yield;}
	col = rand(193, 200);
	shotSound(shot, -1, 60, 4, objBoss, false, 0);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
	    ascent(i in 0..2){CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, GetAngleToPlayer(objBoss)+ 35 + 72*i +rand(-5,5), col, 0);}
		ascent(i in 0..2){CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 5, GetAngleToPlayer(objBoss)- 107 + 72*i +rand(-5,5), col, 0);}
		wait(4);
	}
}
	    
	
	
	