#TouhouDanmakufu[Single]
#ScriptVersion[3]

#include "./functions.txt"

timer = -1;
life = 1;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);

	TEnemyWork;
}

task TEnemyWork
{
	
	loop(1){yield;}
	SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
	loop(180){yield;}

	if(GetCommonData("PLAYER",0) == 0)
		{
		InitializeEvent(1,1);
		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Rei_Mad,1,50,0); 
		SetText(LEFT,0,0,-1,"Come out, goddess!",5,0);
		SetText(LEFT,0,0,-1,"Sanae already told me that you're hiding here.",5,0);

		Talking(0,RIGHT);
		SetText(RIGHT,0,0,-1,"So you've gotten this far...",5,0);
		let x = GetStgFrameWidth*0.5;
		let y = GetStgFrameHeight*0.5-75;
		BossEnter(x,y,[155,155,0]);
		loop(120){yield;}
		ObjMove_SetPosition(objEnemy,x,y);
		ObjEnemy_Render(objEnemy);
		loop(120){yield;}
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"I'm impressed that you would climb to the mountain's peak[r]in the middle of a storm like this.",5,0);

		Talking(0,LEFT);
		SetText(LEFT,0,0,-1,"Cut the small talk.",5,0);
		SetText(LEFT,0,0,-1,"Turn all the women back into... women.",5,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Happy,1,50,0); 
		SetText(RIGHT,0,0,-1,"I can assure you, this is for the greater good.[r]What's going on is a good thing.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"You see, Gensokyo's in the middle of a great catastrophe.",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Rei_Plain,1,50,0); 
		SetText(LEFT,0,0,-1,"I noticed. Girls turned into guys![r]The village is in an uproar!",5,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Sad,1,50,0); 
		SetText(RIGHT,0,0,-1,"Oh you poor thing. That isn't the catastrophe.",5,0);
		SetText(RIGHT,0,0,-1,"What's happening to you is the solution.",5,0);
	
		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Rei_Talk,1,50,0); 
		SetText(LEFT,0,0,-1,"I don't know what this is supposed to change. I'm completely at a loss!",5,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Sad,1,50,0); 
		TName;
		SetText(RIGHT,0,0,-1,"From our platforms atop the mountain, we gods can see what's best." ,5,0);
		SetText(RIGHT,0,0,-1,"But the pitiful creatures of the Earth[r]aren't capable of seeing the bigger picture.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Calm,1,50,0); 
		SetText(RIGHT,0,0,-1,"They'll fight for their fleeting sense of identity.[r]Even if it means the destruction of their species." ,5,0);
		SetText(RIGHT,0,0,-1,"From the ground you might not be able to see it, but[r]Gensokyo really is facing a terrible catastrophe." ,5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"I'm not from this country. I simply came here on a whim.",5,0);
		SetText(RIGHT,0,0,-1,"But despite that, it's my duty to prevent cataclysm. And that's what I did.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Happy,1,50,0); 
		SetText(RIGHT,0,0,-1,"So you're welcome.",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Rei_Mad,1,50,0); 
		SetText(LEFT,0,0,-1,"You're not making any sense. Quit speaking in riddles.",5,0);
		SetText(LEFT,0,0,-1,"What exactly is the problem.",5,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Calm,1,50,0); 
		SetText(RIGHT,0,0,-1,"Gensokyo is full of nothing but women. Sustaining the population is impossible."  ,5,0);
		SetText(RIGHT,0,0,-1,"Had I not intervened, this would have been Gensokyo's last generation of humans.[r]And thus, the last generation of youkai and gods as well.",5,0);
		SetText(RIGHT,0,0,-1,"So you're welcome."  ,5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Rei_Shock,1,50,0); 
		SetText(LEFT,0,0,-1,"That's...",5,0);
		ObjEvent_SetGraphic(LEFT,0,Rei_Pout,1,50,0); 
		SetText(LEFT,0,0,-1,"That's not how that works at all![r]Are you an idiot?",5,0);
		SetText(LEFT,0,0,-1,"You realize these are still girls, right?[r]All you did was make things more complicated!",5,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"Their sense of femininity will not last.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Happy,1,50,0); 
		SetText(RIGHT,0,0,-1,"Well, at least now you know the truth.[r]It's not like you can do anything anyway.",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Rei_Mad,1,50,0); 
		SetText(LEFT,0,0,-1,"You're not from around here, so you must not know the rules.",5,0);
		SetText(LEFT,0,0,-1,"If I defeat you, everything goes back to normal.",5,0);
		SetText(LEFT,0,0,-1,"That's how it is in Gensokyo.",5,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"Is that so~?",5,0);
		SetText(RIGHT,0,0,-1,"I am the goddess who grants the masses the means to survive." ,5,0);
		SetText(RIGHT,0,0,-1,"If your goal is to overturn my blessing, then you're a threat to mankind's survival.",5,0);
		SetText(RIGHT,0,0,-1,"You understand this, right?",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Rei_Smug,1,50,0); 
		SetText(LEFT,0,0,-1,"I am the shrine maiden who defends Gensokyo from perverts like you.",5,0);
		SetText(LEFT,0,0,-1,"If your goal is to force your weird fetishes on us, then I have to teach you a lesson.",5,0);

		Obj_SetValue(GetPlayerObjectID,"BGM_PLAY",false);
		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"Then so be it.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Happy,1,50,0); 
		Obj_SetValue(GetPlayerObjectID,"BGM_PLAY",true);
		SetText(RIGHT,0,0,150,"Allow me to introduce myself.",5,0);
		SetText(RIGHT,0,0,240,"Hi! I'm your weather girl. And have I got news for you.",5,0);
		SetText(RIGHT,0,0,240,"Get ready, all you lonely girls, and leave those umbrellas at home.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Bolt,1,50,0); 
		SetText(RIGHT,0,0,120,"Alright!",5,0);
		Talking(0,NONE);
		loop(15){yield;}
		FinalizeEvent;
		}
	else if(GetCommonData("PLAYER",0) == 1)
		{
		InitializeEvent(1,1);
		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Mari_Plain,1,125,0); 
		SetText(LEFT,0,0,-1,"And somehow I wound up here.",25,0);
		ObjEvent_SetGraphic(LEFT,0,Mari_Sigh,1,125,0); 
		SetText(LEFT,0,0,-1,"I guess this would be a Moriya Shrine conspiracy",25,0);

		Talking(0,RIGHT);
		SetText(RIGHT,0,0,-1,"So you've gotten this far...",5,0);
		let x = GetStgFrameWidth*0.5;
		let y = GetStgFrameHeight*0.5-75;
		BossEnter(x,y,[155,155,0]);
		loop(120){yield;}
		ObjMove_SetPosition(objEnemy,x,y);
		ObjEnemy_Render(objEnemy);
		loop(120){yield;}
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"I'm impressed that you would climb to the mountain's peak[r]in the middle of a storm like this.",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Mari_Plain,1,125,0); 
		SetText(LEFT,0,0,-1,"...",25,0);
		SetText(LEFT,0,0,-1,"You aren't Martha Wash.",25,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Happy,1,50,0); 
		SetText(RIGHT,0,0,-1,"I'm sure you're wondering about what's going on here, but...",5,0);
		SetText(RIGHT,0,0,-1,"I can assure you, this is for the greater good.[r]What's going on is a good thing.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"You see, Gensokyo's in the middle of a great catastrophe.",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Mari_Plain,1,125,0); 
		SetText(LEFT,0,0,-1,"I see, I see...",25,0);
		ObjEvent_SetGraphic(LEFT,0,Mari_Star,1,125,0); 
		SetText(LEFT,0,0,-1,"\"If I can't find a man, I'll just make one.\" Right?",25,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Calm,1,50,0); 
		SetText(RIGHT,0,0,-1,"...",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Sad,1,50,0);
		SetText(RIGHT,0,0,-1,"You're a bit of an idiot, arent you?",5,0);
	
		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Mari_Plain,1,125,0); 
		SetText(LEFT,0,0,-1,"Well if you're not going to get to the point[r]It's only natural I'd get bored.",25,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Sad,1,50,0); 
		TName;
		SetText(RIGHT,0,0,-1,"From our platforms atop the mountain, we gods can see what's best." ,5,0);
		SetText(RIGHT,0,0,-1,"But the pitiful creatures of the Earth[r]aren't capable of seeing the bigger picture.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Calm,1,50,0); 
		SetText(RIGHT,0,0,-1,"They'll fight for their fleeting sense of identity.[r]Even if it means the destruction of their species." ,5,0);
		SetText(RIGHT,0,0,-1,"From the ground you might not be able to see it, but[r]Gensokyo really is facing a terrible catastrophe." ,5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"I'm not from this country. I simply came here on a whim.",5,0);
		SetText(RIGHT,0,0,-1,"But despite that, it's my duty to prevent cataclysm. And that's what I did.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Happy,1,50,0); 
		SetText(RIGHT,0,0,-1,"So you're welcome.",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Mari_Plain,1,125,0); 
		SetText(LEFT,0,0,-1,"And yet, you didn't change your own identity to prevent this \"cataclysm\".",25,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"Of course not. I'm a goddess."  ,5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Calm,1,50,0); 
		SetText(RIGHT,0,0,-1,"Gensokyo is full of nothing but women. Sustaining the population is impossible."  ,5,0);
		SetText(RIGHT,0,0,-1,"Had I not intervened, this would have been Gensokyo's last generation of humans.[r]And thus, the last generation of youkai and gods as well.",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Mari_Shock,1,125,0); 
		SetText(LEFT,0,0,-1,"That's...",5,0);
		ObjEvent_SetGraphic(LEFT,0,Mari_Sigh,1,125,0); 
		SetText(LEFT,0,0,-1," I'm going to keep it real with you, thunder goddess Yoneka Oyama.",25,0);
		SetText(LEFT,0,0,-1,"I don't think this is going to help Gensokyo's declining birth rate.",25,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Calm,1,50,0); 
		SetText(RIGHT,0,0,-1,"I've overseen Mount Oyama for over a thousand years,[r]and my people have never once suffered.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Happy,1,50,0); 
		SetText(RIGHT,0,0,-1,"What makes you think you know what's better for humanity[r]than a goddess like myself?",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Mari_Plain,1,125,0); 
		SetText(LEFT,0,0,-1,"I've been here my whole life.[r]I grew up with these men and women.",25,0);
		SetText(LEFT,0,0,-1,"And whatever Alice is.",25,0);
		SetText(LEFT,0,0,-1,"And you, a foreigner, who's only just arrived.",25,0);
		SetText(LEFT,0,0,-1,"You think you know what's better for them?",25,0);
		ObjEvent_SetGraphic(LEFT,0,Mari_Plain,1,125,0); 
		SetText(LEFT,0,0,-1,"Your common sense is as lacking as your breasts.",25,0);

		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"And yet, you let your country reach this point.",5,0);
		SetText(RIGHT,0,0,-1,"I am the goddess who grants the masses the means to survive." ,5,0);
		SetText(RIGHT,0,0,-1,"If your goal is to overturn my blessing, then you're a threat to mankind's survival.",5,0);
		SetText(RIGHT,0,0,-1,"You understand this, right?",5,0);

		Talking(0,LEFT);
		ObjEvent_SetGraphic(LEFT,0,Mari_Smug,1,125,0); 
		SetText(LEFT,0,0,-1,"I am an ordinary witch.",25,0);
		SetText(LEFT,0,0,-1,"I think I outrank you.",25,0);

		Obj_SetValue(GetPlayerObjectID,"BGM_PLAY",false);
		Talking(0,RIGHT);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Plain,1,50,0); 
		SetText(RIGHT,0,0,-1,"Then so be it.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Happy,1,50,0); 
		Obj_SetValue(GetPlayerObjectID,"BGM_PLAY",true);
		SetText(RIGHT,0,0,150,"Allow me to introduce myself.",5,0);
		SetText(RIGHT,0,0,240,"Hi! I'm your weather girl. And have I got news for you.",5,0);
		SetText(RIGHT,0,0,240,"Get ready, all you lonely girls, and leave those umbrellas at home.",5,0);
		ObjEvent_SetGraphic(RIGHT,0,Yon_Bolt,1,50,0); 
		SetText(RIGHT,0,0,120,"Alright!",5,0);
		Talking(0,NONE);
		loop(15){yield;}
		FinalizeEvent;
		}
	loop(60){yield;}
	
	SetForbidPlayerShot(false);
	SetForbidPlayerSpell(false);
	ObjEnemy_SetLife(objEnemy,0);
	TEnd;

}

task TName
{
	let distx = 128;
	let back;
	local
		{
		back = ObjPrim_Create(OBJ_SPRITE_LIST_2D);
		ObjPrim_SetTexture(back,"");
		Obj_SetRenderPriority(back,0.9);

		descent(i in 0..2)
			{	
			ObjSpriteList2D_SetDestRect(back,-distx-i*2,-distx*0.5-i*2,distx+i*2,distx*0.5+i*2);
			ObjRender_SetColorHSV(back,0,0,i*155);
			ObjSpriteList2D_AddVertex(back);	
			}
		ObjSpriteList2D_CloseVertex(back);
		}	
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj,GetCurrentScriptDirectory ~ "./img/name.png");
	ObjSprite2D_SetSourceRect(obj,0,0,512,256);
	ObjSprite2D_SetDestRect(obj,0,0,1,1);
	ObjRender_SetScaleXYZ(obj,distx*2,distx,0);
	Obj_SetRenderPriority(obj,0.9);
	ObjRender_SetPosition(obj,GetStgFrameLeft+GetStgFrameWidth-80,GetScreenHeight-110,0);
	ObjRender_SetPosition(back,GetStgFrameLeft+GetStgFrameWidth-80,GetScreenHeight-110,0);
	let time = 60;
	ascent(t in 0..time)
		{
		ObjRender_SetAlpha(obj,t*255/(time-1));
		ObjRender_SetAlpha(back,t*255/(time-1));
		yield;
		}
	loop(120){yield;}
	descent(t in 0..time)
		{
		ObjRender_SetAlpha(obj,t*255/(time-1));
		ObjRender_SetAlpha(back,t*255/(time-1));
		yield;
		}
	Obj_Delete(obj);
	Obj_Delete(back);
}