//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Rain2"]
#include "./../ZUNShot/ZUNShot_Const.txt"
#include "./sharedfuncMario.dnh"


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


@Event{
    alternative(GetEventType())
    case(EV_REQUEST_LIFE){
        SetScriptResult(life);
    }
    case(EV_REQUEST_TIMER){
        SetScriptResult(50);
    }
    case(EV_REQUEST_SPELL_SCORE){
        SetScriptResult(1000000);
    }
}


@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	Indicator(objBoss);
    
	animNon(objBoss);
	
	
	TFinalizeNon(objBoss);
	ObjMove_SetDestAtFrame(objBoss, width/2, 3* height/10+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{
    takeDamage(objBoss, scene, life);
    ObjEnemy_SetDamageRate(objBoss, 100, 60);
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "../SFX/Charge.WAV", 90));
	let shot = LoadEffect(GetCurrentScriptDirectory~"../SFX/ATTACK5.WAV", 60);
	wait(60);
    move(2*width/5, 4*width/5, height/5 +24, height/5+25, 260, objBoss);
	rain(409, 417, [0], 180, 80, 0.05, 60, rand(0.015, 0.02), objBoss);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 2*life/3){yield;}
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
	    let ang= rand(0,180);
	    ascent(i in 0..6){if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) <= 0) {return;} ObjSound_Play(shot); let obj =CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 3, ang+60*i, 379, 0); control(obj, 1, 60, 300);}
		if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > life/3){wait(60);}
		else{wait(20);}
	}
}