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



let objBoss;
let mario; let james;
let dave; let saul;
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);
	mario= ObjEnemy_Create(OBJ_ENEMY); james= ObjEnemy_Create(OBJ_ENEMY);
	dave= ObjEnemy_Create(OBJ_ENEMY); saul= ObjEnemy_Create(OBJ_ENEMY);
    ObjEnemy_Regist(objBoss);
	ObjEnemy_Regist(mario); ObjEnemy_Regist(james);
	ObjEnemy_Regist(dave); ObjEnemy_Regist(saul);
	SetCommonData("non1", "yes");
	
	animNon(objBoss, 1);
	drawDave(dave); 
	drawMario(mario);
	drawSaul(saul);
	drawJames(james);
	TFinalize(objBoss);
	skip(objBoss);
	
	Name(1, objBoss);
    Indicator(objBoss, 1);
	
	ObjMove_SetPosition(mario, -60, height/4 + rand(-40,-20));
	ObjMove_SetPosition(james, width +60, height/4 + rand(-40,-20));
	ObjMove_SetPosition(dave, width+60, 3*height/4 + rand(20,40));
	ObjMove_SetPosition(saul, -60, 3*height/4 + rand(20,40));
	
    ObjMove_SetDestAtFrame(objBoss, width/2, height/3, 60);
	
	Main;
}




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


task Main{
	SetForbidPlayerSpell(true);
	NotifyEventAll(EV_USER_STAGE+1, 0);
    ObjEnemy_SetDamageRate(objBoss, 0,0);
	let time = 180;
	wait(150);
	SetForbidPlayerSpell(true);
	let t=0;
	let text = speak(true, "Congratulations.[r]You are still standing.", 255, 255, 255);
	while(t<time){
	    if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	t=0;
	text = speak(true, "By now you should know[r]how this goes.", 255, 255, 255);
	while(t<time){
	    if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	t=0;
	text = speak(true, "Show yourselves, guys!", 255, 255, 255);
	while(t<time){
	    if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	
	NotifyEventAll(EV_USER_STAGE+2, 0);
	wait(20);
	ObjMove_SetDestAtFrame(mario, width/4, height/4, 30);
	wait(90);
	ObjMove_SetDestAtFrame(james, 3*width/4, height/4, 30);
	wait(90);
	ObjMove_SetDestAtFrame(dave, 3*width/4, height/2, 30);
	wait(90);
	ObjMove_SetDestAtFrame(saul, width/4, height/2, 30);
	wait(30);
	SetCommonData("non1", "no");
	SetCommonData("change", "yes");
	wait(90);
	t=0;
	text = speak(false, "Let's get serious!", 255, 255, 255);
	while(t<time){
	    if(GetVirtualKeyState(VK_CANCEL) == KEY_PUSH){t=time;}
		t++; yield;
	}
	Obj_Delete(text);
	ObjMove_SetDestAtFrame(mario, -50, -50, 20);
	ObjMove_SetDestAtFrame(james, width+50, -50, 20);
	ObjMove_SetDestAtFrame(dave, width+60, Y(dave), 20);
	ObjMove_SetDestAtFrame(saul, -60, Y(saul), 20);
	ObjMove_SetDestAtFrame(objBoss, width/2, -80, 30);
	wait(60);
	Obj_Delete(mario); Obj_Delete(james);
	Obj_Delete(dave); Obj_Delete(saul);
	ObjEnemy_SetLife(objBoss, 0);
	
}

task drawMario(enemy2){
    let img = GetCurrentScriptDirectory() ~ "../img/nonMario.png";
	let i=0;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
		ObjPrim_SetTexture(enemy2, img);
		if(i%2==0){ObjSprite2D_SetSourceRect(enemy2, 166, 250, 340, 770);}
		else{ObjSprite2D_SetSourceRect(enemy2, 166+512, 250, 340+512, 770);}
		ObjSprite2D_SetDestRect(enemy2, -30, -60, 30, 60);
		i++;
		wait(20);
	}
}

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 drawSaul(enemy2){
    let img = GetCurrentScriptDirectory() ~ "../img/NonSpellSaul.png";
	let i=0;
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
		ObjPrim_SetTexture(enemy2, img);
		if(i%2==0){
			    ObjSprite2D_SetSourceRect(enemy2, 96, 245, 396, 800); 
				ObjSprite2D_SetDestRect(enemy2, -35, -75, 45, 75);
			}
		else{
			    ObjSprite2D_SetSourceRect(enemy2, 65+512, 260, 415+512, 790); 
				ObjSprite2D_SetDestRect(enemy2, -45, -75, 55, 75);
			}
		i++;
		wait(30);
	}
}

task drawDave(obj){
	let img = GetCurrentScriptDirectory() ~ "../img/NonSpellDave.png";
	let i=0;
	ObjPrim_SetTexture(obj, img);
	while(ObjEnemy_GetInfo(objBoss, INFO_LIFE)>0){
		if(i%2 ==0){
			ObjSprite2D_SetSourceRect(obj, 78, 85, 270, 385); 
			ObjSprite2D_SetDestRect(obj, -47, -70, 47, 70);
		}
		else{
			ObjSprite2D_SetSourceRect(obj, 78, 580, 270, 890); 
			ObjSprite2D_SetDestRect(obj, -47, -70, 47, 70);
		}
		i++;
		wait(20);
	}
}

