#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell3"]
#Text["Woop"]


let objBoss;

let BossX;
let BossY;

let AttackX;
let AttackY;

#include "./Functions/Index.txt"
#include "./Functions/Dialogue.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	RenderClause(objBoss);
	BossShotSound(objBoss, 50, 600);
	DrawName("Wilhelm von Clausewitz Halcyon HISUIMARUUUU", [255, 0, 255], 12.7);
	BottomEnemyMarker(objBoss, objBoss);
	MagicRing(objBoss, true);
	mainTask;
	end;

} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(2500);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(80000000);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

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

@Finalize {

} 

let Gravity;

task mainTask { 
wait(60);
ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/4, 5, 4);
wait(60);
Grav;
Shooting;
}

task Shooting{
let random = rand(0,360);
loop{
	ascent(i in 0..7){
		ascent(j in 0..7){
		let obj = CreateShotA2(BossX, BossY, 2, random-i+(j*360/7), 0.02, 4, PELLET_PURPLE, 0);
		Revolve(obj, 1);
		}
	wait(2);
	}
		ascent(j in 0..4){
		let obj = CreateShotA1(BossX, BossY, 1+j, 90, PELLET_PURPLE, 0);
		}
random = rand(0,360);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/e_shot_00.wav", 60);
wait(40);
	ascent(i in 0..7){
		ascent(j in 0..7){
		let obj = CreateShotA2(BossX, BossY, 2, random+i-(j*360/7), 0.02, 4, PELLET_PURPLE, 0);
		Revolve(obj, -1);
		}
	wait(2);
	}
		ascent(j in 0..4){
		let obj = CreateShotA1(BossX, BossY, 1+j, 90, PELLET_PURPLE, 0);
		}
random = rand(0,360);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/e_shot_00.wav", 60);
wait(40);
}

	task Revolve(obj, mult){
		descent(i in 0..10){
		ObjMove_SetAngularVelocity(obj, i*mult);
		wait(15);
		}
	}
}

task Grav{
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser_2.wav", 60);
	let obj = GravityWell;
	let ang = 0;
	let sinner = 0;
	loop{
	Well(obj,ang);
	ObjRender_SetAngleZ(obj, ObjRender_GetAngleZ(obj)+5);
	ObjRender_SetPosition(obj, GetPlayerX,GetPlayerY-40, 0);
	ang-=0.4*sin(sinner);
	sinner++;
	yield;
	}	
	
	task Well(obj,ang){
		let shot =  GetShotIdInCircleA2(GetPlayerX,GetPlayerY-40,20,TARGET_ALL);
		if(length(shot)>0){
			let i = 0;
			loop(length(shot)){
				let pos	= [ObjMove_GetX(shot[i]),ObjMove_GetY(shot[i])];
				if(ObjShot_GetImageID(shot[i])!=PELLET_PURPLE){ObjMove_SetAngle(shot[i], ObjMove_GetAngle(shot[i])+(22.5)+ang);}
				i++;
			}
		}
	yield;
	}
}

task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
	wait(1);
	SetCommonData("deathsound",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
