#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell 2"]
#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(35);
	}
	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;
Movement;
ObjEnemy_SetDamageRate(objBoss,60,40);
}

task Movement{
loop{
wait(240);
ObjMove_SetDestAtWeight(objBoss,GetPlayerX+rand(-30,30),120+rand(-20,20),10,5);
}
}

task Orbit(obj,tar,angle,rad,spd){
    let radius = 0;
    let speed = 0;
    let accel = 3;
    while(!Obj_IsDeleted(obj)){
	let tarX = ObjMove_GetX(tar);
	let tarY = ObjMove_GetY(tar);
    ObjMove_SetPosition(obj,tarX+radius*cos(angle+speed*spd),tarY+radius*sin(angle+speed*spd));
	ObjMove_SetAngle(obj, GetAngleTo(obj,tar)+180);
    if(radius<rad){radius+=3;}
    speed+=accel;
    if(accel>0.5){accel -= 0.03;}
    yield;
    }
}

task Attack {
	let ang = 0;
	
		loop(3){
		let obj = CreateShotA1(0, 0, 1, ang, ORB_L_PINK, 5);
		ObjShot_SetSpellResist(obj, 1);
		ObjShot_SetAutoDelete(obj, 0);
		Orbit(obj,objBoss,ang,75,6);
		ObjShot_SetSpellResist(obj, 1);
		Shoot(obj);
		ang += 360/3;
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage.wav", 50);
	wait(120);
	
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0) {
	ang = rand(0,360);
	loop(6){
	let obj2 = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 0.1, ang, 0.02, 5, ORB_M_GRAY, 5);
	ObjMove_SetAngularVelocity(obj2, 6);
	delete(obj2);
	ang += 360/6;
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/sparkle.wav", 50);
	wait(60);
	}
	
	
	task delete(tar){
	wait(30);
	ObjMove_SetAngularVelocity(tar, 3);
	wait(30);
	ObjMove_SetAngularVelocity(tar, 1.5);
	wait(30);
	ObjMove_SetAngularVelocity(tar, 0.7);
	}
	
	
	task Shoot(tar){
	wait(120);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0) {
	let angle = ObjMove_GetAngle(tar)-90;
	loop(5){
	loop(5){
	let obj = CreateShotA1(ObjMove_GetX(tar), ObjMove_GetY(tar), 2, angle, ICE_PURPLE, 40);
	angle += 45;
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 50);
	wait(1);
	angle = ObjMove_GetAngle(tar)-90;
	}
	wait(30);
	}
	}
}


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

