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


let objBoss;

let BossX;
let BossY;

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

@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderkisume(objBoss);
	BossShotSound(objBoss, 100, 600);
	FlameAura(objBoss,[25,25,255],2);
	DrawName("Kisume", [25, 25, 122], 11);
	ObjMove_SetPosition(objBoss, GetStgFrameWidth/2,-60);
	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 { 

let Player = 0;
if(GetCommonData("Reimu",1)==1){Player = 0}
if(GetCommonData("Marisa",0)==1){Player = 1}
if(GetCommonData("Sakuya",0)==1){Player = 2}
if(GetCommonData("Sanae",0)==1){Player = 3}
if(GetCommonData("Youmu",0)==1){Player = 4}

wait(50);
	SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
SetCommonData("PlayerCutin",Characters[Player][0]);
SetCommonData("PlayerTalk",0);
DialogueCutinPlayer;
DialogueBox;
Dialogue(1, "Halt!", 0, 0,  0,0,0);

	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);

ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/3, 5, 4);
DialogueCutinBoss;
SetCommonData("EnemyCutin",Bosses[0][0]);
Dialogue(1, "I won't let you touch the Spider Queen,[r] Human!", 0, 0,  0,0,0);

	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);

if(Player==0){
Dialogue(0, "Go away..", 0, 6,  0,0,0);
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
}
if(Player==1){
Dialogue(0, "WARNING WITCH COMING THROUGH", 1, 3,  0,0,0);
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
}
if(Player==2){
Dialogue(0, "Move.", 2, 0,  -200,0,0);
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
}
if(Player==3){
Dialogue(0, "O w O What's this?", 3, 3,  100,0,32.5);
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
}
if(Player==4){
Dialogue(0, "Excuse you, I'm only HALF Human!", 4, 4,  0,0,0);
	wait(5);
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/shot.wav", 200);
	wait(5);
}
	
SetCommonData("EndDialogue",1);
	SetForbidPlayerShot(false);
	SetForbidPlayerSpell(false);
wait(50);
BottomEnemyMarker(objBoss, objBoss);
SetCommonData("EndDialogue",0);
ObjEnemy_SetDamageRate(objBoss, 100,100);
Movement;
KisumeSpiral;
wait(120);
Rings;
}

task Movement{
	loop{
	ObjMove_SetDestAtWeight(objBoss,GetPlayerX,GetStgFrameHeight/3+rand(-50,50), 5, 4);
	wait(200);
	}
}

task KisumeSpiral{
let offset = 0;
	loop{
	ascent(j in 0..3){
		ascent(i in 0..5){
		CreateShotA2(BossX+25*cos((i*360/5)+offset), BossY+25*sin((i*360/5)+offset), 1.5+(j*0.2), offset+(i*360/5), 0.03, 5, ARROWHEAD_RED+j, 10);
		}
	}
	offset+=16.5;
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
	wait(5);
	}
}

task Rings{
	loop{
	ascent(i in 0..52){
	CreateShotA2(BossX, BossY, 4, 0+(i*360/52), -0.05, 2, SMALL_BLUE, 10);
	}
	ascent(i in 0..52){
	CreateShotA2(BossX, BossY, -3, 360/104+(i*360/52), 0.05, 2, SMALL_BLUE, 10);
	}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/labullet.wav", 65);
	wait(150);
	}
}

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