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

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


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

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(2500);
        }
	case(EV_REQUEST_TIMER){
		SetScriptResult(30);
	}
	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 { 
	renderdiancie(objBoss);
	BottomEnemyMarker(objBoss, objBoss);
	end;
	action;
	BossShotSound(objBoss, 75, 300);
} 

task action{
wait(90);
Attack;
ObjEnemy_SetDamageRate(objBoss,60,40);
}

task Attack {
while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0) {
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 90);
		Faiar(1);
		wait(45);
		ObjMove_SetDestAtWeight(objBoss,GetPlayerX+rand(-30,30),120+rand(-20,20),10,5);
		wait(45);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 90);
		Faiar(-1);
		wait(45);
		ObjMove_SetDestAtWeight(objBoss,GetPlayerX+rand(-30,30),120+rand(-20,20),10,5);
		wait(45);
		Faiar2;
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 90);
		wait(60);
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/charge.wav", 100);
		ConcentrationA1(objBoss,"MAGIC",60,2,120,[255,150,255]);
		wait(60);
}
}

task Faiar2{
let ang = 0;
let multmult = -1;
    loop(2){
        let obj = CreateShotA1(BossX+15*cos(ang),BossY+15*sin(ang),2,90,ORB_L_ROSE,10);
		Redirect(obj,multmult);
		multmult = 1;
		Spawn(obj);
		ObjShot_SetSpellResist(obj, 1);
        ang+=360/2;
        }
	task Spawn(tar){
	wait(10);
let accel = 1;
let count = 0;
	while(!Obj_IsDeleted(tar)){
let angle = 16+180;
	loop(5){
	loop(10){
	let obj = CreateShotA2(ObjMove_GetX(tar)+15*cos(angle),ObjMove_GetY(tar)+15*sin(angle),0.5,angle+180,0.02*accel, 5, BALL_S_ROSE,25);
	accel += 0.1;
	}
	accel = 1;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 65);
	angle += 360/5;
	}
	count++;
	if(count == 4){break;}
	wait(30);
}
}
}

task Faiar(mult){
let ang = 0;
    loop(2){
        let obj = CreateShotA1(BossX+15*cos(ang),BossY+15*sin(ang),4,ang,ORB_L_ROSE,10);
		Redirect(obj,mult);
		Spawn(obj);
		ObjShot_SetSpellResist(obj, 1);
        ang+=360/2;
        }
	task Spawn(tar){
	wait(10);
let accel = 1;
let count = 0;
	while(!Obj_IsDeleted(tar)){
let angle = 16+180;
	loop(5){
	loop(10){
	let obj = CreateShotA2(ObjMove_GetX(tar)+15*cos(angle),ObjMove_GetY(tar)+15*sin(angle),0.5,angle,0.02*accel, 5, BALL_S_ROSE,25);
	accel += 0.1;
	}
	accel = 1;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 65);
	angle += 360/5;
	}
	count++;
	if(count == 4){break;}
	wait(30);
}
}
}

task Redirect(obj,mult){
wait(20);
ObjMove_AddPatternA4(obj, 0, ObjMove_GetSpeed(obj), ObjMove_GetAngle(obj), -0.03, 2*mult, 0, 0, ORB_L_ROSE);
wait(45);
ObjMove_AddPatternA4(obj, 0, ObjMove_GetSpeed(obj), ObjMove_GetAngle(obj), 0.03, 0, 5, 0, ORB_L_ROSE);
}


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

