#include".\shot\AllStarShot_Const.txt"
#include".\Resources.txt"
#include".\selibrary.txt"
#include".\lib\AnimLib.h"
#include".\lib\DialogueLibrary.h"
#include".\OzzieEffects.txt"

let Koishi = ID_INVALID;
let KoishiX = 0;
let KoishiY = 0;

let Flandre = ID_INVALID;
let FlandreX = 0;
let FlandreY = 0;

let Clownpiece = ID_INVALID;
let ClownpieceX = 0;
let ClownpieceY = 0;

let imgKoishi = CSD~"./img/dot_Koishi.png";
let imgFlandre = CSD~"./img/dot_Flandre.png";
let imgClownpiece = CSD~"./img/dot_Clownpiece.png";

@Event{
    SetTimer(999);
    SetLife(1200);
    SetScore(1000000);
}
 
@Initialize{
	SetAutoDeleteObject(true);
	Koishi = ObjEnemy_Create(OBJ_ENEMY_BOSS);	
	Flandre = ObjEnemy_Create(OBJ_ENEMY);	
	Clownpiece = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(Clownpiece);
    ObjEnemy_Regist(Koishi);
    ObjEnemy_Regist(Flandre);		
	
	SetForbidPlayerSpell(true);
    SetForbidPlayerShot(true);
	
	ObjMove_SetY(Koishi, GetCenterY-520);
	ObjMove_SetY(Flandre, GetCenterY-520);
	ObjMove_SetY(Clownpiece, GetCenterY-520);
	
	RenderKoishi;
	RenderClownpiece;
	RenderFlandre;
	ClownpieceManage;
	MainTask;     
}

task RenderClownpiece{
	ObjPrim_SetTexture(Clownpiece,imgClownpiece);
	ObjSprite2D_SetDestCenter(Clownpiece);	
	ObjRender_SetScaleXYZ(Clownpiece,1,1,0);
	
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 32, 32, 96, 96);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 32, 160, 96, 224);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 32, 288, 96, 352);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 160, 32, 224, 96);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 160, 160, 224, 224);
	
	ObjAnim_AddFrameA1(Clownpiece, ANIM_MOVE, 288, 288, 352, 352);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_MOVE, 288, 416, 352, 480);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_MOVEEND, 288, 288, 352, 352);
		
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 544, 32, 608, 96);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 544, 160, 608, 224);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 544, 288, 608, 352);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 672, 32, 736, 96);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 672, 160, 736, 224);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 672, 288, 736, 352);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACKEND, 544, 160, 608, 224);
	
	ObjAnim_SetLoopPointA1(Clownpiece, ANIM_MOVE, 1);
	ObjAnim_SetLoopPointA1(Clownpiece, ANIM_ATTACK, 5);
	ObjAnim_SetSpeedA1(Clownpiece, ANIM_IDLE, 7);
	ObjAnim_SetSpeedA1(Clownpiece, ANIM_MOVE, 4);
	ObjAnim_SetSpeedA1(Clownpiece, ANIM_ATTACK, 3);
	ObjAnim_SetSpeedA1(Clownpiece, ANIM_ATTACKEND, 3);
	ObjAnim_StartAnimationA1(Clownpiece, 10, 3);
}

task RenderKoishi{
	ObjPrim_SetTexture(Koishi,imgKoishi);
	ObjSprite2D_SetDestCenter(Koishi);	
	ObjRender_SetScaleXYZ(Koishi,1,1,0);
	
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 32, 32, 96, 96);
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 32, 160, 96, 224);
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 32, 288, 96, 352);
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 160, 32, 224, 96);
	ObjAnim_AddFrameA1(Koishi, ANIM_IDLE, 160, 160, 224, 224);
	
	ObjAnim_AddFrameA1(Koishi, ANIM_MOVE, 288, 288, 352, 352);
	ObjAnim_AddFrameA1(Koishi, ANIM_MOVE, 288, 416, 352, 480);
	ObjAnim_AddFrameA1(Koishi, ANIM_MOVEEND, 288, 288, 352, 352);
		
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 544, 32, 608, 96);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 544, 160, 608, 224);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 544, 288, 608, 352);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 672, 32, 736, 96);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 672, 160, 736, 224);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACK, 672, 288, 736, 352);
	ObjAnim_AddFrameA1(Koishi, ANIM_ATTACKEND, 544, 160, 608, 224);
	
	ObjAnim_SetLoopPointA1(Koishi, ANIM_MOVE, 1);
	ObjAnim_SetLoopPointA1(Koishi, ANIM_ATTACK, 5);
	ObjAnim_SetSpeedA1(Koishi, ANIM_IDLE, 7);
	ObjAnim_SetSpeedA1(Koishi, ANIM_MOVE, 4);
	ObjAnim_SetSpeedA1(Koishi, ANIM_ATTACK, 3);
	ObjAnim_SetSpeedA1(Koishi, ANIM_ATTACKEND, 3);
	ObjAnim_StartAnimationA1(Koishi, 10, 3);
}

task RenderFlandre{
	ObjPrim_SetTexture(Flandre,imgFlandre);
	ObjSprite2D_SetDestCenter(Flandre);	
	ObjRender_SetScaleXYZ(Flandre,1,1,0);
	
	ObjAnim_AddFrameA1(Flandre, ANIM_IDLE, 32, 32, 96, 96);
	ObjAnim_AddFrameA1(Flandre, ANIM_IDLE, 32, 160, 96, 224);
	ObjAnim_AddFrameA1(Flandre, ANIM_IDLE, 32, 288, 96, 352);
	ObjAnim_AddFrameA1(Flandre, ANIM_IDLE, 160, 32, 224, 96);
	ObjAnim_AddFrameA1(Flandre, ANIM_IDLE, 160, 160, 224, 224);
	
	ObjAnim_AddFrameA1(Flandre, ANIM_MOVE, 288, 288, 352, 352);
	ObjAnim_AddFrameA1(Flandre, ANIM_MOVE, 288, 416, 352, 480);
	ObjAnim_AddFrameA1(Flandre, ANIM_MOVEEND, 288, 288, 352, 352);
		
	ObjAnim_AddFrameA1(Flandre, ANIM_ATTACK, 544, 32, 608, 96);
	ObjAnim_AddFrameA1(Flandre, ANIM_ATTACK, 544, 160, 608, 224);
	ObjAnim_AddFrameA1(Flandre, ANIM_ATTACK, 544, 288, 608, 352);
	ObjAnim_AddFrameA1(Flandre, ANIM_ATTACK, 672, 32, 736, 96);
	ObjAnim_AddFrameA1(Flandre, ANIM_ATTACK, 672, 160, 736, 224);
	ObjAnim_AddFrameA1(Flandre, ANIM_ATTACK, 672, 288, 736, 352);
	ObjAnim_AddFrameA1(Flandre, ANIM_ATTACKEND, 544, 160, 608, 224);
	
	ObjAnim_SetLoopPointA1(Flandre, ANIM_MOVE, 1);
	ObjAnim_SetLoopPointA1(Flandre, ANIM_ATTACK, 5);
	ObjAnim_SetSpeedA1(Flandre, ANIM_IDLE, 7);
	ObjAnim_SetSpeedA1(Flandre, ANIM_MOVE, 4);
	ObjAnim_SetSpeedA1(Flandre, ANIM_ATTACK, 3);
	ObjAnim_SetSpeedA1(Flandre, ANIM_ATTACKEND, 3);
	ObjAnim_StartAnimationA1(Flandre, 10, 3);
}


@MainLoop{
	yield;
}

task MainTask{	
	//movement;
	ObjEnemy_SetDamageRate(Koishi,0,0);
	wait(60);
	ObjEnemy_SetDamageRate(Koishi,30,4);
	TEvent;		
}

task movement{
	ObjMove_SetDestAtSpeed(Koishi,GetCenterX-120,GetCenterY-120,5);
	ObjMove_SetDestAtSpeed(Flandre,GetCenterX+120,GetCenterY-120,5);
}

task TEvent {
    // Obtain relevant objects
    let dialogueobjects = CreateDialogueEvent();
    let textobj = dialogueobjects[1];
    let leftportrait = dialogueobjects[2];
    let rightportrait = dialogueobjects[3];
    let pathCirno1 = GetCurrentScriptDirectory() ~ "./img/Convo/Cirno_1.png";//HappyNormal
    let pathCirno2 = GetCurrentScriptDirectory() ~ "./img/Convo/Cirno_2.png";//Confused
    let pathCirno3 = GetCurrentScriptDirectory() ~ "./img/Convo/Cirno_3.png";//Sinister Smile
	let pathCirno4 = GetCurrentScriptDirectory() ~ "./img/Convo/Cirno_4.png";//Proud
	let pathCirno5 = GetCurrentScriptDirectory() ~ "./img/Convo/Cirno_5.png";//Surprised
	let pathCirno6 = GetCurrentScriptDirectory() ~ "./img/Convo/Cirno_6.png";//Angry
	let pathCirno7 = GetCurrentScriptDirectory() ~ "./img/Convo/Cirno_7.png";//Sonrised
	
    let pathAnyone = GetCurrentScriptDirectory() ~ "./img/Convo/Enemy.png";//Anyone
	
    let pathFlandre1 = GetCurrentScriptDirectory() ~ "./img/Convo/Flandre_1.png";//NormalHappy
    let pathFlandre2 = GetCurrentScriptDirectory() ~ "./img/Convo/Flandre_2.png";//No happy
	let pathFlandre3 = GetCurrentScriptDirectory() ~ "./img/Convo/Flandre_3.png";//RevengerScary
	let pathFlandre4 = GetCurrentScriptDirectory() ~ "./img/Convo/Flandre_4.png";//Angry medium closed eyes
	let pathFlandre5 = GetCurrentScriptDirectory() ~ "./img/Convo/Flandre_5.png";//Proud
	let pathFlandre6 = GetCurrentScriptDirectory() ~ "./img/Convo/Flandre_6.png";//Much Happy
	let pathFlandre7 = GetCurrentScriptDirectory() ~ "./img/Convo/Flandre_7.png";//Normal Angry
	let pathFlandre8 = GetCurrentScriptDirectory() ~ "./img/Convo/Flandre_8.png";//Angry - Sunrised
	
	let pathKoishi1 = GetCurrentScriptDirectory() ~ "./img/Convo/Koishi_1.png";//Normal
    let pathKoishi2 = GetCurrentScriptDirectory() ~ "./img/Convo/Koishi_2.png";//Serious
	let pathKoishi3 = GetCurrentScriptDirectory() ~ "./img/Convo/Koishi_3.png";//Curious Scary
	let pathKoishi4 = GetCurrentScriptDirectory() ~ "./img/Convo/Koishi_4.png";//Surprised
	let pathKoishi5 = GetCurrentScriptDirectory() ~ "./img/Convo/Koishi_5.png";//Surprised sunrise
	
	let pathClownpiece1 = GetCurrentScriptDirectory() ~ "./img/Convo/Clownpiece_1.png";//Normal
	let pathClownpiece2 = GetCurrentScriptDirectory() ~ "./img/Convo/Clownpiece_2.png";//Revenger
	let pathClownpiece3 = GetCurrentScriptDirectory() ~ "./img/Convo/Clownpiece_3.png";//Nervious
	let pathClownpiece4 = GetCurrentScriptDirectory() ~ "./img/Convo/Clownpiece_4.png";//Angry
	
    // Set initial textures
    ObjPrim_SetTexture(leftportrait, pathCirno1);
    //ObjPrim_SetTexture(rightportrait, pathAnyone);
    let maxwidth = GetStgFrameWidth - 16*2 - 8*2; // same as TEXT_MAXWIDTH in lib_dialogue.dnh
	
    autoformLineInsertionA2("Cirno:[r]I think i would be more dangerous.", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
    autoformLineInsertionA2("Cirno:[r]Marisa was soo hard!!...", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno2);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
    autoformLineInsertionA2("Cirno:[r]Well that doesn't say nothing", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno3);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
    autoformLineInsertionA2("???:[r]For me say Anything", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
    ObjPrim_SetTexture(leftportrait, pathCirno3);
	ObjPrim_SetTexture(rightportrait, pathAnyone);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Cirno:[r]Who are you?, show yourself!!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno5);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
	ObjMove_SetDestAtSpeed(Koishi,GetCenterX,GetCenterY-120,5);
	wait(120);
    autoformLineInsertionA2("Koishi Komeiji:[r]You need to know who is your enemy", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(rightportrait, pathKoishi2);
	ObjSprite2D_SetSourceRect(rightportrait, 0, 0, 753, 524);
	ObjRender_SetScaleXYZ(rightportrait,0.78,0.78,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Koishi Komeiji:[r]Sure, you know who i am?", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(rightportrait, pathKoishi3);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Cirno:[r]No, i have no idea...", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno4);
	ObjPrim_SetTexture(rightportrait, pathKoishi4);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
    autoformLineInsertionA2("Cirno:[r]I never see you in my life..", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno2);
	ObjPrim_SetTexture(rightportrait, pathKoishi2);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
    autoformLineInsertionA2("Cirno:[r]I have to be scared?", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno3);
	ObjPrim_SetTexture(rightportrait, pathKoishi4);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
    autoformLineInsertionA2("Koishi Komeiji:[r]Anyway, i never see you in my life.", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(rightportrait, pathKoishi1);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Koishi Komeiji:[r]I think you're one of those useless fairies", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(leftportrait, pathCirno6);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Koishi Komeiji:[r]True?", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(rightportrait, pathKoishi3);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Cirno:[r]I'm a Useful FAIRY...", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
	ObjPrim_SetTexture(rightportrait, pathKoishi1);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
    autoformLineInsertionA2("Cirno:[r]I'm The Strongest...The most powerfull in Gensokyo...", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
	ObjPrim_SetTexture(rightportrait, pathKoishi2);
	ObjPrim_SetTexture(leftportrait, pathCirno7);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
	autoformLineInsertionA2("???:[r]fufu - So Funny", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 198, 107, 111);
	ObjPrim_SetTexture(rightportrait, pathAnyone);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Cirno:[r]Another One who is making fools!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno6);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
	ObjMove_SetDestAtSpeed(Clownpiece,GetCenterX,GetCenterY-120,5);
	ObjMove_SetDestAtSpeed(Koishi,GetCenterX-120,GetCenterY-130,5);
	wait(120);
	autoformLineInsertionA2("Clownpiece:[r]Its funny see you say that!!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 198, 107, 111);
	ObjPrim_SetTexture(rightportrait, pathClownpiece1);
	ObjSprite2D_SetSourceRect(rightportrait, 53, 63, 753, 969);
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 150);
	ObjRender_SetScaleXYZ(rightportrait,0.6,1.1,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Clownpiece:[r]You are not the strongest", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 198, 107, 111);
	ObjPrim_SetTexture(leftportrait, pathCirno6);
	ObjPrim_SetTexture(rightportrait, pathClownpiece2);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Cirno:[r]Clownpiece, Again!!!?", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno6);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
    autoformLineInsertionA2("Clownpiece:[r]Cirno, Acept it", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 198, 107, 111);
	ObjPrim_SetTexture(rightportrait, pathClownpiece1);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Clownpiece:[r]You are an ussual Fairy", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 198, 107, 111);
	ObjPrim_SetTexture(rightportrait, pathClownpiece2);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Clownpiece:[r]Im the Really Strongest", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 198, 107, 111);
    ObjPrim_SetTexture(leftportrait, pathCirno2);
	ObjPrim_SetTexture(rightportrait, pathClownpiece2);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Koishi Komeiji:[r]Clownpiece, Can you stop?", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(rightportrait, pathKoishi2);
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 250);
	ObjSprite2D_SetSourceRect(rightportrait, 0, 0, 753, 524);
	ObjRender_SetScaleXYZ(rightportrait,0.78,0.78,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    autoformLineInsertionA2("Koishi Komeiji:[r]You are making Cirno feel bad", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(rightportrait, pathKoishi3);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Cirno:[r]Can you Stop, Stranger!!!?", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno6);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
    autoformLineInsertionA2("Koishi Komeiji:[r]Im Koishi Komeiji...", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(rightportrait, pathKoishi1);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Cirno:[r]Can you Stop, KOISHI!!!?", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno6);
	ObjPrim_SetTexture(rightportrait, pathKoishi5);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
	autoformLineInsertionA2("Clownpiece:[r]Shut up Please!!!!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 198, 107, 111);
	ObjPrim_SetTexture(rightportrait, pathClownpiece4);
	ObjSprite2D_SetSourceRect(rightportrait, 53, 63, 753, 969);
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 150);
	ObjRender_SetScaleXYZ(rightportrait,0.6,1.1,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("???:[r]Hey, Koishi, What is Happening?", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 171, 010, 014);
	ObjPrim_SetTexture(rightportrait, pathAnyone);
    SetPortraitToForeground(rightportrait); 
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 250);
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Cirno:[r]REALLY, ANOTHER ONE!!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno6);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
	ObjMove_SetDestAtSpeed(Flandre,GetCenterX+120,GetCenterY-120,5);
	wait(160);
	autoformLineInsertionA2("Flandre Scarlet:[r]I heard a lot of loud here", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 171, 010, 014);
	ObjPrim_SetTexture(rightportrait, pathFlandre2);
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 190);
	ObjSprite2D_SetSourceRect(rightportrait, 0, 0, 753, 685);
	ObjRender_SetScaleXYZ(rightportrait,0.64,0.84,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Cirno:[r]You are that vampire of the SDM!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno5);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
	autoformLineInsertionA2("Flandre Scarlet:[r]And you are that ice Fairy", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 171, 010, 014);
	ObjPrim_SetTexture(rightportrait, pathFlandre4);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Flandre Scarlet:[r]And that vampire is my Sister", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 171, 010, 014);
	ObjPrim_SetTexture(rightportrait, pathFlandre8);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Cirno:[r]And you are her Sister!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno1);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
	autoformLineInsertionA2("Flandre Scarlet:[r]My name is Flandre Scarlet", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 171, 010, 014);
	ObjPrim_SetTexture(rightportrait, pathFlandre3);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Flandre Scarlet:[r]Clownpiece Call Us to...", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 171, 010, 014);
	ObjPrim_SetTexture(rightportrait, pathFlandre8);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Clownpiece:[r]Destroy you!!!!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 198, 107, 111);
	ObjPrim_SetTexture(rightportrait, pathClownpiece2);
	ObjSprite2D_SetSourceRect(rightportrait, 53, 63, 753, 969);
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 150);
	ObjRender_SetScaleXYZ(rightportrait,0.6,1.1,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Koishi Komeiji:[r]Don't Worry, will be Kind", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(rightportrait, pathKoishi1);
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 250);
	ObjSprite2D_SetSourceRect(rightportrait, 0, 0, 753, 524);
	ObjRender_SetScaleXYZ(rightportrait,0.78,0.78,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Cirno:[r]Well, a New Challenge for me!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 30, 53, 191);
    ObjPrim_SetTexture(leftportrait, pathCirno3);
    SetPortraitToForeground(leftportrait); 
	SetPortraitToBackground(rightportrait);
    EventWaitA3(15);
	autoformLineInsertionA2("Clownpiece:[r]Prepare!!!!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 198, 107, 111);
	ObjPrim_SetTexture(rightportrait, pathClownpiece2);
	ObjSprite2D_SetSourceRect(rightportrait, 53, 63, 753, 969);
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 150);
	ObjRender_SetScaleXYZ(rightportrait,0.6,1.1,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Koishi Komeiji:[r]To", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 48, 118, 066);
	ObjPrim_SetTexture(rightportrait, pathKoishi3);
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 250);
	ObjSprite2D_SetSourceRect(rightportrait, 0, 0, 753, 524);
	ObjRender_SetScaleXYZ(rightportrait,0.78,0.78,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	autoformLineInsertionA2("Flandre Scarlet:[r]Die!!!", textobj, maxwidth);
    ObjText_SetFontBorderColor(textobj, 171, 010, 014);
	ObjPrim_SetTexture(rightportrait, pathFlandre3);
	ObjRender_SetX(rightportrait, GetStgFrameLeft() + GetStgFrameWidth()/2 + 190);
	ObjSprite2D_SetSourceRect(rightportrait, 0, 0, 753, 685);
	ObjRender_SetScaleXYZ(rightportrait,0.64,0.84,0);
    SetPortraitToForeground(rightportrait); 
	SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
    DestroyDialogueEvent(dialogueobjects);
	wait(130);
	SE_Play(charge1,100);
	ConcentrationA2(Koishi,"HEART",60,7,150,[255,100,255]);
	SE_Play(charge1,100);
	ConcentrationA2(Clownpiece,"STAR",60,7,150,[0,0,255]);
	ConcentrationA2(Flandre,"MAPLE",60,7,150,[255,0,0]);
	NotifyEventAll(EV_USER +1,0);
	SetForbidPlayerShot(false);
	ObjEnemyBossScene_SetSpellTimer(GetEnemyBossSceneObjectID,5940);
	SetForbidPlayerSpell(false);
	FireTask;
}

task FireTask{
	wait(130);
	FlanRings;
	ClownLazers;
	KoishiFire;
}

task FlanRings{
	let angle;
	let numberofbullets = 30;
	loop{
		angle = rand(0,360);
		SE_Play(chime,30);
		
		loop(numberofbullets){
		CreateShotA1(FlandreX,FlandreY,2,angle,551,10);
		CreateShotA1(FlandreX,FlandreY,4,angle,551,10);
		angle+=360/numberofbullets;}
	wait(60);}
}

task ClownLazers{
loop{
SE_Play(lazer,70);	
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
CreateStraightLaserA1(ObjMove_GetX(Clownpiece),ObjMove_GetY(Clownpiece),rand(0,360),1000,20,120,1007,120);
wait(120);}
}

task KoishiFire{
	let angle = GetAngleToPlayer(Koishi);
	let numberofbullets = 2;
	loop{
		
		SE_Play(shot,30);
		
		loop(numberofbullets){
			let shot = CreateShotA2(KoishiX,KoishiY, 1, angle, 0.11, 4, 832,10);
			Obj_GetValue(shot, "Fireball");
		angle+=360/numberofbullets;}
		angle+=5;
	wait(5);}
}

task ClownpieceManage{

	while(ObjEnemy_GetInfo(Koishi,INFO_LIFE)>0){
        KoishiX = ObjMove_GetX(Koishi);
        KoishiY = ObjMove_GetY(Koishi);
		
		FlandreX = ObjMove_GetX(Flandre);
        FlandreY = ObjMove_GetY(Flandre);
		
		ClownpieceX = ObjMove_GetX(Clownpiece);
        ClownpieceY = ObjMove_GetY(Clownpiece);

        ObjEnemy_SetIntersectionCircleToShot(Koishi, KoishiX, KoishiY, 20);
		ObjEnemy_SetIntersectionCircleToShot(Koishi, FlandreX, FlandreY, 20);
		ObjEnemy_SetIntersectionCircleToShot(Koishi, ClownpieceX, ClownpieceY, 20);
		yield;
	}
	
	Obj_Delete(Koishi);
	Obj_Delete(Flandre);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    CloseScript(GetOwnScriptID()); 
}