
#ScriptVersion[3]
#Title["DoremyEnd"]
#Text["DoremyEnd"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./bg-klong.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/JINXShot_Const.txt"
#include"./system/Default_Effect.Txt"


let objBoss;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let atk = false;
let fog = 0;
let objScene=GetEnemyBossSceneObjectID();
let color = [0,0];
@Initialize
{
SetBoss("Doremy",false);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(0);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(9999);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	SetCommonData("ForceLifebar",1);
	}

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

task TEnd{
		while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
	SetCommonData("ForceLifebar",1);
	//PlaySound("bossdeath",92,0);
	SetPlayerInvincibilityFrame(350);
	//ClearBullet(120,10);
	//FakeEnd;
	//wait( 100 );
	//FakeEnd2;
	//DelaySound;
	//StartSlow( TARGET_ALL, 30 );
	//ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2 + rand( -150, 150 ),0,0.5,0.5);
	//wait( 130 );	
		//StopSlow( TARGET_ALL);
	PlaySound("SpellStart",100,0);
	wait( 60 );
	ObjMove_SetDestAtWeight(objBoss,414,0,30,10);
	wait(90);	
		EndBoss(0);
		yield;
		CloseScript(GetOwnScriptID());	
	}
	
	
	
let Tnd = GetCurrentScriptDirectory() ~ "img/boss_del_eff_00.png";
let Tnd2 = GetCurrentScriptDirectory() ~ "img/boss_eff_momiji_001.png";

task FakeEnd{
	loop( 10 ){
	loop( 1 ){
    let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	PlaySound("LenenShot3",92,0);
	let c = 0;
	let s = 0;
	let count = 0;
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(obj,41);
	ObjPrim_SetTexture(obj,Tnd);
	ObjSprite2D_SetSourceRect(obj,0,0,30,30);
	ObjSprite2D_SetDestCenter(obj);
	rescale4( obj );
	realpha4( obj );
	delbossdie( objBoss, obj );
	ObjRender_SetPosition(obj,ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ), 0);
	ObjRender_AddPatternA1(obj,0,5,rand( 0, 360 ),300);
	}	
	wait( 10 );
	}
}

task FakeEnd2{
	loop( 45 ){
	loop( 3 ){
    let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	//PlaySound("LenenShot3",92,0);
	let c = 0;
	let s = 0;
	let count = 0;
	let n = round(rand( 0, 4 ));
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(obj,41);
	ObjPrim_SetTexture(obj,Tnd2);
	ObjSprite2D_SetSourceRect(obj,42*n,49*0,42*(n+1),49*1);
	ObjSprite2D_SetDestCenter(obj);
	rescale4( obj );
	realpha4( obj );
	spin2( obj );
	delbossdie( objBoss, obj );
	ObjRender_SetPosition(obj,ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ), 0);
	ObjRender_AddPatternA1(obj,0,rand( 5, 8 ),rand( 0, 360 ),300);
	}	
	wait( 2 );
	}
}

task FakeEnd3{
	loop( 5 ){
	loop( 25 ){
    let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	//PlaySound("LenenShot3",92,0);
	let c = 0;
	let s = 0;
	let count = 0;
	let n = round(rand( 0, 4 ));
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(obj,41);
	ObjPrim_SetTexture(obj,Tnd2);
	ObjSprite2D_SetSourceRect(obj,42*n,49*0,42*(n+1),49*1);
	ObjSprite2D_SetDestCenter(obj);
	rescale4( obj );
	realpha4( obj );
	spin2( obj );
	delbossdie( objBoss, obj );
	ObjRender_SetPosition(obj,ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ), 0);
	ObjRender_AddPatternA1(obj,0,rand( 8, 12 ),rand( 0, 360 ),300);
	}	
	wait( 5 );
	}
}

	task rescale4( obj ){
	ascent( i in 1*5..7*5 ){
	ObjRender_SetScaleXYZ(obj,i/5,i/5,0);
	yield;
	}
	}

	task realpha4( obj ){
	descent( i in 0..255/10 ){
	ObjRender_SetAlpha(obj,i*10);
	yield;
	}
	Obj_Delete( obj );
	}

	task spin2( obj ){
	let a = rand( 0, 360 );
	let f = rand( 2, 4 );
	loop( 160 ){	
	ObjRender_SetAngleZ( obj, a );
	a += f;
	yield;
	}
	}

	task DelaySound{
	PlaySound("enemoff",92,0);
	wait( 30 );
	PlaySound("enemoff",92,0);
	wait( 60 );
	PlaySound("enemoff",92,0);
	FakeEnd3;
	wait( 10 );
	StopSlow( TARGET_ALL);
	//ObjRender_SetScaleXYZ(objBoss,0.001,0.001,0);
	}
