#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell1"]
#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, false);
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/4, 5, 4);
	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 {

} 

task mainTask { 
SpellCard("Spacial Relativity &quot;Schwarzschild Radius&quot;");
let angle = 0;
let count = 0;
let count2 = 0;
Grav;
	loop{
		ascent(i in 0..12){
		CreateShotA1(BossX, BossY, 2, angle+(i*360/12), PELLET_PURPLE, 0);
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/e_shot_00.wav", 60);
		count++;
		if(count>15){count=0; count2++; angle+=45;}
		if(count2>2){count2=0; ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2+rand(-80,80),GetStgFrameHeight/4+rand(-25,25), 5, 4);}
		wait(3);
	}
}

task Grav{
let obj = GravityWell;
let scale = 1;
let warning = 0;
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/laser_2.wav", 60);
loop{
	loop(120){
	ObjRender_SetPosition(obj, GetPlayerX, GetPlayerY, 0);
	ObjRender_SetScaleXYZ(obj, scale, scale, 1);
	scale+=0.05/2;
	if(warning<100){warning++}
	if(warning==100){SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/warning.wav", 90); warning=0;}
	yield;
	}
	boom;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/burst_01.wav", 60);
	loop(30){
	ObjRender_SetPosition(obj, GetPlayerX, GetPlayerY, 0);
	ObjRender_SetAngleZ(obj, ObjRender_GetAngleZ(obj)+25);
	ObjRender_SetScaleXYZ(obj, scale, scale, 1);
	scale-=0.05*2;
	yield;
	}
	warning=0;
}

	task boom{
	wait(5);
		let shot =  GetShotIdInCircleA2(GetPlayerX,GetPlayerY,90,TARGET_ALL);
		if(length(shot)>0){
			let i = 0;
			loop(length(shot)){
				let pos	= [ObjMove_GetX(shot[i]),ObjMove_GetY(shot[i])];
				ObjMove_SetAcceleration(shot[i],0.01);
				ObjMove_SetMaxSpeed(shot[i], ObjMove_GetSpeed(shot[i])/2);
				ObjMove_SetMaxSpeed(shot[i],99999);
				ObjMove_SetAngle(shot[i], GetAngleToPlayer(shot[i]));
				i++;
			}
		}
	}
	
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Emotions/Cla1.png";
	ObjCutin_SetSpellcardS3(name,255, 0, 255);
	ObjCutin_LaunchS3("YABUSAME", Cutin, "Normal");
	TCallBg;
	bspell = true;
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	wait(210);
}


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());
} 
