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



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

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


@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	NotifyEventAll(EV_USER_STAGE, 0);
	
	animNon(objBoss);
	TFinalizeNon(objBoss);
	
	
    ObjMove_SetDestAtFrame(objBoss, width/2, 3*height/10, 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{
    Indicator(objBoss);
    takeDamage(objBoss, scene, life);
	progress;
    let shot= LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK5.WAV", 70);
	let charge = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/Wave.WAV", 90);
    SetForbidPlayerShot(false);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
    wait(60);
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../SFX/POWER UP.WAV", 90));
	ObjEnemy_SetDamageRate(objBoss, 20,0);
	wait(100);
	familiars;
	wait(120);
	ObjEnemy_SetDamageRate(objBoss, 100, 60);
	wait(120);
    move(objBoss, 3*width/10, 7*width/10, 2*height/5, height/2, 210, objBoss, 0);
	ObjSound_Play(charge);
	wait(60);
	let dir = 1;
	let num;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > life/2){num = 40;} else{num=65;}
	    let col = truncate(rand(91,95));
	    if(dir ==1){ascent(i in 0..3){if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<= 0){return;} ObjSound_Play(shot); launch(objBoss, num, 220 + 50*i, 30, rand(4, 5), -0.1, -0.05, 0, col, 0, true, 60-20*i, 0.01, 0.04, 0.06, 3, false, objBoss); wait(30);}}
		else{ascent(i in 0..3){if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<= 0){return;} ObjSound_Play(shot); launch(objBoss, num, 320 - 50*i, 30, rand(4, 5), -0.1, -0.05, 0, col, 0, true, 60-20*i, 0.01, 0.04, 0.06, 3, false, objBoss); wait(30);}}
		wait(60);
		ObjSound_Play(charge);
		wait(60);
		dir*=-1;
	}
}

task progress{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > life/2){yield;}
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK3.WAV", 80));
}


task familiars{
    ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK5.WAV", 80));
	let obj1= CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 0, 0, 399, 0);
	ObjShot_SetSpellResist(obj1, true);
	let obj2= CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 0, 0, 399, 0);
	ObjShot_SetSpellResist(obj2, true);
	let col1; let col2;
	let pause = true;
	let shot = LoadEffect(GetCurrentScriptDirectory~ "./../SFX/ATTACK4.WAV", 60);
	let i = 0;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
	    col1 = truncate(rand(79,85)); col2 = truncate(rand(85, 89));
		ObjMove_SetDestAtFrame(obj1, rand(width/5, 2*width/5), rand(height/5, 2*height/5), 60);
		ObjMove_SetDestAtFrame(obj2,  rand(3*width/5, 4*width/5), rand(height/5, 2*height/5), 60);
		if(pause){wait(120);}
		else{wait(60);}
		shotSound(shot, 300, 50, 12, objBoss,0);
		spiral(ObjMove_GetX(obj1), ObjMove_GetY(obj1), 7+(i+1)%2, rand(0,360), 12, -1, 300, 1, 10, rand(1.1, 1.3), 0,0,0, col1, objBoss, 0, false);
        spiral(ObjMove_GetX(obj2), ObjMove_GetY(obj2), 7+i%2, rand(0,360), 12, 1, 300, 1, 10, rand(1.1, 1.3), 0,0, 0, col2, objBoss, 0, false);
		wait(240);
		spiral(ObjMove_GetX(obj1), ObjMove_GetY(obj1), 5 , rand(0,360), 12, 1, 60, 1, 10, rand(1.1, 1.3), 0,0,0, col2, objBoss, 0, false);
		spiral(ObjMove_GetX(obj2), ObjMove_GetY(obj2), 5, rand(0,360), 12, -1, 60, 1, 10, rand(1.1, 1.3), 0,0,0, col1, objBoss, 0, false);
		wait(60);
		pause = false;
		i++;
	}
}
