task DialogueBox{
let alpha = 0;
let mult = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/black.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, GetStgFrameWidth, 148);
	ObjRender_SetScaleXYZ(obj,1,1.1,1);
	Obj_SetRenderPriorityI(obj,65);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,410,0);
	loop(30){
	ObjRender_SetAlpha(obj,alpha);	
	mult+=1;
	alpha+=mult/3;
	yield;
	}
	loop{
	if(GetCommonData("EndDialogue",0) == 1){break;}
	yield;
	}
	loop(30){
	ObjRender_SetAlpha(obj,alpha);	
	mult-=1;
	alpha-=mult/3;
	yield;
	}
	yield;
	Obj_Delete(obj);
}

task DialogueCutinPlayer{
	let alpha = 0;
	let mult = 0;
	let X = 90;
	let Y = 280;
	
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}

	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCommonData("PlayerCutin",0) );
	if(Player==0){ObjSprite2D_SetSourceRect(obj,0, 0, 272, 518);}
	
	ObjRender_SetScaleXYZ(obj,0.6,0.6,1);
	Obj_SetRenderPriorityI(obj,60);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj,X,Y,0);
	loop(30){
	ObjRender_SetAlpha(obj,alpha);	
	mult+=1;
	alpha+=mult;
	yield;
	}
	loop{
	if(GetCommonData("EndDialogue",0) == 1){Obj_Delete(obj);}
	if(GetCommonData("PlayerTalk",0) == 1){ObjRender_SetAlpha(obj,255);}
	else{ObjRender_SetAlpha(obj,90);}
	ObjPrim_SetTexture(obj, GetCommonData("PlayerCutin",0) );
	ObjRender_SetPosition(obj,X+GetCommonData("X",0),Y+GetCommonData("Y",0),0);
	ObjRender_SetAngleZ(obj, GetCommonData("Angle",0));
	yield;
	}
}

task DialogueCutinBoss{
	let alpha = 0;
	let mult = 0;
	let X = 310;
	let Y = 280;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCommonData("EnemyCutin",0) );
	ObjSprite2D_SetSourceRect(obj,0, 0, 300, 515);
	ObjRender_SetScaleXYZ(obj,0.6,0.6,1);
	Obj_SetRenderPriorityI(obj,60);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj,X,Y,0);
	//ObjRender_SetAngleY(obj, 180);
	loop(30){
	ObjRender_SetAlpha(obj,alpha);	
	mult+=1;
	alpha+=mult;
	yield;
	}
	loop{
	if(GetCommonData("EndDialogue",0) == 1){Obj_Delete(obj);}
	if(GetCommonData("PlayerTalk",0) == 0){ObjRender_SetAlpha(obj,255);}
	else{ObjRender_SetAlpha(obj,90);}
	ObjPrim_SetTexture(obj, GetCommonData("EnemyCutin",0) );
	ObjRender_SetPosition(obj,X+GetCommonData("EX",0),Y+GetCommonData("EY",0),0);
	ObjRender_SetAngleZ(obj, GetCommonData("EAngle",0));
	yield;
	}
}

let count = 0;

task Dialogue(which, text, player, emotion, x, y, ang){

if(which==0){SetCommonData("PlayerCutin",Characters[player][emotion]);}
if(which==1){SetCommonData("EnemyCutin",Bosses[player][emotion])}

if(which==0){SetCommonData("PlayerTalk",1);}
else{SetCommonData("PlayerTalk",0);}

let Pos = [x,y];
if(which==0){
SetCommonData("X",Pos[0]);
SetCommonData("Y",Pos[1]);
SetCommonData("Angle",ang);
}
if(which==1){
SetCommonData("EX",Pos[0]);
SetCommonData("EY",Pos[1]);
SetCommonData("EAngle",ang);
}

let ColorArray;
if(which==0){ColorArray = [[122,122,122]];}
if(which==1){ColorArray = [[255,5,255],[255,122,0]];}
let CurrentColor = ColorArray[player];

count++;

let alpha = 255;
	
    let obj = ObjText_Create();
    ObjText_SetText(obj, text);
	Obj_SetRenderPriorityI(obj,66);
    ObjText_SetFontSize(obj, 18);
    ObjText_SetFontType(obj, "Verdana");
    ObjText_SetFontBold(obj, false);
    ObjText_SetFontColorTop(obj, 255, 255, 255);
    ObjText_SetFontColorBottom(obj, 255, 255, 255);
    ObjText_SetFontBorderType(obj, BORDER_FULL);
	if(which==0){ObjText_SetFontBorderColor(obj, CurrentColor[0], CurrentColor[1], CurrentColor[2]);}
	if(which==1){ObjText_SetFontBorderColor(obj, CurrentColor[0], CurrentColor[1], CurrentColor[2]);}
    ObjText_SetFontBorderWidth(obj, 1);
	ObjRender_SetPosition(obj,10,340,0);
	let counter = count;
	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	loop(5){
		alpha-=255/5;
		ObjRender_SetAlpha(obj,alpha);
	yield;}
	yield;
	Obj_Delete(obj);
}

task TimedDialogue(which, text, player, emotion, x, y, ang, time){

if(which==0){SetCommonData("PlayerCutin",Characters[player][emotion]);}
if(which==1){SetCommonData("EnemyCutin",Bosses[player][emotion])}

if(which==0){SetCommonData("PlayerTalk",1);}
else{SetCommonData("PlayerTalk",0);}

let Pos = [x,y];
if(which==0){
SetCommonData("X",Pos[0]);
SetCommonData("Y",Pos[1]);
SetCommonData("Angle",ang);
}
if(which==1){
SetCommonData("EX",Pos[0]);
SetCommonData("EY",Pos[1]);
SetCommonData("EAngle",ang);
}

let ColorArray;
if(which==0){ColorArray = [[122,122,122]];}
if(which==1){ColorArray = [[255,5,255],[255,122,0]];}
let CurrentColor = ColorArray[player];

count++;

let alpha = 255;
	
    let obj = ObjText_Create();
    ObjText_SetText(obj, text);
	Obj_SetRenderPriorityI(obj,66);
    ObjText_SetFontSize(obj, 18);
    ObjText_SetFontType(obj, "Verdana");
    ObjText_SetFontBold(obj, false);
    ObjText_SetFontColorTop(obj, 255, 255, 255);
    ObjText_SetFontColorBottom(obj, 255, 255, 255);
    ObjText_SetFontBorderType(obj, BORDER_FULL);
	if(which==0){ObjText_SetFontBorderColor(obj, CurrentColor[0], CurrentColor[1], CurrentColor[2]);}
	if(which==1){ObjText_SetFontBorderColor(obj, CurrentColor[0], CurrentColor[1], CurrentColor[2]);}
    ObjText_SetFontBorderWidth(obj, 1);
	ObjRender_SetPosition(obj,10,340,0);
	let counter = count;
	loop(time){yield;}
	loop(5){
		alpha-=255/5;
		ObjRender_SetAlpha(obj,alpha);
	yield;}
	yield;
	Obj_Delete(obj);
}

task SATURATION{
	let alpha = 0;
	let mult = 0;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"./img/SATURATION.png");
	ObjSprite2D_SetSourceRect(obj,0, 0, 819, 157);
	ObjRender_SetScaleXYZ(obj,0.47,0.7,1);
	Obj_SetRenderPriorityI(obj,67);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj, alpha);
	ObjRender_SetPosition(obj,GetStgFrameWidth/2,370,0);
	loop(30){
	ObjRender_SetAlpha(obj,alpha);	
	mult+=1;
	alpha+=mult;
	yield;
	}

	while(GetVirtualKeyState(VK_SHOT)!=KEY_PUSH){yield;}
	loop(5){
		alpha-=255/5;
		ObjRender_SetAlpha(obj,alpha);
	yield;}
	yield;
	Obj_Delete(obj);
}


//Massive Library of Cutinness!

let Tsu1 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu1.png";
let Tsu2 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu2.png";
let Tsu3 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu3.png";
let Tsu4 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu4.png";
let Tsu5 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu5.png";
let Tsu6 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu6.png";
let Tsu7 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu7.png";
let Tsu8 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu8.png";
let Tsu9 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu9.png";
let Tsu10 =  GetCurrentScriptDirectory~"./img/Emotions/Tsu10.png";
let Tsubakura = [Tsu1, Tsu2, Tsu3, Tsu4, Tsu5, Tsu6, Tsu7, Tsu8, Tsu9, Tsu10];

let Yab =  GetCurrentScriptDirectory~"./img/Emotions/ohhellno.png";
let Yabusame = [Yab];

let Cla1 =  GetCurrentScriptDirectory~"./img/Emotions/Cla1.png";
let Cla2 =  GetCurrentScriptDirectory~"./img/Emotions/Cla2.png";
let Cla3 =  GetCurrentScriptDirectory~"./img/Emotions/Cla3.png";
let Cla4 =  GetCurrentScriptDirectory~"./img/Emotions/Cla4.png";
let Cla5 =  GetCurrentScriptDirectory~"./img/Emotions/Cla5.png";
let Cla6 =  GetCurrentScriptDirectory~"./img/Emotions/Cla6.png";
let Cla7 =  GetCurrentScriptDirectory~"./img/Emotions/Cla7.png";
let Cla8 =  GetCurrentScriptDirectory~"./img/Emotions/Cla8.png";
let Cla9 =  GetCurrentScriptDirectory~"./img/Emotions/Cla9.png";
let Cla10 =  GetCurrentScriptDirectory~"./img/Emotions/Cla10.png";
let Cla11 =  GetCurrentScriptDirectory~"./img/Emotions/ClaIsThatSo.png";
let Cla12 =  GetCurrentScriptDirectory~"./img/Emotions/ClaOhmy.png";
let Clause = [Cla1, Cla2, Cla3, Cla4, Cla5, Cla6, Cla7, Cla8, Cla9, Cla10, Cla11, Cla12];

let Characters = [Tsubakura];
let Bosses = [Clause, Yabusame];