//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["geyserNon"]
#System["./../../system/NSystem.dnh"]
#Player["./../../player/Reimu by plasmaflame22/Reimu_A.txt", "./../../player/Reimu by plasmaflame22/Reimu_C.txt"]
#include "./../../ZUNShot/ZUNShot_Const.txt"
#include "./../sharedFuncSaul.dnh"


let objBoss;
let width = 444;
let height = 448;
let life = 3800;
let time= 50;
let scene = GetEnemyBossSceneObjectID();
let path = GetCurrentScriptDirectory~"./../../SFX/";
let explosion = LoadEffect(path~ "SmallExplosion.WAV", 100);

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


@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	SetCommonData("non1", "yes");
	
	animNon(objBoss, 1);
	TFinalizeNon(scene, objBoss);
	
	ObjMove_SetDestAtFrame(objBoss, width/2, height/4, 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);
	ObjSound_Play(LoadEffect(path ~"Charge.WAV", 80));
    wait(60);
	ObjEnemy_SetDamageRate(objBoss, 100, 50);
	let shot = LoadEffect(path ~"ATTACK4.WAV", 60);
	let dir = 1; if(rand(0,1)>1/2){dir*=-1;}
	move(width/4, 3*width/4, height/5, 3*height/10, 0, 120, 180, objBoss, 0, scene, 0);
	geyserBul;
	wait(150);
	ObjSound_Play(LoadEffect(path ~"Charge.WAV", 80));
	wait(60);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    let delayBetweenBul = floor(rand(11,13)); let wvel = rand(2,3); let delayBetweenWvel = rand(30, 45);
		let speed = rand(2.5,2.7); if(ObjMove_GetY(objBoss)<3*height/10){speed = rand(3,3.5);}
		shotSound(shot, 300, 65, delayBetweenBul, objBoss, false, 0, scene, 0);
		wavySpiral(5,300,dir,delayBetweenBul, speed, wvel,delayBetweenWvel,288,292,objBoss, 0); 
		wait(390);
	}
}


	
	
task geyserBul{
    let shot2 = LoadEffect(path ~"ATTACK5.WAV", 70);
	let col = 403; let i=1; let ang;
    loop(2){
		ObjSound_Play(shot2);
		let ang = rand(50, 130); 
		if(col == 403){ang = rand(-30, 30);} 
		let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(2,2.4), ang, col, 0);
		ObjShot_SetSpellResist(obj, true);
		aimPlayer(obj, 60, 20);
		geyser(obj, 4); col= 403+i%2; i++; wait(80);
	}
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
	    ObjSound_Play(shot2);
	    ang = rand(20,160); 
	    if(col == 403){ang = rand(-30, 30);} 
	    let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(2,2.4), ang, col, 0);
		ObjShot_SetSpellResist(obj, true);
		aimPlayer(obj, 60, 20);
		geyser(obj, 4); col= 403+i%2; i++;
		wait(200);
	}
}
	
	
	
task geyser(obj, numBul){
    while(ObjMove_GetY(obj)<height && !Obj_IsDeleted(obj)){yield;}
	if(Obj_IsDeleted(obj)){return;}
	if(ObjMove_GetX(obj)>-5 || ObjMove_GetX(obj)< width+5){
		let graph = 61; if(ObjShot_GetImageID(obj)== 404){graph=63;}
		ObjSound_Play(explosion);
		loop(20){
			loop(numBul){
			    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
				let obja = CreateShotA1(ObjMove_GetX(obj)+rand(-5,5), height, rand(0.06, 6), rand(250,290),graph, 0);
			}
			yield;
		}
		wait(60);
	}
	Obj_Delete(obj);
}
	
	
	

