#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Nonspell2"]
#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(4500);
     	}
	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(120);
ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2-100,GetStgFrameHeight/4, 5, 4);
wait(30);
GravityLoop;
	loop{
	ascent(j in 0..12){
		ascent(i in 0..4){
		let obj = CreateShotB2(BossX, BossY, rand(-4, 1), rand(3, 4), 0, 0.1, 10, 10, PELLET_PURPLE, 0);
		Boop(obj, ObjMove_GetSpeed(obj));
		let obj2 = CreateShotB2(BossX, BossY, rand(-3, 1), rand(-5, 0), 0, 0.08, 10, 10, D_BULLET_PURPLE, 0);
		Boop(obj2, ObjMove_GetSpeed(obj2));
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/e_shot_00.wav", 60);
		wait(5);
		}
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2+100,GetStgFrameHeight/4, 5, 4);
	wait(80);
	ascent(j in 0..12){
		ascent(i in 0..4){
		let obj = CreateShotB2(BossX, BossY, rand(-1, 4), rand(3, 4), 0, 0.1, 10, 10, PELLET_PURPLE, 0);
		Boop2(obj, ObjMove_GetSpeed(obj));
		let obj2 = CreateShotB2(BossX, BossY, rand(-1, 3), rand(-5, 0), 0, 0.08, 10, 10, D_BULLET_PURPLE, 0);
		Boop2(obj2, ObjMove_GetSpeed(obj2));
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/e_shot_00.wav", 60);
		wait(5);
	}
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2-100,GetStgFrameHeight/4, 5, 4);
	wait(80);
	}
	
	task GravityLoop{
		loop{
		Gravity = GravityPush(-99,GetStgFrameHeight/2, 90);
		MoveGrav(Gravity);
		wait(140);
		Gravity = GravityPush(GetStgFrameWidth+99,GetStgFrameHeight/2, 90);
		MoveGrav2(Gravity);
		wait(140);
		}
	}
	task MoveGrav(obj){
	let mult = 1;
	wait(60);
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(obj, ObjMove_GetX(obj)+(5*mult), GetStgFrameHeight/2);
		mult+=0.2;
		yield;
		}
	}
	task MoveGrav2(obj){
	let mult = 1;
	wait(60);
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(obj, ObjMove_GetX(obj)-(5*mult), GetStgFrameHeight/2);
		mult+=0.2;
		yield;
		}
	}
	task Boop(obj, spd){
	let count = 0;
		while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetX(Gravity)>ObjMove_GetX(obj)&&count==0){
			ObjMove_AddPatternB2(obj, 0 , ObjMove_GetSpeed(obj)/1.2, ObjMove_GetSpeed(obj)/2, 0, 0, 0, 0);
			count++;
			}
		yield;
		}
	}
	task Boop2(obj, spd){
	let count = 0;
		while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetX(Gravity)<ObjMove_GetX(obj)&&count==0){
			ObjMove_AddPatternB2(obj, 0 , -ObjMove_GetSpeed(obj)/1.2, ObjMove_GetSpeed(obj)/2, 0, 0, 0, 0);
			count++;
			}
		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());
} 
