
#ScriptVersion[3]
#Title["TsurubamiN1"]
#Text["TsurubamiN1"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#include"./system/Default_Effect.Txt"
#include"./Functions/DialogueFunctions.dnh"
#include"./Functions/Portrait_Const.dnh"


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
{
SetCommonData("Scroll",0);
SetBoss("Doremy",false);
}

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

}

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

//----------------------------------------------------
task mainTask{
	SetCommonData("ForceLifebar",1);
	ObjMove_SetDestAtWeight(objBoss,stgx,110,10,10);
	SetCommonData("Scroll",1);
	wait( 120 );
	Talk;
	while( IsOnEvent == true ){ yield; }
	SetForbidPlayerShot( false );
	SetForbidPlayerSpell( false );
	wait( 45 );
	StartCountDown;
	//ObjPlayer_ClearIntersection(GetPlayerObjectID);
	wait(150);
	SetCommonData("ForceLifebar",0);
	DamageRateAtFrame(70,0,0);
	TShot1;
	yield;
	}

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

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
                	PatternMonochrome1;
	
	}



             task PatternMonochrome1{ 
             let Wait = 80;
             while( !Obj_IsDeleted( objBoss )){
             loop( 1 ){

		            let angle = GetAngleToPlayer( objBoss ) + 35;
                                                    let speed = 40;
	                                let way = 1;
                                                    let shote = 129;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = CreateLooseLaserA1( sx, sy, speed, angle, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				PatternMonochrome2( sht1 );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                    		if( wait( Wait ) ){ return; }

	}
             loop( 1 ){

		            let angle = GetAngleToPlayer( objBoss ) - 35;
                                                    let speed = 40;
	                                let way = 1;
                                                    let shote = 129;
		            let delay = 0;

			loop( way ){

                      	                    let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss );
				
				let sht1 = CreateLooseLaserA1( sx, sy, speed, angle, 150, 18, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				PatternMonochrome2( sht1 );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                    		if( wait( Wait ) ){ return; }

	}
	}

   }

              task PatternMonochrome2( obj ){ 
              while( !Obj_IsDeleted( obj )){

	                                let way = 15;
                                                    let shote = 64;
		            let delay = 0;

			loop( way ){
			
                                                    	let speed = rand( 0.8, 2 );
			let angle = rand( 0, 360 );
                      	                    let sx = ObjMove_GetX( obj );
                        		let sy = ObjMove_GetY( obj );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjRender_SetBlendType( sht1, BLEND_ALPHA );
				ObjRender_SetColor( sht1, 0, 0, 0 );
				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle -= 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                        		if( wait( 2 ) ){ return; }

	}

   }

	task ReflectAndChange(obj, acceleration, angular, v)
{
   while(!Obj_IsDeleted(obj) && ObjMove_GetX(obj)>0 && ObjMove_GetX(obj)<GetStgFrameWidth && ObjMove_GetY(obj)>0  && ObjMove_GetY(obj)<GetStgFrameHeight){yield;}
   if(ObjMove_GetX(obj)<0 || ObjMove_GetX(obj)>GetStgFrameWidth)
   {ObjMove_AddPatternA2( obj, 0, NO_CHANGE, ObjMove_GetAngle( obj ), acceleration, angular, v );}
   if(ObjMove_GetY(obj)<0 || ObjMove_GetY(obj)>GetStgFrameHeight)
   {ObjMove_AddPatternA2( obj, 0, NO_CHANGE, -ObjMove_GetAngle( obj ), acceleration, angular, v );}

PlaySound("BulletWave",60,0);

}

	task StartCountDown
	{
		wait((85*60) - (10*60));
		loop(10)
		{
			PlaySound("time",100,0);
			wait(60);
		}

	}

/*ObjEvent_SetGraphic( RIGHT, 1, DontCare );
ObjEvent_SetGraphic( RIGHT, 2, Happy );
ObjEvent_SetGraphic( RIGHT, 3, Humming );
ObjEvent_SetGraphic( RIGHT, 4, Normal );
ObjEvent_SetGraphic( RIGHT, 5, Really );
ObjEvent_SetGraphic( RIGHT, 6, Serious );
ObjEvent_SetGraphic( RIGHT, 7, Wow );*/

task Talk{
IntiallizeEvent( 1, 8, 0.8, 0.8, 0.8 );

ObjEvent_SetGraphic( RIGHT, 0, Humming );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Phew...The outside world was fun!");

ObjEvent_SetGraphic( RIGHT, 0, Cool );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "I think I should go back now...");

ObjEvent_SetGraphic( RIGHT, 0, Happy );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "But I'm lazy to do any works~");

ObjEvent_SetGraphic( RIGHT, 0, Happy );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "So I guess I will...");

ObjEvent_SetGraphic( LEFT, 0, Normal2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "There you are, Tsurubami.");

ObjEvent_SetGraphic( RIGHT, 0, Wow );
Talking( 0, RIGHT );
SelfName;
SetText( RIGHT, -0.4, 0, "Ehh?? Since when there's[r] a mirror in front of me ?   ");

ObjEvent_SetGraphic( LEFT, 0, Nothing2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Now I'm a mirror ??");

ObjEvent_SetGraphic( RIGHT, 0, Happy );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Oh hey! The mirror turned[r] into Tsuba-chan.~        ");

ObjEvent_SetGraphic( RIGHT, 0, Cool );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Heh heh...");

ObjEvent_SetGraphic( RIGHT, 0, Serious );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Now, how did you get here?");

ObjEvent_SetGraphic( LEFT, 0, DontCare2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Just came out from the [r]cracks in the barrier.");

ObjEvent_SetGraphic( RIGHT, 0, Wow );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "The barrier was cracked ?[r]How did that happen?     ");

ObjEvent_SetGraphic( LEFT, 0, SmileHumClosed2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "A certain light youkai did it.");

ObjEvent_SetGraphic( LEFT, 0, SmileHumClosed2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Actually there were a lot of things[r]happened while you were gone.");

ObjEvent_SetGraphic( RIGHT, 0, Cool );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Like a giant flower sprouting [r]out of the blue ?             ");

ObjEvent_SetGraphic( LEFT, 0, SmileHum2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Exactly.");

ObjEvent_SetGraphic( RIGHT, 0, Really );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Ha..I knew it'd happen someday...");

ObjEvent_SetGraphic( RIGHT, 0, DontCare );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "But I didn't expect it [r]to happen so soon...");

ObjEvent_SetGraphic( RIGHT, 0, DontCare );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "So I didn't give you [r]a warning, sorry... ");

ObjEvent_SetGraphic( RIGHT, 0, Happy );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "So, did you get rid [r]of the said flower?");

ObjEvent_SetGraphic( LEFT, 0, SmileHumClosed2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Nope, because I and [r]Yabusame were too late...");

ObjEvent_SetGraphic( LEFT, 0, SmileHum2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "A human-shaped spirit has[r] emerged from that flower..");

ObjEvent_SetGraphic( RIGHT, 0, Serious );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "!!!");

ObjEvent_SetGraphic( RIGHT, 0, Cool );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "It's...really too late, huh ?");

ObjEvent_SetGraphic( LEFT, 0, SmileHum2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "But ze hadn't done [r]anything bad to us so far.");

ObjEvent_SetGraphic( RIGHT, 0, Serious );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Had or hadn't, I still [r]have to get rid of it. ");

ObjEvent_SetGraphic( RIGHT, 0, Serious );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "It's my job as the ruler of Mugenri.");

ObjEvent_SetGraphic( RIGHT, 0, Serious );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "I had asked you to watch [r] over Mugenri for me.    [r] Had I not?               ");
 
ObjEvent_SetGraphic( RIGHT, 0, Serious );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "But now the barrier is cracked!  [r]You also failed to get rid         [r]of that flower too!               ");

ObjEvent_SetGraphic( LEFT, 0, SmileHumClosed2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "What can be done now~ ");

ObjEvent_SetGraphic( LEFT, 0, SmileHumClosed2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "I don't know how [r]to fix the barrier~");

ObjEvent_SetGraphic( RIGHT, 0, Normal );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "My friend Tenkai could fix it. [r] Ask hir and ze'll do it.       ");

ObjEvent_SetGraphic( LEFT, 0, SmileHumClosed2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Oh, I've already met hir.");

ObjEvent_SetGraphic( LEFT, 0, SmileHumClosed2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Can you guess what did ze said ?");

ObjEvent_SetGraphic( LEFT, 0, SmileHum2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Ze doesn't care.");

ObjEvent_SetGraphic( RIGHT, 0, Really );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Well, It's not that surprising if you[r]are the one who asked.          ");

ObjEvent_SetGraphic( RIGHT, 0, Happy );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "So...for now, I shall         [r]make haste to get rid       [r]of that flower and its spirit.");

ObjEvent_SetGraphic( LEFT, 0, Nothing2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Hey, who said I'd let you do that ?");

ObjEvent_SetGraphic( RIGHT, 0, Normal );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Do I require your permission ?");

ObjEvent_SetGraphic( LEFT, 0, Angry2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Ze just harmlessly [r]    absorbs spirits!");

ObjEvent_SetGraphic( RIGHT, 0, Serious );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "What if ze absorbs yours ?");

ObjEvent_SetGraphic( LEFT, 0, Angry2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "I already told you, [r]ze hadn't done that! [r]             And ze will not!");

ObjEvent_SetGraphic( RIGHT, 0, Serious );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Then you have to stop me [r]before I get rid of hir.    ");

ObjEvent_SetGraphic( LEFT, 0, Normal2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "A rematch ? In that case, don't [r]you go easy on me this time.");

ObjEvent_SetGraphic( RIGHT, 0, Cool );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "The last time was just a pre-test! [r]I was just testing if you          [r]can be my successor.           ");

ObjEvent_SetGraphic( RIGHT, 0, Normal );
Talking( 0, RIGHT );
NotifyEventAll(EV_SET_SONG,1);
MusicName;
SetText( RIGHT, -0.4, 0, "But now, shall we do the real test ?");

ObjEvent_SetGraphic( LEFT, 0, SmileHum2 );
Talking( 0, LEFT );
SetText( LEFT, -2.8, 0, "Bring it on then! I'm always ready!");

ObjEvent_SetGraphic( RIGHT, 0, Normal );
Talking( 0, RIGHT );
SetText( RIGHT, -0.4, 0, "Then let the test begin!");


FinallizeEvent;
}

let Music = GCSD~"img/musicname.png";

task MusicName{ 
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,91);
	ObjPrim_SetTexture(obj,Music);
	ObjSprite2D_SetSourceRect(obj,0,0,800,40);
	ObjSprite2D_SetDestRect(obj,-800,-40,800,40);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,0.5,0.5,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,384/2 + 28,450,0);
	Appear( obj );
	Fade( obj, 370 );
	while( !Obj_IsDeleted(objBoss)){
	yield;
	}
	Obj_Delete(obj);
}

let Name = GCSD~"img/turu_name.png";

task SelfName{ 
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,91);
	ObjPrim_SetTexture(obj,Name);
	ObjSprite2D_SetSourceRect(obj,0,0,250,91);
	ObjSprite2D_SetDestRect(obj,-250,-91,250,91);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,320,340,0);
	Appear( obj );
	Fade( obj, 240 );
	while( !Obj_IsDeleted(objBoss)){
	yield;
	}
	Obj_Delete(obj);
}

	task Appear( obj ){
	ascent( i in 0..255/3 ){
	ObjRender_SetAlpha( obj, i*3 );
	yield;
	}
	ObjRender_SetAlpha( obj, 255 );
	}	

	task Fade( obj, t ){
	wait( t );
	descent( i in 0..255/3 ){
	ObjRender_SetAlpha( obj, i*3 );
	yield;
	}
	Obj_Delete( obj );
	}







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

task SizeCircle
{
	ascent(i in 0..60)
	{
		SetCommonData("CircleSize",sin(i*1.5));
		yield;
	}
}	

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

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		EndBoss(0);
		yield;
		CloseScript(GetOwnScriptID());
	}