//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#System["./../system/NSystem.dnh"]
#Player["./../player/Reimu by plasmaflame22/Reimu_A.txt", "./../../player/Reimu by plasmaflame22/Reimu_C.txt"]
#Title["BG transition"]
#include "./sharedfuncSaul.dnh"



let objBoss;
let width = 444;
let height = 448;
let life = 1;
let scene = GetEnemyBossSceneObjectID();

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


@Initialize{
    objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
    ObjEnemy_Regist(objBoss);
	SetCommonData("non1", "yes");
	
	animNon(objBoss, 1);
	TFinalize(objBoss);
	skip(objBoss);
	
	
    ObjMove_SetDestAtFrame(objBoss, width/2, height/2, 60);
	Main;
}




@MainLoop{
    ObjEnemy_SetIntersectionCircleToShot(objBoss, ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 32); 
    yield;
}


task Main{
    Name(1, objBoss);
    Indicator(objBoss, 1);
	NotifyEventAll(EV_USER_STAGE+3, 0);
    //SetForbidPlayerShot(true);
	SetForbidPlayerSpell(true);
    ObjEnemy_SetDamageRate(objBoss, 0,0);
	let time = 180; let r= 255; let g= 255; let b = 255; let d = Dave; ObjRender_SetPosition(d, width+50, height/2, 1);
	wait(90);
	let t=0;
	let text = speak(false, "Damn you! My colleagues[r]were not exaggerating", r, g, b);
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	t=0;
	text = speak(false, "about the immensity[r]of your might!", r, g, b);
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	r=255; g= 165; b=50;
	t=0;
	text = speak(false, "Ah, Saul, I see [r]that even you", r, g, b);
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	t=0;
	Obj_Delete(text);
	text = speak(false, "are having trouble[r]with this one.", r, g, b);
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	t=0;
	text = speak(false, "Let me give you a hand...", r, g, b);
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	NotifyEventAll(EV_USER_STAGE +4, 0);
	ObjMove_SetDestAtFrame(objBoss, width/3, height/2, 120);
	ascent(i in 0..120){ObjRender_SetX(d, width+50-1.65*i); yield;}
	wait(120); 
	t=0;
	text = speak(false, "Miss me, dear player?", r, g, b);
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	r=255; g=255; b=255;
	t=0;
	text = speak(false, "Not just yet, Dave.[r]This has become personal!", r, g, b);
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	r=255; g= 165; b=50;
	t=0;
	text = speak(false, "As you wish.[r]I'll be watching!", r, g, b);
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	r=255; g=255; b=255;
	ascent(i in 0..60){ObjRender_SetPosition(d, 2*width/3 +4*i, height/2-4*i, 1); yield;} Obj_Delete(d);
	t=0;
	text = speak(false, "Ugh..I need a change[r]of scenery!", r, g, b);
	while(t<time){
	    if(GetVirtualKeyState(VK_OK) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	ObjEnemy_SetLife(objBoss, 0);
	
}


task drawDave(enemy1){
    let img = GetCurrentScriptDirectory() ~ "../img/NonSpellDave.png";
	let i=0;
	ObjPrim_SetTexture(enemy1, img);
	while(!Obj_IsDeleted(enemy1)){
		if(i%2 ==0){
			ObjSprite2D_SetSourceRect(enemy1, 78, 85, 270, 385); 
			ObjSprite2D_SetDestRect(enemy1, -47, -70, 47, 70);
		}
		else{
			ObjSprite2D_SetSourceRect(enemy1, 78, 580, 270, 890); 
			ObjSprite2D_SetDestRect(enemy1, -47, -70, 47, 70);
		}
		i++;
		wait(30);
	}
	Obj_Delete(enemy1);
}



function Dave{
    let enemy1 = ObjPrim_Create(OBJ_SPRITE_2D);
	drawDave(enemy1);
	return enemy1;
}