#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Midboss Nonspell"]
#Text["Wooooooop"]

let objBoss;
#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjEnemy_SetDamageRate(objBoss,0,0);
	
	ObjMove_SetPosition(objBoss,384,0);
	ObjMove_SetDestAtSpeed(objBoss,384/2,150,2);
	
	mainTask;	
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(1500);
        }
	case(EV_REQUEST_TIMER){
		SetScriptResult(49);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

let BossX = 0;
let BossY = 0;

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,24);
	
	yield;
} 

@Finalize {

} 

task mainTask { 
	rendercarbink(objBoss);
	BottomEnemyMarker(objBoss, objBoss);
	end;
	action;
	BossShotSound(objBoss, 75, 300);
} 

task action{
wait(120);
Fire;
wait(120);
ObjEnemy_SetDamageRate(objBoss,50,40);
}

task FireComp(mod){
let ang = GetAngleToPlayer(objBoss)-90;
loop(2){
    let obj = CreateShotA1(BossX+15*cos(ang),BossY+15*sin(ang),3,ang+mod,BALL_M_AZURE,11);
	ObjShot_SetSpellResist(obj, 1);
	Spawn(obj);
	ang += 180;
    }
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 65);
}

task Fire {
while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0) {
let angle = 0;
	FireComp(0);
	wait(20);
	FireComp(22.5);
	wait(20);
	FireComp(-22.5);
	ObjMove_SetDestAtWeight(objBoss,GetPlayerX+rand(-15,15),120+rand(-20,20),10,5);
	wait(80);
	FireComp(0);
	wait(20);
	FireComp(-22.5);
	wait(20);
	FireComp(22.5);	
	ObjMove_SetDestAtWeight(objBoss,GetPlayerX+rand(-15,15),120+rand(-20,20),10,5);
	wait(80);
}
}

task Spawn(tar){
let angle = ObjMove_GetAngle(tar);
let adder = 0;
let count = 0;
let default = 7;
wait(13);
	while(!Obj_IsDeleted(tar)){
	loop(3){
	let obj = CreateShotA1(ObjMove_GetX(tar),ObjMove_GetY(tar),2,angle+adder,ICE_AZURE,10);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 65);
	adder += 360/3;
	}
	if(count<default){wait(2);}
	if(count>default){wait(40);count=0;}
	count++;
}
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
    DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
}

