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


let objBoss; let enemy2;
let width = 420;
let height = 440;
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);
	enemy2 = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(enemy2);
	SetPlayerClip(5,5, 415, 435);
	SetCommonData("non1", "no");
	
	animNon(objBoss, 3); James;
	TFinalize(objBoss);
	skip(objBoss);
	
	Name(3, objBoss);
    Indicator(objBoss, 3);
    takeDamage(objBoss, scene, life);
	
	Main;
}

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




task Main{
    SetForbidPlayerSpell(true);
	ObjEnemy_SetDamageRate(objBoss, 0, 0);
	DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
    ObjMove_SetPosition(objBoss, 2*width/3, -100);
	let time = 180;
	wait(90);
	SetForbidPlayerSpell(true);
	ObjMove_SetDestAtFrame(objBoss, width*0.6, height/2, 60);
	let t=0;
	let text = speak(false, "Now you must deal[r]with us, dear player!", 255, 255, 255);
	while(t<time){
	    if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	wait(60);
	ObjEnemy_SetLife(objBoss, 0);
}
	
    	
	
	
task drawJames(enemy2){
    let img = GetCurrentScriptDirectory() ~ "../img/NonSpell.png";
	let i=0; ObjPrim_SetTexture(enemy2, img);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
		if(i%2 ==0){
			ObjSprite2D_SetSourceRect(enemy2, 316, 70, 436, 410); 
			ObjSprite2D_SetDestRect(enemy2, -25, -70, 25, 70);
		}
		else{
			ObjSprite2D_SetSourceRect(enemy2, 25, 125, 180, 420); 
			ObjSprite2D_SetDestRect(enemy2, -43, -70, 43, 70);
		}
		
		i++;
		wait(30);
	}
}



task James{
	drawJames(enemy2); 
	ObjMove_SetPosition(enemy2, width/4, -80);
	wait(90);
	Obj_SetRenderPriorityI(enemy2, Obj_GetRenderPriorityI(objBoss)-1);
	ObjMove_SetDestAtFrame(enemy2, width/3, height/3, 60);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){yield;}
	Obj_Delete(enemy2);
}






