#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell4"]
#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);
	mainTask;
	end;

} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4500);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(50);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
	case(EV_REQUEST_IS_DURABLE_SPELL){
		SetScriptResult(true);
	}
} 

@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 { 
ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,-300, 5, 2);
SpellCard("&quot;Eternal Oppresive Force&quot;");
LeftGrav;
wait(120);
RightGrav;
wait(170);
Wall;
wait(60);
LeftGrav;
wait(120);
RightGrav;
wait(170);
Wall2;
wait(60);
LeftGrav;
wait(120);
UpGrav;
wait(120);
DownGrav;
wait(120);
RightGrav;
wait(170);
Wall3;
wait(90);
RightGrav;
wait(90);
LeftGrav;
wait(90);
RightGrav;
wait(90);
DownGrav;
wait(90);
RightGrav;
wait(90);
UpGrav;
wait(140);
defmult +=1;
	loop{
	let number = trunc(rand(1,5));
	if(number==1){LeftGrav;}
	if(number==2){UpGrav;}
	if(number==3){DownGrav;}
	if(number==4){RightGrav;}
	wait(55);
	}
}



task Wall{
let las = CreateStraightLaserA1(GetStgFrameWidth/2, -20, 90, 700, 30, 0, S_LASER_GREY, 9999);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/warning.wav", 90);
wait(30);
	ascent(i in 0..270){
	let obj = CreateShotA1(GetStgFrameWidth/2, -600+(30*i), 0.2, 90, C_BULLET_PURPLE, 0);
	ObjShot_SetAutoDelete(obj, 0);
	ObjShot_SetSpellResist(obj, 1);
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/e_shot_01.wav", 50);
	Obj_Delete(las);
}

task Wall2{
let las = CreateStraightLaserA1(-20, GetStgFrameHeight/2, 0, 700, 30, 0, S_LASER_GREY, 9999);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/warning.wav", 90);
wait(30);
	ascent(i in 0..270){
	let obj = CreateShotA1(-600+(30*i), GetStgFrameHeight/2, 0.2, 0, C_BULLET_PURPLE, 0);
	ObjShot_SetAutoDelete(obj, 0);
	ObjShot_SetSpellResist(obj, 1);
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/e_shot_01.wav", 50);
	Obj_Delete(las);
}

task Wall3{
let las = CreateStraightLaserA1(GetStgFrameWidth/2-125, -20, 90, 700, 30, 0, S_LASER_GREY, 9999);
let las2 = CreateStraightLaserA1(GetStgFrameWidth/2+125, -20, 90, 700, 30, 0, S_LASER_GREY, 9999);
let las3 = CreateStraightLaserA1(-20, GetStgFrameHeight/2-125, 0, 700, 30, 0, S_LASER_GREY, 9999);
let las4 = CreateStraightLaserA1(-20, GetStgFrameHeight/2+125, 0, 700, 30, 0, S_LASER_GREY, 9999);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/warning.wav", 90);
wait(30);
	ascent(i in 0..64){
	let obj = CreateShotA1(-50+(50*i), GetStgFrameHeight/2-125, 0, 0, C_BULLET_PURPLE, 0);
	ObjShot_SetAutoDelete(obj, 0);
	ObjShot_SetSpellResist(obj, 1);
	}
	ascent(i in 0..64){
	let obj = CreateShotA1(-50+(50*i), GetStgFrameHeight/2+125, 0, 0, C_BULLET_PURPLE, 0);
	ObjShot_SetAutoDelete(obj, 0);
	ObjShot_SetSpellResist(obj, 1);
	}
	ascent(i in 0..64){
	let obj = CreateShotA1(GetStgFrameWidth/2+125, -50+(50*i),0,0, C_BULLET_PURPLE, 0);
	ObjShot_SetAutoDelete(obj, 0);
	ObjShot_SetSpellResist(obj, 1);
	}
	ascent(i in 0..64){
	let obj = CreateShotA1(GetStgFrameWidth/2-125, -50+(50*i),0,0, C_BULLET_PURPLE, 0);
	ObjShot_SetAutoDelete(obj, 0);
	ObjShot_SetSpellResist(obj, 1);
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/e_shot_01.wav", 50);
	Obj_Delete(las); Obj_Delete(las2); Obj_Delete(las3);Obj_Delete(las4);
}

let defmult = 1;
let mult = defmult;
task LeftGrav{
	let Gravity = GravityPush(-50,GetStgFrameHeight/2, 90);
	mult = defmult;
	MoveGrav(Gravity);
	Pushy(Gravity);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/warning.wav", 90);

	task MoveGrav(obj){
	wait(60);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/bom_flash_01.wav", 90);
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(obj, ObjMove_GetX(obj)+(5*mult), GetStgFrameHeight/2);
		mult+=0.2;
		yield;
		}
	}
	task Pushy(obj){
		while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetX(Gravity)>ObjMove_GetX(GetPlayerObjectID)){
			ObjMove_SetPosition(GetPlayerObjectID, ObjMove_GetX(obj), GetPlayerY);
			}
		yield;
		}
	}
}

task UpGrav{
let	Gravity = GravityPush(GetStgFrameWidth/2,-50, 0);
	mult = defmult;
	MoveGrav(Gravity);
	Pushy(Gravity);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/warning.wav", 90);
	task MoveGrav(obj){
	wait(60);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/bom_flash_01.wav", 90);
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(obj, GetStgFrameWidth/2, ObjMove_GetY(obj)+(5*mult));
		mult+=0.2;
		yield;
		}
	}
	task Pushy(obj){
		while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetY(Gravity)>ObjMove_GetY(GetPlayerObjectID)){
			ObjMove_SetPosition(GetPlayerObjectID, GetPlayerX, ObjMove_GetY(obj));
			}
		yield;
		}
	}
}

task RightGrav{
let	Gravity = GravityPush(GetStgFrameWidth+50,GetStgFrameHeight/2, 270);
	mult = defmult;
	MoveGrav(Gravity);
	Pushy(Gravity);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/warning.wav", 90);
	task MoveGrav(obj){
	wait(60);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/bom_flash_01.wav", 90);
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(obj, ObjMove_GetX(obj)-(5*mult), GetStgFrameHeight/2);
		mult+=0.2;
		yield;
		}
	}
	task Pushy(obj){
		while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetX(Gravity)<ObjMove_GetX(GetPlayerObjectID)){
			ObjMove_SetPosition(GetPlayerObjectID, ObjMove_GetX(obj), GetPlayerY);
			}
		yield;
		}
	}
}

task DownGrav{
let	Gravity = GravityPush(GetStgFrameWidth/2,GetStgFrameHeight+50, 180);
	mult = 1.1;
	MoveGrav(Gravity);
	Pushy(Gravity);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/warning.wav", 90);
	task MoveGrav(obj){
	wait(60);
SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/bom_flash_01.wav", 90);
		while(!Obj_IsDeleted(obj)){
		ObjMove_SetPosition(obj, GetStgFrameWidth/2, ObjMove_GetY(obj)-(5*mult));
		mult+=0.2;
		yield;
		}
	}
	task Pushy(obj){
		while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetY(Gravity)<ObjMove_GetY(GetPlayerObjectID)){
			ObjMove_SetPosition(GetPlayerObjectID, GetPlayerX, ObjMove_GetY(obj));
			}
		yield;
		}
	}
}



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