#TouhouDanmakufu[Plural]
	#ScriptVersion[3]
	#System["./tricky_system/Default_System.txt"]
	#Title["System Tutorial - PLAY FIRST"]
	#Text["TUTORIAL!"]
	#Image[""]
	#Background["./tricky_system/Default_Background_IceMountain.txt"]
	#Player["/script/player/", "./Ultima's DDC Reimu B/ReimuH.dnh"]
	let white = GetCurrentScriptDirectory~"sprites/white.png";
	let pldead = GetCurrentScriptDirectory~"sfx/se_pldead00.wav";
		let scream = GetCurrentScriptDirectory~"sfx/scream.wav";
	LoadTexture(white);
	let moo2 = false;
	let moo3 = false;
	let xcoord = 0;
	let sound3set = false;
	let soundset = false;
	let moo7 = false;
	let playx = GetStgFrameWidth/2;
	let playy = GetStgFrameHeight-32;
	let initx = 0;
	let inity = 0;
	let objSound;
	let objSound2;
	let objSound3;
	let obj = ObjEnemyBossScene_Create();
	let obj2 = ObjEnemyBossScene_Create();

	let obj3 = ObjEnemyBossScene_Create();
	let thunder = GetCurrentScriptDirectory~"sfx/thunder.wav";
	let vol = 95;
	let sound2set = false;
	let bossx = 0;
	let dir = GetCurrentScriptDirectory();
	let bossy = 0;
	let ycoord = 0;
	let moo = false;
	let maxlife = 0;
	let reimucut = GetCurrentScriptDirectory~"sprites/reimucut.png";
	let koakumacut = GetCurrentScriptDirectory~"sprites/koakumacut.png";
	let reimucut2 = GetCurrentScriptDirectory~"sprites/reimucut2.png";
	
	
	#include"./stage.eventdialogue.dnh"
	
	@Initialize
	{

	
		LoadTexture(reimucut);
	LoadTexture(reimucut2);
	
		LoadTexture(koakumacut);
	SetPlayerLife(12);
	
		ObjEnemyBossScene_Add(obj, 0, dir ~ "KoakumaT1.txt");
		ObjEnemyBossScene_Add(obj, 1, dir ~ "KoakumaT2.txt");
		ObjEnemyBossScene_Add(obj, 2, dir ~ "KoakumaT3.txt");
		ObjEnemyBossScene_LoadInThread(obj);
	wait(30);
		TPlural();
	objSound2 = ObjSound_Create;
	ObjSound_Load(objSound2, GetCurrentScriptDirectory~"bgm/bgm.ogg");
	}

	@MainLoop
	{
	  xcoord = GetCommonData("kogasax", GetStgFrameWidth/2)+32;
	   ycoord = GetCommonData("kogasay", 120);
	   if(xcoord>32){ bossx = xcoord; }
	   if(ycoord>0){ bossy = ycoord; }
		yield;
	}

	@Finalize
	{
	}

		

	@Event{
alternative(GetEventType())	
case(EV_PAUSE_ENTER)
{
if(soundset==true){
ObjSound_Stop(objSound);
}
if(sound2set==true){
ObjSound_Stop(objSound2);
}
if(sound3set==true){
ObjSound_Stop(objSound3);
}
}

case(EV_PAUSE_LEAVE)
{
if(soundset==true){
ObjSound_Play(objSound);
}

if(sound2set==true){
ObjSound_Play(objSound2);
}
if(sound3set==true){
ObjSound_Play(objSound3);
}
}


}

function wait(w){loop(w){yield;}}

	task TPlural
	{
	wait(1);
	SetCommonData("interruptavail", false);
			wait(179);
			
			Event1A;
			wait(120);
			SetCommonData("koakumaT1", true);
		
	
		

		while(!Obj_IsDeleted(obj) && GetCommonData("koakumaT1", false)==true)
		{
			yield;
		}
		
		Event1B;
		wait(120);
		SetCommonData("koakumaT2", true);
		while(!Obj_IsDeleted(obj) && GetCommonData("koakumaT2", false)==true)
		{
			yield;
		}
		
		Event1C;
		wait(120);
		SetCommonData("koakumaT3", true);
		while(!Obj_IsDeleted(obj) && GetCommonData("koakumaT3", false)==true)
		{
			yield;
		}
		Event1D;
		SetCommonData("koakumaT3", true);
		while(!Obj_IsDeleted(obj) && GetCommonData("koakumaT3", false)==true)
		{
			yield;
		}
		wait(120);
		CloseStgScene;
		CloseScript(GetOwnScriptID());
	}


task magiccircle2(size,type){ // draw magic circle
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	let imgcircle=GetCurrentScriptDirectory~"sprites/MG.png";
	let spin = 0;
	let s = 0;
	LoadTexture(imgcircle);
	ObjPrim_SetTexture(obj,imgcircle);
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,size,size,size);
	ObjRender_SetAlpha(obj,192);
	Obj_SetRenderPriorityI(obj, 28);
	ObjRender_SetBlendType(obj,BLEND_ADD_RGB);
	while(!Obj_IsDeleted(GetEnemyBossSceneObjectID)){
	spin += 2;
	ObjRender_SetAngleXYZ(obj,0,0,spin*2);
	ObjRender_SetPosition(obj,bossx-32,bossy,0);
	ObjRender_SetColor(obj,1*(192+42*sin(spin+180)),1*(192+42*sin(spin)),0);
	if(type==true){
	ObjRender_SetScaleXYZ(obj,size*1.1+0.1*sin(spin),size*1.1+0.1*sin(spin),0);
	}
	ObjMove_SetPosition(obj,bossx-32,bossy);
	yield;
	}
	Obj_Delete(obj);
	}


task BottomEnemyMarker{
  let imgnumber = GetCurrentScriptDirectory~"sprites/enemymarker.png";
  let objMarker = ObjPrim_Create(OBJ_SPRITE_2D);
  ObjRender_SetPosition(objMarker, GetStgFrameWidth/2, GetStgFrameHeight+32, 1); 
  ObjPrim_SetPrimitiveType(objMarker, PRIMITIVE_TRIANGLESTRIP);
  ObjRender_SetBlendType(objMarker, BLEND_ALPHA);
  Obj_SetRenderPriority(objMarker, 0.85);
  ObjPrim_SetTexture(objMarker, imgnumber);
  ObjRender_SetAlpha(objMarker, 255);
  ObjSprite2D_SetSourceRect(objMarker, 0, 0, 48, 16);
  ObjSprite2D_SetDestRect(objMarker, -25, -8, 25, 8);

 
  while(!Obj_IsDeleted(GetEnemyBossSceneObjectID)){
	
    ObjRender_SetPosition(objMarker, bossx, GetStgFrameHeight+24, 1);
	
    yield;
  }
  Obj_Delete(objMarker);
}
	

	task ManipulatePlayer{
	initx = ObjMove_GetX(GetPlayerObjectID);
	inity = ObjMove_GetY(GetPlayerObjectID);
	 let incx = ((GetStgFrameWidth/2-initx)/60);
	let incy = (playy-inity)/60;
	loop(60){
	ObjMove_SetPosition(GetPlayerObjectID, ObjMove_GetX(GetPlayerObjectID)+incx, ObjMove_GetY(GetPlayerObjectID)+incy);
	yield;
	}
	loop{
	ObjMove_SetPosition(GetPlayerObjectID, GetStgFrameWidth/2, playy);
	yield;
	}
	}
	
	
	function Event1B {

	let dispX_Player = 0;
	let dispX_Enem = -120;
	InitializeEvent(1, 1);
	HandleEventLogic();
	SetCutinGraphic(0, 0, reimucut, dispX_Player, 0);
	SetCutinGraphic(1, 0, koakumacut, dispX_Enem, -50);
	SetCharStatusPresent(1, 0, true);
	SetCharStatusPresent(0, 0, true);
	Talking(0);
	SetEventText(0, 0, "I see...", 0);
	SetCharStatusPresent(0, 0, false);
	Talking(1);
	SetEventText(1, 0, "Excellent.", 0);
	SetEventText(1, 4, "It's not always this simple.[r]Try this next pattern out...", 0); 
	SetEventText(1, 4, "There will be normal danmaku[r]and a spell with a cast time.", 0); 
	SetEventText(1, 4, "Dodge one, and keep an eye on the other.[r]Be ready to interrupt it. Multitask!", 0);
	SetCharStatusPresent(1, 0, false); wait(45);
	FinalizeEvent;
	//SetCommonData("readytheint", true);
	SetCommonData("koakumadie", true);
	
	
}

function Event1C {

	let dispX_Player = 0;
	let dispX_Enem = -120;
	InitializeEvent(1, 1);
	HandleEventLogic();
	SetCutinGraphic(0, 0, reimucut, dispX_Player, 0);
	SetCutinGraphic(1, 0, koakumacut, dispX_Enem, -50);
	SetCharStatusPresent(1, 0, true);
	SetCharStatusPresent(0, 0, true);
	Talking(0);
	SetEventText(0, 0, "Ah...", 0);
	SetCharStatusPresent(0, 0, false);
	Talking(1);
	SetEventText(1, 0, "Good.", 0);
	SetEventText(1, 4, "Some spells are not as[r]threatening as others.", 0); 
	SetEventText(1, 4, "Generally, danger is proportional[r]to how long it takes to cast.", 0); 
	SetEventText(1, 4, "Ignore short spells.[r]Save your interrupts for longer ones.", 0);
	SetCharStatusPresent(1, 0, false); wait(45);
	FinalizeEvent;
	//SetCommonData("readytheint", true);
	SetCommonData("koakumadie", true);
	
	
}

function Event1D {

	let dispX_Player = 0;
	let dispX_Enem = -120;
	InitializeEvent(1, 1);
	HandleEventLogic();
	SetCutinGraphic(0, 0, reimucut, dispX_Player, 0);
	SetCutinGraphic(1, 0, koakumacut, dispX_Enem, -50);
	SetCharStatusPresent(1, 0, true);
	SetCharStatusPresent(0, 0, true);
	Talking(0);
	SetEventText(0, 0, "durr", 0);
	SetCharStatusPresent(0, 0, false);
	Talking(1);
	SetEventText(1, 0, "...", 0);
	SetEventText(1, 4, "Well, at least[r]YOU get it.", 0);
	SetEventText(1, 4, "The actual fight is a lot[r]more complex than this.", 0); 	
	SetEventText(1, 4, "But I believe you'll[r]do quite well.", 0); 
	SetEventText(1, 4, "As a tip, try to interrupt[r]spells near the end of their cast.", 0); 
	SetEventText(1, 4, "This way, your enemies[r]spend more time doing nothing.", 0);
	wait(30);
	SetEventText(1, 4, "Oh, Miss Patchouli is on[r]her way now. I'd better run...", 0); 
	SetEventText(1, 0, "Good luck, and have fun!", 0);
	SetCharStatusPresent(1, 0, false); wait(45);
	FinalizeEvent;
	SetCommonData("koakumadone", true);
	
	
}
	
	
	function Event1A {

	let dispX_Player = 0;
	let dispX_Enem = -120;
	InitializeEvent(1, 1);
	HandleEventLogic();
	SetCutinGraphic(0, 0, reimucut, dispX_Player, 0);
	SetCharStatusPresent(0, 0, true);
	SetCutinGraphic(1, 0, reimucut, dispX_Enem, 5000);
	SetCharStatusPresent(1, 0, false);
	Talking(0);
	SetEventText(0, 2, "Huh...what is this?", 0);
	SetEventText(0, 2, "There's something on my skirt...", 0);
	SetEventText(0, 2, "What? READY?", 0);
	SetEventText(0, 1, "GET THIS THING OFF OF ME!!!", 0);
	SetCommonData("interruptavail", true);
	SetEventTextS(1, 4, "Press 'C' to try to[r]get it off of Reimu.", 0);
	wait(120);
	SetEventText(0, 2, "...What on earth was that?", 200);
	SetEventText(0, 2, "This seems to be counting down...", 200);
	SetEventText(0, 6, "Maybe this is a type[r] of 'skirt annoyance' youkai?", 240);
	SetEventText(0, 2, "Oh, it's READY again...", 0);

	

	SetCutinGraphic(1, 0, koakumacut, dispX_Enem, -50);
	SetCharStatusPresent(1, 0, true);
	SetCommonData("koakumamove", true);
	BottomEnemyMarker;
	ObjEnemyBossScene_Regist(obj);
	Talking(1); SetEventText(1, 6, "Oh my, the spell[r]got further than anticipated...", 0);
	SetEventText(1, 6, "It's even on me.[r]Ew...", 0); 
	SetEventText(1, 4, "Ah, Reimu. I see[r]it's affected you as well.", 0); 
	Talking(0); 
	SetEventText(0, 0, "What exactly IS this?", 0);
	Talking(1);
	SetEventText(1, 4, "Patchouli was experimenting with[r]concepts from the outside world.", 0);
	SetEventText(1, 4, "One of these concepts was a[r]'Spell Casting and Interruption System'", 0);
	SetEventText(1, 0, "Quite interesting, really...", 0);
	Talking(0);
	SetEventText(0, 4, "Does that explain the[r]timer thingy on my skirt?", 0);
	Talking(1);
	SetEventText(1, 4, "Yes. That displays the current[r]status of your interruption ability.", 0);
	Talking(0);
	wait(90);
	SetEventText(0, 4, "...sounds dumb.[r]How do I get rid of it?", 0);
	Talking(1);
	SetEventText(1, 4, "I'm afraid only[r]Lady Patchouli knows.", 0);
	SetEventText(1, 4, "She'll probably want to[r]beat it out of you.", 0);
	SetEventText(1, 4, "However, I'll run you through[r]some examples to prepare you.", 0);
	Talking(0);
	SetEventText(0, 6, "This is both sudden[r]AND convenient...", 0);
	Talking(1);
	SetCharStatusPresent(0, 0, false);
	SetEventText(1, 0, "Now, you there, behind the screen.", 0);
	SetEventText(1, 0, "This script works as follows...", 0);
	SetEventText(1, 4, "Your enemy may cast spells.[r]You may interrupt them with 'C'", 0);
	SetEventText(1, 4, "The spell name, and a bar displaying the time[r]until completion will appear on the right side.", 0);
	SetEventText(1, 0, "The bar fills from the bottom to the top.", 0);
	magiccircle2(0.7, true);
	PlayMusic2;
	SetEventText(1, 4, "I'll start off with a [r]simple attack. Interrupt it!", 0);
	soundset = true;
	SetCharStatusPresent(1, 0, false); wait(45);
	FinalizeEvent;
	//SetCommonData("readytheint", true);
	SetCommonData("koakumadie", true);
	
	
}


	
	
	
	

function screenflash(r,g,b){
let time = 0;
let objWhite = ObjPrim_Create(OBJ_SPRITE_2D);

let alphavar = 0;

ObjPrim_SetTexture(objWhite, white);
ObjSprite2D_SetSourceRect(objWhite, 0, 0, 691, 607);
ObjSprite2D_SetDestCenter(objWhite);
ObjRender_SetColor(objWhite, r, g, b);
ObjRender_SetAlpha(objWhite, 127.5);
ObjMove_SetX(objWhite, GetStgFrameWidth/2);
ObjMove_SetY(objWhite, GetStgFrameHeight/2);
ObjRender_SetScaleXYZ(objWhite, 2, 2, 1);
loop(60){
	ObjRender_SetAlpha(objWhite, 125+125*sin(alphavar));
	if(time<=10){
	alphavar+=9;
	}
	if(time>=30){
	alphavar+=180/30;
	}
	wait2(1);
	time++;
	}
Obj_Delete(objWhite);
function wait2(w){ loop(w){ yield; } }
}
	
	
	
	


	task PlayMusic{
	let rate = 100;
	sound2set = true;
	
	ObjSound_SetVolumeRate(objSound2, 100);
	ObjSound_SetLoopEnable(objSound2, true);
	ObjSound_SetRestartEnable(objSound2, true);
	ObjSound_SetLoopSampleCount(objSound2, 0, 5715528);
	ObjSound_SetSoundDivision(objSound2, SOUND_BGM);
	ObjSound_Play(objSound2);
	loop{
	if(moo3==true){
	ObjSound_SetFade(objSound2, 2);
	loop(120){
	wait(1);
	ObjSound_SetVolumeRate(objSound2, rate);
	rate-=100/140;
	}
	ObjSound_Stop(objSound2);
	Obj_Delete(objSound2);
	}
	
	yield;
	}
	}
	
	task PlayMusic2{
	let rate = 100;
	objSound = ObjSound_Create;
	ObjSound_Load(objSound, GetCurrentScriptDirectory~"bgm/bgm2.ogg");
	ObjSound_SetVolumeRate(objSound, 100);
	ObjSound_SetLoopEnable(objSound, true);
	ObjSound_SetRestartEnable(objSound, true);
	ObjSound_SetLoopSampleCount(objSound, 0, 6670113);
	ObjSound_SetSoundDivision(objSound, SOUND_BGM);
	ObjSound_Play(objSound);
	
	while(!Obj_IsDeleted(objSound)){
	if(moo2==true){
	ObjSound_SetFade(objSound, 2);
	loop(120){
	wait(1);
	ObjSound_SetVolumeRate(objSound, rate);
	rate-=100/140;
	}
	ObjSound_Stop(objSound);
	Obj_Delete(objSound);
	}
	
	yield;
	}
	}
	task PlayMusic3{
	let rate = 100;
	objSound3 = ObjSound_Create;
	ObjSound_Load(objSound3, GetCurrentScriptDirectory~"bgm/bgm3.ogg");
	ObjSound_SetVolumeRate(objSound3, 100);
	ObjSound_SetLoopEnable(objSound3, true);
	ObjSound_SetRestartEnable(objSound3, true);
	ObjSound_SetLoopSampleCount(objSound3, 0, 12606636);
	ObjSound_SetSoundDivision(objSound3, SOUND_BGM);
	ObjSound_Play(objSound3);
	
	loop{
	if(moo7==true){
	ObjSound_SetFade(objSound3, 2);
	loop(120){
	wait(1);
	ObjSound_SetVolumeRate(objSound3, rate);
	rate-=100/140;
	}
	ObjSound_Stop(objSound3);
	Obj_Delete(objSound3);
	}
	
	yield;
	}
	}
	