//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["geyser 1"]
#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 = 4200;
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/2, 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{
	SetForbidPlayerShot(false);
	SetForbidPlayerSpell(false);
    Name(1, objBoss);
    Indicator(objBoss, 1);
    takeDamage(objBoss, scene, life);
    ObjEnemy_SetDamageRate(objBoss, 0, 0);
	wait(80);
	NotifyEventAll(EV_USER_STAGE+2, 0);
	ObjEnemy_SetDamageRate(objBoss, 20, 0);
	ObjSound_Play(LoadEffect(path ~"Charge.WAV", 90));
	wait(60);
	move(width/3, 2*width/3, 0.35*height, height/2, 180, 120, 180, objBoss, 0, scene, 0);
	ObjEnemy_SetDamageRate(objBoss, 100, 60);
	ascent(i in 0..2){
	    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
	    ObjSound_Play(LoadEffect(path ~"ATTACK5.WAV", 70));
	    let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3, 125-70*i, 404,0); geyser(obj, true, 20);
		ObjShot_SetSpellResist(obj, true); wait(30);
	}
	wait(60);
	geyserBul;
	wait(60);
}



task geyserBul{
    let shot = LoadEffect(path~"ATTACK4.WAV", 70); let shot2 = LoadEffect(path ~"ATTACK5.WAV", 75);
    let col = [400,401,407,402]; let dir=1;
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    ObjSound_Play(LoadEffect(path ~"Charge.WAV", 80));
		wait(60);
	    ascent(i in 0..4){
			if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
		    ObjSound_Play(shot2);
			let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(2.8,3.2), 270+ dir*(20*i-30) +rand(-6,6), col[i], 0);
			ObjShot_SetSpellResist(obj, true);
			let numBul =1; if(i==2){numBul=2;} 
			geyser(obj, false, numBul);
			wait(20);
		}
		wait(240); dir*=-1;
		loop(5){
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
		ObjSound_Play(shot);
			ascent(i in 0..25){CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3.5, GetAngleToPlayer(objBoss)+14.4*i, 200, 0);}
			wait(20);
		}
	}
}



task geyser(obj, floor, numBul){
    let graph; let s; let ang; let y;
    while(ObjMove_GetY(obj)<height && ObjMove_GetY(obj)>0 && !Obj_IsDeleted(obj)){yield;}
	if(Obj_IsDeleted(obj)){return;}
	ObjSound_Play(explosion);
	if(ObjMove_GetX(obj)>-5 && ObjMove_GetX(obj)< width+5){
	    alternative(ObjShot_GetImageID(obj))
		case(400){graph=60;}
		case(401){graph=65;}
		case(404){graph=63;}
		case(407){graph=72;}
		case(402){graph=68;}
		loop(20){
			loop(numBul){
			    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0 || Obj_IsDeleted(obj)){return;}
				s = rand(0.04, 2.2); ang = rand(70,110); y = 0;
				if(floor){s=rand(0.01, 6); ang= rand(250,290); y = height;}
				let obja = CreateShotA1(ObjMove_GetX(obj)+rand(-5,5), y, s, ang,graph, 0);
				if(floor){ObjShot_SetSpellResist(obja, true);}
			}
			yield;
		}
		wait(60);
	}
	Obj_Delete(obj);
}