#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["DialogLuigi"]
#Text["Dialog"]

let CSD = GetCurrentScriptDirectory;

let objEnemy;

let imgBoss = GetCurrentScriptDirectory ~ "sprite/boss.png";

@Initialize {
  objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objEnemy);
TEvent;
TEnd;}


@MainLoop {
    yield;
}


@Event {
    alternative(GetEventType())
    case(EV_REQUEST_LIFE) {
        SetScriptResult(1500);
    
    }
}

//----------------------------------------------------------------------------------------------
function CreateDialogueEvent {

    let imgpathL = GetCurrentScriptDirectory() ~ "./sprite/starbig.png";
    let objImgLeft = ObjPrim_Create(OBJ_SPRITE_2D);
    Obj_SetRenderPriorityI(objImgLeft, 81);
    ObjPrim_SetTexture(objImgLeft, imgpathL);
    ObjSprite2D_SetSourceRect(objImgLeft, 0, 0, 512, 1024);
	ObjRender_SetScaleXYZ(objImgLeft,0.8,0.8,0);
    ObjSprite2D_SetDestCenter(objImgLeft);
    ObjRender_SetX(objImgLeft, GetStgFrameLeft() + GetStgFrameWidth()/2-100);
    ObjRender_SetY(objImgLeft, 400);
    let imgpathR = GetCurrentScriptDirectory() ~ "./sprite/weeg.png";
    let objImgRight = ObjPrim_Create(OBJ_SPRITE_2D);
    Obj_SetRenderPriorityI(objImgRight, 81);
    ObjPrim_SetTexture(objImgRight, imgpathR);
    ObjSprite2D_SetSourceRect(objImgRight, 0, 0, 380, 466);
    ObjSprite2D_SetDestCenter(objImgRight);
    ObjRender_SetX(objImgRight, GetStgFrameLeft() + GetStgFrameWidth()/2 + 200);
    ObjRender_SetY(objImgRight, 288);
    // Prepare text background. We will use render priority 83.
    let TEXTBOX_BUFFER = 16; // Buffers on edges
    let TEXTBOX_WIDTH = GetStgFrameWidth - TEXTBOX_BUFFER*2;
    let TEXTBOX_HEIGHT = 48;
    let objTextBack = ObjPrim_Create(OBJ_SPRITE_2D);
    Obj_SetRenderPriorityI(objTextBack, 83);
    ObjSprite2D_SetSourceRect(objTextBack, 0, 0, 1, 1); // Use default white texture
    ObjSprite2D_SetDestRect(objTextBack, 0, 0, TEXTBOX_WIDTH, TEXTBOX_HEIGHT);
    ObjRender_SetX(objTextBack, GetStgFrameLeft() + TEXTBOX_BUFFER);
    ObjRender_SetY(objTextBack, GetStgFrameTop() + GetStgFrameHeight() - TEXTBOX_HEIGHT - TEXTBOX_BUFFER);
    ObjRender_SetColor(objTextBack, 0, 0, 0);
    ascent(i in 0..30){
        ObjRender_SetAlpha(objTextBack, 192/30*i);
        yield;
    }
    ObjRender_SetAlpha(objTextBack, 192);
    // Prepare text object. We will use render priority 83.
    let TEXT_MARGIN_LR = 8; // Left and Right Margins.
    let TEXT_MARGIN_TOP = 6; // Top Margin
    let TEXT_MAXWIDTH = TEXTBOX_WIDTH - TEXT_MARGIN_LR*2;
    let objText = ObjText_Create();
    ObjText_SetText(objText, "Default[r]Default");
    ObjText_SetFontSize(objText, 15);
    ObjText_SetFontBold(objText, false);
    ObjText_SetFontType(objText, "Helvetica");
    Obj_SetRenderPriorityI(objText, 83);
    ObjText_SetFontColorTop(objText, 255, 255, 255); //Will be altered inside the event
    ObjText_SetFontColorBottom(objText, 255, 255, 255);
    ObjText_SetFontBorderType(objText, BORDER_FULL);
    ObjText_SetFontBorderColor(objText, 255, 255, 255);
    ObjText_SetFontBorderWidth(objText, 1);
    ObjText_SetMaxWidth(objText, TEXT_MAXWIDTH);
    ObjRender_SetX(objText, GetStgFrameLeft() + TEXTBOX_BUFFER + TEXT_MARGIN_LR);
    ObjRender_SetY(objText, GetStgFrameTop() + GetStgFrameHeight() - TEXTBOX_HEIGHT - TEXTBOX_BUFFER + TEXT_MARGIN_TOP);
    return [objTextBack, objText, objImgLeft, objImgRight];
}

//-------------------------------------------------------------------------------------------

// Given an array of object IDs, destroys all of them
function DestroyDialogueEvent(objects) {
    ascent(i in 0..length(objects)) {
        Obj_Delete(objects[i]);
    }
}




// On player key press, wait specified number of frames
function EventWaitA1(frames) {
    while(GetVirtualKeyState(VK_OK) == KEY_FREE || GetVirtualKeyState(VK_OK) == KEY_HOLD){yield;}
    loop(frames){yield;}
}
// Timed wait for specified number of frames
function EventWaitA2(frames) {
    loop(frames){yield;}
}
// At start of event, wait for key to be released, wait for key to be pressed, and then wait specified number of frames
function EventWaitA3(frames) {
    while(GetVirtualKeyState(VK_OK) == KEY_HOLD){yield;}
    while(GetVirtualKeyState(VK_OK) != KEY_PUSH){yield;}
    loop(frames){yield;} 
}
// Sets portrait to background
function SetPortraitToBackground(portrait) {
    ObjRender_SetAlpha(portrait, 192);
    ObjRender_SetColor(portrait, 192, 192, 192);
}
// Sets portrait to foreground
function SetPortraitToForeground(portrait) {
    ObjRender_SetAlpha(portrait, 255);
    ObjRender_SetColor(portrait, 255, 255, 255);
}

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

task TEvent {
    // Obtain relevant objects
    let dialogueobjects = CreateDialogueEvent();
    let textobj = dialogueobjects[1];
    let leftportrait = dialogueobjects[2];
    let rightportrait = dialogueobjects[3];
    SetForbidPlayerSpell(true);
    SetForbidPlayerShot(true);
    let pathstar1 = GetCurrentScriptDirectory() ~ "./sprite/starbig.png";
	 let pathstar2 = GetCurrentScriptDirectory() ~ "./sprite/starwhat.png";
	 let pathstar3 = GetCurrentScriptDirectory() ~ "./sprite/starsmile.png";
    
    let pathweeg1 = GetCurrentScriptDirectory() ~ "./sprite/weeg2.png";
	let pathweeg2 = GetCurrentScriptDirectory() ~ "./sprite/weeg4.png";
	let pathweeg3 = GetCurrentScriptDirectory() ~ "./sprite/weeg3.png";
	let pathweeg4 = GetCurrentScriptDirectory() ~ "./sprite/weeg2.png";
	
    
    // Set initial textures
    ObjPrim_SetTexture(leftportrait, pathstar2);
    ObjPrim_SetTexture(rightportrait, pathweeg1 );
    ObjText_SetText(textobj, "What the...? What are you?");
    ObjText_SetFontBorderColor(textobj, 200, 2, 192);
    SetPortraitToForeground(leftportrait); SetPortraitToBackground(rightportrait);
    EventWaitA1(15);
    ObjText_SetText(textobj, "Thats mama luigi to you! *wheeze*");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg4);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
    EventWaitA1(15);
	 ObjText_SetText(textobj, "Mama? Mama Luigi? You dont look like you're from around here...");
    ObjText_SetFontBorderColor(textobj,  200, 2, 192);
    SetPortraitToForeground(leftportrait); SetPortraitToBackground(rightportrait);
    EventWaitA1(15);
	ObjText_SetText(textobj, "Whatever you are, I am Wolfie, cutter of stars.");
    ObjText_SetFontBorderColor(textobj, 200, 2, 192);
	ObjPrim_SetTexture(leftportrait, pathstar3);
    SetPortraitToForeground(leftportrait); SetPortraitToBackground(rightportrait);
	 EventWaitA1(15);
	ObjText_SetText(textobj, "Whatever hole you came from, it brought a bunch of your friends to my turf.");
    ObjText_SetFontBorderColor(textobj, 200, 2, 192);
	ObjPrim_SetTexture(leftportrait, pathstar1);
    SetPortraitToForeground(leftportrait); SetPortraitToBackground(rightportrait);
	EventWaitA1(15);
    ObjText_SetText(textobj, "Yeah well, all that matters to me is im OUTA there!");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg3);
	SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	EventWaitA1(15);
    ObjText_SetText(textobj, "I dunno what you call it here, but I'm from a Youtube Poop.");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg3);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	EventWaitA1(15);
    ObjText_SetText(textobj, "More specifically, a YTP named 'Robotnik reads [r] a waiting room magazine'");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg3);
	EventWaitA1(15);
    ObjText_SetText(textobj, "It was horrible, in the world of that YTP, my dear [r] brother and I just...");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg3);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	EventWaitA1(15);
    ObjText_SetText(textobj, "Violently clipped through the mushroom [r]kingdom with gun noises, and did these weird [r] nonsensical dances to music WAY too loud");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg3);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	EventWaitA1(15);
    ObjText_SetText(textobj, "I just wanted some peace n quiet....[r]but it looks like this world is chaotic as well!");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg2);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	 EventWaitA1(15);
	ObjText_SetText(textobj, "Thats right, bub! And I like my chaotic world,[r] so don't go throwing a wet blanket on it");
    ObjText_SetFontBorderColor(textobj, 200, 2, 192);
	ObjPrim_SetTexture(leftportrait, pathstar3);
    SetPortraitToForeground(leftportrait); SetPortraitToBackground(rightportrait);
	EventWaitA1(15);
	ObjText_SetText(textobj, "No no, this wont do...the portal only works once. Im either here or back in the YTP....");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg3);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	EventWaitA1(15);
	ObjText_SetText(textobj, "Maybe while I'm here, I can forge a NEW world, one of my own! yeah!");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg1);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	EventWaitA1(15);
	ObjText_SetText(textobj, "Pardon?!?!");
    ObjText_SetFontBorderColor(textobj, 200, 2, 192);
	ObjPrim_SetTexture(leftportrait, pathstar2);
    SetPortraitToForeground(leftportrait); SetPortraitToBackground(rightportrait);
    EventWaitA1(15);
	ObjText_SetText(textobj, "Yeah, after all...If someone sweeps all life away,[r] copies it, and says they are god...");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg1);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	  EventWaitA1(15);
	ObjText_SetText(textobj, "Who could ever prove that they are not god?");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg1);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	EventWaitA1(15);
	ObjText_SetText(textobj, "Hmph, guess I'll have to prove to you im un-sweepable!");
    ObjText_SetFontBorderColor(textobj, 200, 2, 192);
	ObjPrim_SetTexture(leftportrait, pathstar1);
    SetPortraitToForeground(leftportrait); SetPortraitToBackground(rightportrait);
	  EventWaitA1(15);
	ObjText_SetText(textobj, "If I had to be born in a world of chaos, I can use that chaos to destroy another");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg2);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	ObjText_SetText(textobj, "I was once face to face with a [r]fire sumo! Nothing can surprise me now");
    ObjText_SetFontBorderColor(textobj, 1, 200, 1);
    ObjPrim_SetTexture(rightportrait, pathweeg2);
    SetPortraitToForeground(rightportrait); SetPortraitToBackground(leftportrait);
	EventWaitA1(15);
	ObjText_SetText(textobj, "Have at you!");
    ObjText_SetFontBorderColor(textobj, 200, 2, 192);
	ObjPrim_SetTexture(leftportrait, pathstar3);
    SetPortraitToForeground(leftportrait); SetPortraitToBackground(rightportrait);
	
	
    EventWaitA1(15);
    DestroyDialogueEvent(dialogueobjects);
    SetForbidPlayerSpell(false);
    SetForbidPlayerShot(false);
    ObjEnemy_SetLife(objEnemy, -1); // Trigger script end
}




task TEnd {
    while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0) {
        yield;
    }
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    Obj_Delete(objEnemy);
    loop(30){yield;}
    CloseScript(GetOwnScriptID());
}