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,60);
	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;
	}
	Obj_Delete(obj);
}

task DialogueCutinPlayer{
	let alpha = 0;
	let mult = 0;
	let X = 90;
	let Y = 218;
	
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, 212, 320);}
	if(Player==1){ObjSprite2D_SetSourceRect(obj,0, 0, 180, 320);}
	if(Player==2){ObjSprite2D_SetSourceRect(obj,0, 0, 180, 320);}
	if(Player==3){ObjSprite2D_SetSourceRect(obj,0, 0, 144, 320);}
	if(Player==4){ObjSprite2D_SetSourceRect(obj,0, 0, 288, 320);}
	
	ObjRender_SetScaleXYZ(obj,0.7,0.7,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,155);}
	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 = 300;
	let Y = 218;
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCommonData("EnemyCutin",0) );
	ObjSprite2D_SetSourceRect(obj,0, 0, 256, 320);
	ObjRender_SetScaleXYZ(obj,0.7,0.7,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,155);}
	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/2])}

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 = [[180,0,0], [188,188,0], [0,0,255], [0,255,0], [122,122,122]];}
if(which==1){ColorArray = [[100,100,200], [255, 122, 0]];}
let CurrentColor = ColorArray[player];

count++;

let alpha = 255;
	
    let obj = ObjText_Create();
    ObjText_SetText(obj, text);
	Obj_SetRenderPriorityI(obj,61);
    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;}
	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/2])}

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 = [[180,0,0], [188,188,0], [0,0,255], [0,255,0], [122,122,122]];}
if(which==1){ColorArray = [[100,100,200], [255, 122, 0]];}
let CurrentColor = ColorArray[player];

count++;

let alpha = 255;
	
    let obj = ObjText_Create();
    ObjText_SetText(obj, text);
	Obj_SetRenderPriorityI(obj,61);
    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;}
	Obj_Delete(obj);
}



//Massive Library of Cutinness!

let Rei1 =  GetCurrentScriptDirectory~"./img/Emotions/Rei1.png";
let Rei2 =  GetCurrentScriptDirectory~"./img/Emotions/Rei2.png";
let Rei3 =  GetCurrentScriptDirectory~"./img/Emotions/Rei3.png";
let Rei4 =  GetCurrentScriptDirectory~"./img/Emotions/Rei4.png";
let Rei5 =  GetCurrentScriptDirectory~"./img/Emotions/Rei5.png";
let Rei6 =  GetCurrentScriptDirectory~"./img/Emotions/Rei6.png";
let Rei7 =  GetCurrentScriptDirectory~"./img/Emotions/Rei7.png";
let Rei8 =  GetCurrentScriptDirectory~"./img/Emotions/Rei8.png";
let Reimu = [Rei1, Rei2, Rei3, Rei4, Rei5, Rei6, Rei7, Rei8];

let Mar1 =  GetCurrentScriptDirectory~"./img/Emotions/Mar1.png";
let Mar2 =  GetCurrentScriptDirectory~"./img/Emotions/Mar2.png";
let Mar3 =  GetCurrentScriptDirectory~"./img/Emotions/Mar3.png";
let Mar4 =  GetCurrentScriptDirectory~"./img/Emotions/Mar4.png";
let Mar5 =  GetCurrentScriptDirectory~"./img/Emotions/Mar5.png";
let Mar6 =  GetCurrentScriptDirectory~"./img/Emotions/Mar6.png";
let Mar7 =  GetCurrentScriptDirectory~"./img/Emotions/Mar7.png";
let Mar8 =  GetCurrentScriptDirectory~"./img/Emotions/Mar8.png";
let Marisa = [Mar1, Mar2, Mar3, Mar4, Mar5, Mar6, Mar7, Mar8];

let Sak1 =  GetCurrentScriptDirectory~"./img/Emotions/Sak1.png";
let Sak2 =  GetCurrentScriptDirectory~"./img/Emotions/Sak2.png";
let Sak3 =  GetCurrentScriptDirectory~"./img/Emotions/Sak3.png";
let Sak4 =  GetCurrentScriptDirectory~"./img/Emotions/Sak4.png";
let Sak5 =  GetCurrentScriptDirectory~"./img/Emotions/Sak5.png";
let Sak6 =  GetCurrentScriptDirectory~"./img/Emotions/Sak6.png";
let Sak7 =  GetCurrentScriptDirectory~"./img/Emotions/Sak7.png";
let Sak8 =  GetCurrentScriptDirectory~"./img/Emotions/Sak8.png";
let Sakuya = [Sak1, Sak2, Sak3, Sak4, Sak5, Sak6, Sak7, Sak8];

let San1 =  GetCurrentScriptDirectory~"./img/Emotions/San1.png";
let San2 =  GetCurrentScriptDirectory~"./img/Emotions/San2.png";
let San3 =  GetCurrentScriptDirectory~"./img/Emotions/San3.png";
let San4 =  GetCurrentScriptDirectory~"./img/Emotions/San4.png";
let San5 =  GetCurrentScriptDirectory~"./img/Emotions/San5.png";
let San6 =  GetCurrentScriptDirectory~"./img/Emotions/San6.png";
let San7 =  GetCurrentScriptDirectory~"./img/Emotions/San7.png";
let San8 =  GetCurrentScriptDirectory~"./img/Emotions/San8.png";
let Sanae = [San1, San2, San3, San4, San5, San6, San7, San8];

let You1 =  GetCurrentScriptDirectory~"./img/Emotions/You1.png";
let You2 =  GetCurrentScriptDirectory~"./img/Emotions/You2.png";
let You3 =  GetCurrentScriptDirectory~"./img/Emotions/You3.png";
let You4 =  GetCurrentScriptDirectory~"./img/Emotions/You4.png";
let You5 =  GetCurrentScriptDirectory~"./img/Emotions/You5.png";
let You6 =  GetCurrentScriptDirectory~"./img/Emotions/You6.png";
let You7 =  GetCurrentScriptDirectory~"./img/Emotions/You7.png";
let You8 =  GetCurrentScriptDirectory~"./img/Emotions/You8.png";
let Youmu = [You1, You2, You3, You4, You5, You6, You7, You8];

let Kis =  GetCurrentScriptDirectory~"./img/Emotions/Kisume.png";
let Kisume = [Kis];

let Yam1 =  GetCurrentScriptDirectory~"./img/Emotions/Yam1.png";
let Yam2 =  GetCurrentScriptDirectory~"./img/Emotions/Yam2.png";
let Yam3 =  GetCurrentScriptDirectory~"./img/Emotions/Yam3.png";
let Yam4 =  GetCurrentScriptDirectory~"./img/Emotions/Yam4.png";
let Yamame = [Yam1, Yam2, Yam3, Yam4];

let Characters = [Reimu, Marisa, Sakuya, Sanae, Youmu];
let Bosses = [Kisume, Yamame];