//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["spinRingSlow"]
#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 "./../sharedFuncSamir.dnh"


let objBoss;
let width = 420;
let height = 440;
let life = 3000;
let time= 50;
let scene = GetEnemyBossSceneObjectID();
let path = GetCurrentScriptDirectory~"./../../SFX/";

let charge = LoadEffect(path~ "Charge.WAV", 80);
let shot4 = LoadEffect(path~ "ATTACK4.WAV", 60);
let shot5 = LoadEffect(path~ "ATTACK5.WAV", 70);


@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);
	SetPlayerClip(5,5, 415, 435);
	SetCommonData("non1", "yes");
	
	animNon(objBoss, 1);
	TFinalizeNon(scene, objBoss);
	
	Name(1, objBoss);
    Indicator(objBoss, 1);
    takeDamage(objBoss, scene, life);
	
	ObjMove_SetDestAtFrame(objBoss, width/2, height*0.3, 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 spinRing(xini, yini, numBul, rad, ang, speed, angSpeed, dir, graphic, delay){


task Main{
    ObjEnemy_SetDamageRate(objBoss, 0, 0);
	wait(120);
	ObjEnemy_SetDamageRate(objBoss, 20, 0);
	ObjSound_Play(LoadEffect(path ~"Charge.WAV", 80));
    wait(60);
	move(objBoss, width/3, 2*width/3, height/4 ,height*0.36, 0, 150, 60, objBoss, 0, scene, 0);
	ObjEnemy_SetDamageRate(objBoss, 100, 60);
	
	// data = [rad, numBul, numBranch]
	
	let data2 = [[65,80], [6,8], [7,9]];
	
	let dir = 1; let i=0;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    let numBranch = truncate(rand(data2[2][0], data2[2][1])); let speed = rand(1,1.4); let angSpeed= rand(0.5, 0.7); let ang = rand(0,360);
		let rad = rand(data2[0][0], data2[0][1]); let numBul = rand(data2[1][0], data2[1][1]);
		let graphic = 249 + i%4;
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){ObjSound_Play(shot5);}
	    ascent(i in 0..numBranch){
		    spinRing(X(objBoss), Y(objBoss), truncate(numBul), rad, ang+360/numBranch *i, speed, angSpeed, dir, graphic, 10);
		}
		wait(60); dir*=-1; i++;
	}
}
	
	
	
	
	
	
	
	
	
	
