//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Integral part"]
#include "./../../ZUNShot/shotInteg_Const.txt"
#include "./../sharedFuncDave.dnh"



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

@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);
	ObjEnemyBossScene_StartSpell(scene);
	SetCommonData("non1", "no");
	SetCommonData("spell", "Integral");
	
	
	animSpell(objBoss, 1);
	TFinalizeSpell(scene, objBoss, false, false);
	
	
    ObjMove_SetDestAtFrame(objBoss, width/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{
    Name(1, objBoss);
    Indicator(objBoss, 1);
    takeDamage(objBoss, scene, life);
    ObjEnemy_SetDamageRate(objBoss, 0, 0);
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/SPELLCARD.WAV", 100));
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/CAUTIONSHORT.WAV", 100));
	Spell("Chaos sign:[r]Integral part", objBoss, 1);
	ObjMove_SetDestAtFrame(objBoss, width/2, height/5, 60); let ini = 0;
	let shot = LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/ATTACK5.WAV", 60);
	ObjSound_SetRestartEnable(shot, true);
	wait(240); 
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/Charge.WAV", 80));
	wait(60);
	damage;
	let t=0;
	while(t<500){
	    ObjSound_Play(shot);
	    let obj = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(2,3), rand(190, 350), rand(-0.1, -0.01), -1, rand(450, 455), 0);
		ObjShot_SetSpellResist(obj, true);
        ObjRender_SetAngleZ(obj, 180);
		Command(obj, 1, 0, rand(0.02, 0.05), 4);
		wait(20-0.036*t); t+= 20-0.036*t;
	}
	moveEdge(objBoss, ini, 1, width/4, 3*width/4, 0, objBoss, life/2); t=0;
	shotSound(shot, -1, 55, 4, objBoss, false, life/2);
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>life/2 && ObjEnemyBossScene_GetInfo(scene, INFO_TIMER)> 20){
		let obj = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(2,5), rand(190, 350), rand(-0.1, -0.05), -1, rand(450, 456), 0);
		ObjShot_SetSpellResist(obj, true);
		ObjRender_SetAngleZ(obj, 180);
		Command(obj, 1, 0, rand(0.02, 0.04), 4);
		wait(2);
	}
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/ATTACK3.WAV", 90));
	ObjEnemy_SetLife(objBoss, life/2);
	DeleteShotAll(TYPE_ALL, TYPE_FADE);
	ObjEnemy_SetDamageRate(objBoss, 10, 0);
	ObjMove_SetDestAtFrame(objBoss, width/2, 200, 60);
	wait(90);
	ObjSound_Play(LoadEffect(GetCurrentScriptDirectory~ "./../../SFX/POWER UP.WAV", 80));
	wait(120);
	ObjEnemy_SetDamageRate(objBoss, 60, 20);
	t=0;
	shotSound(shot, -1, 60, 3, objBoss, false, 0);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
	    if(ObjEnemy_GetInfo(objBoss, INFO_LIFE)<=0){return;}
		let ang=rand(0,360);
		let obj=CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(2,3), ang, rand(450, 456), 0);
		ObjRender_SetAngleZ(obj, 180);
		if(t%10==0){
			let ang=rand(0,360);
			let obj=CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), rand(2,3), ang, rand(453, 456), 0);
			ObjRender_SetAngleZ(obj, 180);
		}
		wait(2); t++;
	}
}		

task damage{ObjEnemy_SetDamageRate(objBoss, 20, 0); wait(300); ObjEnemy_SetDamageRate(objBoss, 60, 20); }






