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


let objBoss;

let BossX;
let BossY;

#include "./Functions/Index.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	rendernue(objBoss);
	BossShotSound(objBoss, 100, 600);
	FlameAura(objBoss,[255,255,255],3);
	ObjMove_SetPosition(objBoss,GetStgFrameWidth+200,150);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	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 { 
	//GETTING CARRIED
	wait(5);
	Lines;
	ObjEnemy_SetDamageRate(objBoss, 100, 100);
	let count = 0;
	loop{
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargelong.wav", 70);
	wait(40);
	attack=true;
	wait(20);
	ascent(j in 0..10){
	let angle = rand(0, 360);
		loop(40){
		let obj = CreateShotA1(BossX, BossY, (0.1+1.5*cos(angle*2))+3.5, angle, AMULET_PURPLE, 0);
		ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
		angle+=360/40;
		}
	angle++;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/spirit.wav", 70);
	wait(10);
	}
	attack=false;
	if(count==0){Subfire; count++;}
	loop(3){
	ObjMove_SetDestAtWeight(objBoss,GetPlayerX,120,2,2.5);
	wait(70);
	}
	}
}

task Subfire{
let angle = 0;
let ang = 0;
	while(!Obj_IsDeleted(objBoss)){
	ascent(i in 0..2){
			loop(6){
			let obj = CreateShotA2(BossX+50*sin(angle), BossY+50*cos(angle), 2, ang+(i*3), 0.02, 5, AMULET_BLUE, 15);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			let obj2 = CreateShotA2(BossX+50*sin(angle+180), BossY+50*cos(angle+180), 2, ang+(i*3), 0.02, 5, AMULET_BLUE, 15);
			ObjRender_SetBlendType(obj2, BLEND_ADD_ARGB);
			ang+=360/6;
			}
		}
		SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
		angle+=360/12;
		ang+=25;
		wait(15);
	}
}

function Lines{
	wait(100);
	SetForbidPlayerShot(true);
	DialogueBox;
	wait(35);
	//----------
	PlayerSetEmotion("Regular");
	PlayerPortait;
	Dialogue("Geez, What was that all about?", "Player");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	Dialogue("UFOs now come in White aparently.", "Player");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	Dialogue("That is not normal!", "Player");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NueTalk;
	PlayerSetEmotion("What");
	ObjMove_SetDestAtWeight(objBoss,384/2,150,25,6);
	TimedDialogue("Not normal you say?", "Nue", 120);
	wait(5);
	
	let start = UFO(BossX, BossY, "white");
	ObjMove_SetAngle(start, 180);
	ObjMove_SetSpeed(start, 0.7);
	stick(start);
	
	loop(120){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	PlayerTalk;
	TimedDialogue(". . .", "Player", 120);
	wait(5);
	loop(120){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NuePortrait;
	PlayerTalk;
	TimedDialogue(". . . . . .", "Player", 120);
	wait(5);
	loop(120){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	PlayerSetEmotion("Angry");
	TimedDialogue(". . . . . . . .", "Player", 120);
	wait(5);
	loop(120){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	PlayerSetEmotion("Angry");
	Dialogue("You had to ride it like a Surfboard...?", "Player");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NueTalk;
	Dialogue("Yes, Because it's amazing.", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	PlayerSetEmotion("Regular");
	PlayerTalk;
	Dialogue("Why is it white anyway...?", "Player");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NueTalk;
	Dialogue("Because, Aparently... [r](And please don't quote me on this)", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NueTalk;
	Dialogue("It's Pure.", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	PlayerTalk;
	PlayerSetEmotion("Ex");
	Dialogue("What? [r]How did that happen?", "Player");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NueTalk;
	Dialogue("Well, I'm pretty sure it went like this...", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	wait(10);
	Fade;
	wait(255);
	let obj = Junko;
	PURIFYYYY(obj);
	ObjMove_SetPosition(obj, GetStgFrameWidth/2,100);
	cutscene = true;
	wait(1);
	CutsceneBackground;
	wait(152);
	SetCommonData("purefuries",1);
	SetCommonData("musicswitch",1);
	wait(30);
	//----------
	JunkoTalk;
	JunkoPortrait;
	Dialogue("PURIFY PURIFY PURIFY PURIFY!!!", "Junko");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	Dialogue("AND YOU GET PURIFIED[r]AND YOU GET PURIFIED", "Junko");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	Dialogue("EVERYONE HERE GETS PURIFIED!!![r]HAHAHAHAHAHAHA!!!", "Junko");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	Fade;
	wait(255);
	cutscene = false;
	Obj_Delete(obj);
	wait(152);
	SetCommonData("purefuries",0);
	SetCommonData("musicswitch",1);
	wait(30);
	//----------
	NuePortrait;
	PlayerPortait;
	PlayerTalk;
	PlayerSetEmotion("Right");
	Dialogue("Soooo that's how it went...?", "Player");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NueTalk;
	PlayerSetEmotion("Regular");
	Dialogue("Preeeeetty much. [r]I think my UFO got hit.", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NueSetEmotion("Heh");
	Dialogue("But now I have these cool powers.[r]And this white shine!", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	PlayerTalk;
	PlayerSetEmotion("Right");
	Dialogue("Talk about flashy...", "Player");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NueTalk;
	PlayerSetEmotion("Regular");
	Dialogue("Well I guess now I gotta fight you.", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	NueSetEmotion("Regular");
	Dialogue("Y'know, to test these.", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	PlayerTalk;
	PlayerSetEmotion("Right");
	Dialogue("*sigh...*", "Player");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	SetCommonData("heianalien",1);
	SetCommonData("musicswitch",1);
	NueTalk;
	TimedDialogue("Well, Here we go.", "Nue", 120);
	wait(5);
	ObjMove_SetAngle(objBoss, 90);
	ObjMove_SetSpeed(objBoss, -2);
	ObjMove_SetAcceleration(objBoss, 0.06);
	ObjMove_SetMaxSpeed(objBoss, 50);
	wait(20);
	ObjMove_SetAcceleration(start, 0.02);
	ObjMove_SetMaxSpeed(start, 50);
	wait(40);
	ObjMove_SetDestAtWeight(objBoss, BossX, BossY, 0, 0);
	BottomEnemyMarker(objBoss, objBoss);
	wait(60);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	Dialogue("Feel the Purity coming out out of this...", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	Dialogue("Pearly White Pure Undefined Flying [r]Object Trademark Patent Pendient!", "Nue");
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
	//----------
	dissapear = true;
	SetForbidPlayerShot(false);
	wait(10);
}

task PURIFYYYY(obj){
	while(!Obj_IsDeleted(obj)){
	let shot = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj), rand(4,7), rand(0,360), ORB_GRAY, 5);
	ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(shot, 66);
	ObjShot_SetIntersectionEnable(shot, 0);
	wait(2);
	}
}

task stick(obj){
	loop{
	ObjMove_SetPosition(objBoss, ObjMove_GetX(obj), ObjMove_GetY(obj)-50);
	if(ObjMove_GetX(objBoss)<GetStgFrameWidth/2){break;}
	yield;
	}
	ObjMove_SetSpeed(obj, 0);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2,100, 2, 2);
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Cutin.png";
	ObjCutin_SetSpellcardS3(name, 25, 25, 25);
	ObjCutin_LaunchS3("KANAKO", 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());
} 
