#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Initialize"]

#include "./../functions_talk.txt"
#include "./functions2.txt"

timer = 0;
let text = GetCommonData("TEXT_ENABLED",true);

@Initialize
{
	Obj_SetValue(GetEnemyBossSceneObjectID,"INIT",true);
	TEnemyWork;
}

@MainLoop
{
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(1/(10^10));
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(timer);
		}
	case(EV_REQUEST_SPELL_SCORE)
		{
		SetScriptResult(0);
		}
}

task TEnemyWork
{
	SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
	loop(30){yield;}
	if(mid == false)
		{
		if(text == true)
			{
			InitializeEvent(1,1);
			Talking(0,LEFT);
			ObjEvent_SetGraphic(LEFT,0,KoishiJoy);
			SetText(LEFT,0,0,"I won! I won! Now everyone will watch me~");
			SetText(LEFT,0,0,"And no one will forget about me anymore.");
			Talking(0,RIGHT);
			SetText(RIGHT,0,9,"Attention like that isn't always a good thing...");
			}
		objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
		ObjEnemy_Regist(objEnemy);
		TXY;
		ObjEnemy_Render; 
		ObjMove_SetPosition(objEnemy,GetStgFrameWidth/2-64,-64);
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-110,20,5);
		loop(89){yield;}
		if(text == true)
			{
			loop(31){yield;}
			ObjEvent_SetGraphic(RIGHT,0,ReisenPlain);
			SetText(RIGHT,0,0,"The nail that sticks out will rot, or so I've been told.");
			Talking(0,LEFT);	
			ObjEvent_SetGraphic(LEFT,0,KoishiPlain);
			SetText(LEFT,0,0,"Oh look, a rabbit appeared!");
			SetText(LEFT,0,0,"I think I'll beat you up now.");
			Talking(0,RIGHT);	
			ObjEvent_SetGraphic(RIGHT,0,ReisenFear);
			SetText(RIGHT,0,0,"Wh-what!? Shouldn't we at least have[r]some dialogue first?");
			Talking(0,LEFT);	
			ObjEvent_SetGraphic(LEFT,0,KoishiJoy);
			SetText(LEFT,0,0,"You'll never reach top ten[r]with that kind of thinking.");
			SetText(LEFT,0,0,"I guess I don't have to worry about you after all~");
			Talking(0,RIGHT);	
			SetText(RIGHT,0,0,"Top ten... Ah, so that's it.");
			ObjEvent_SetGraphic(RIGHT,0,ReisenPlain);
			SetText(RIGHT,0,0,"You must be that popular youkai the villagers[r]have been speaking about.");
			SetText(RIGHT,0,0,"Congratulations on beating the Hakurei maiden.");
			Talking(0,LEFT);
			ObjEvent_SetGraphic(LEFT,0,KoishiPlain);	
			SetText(LEFT,0,0,"It's all thanks to my special treasure.");
			SetText(LEFT,0,0,"Ever since that game, I've just become[r]more and more popular.");
			ObjEvent_SetGraphic(LEFT,0,KoishiJoy);
			SetText(LEFT,0,0,"Hopefully I'll get to keep my spot as queen~");
			Talking(0,RIGHT);	
			SetText(RIGHT,0,0,"It must be nice getting so much attention.");
			SetText(RIGHT,0,0,"Between dealing with Tewi and[r]running errands for the master,");
			SetText(RIGHT,0,0,"I haven't had much time to be in the spotlight.");
			ObjEvent_SetGraphic(RIGHT,0,ReisenJoy);
			SetText(RIGHT,0,0,"But hopefully that will change since I[r]have a lead role in the coming game.");
			Talking(0,LEFT);
			SetText(LEFT,0,0,"What?");	
			Talking(0,RIGHT);
			ObjEvent_SetGraphic(RIGHT,0,ReisenPlain);
			SetText(RIGHT,0,0,"Legacy of Lunatic Kingdom comes out in August.");
			SetText(RIGHT,0,0,"I was hoping it would boost my[r]popularity, since I'll be playable in it.");
			ObjEvent_SetGraphic(RIGHT,0,ReisenJoy);
			SetText(RIGHT,0,0,"Who knows? I might even become number one!");
			Obj_SetValue(objPlayer,"MUSIC",false);
			Talking(0,LEFT);
			SetText(LEFT,0,0,".             ");
			SetText(LEFT,0,0,"..            ");
			SetText(LEFT,0,0,"...           ");
			SetText(LEFT,0,0,"You're currently sixteen...");
			SetText(LEFT,0,0,"I had no idea a rabbit was so popular.");
			Talking(0,RIGHT);
			ObjEvent_SetGraphic(RIGHT,0,ReisenFear);
			SetText(RIGHT,0,0,"Eh? ");
			Obj_SetValue(objPlayer,"MUSIC",true);
			Talking(0,LEFT);
			SetText(LEFT,0,0,"It seems you're more crafty than I thought.");
			SetText(LEFT,0,0,"Abusing your sex appeal.");
			SetText(LEFT,0,0,"But if I take you out now I can still win.");
			Talking(0,RIGHT);
			SetText(RIGHT,0,0,"Wait, what's going on?");
			Talking(0,BOTH);
			ObjEvent_SetGraphic(LEFT,0,KoishiPlain);
			SetText(LEFT,0,0,"I'll sandwich you between a hag and a PC-98 Character!");
			SetText(RIGHT,0,0,"I don't understand what's happening at all!");
			ObjEvent_SetGraphic(LEFT,0,"");
			ObjEvent_SetGraphic(RIGHT,0,"");
			loop(20){yield;}
			FinalizeEvent;
			}
		else
			{
			Obj_SetValue(objPlayer,"MUSIC",false);
			yield;
			Obj_SetValue(objPlayer,"MUSIC",true);
			}
		}
	else
		{
		objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
		ObjEnemy_Regist(objEnemy);
		TXY;
		ObjEnemy_Render; 
		ObjMove_SetPosition(objEnemy,GetStgFrameWidth/2-64,-64);
		ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-110,20,5);
		if(text == true)
			{
			loop(40){yield;}
			InitializeEvent(1,1);
			ObjEvent_SetGraphic(LEFT,0,KoishiPlain);
			Talking(0,RIGHT);
			ObjEvent_SetGraphic(RIGHT,0,Tewi);
			SetText(RIGHT,0,0,"What? A rock in my trap?");
			SetText(RIGHT,0,0,"Oh, but it's a lucky rock.");
			SetText(RIGHT,0,0,"Your win was a fluke! I'll close the sixty one point gap!");
			ObjEvent_SetGraphic(LEFT,0,"");
			ObjEvent_SetGraphic(RIGHT,0,"");
			loop(20){yield;}
			FinalizeEvent;
			}
		else
			{
			loop(89){yield;}
			yield;
			}
		}
	ObjEnemy_SetLife(objEnemy,0);
	Obj_Delete(objEnemy);
	yield;
	SetForbidPlayerShot(false);
	SetForbidPlayerSpell(false);
	CloseScript(GetOwnScriptID);
}