//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["hypoNon"]
#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 = 6000;
let time= 60;
let scene = GetEnemyBossSceneObjectID();
let path = GetCurrentScriptDirectory~"./../../SFX/";

@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", "no");
	
	animNon(objBoss, 1);
	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{
    SetForbidPlayerShot(false);
	SetForbidPlayerSpell(false);
    Name(1, objBoss);
    Indicator(objBoss, 1);
    takeDamage(objBoss, scene, life);
    ObjEnemy_SetDamageRate(objBoss, 0, 0);
	wait(120);
	let shot3= LoadEffect(path~"ATTACK3.WAV", 100);
	let shot4 = LoadEffect(path~"ATTACK4.WAV", 70);
	let shot5 = LoadEffect(path~"ATTACK5.WAV", 70);
	ObjEnemy_SetDamageRate(objBoss, 20, 0);
	ObjSound_Play(LoadEffect(path ~"Charge.WAV", 80));
    wait(60);
	let r = 3*width/(3.8*16); let r2 = 3*width/(2.1*16);  
	let k = 3.8; let k2 = 2.1;
	ObjSound_Play(shot5);
	hypo(r, k, 1.2, 1.5, rand(0,500), 14, rand(90, 180), 10, 404, 275, 60, 60,1);
	hypo(r2,k2, 1.2,1.5, rand(1000, 1500), -15, rand(200, 300), 8, 404, 275, 60,60,1);
	wait(150);
	shotSound(shot4, -1, 55, 5, objBoss, false, 2*life/3, scene, 30);
	wait(80);
	ObjEnemy_SetDamageRate(objBoss, 100, 60);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>2*life/3 +200 && ObjEnemyBossScene_GetInfo(scene, INFO_TIMER)> 40){yield;}
	
	ObjSound_Play(shot3);
	loop(5){DeleteShotAll(TYPE_SHOT, TYPE_FADE); yield;}
	ObjSound_Play(shot5);
	hypo(r, k2, 1.65, 1.7, rand(0,500), 16, rand(90, 180), -12, 402, 279, 0, 20, 1);
	loop(5){DeleteShotAll(TYPE_SHOT, TYPE_FADE); yield;}
	shotSound(shot4, 45, 55, 5, objBoss, false, 0, scene, 0);
	wait(45);
	shotSound(shot4, -1, 55, 4, objBoss, false, life/3, scene, 15);
	
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>life/3 +400 && ObjEnemyBossScene_GetInfo(scene, INFO_TIMER)> 25){yield;}
	ObjSound_Play(shot3);
	loop(5){DeleteShotAll(TYPE_SHOT, TYPE_FADE); yield;}
	ObjSound_Play(shot5);
	hypo(r2, k2, 1.4, 1.5, rand(500,800), -10, rand(50, 100), -13, 400, 271, 0, 10, 1);
	shotSound(shot4, 40, 55, 4, objBoss, false, 0, scene, 0);
	wait(40);
	shotSound(shot4, -1, 55, 3, objBoss, false, 0, scene, 0);
	
	
}


task hypo(r, k, speedMin, speedMax, spawnBegin, incSpawn, angBegin, incAng, graphBall, graphBullets, delay1, delay2, pause){
    let t= spawnBegin; let ang= angBegin;
	let x = width/2 + r*(k-1)*cos(t) + r*cos((k-1)*t); 
	let y = height/3 - r*(k-1)*sin(t) + r*sin((k-1)*t);
    let obj = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 0, 0, graphBall, 0); ObjShot_SetSpellResist(obj, true);
	ObjMove_SetDestAtFrame(obj, x, y, 30); wait(30 + delay1); let time = 0;
	while(time<delay2){
	    x = width/2 + r*(k-1)*cos(t) + r*cos((k-1)*t); 
	    y = height/3 - r*(k-1)*sin(t) + r*sin((k-1)*t);
		ObjMove_SetDestAtFrame(obj, x, y, pause); t+=incSpawn; ang+= incAng; time+= pause; wait(pause);
	}
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    x = width/2 + r*(k-1)*cos(t) + r*cos((k-1)*t); 
	    y = height/3 - r*(k-1)*sin(t) + r*sin((k-1)*t);
		ObjMove_SetDestAtFrame(obj, x, y, 1); 
		CreateShotA1(x, y, rand(speedMin, speedMax),ang, graphBullets, 0);
		t+=incSpawn; ang+= incAng; wait(pause);
	}
}
	    
	
