
#ScriptVersion[3]
#Title["SeiranN1"]
#Text["SeiranN1"]
#Player["./Reisen/Reisen.txt","./MoF_Reimu/Reimu.txt","./sanae/sane.txt","./Marisa/Marisa.txt"]
#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("Yukari",false);
SetCommonData("BGShow",true);
}

@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(4200);
	}
	case(EV_REQUEST_TIMER)
	{
		let x = 385;
		SetScriptResult( x );
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	SetForbidPlayerShot( true );
                    StartCountDown;
                //ObjPlayer_ClearIntersection(GetPlayerObjectID);
	ObjMove_SetPosition(objBoss,384/2,-120);
	SetCommonData("Scroll",1);
	wait( 120 );
	let x = DrawChange;
	wait( 200 );
	Talk;
	while( IsOnEvent == true ){ yield; }
	wait( 120 );
	ObjMove_SetDestAtWeight(objBoss,stgx,100,6,6);
	maple;
	wait( 80 );
	SetForbidPlayerShot( false );
	SetForbidPlayerSpell( false );
	Obj_Delete( x );
              	magiccircle(x,0,0);
	TShot1;
	yield;

	}

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

task TShot1
{
	if( ObjEnemy_GetInfo( objBoss, INFO_LIFE ) == 1 ){ DeleteShotAll( TYPE_ALL, TYPE_IMMEDIATE ); }
	attack( 80,1 );
	let r = 70;
	let angle = rand(0,80);
	let dir = 0;
	let s = 1;
	//maple;
	//wait(80);
	PatternLoop;
	DamageRateAtFrame(170,20,0);
}

	task PatternLoop{
	while( !Obj_IsDeleted( objBoss )){
	PatternEagle;
	PatternEagle2;
	wait( 200 );
              	TMovement( 30, 4, 2 );
	wait( 40 );
	PatternRandom;
	wait( 60 );
	PatternRandom;
	wait( 60 );
	PatternRandom;
	wait( 60 );
	maple;
	attack( 80,1 );
	wait( 80 );
	}
	}


              function DrawChange{ 

              let sx = GetStgFrameWidth / 2;
              let sy = 100;
              let core = TShotA2( sx, sy, 0, 0, 0, 0, 1, 0 );	
              ObjRender_SetAlpha( core, 0 );
              maple3( core );	
              let c = ChangeD( sx, sy );
              wait( 120 );
              //SetCommonData("CircleSize",0);
              //SizeCircle;
              //magiccircle(c,1,-1);
              return core;

   }

              task PatternRandom{
              let e = GetAngleToPlayer( objBoss ) + 3/2;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
              let speed = 2.8;
              ascent(i in 0..10){

                        let way = i;
                        let shote = 119;
                        let delay = 10;
                        let t = 3;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+5, angle, -0.4, speed, shote, delay );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
                        PlaySound("LenenShot1",92,0);
                        wait( 4 );

                }
}


              task PatternEagle{
              let e = GetAngleToPlayer( objBoss ) + 6;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
               let speed = 3;
              ascent(i in 0..(25)){

                        let way = i;
                        let shote = 119;
                        let delay = 10;
                        let t = 12;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+5, angle, -0.5, speed, shote, delay );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
	    speed -= 0.11;
                        PlaySound("LenenShot1",92,0);
                        wait( 5 );

                }
}

              task PatternEagle2{
              let e = GetAngleToPlayer( objBoss ) + 180 + 7.5/2;
              let sx = ObjMove_GetX( objBoss );
              let sy = ObjMove_GetY( objBoss );
               let speed = 3;
              ascent(i in 0..(360/15)*2){

                        let way = i;
                        let shote = 121;
                        let delay = 10;
                        let t = 15/2;
                        ascent(j in 0..way){
 
                                let angle = e+j*t-i*t/2;
                                let sht = TShotA2( sx, sy, speed+5, angle, -0.5, speed, shote, delay );
                                NotifyEventAll( EV_USER + 40, [ sht, delay ] );
                        }
	    speed -= 0.11/2;
                        PlaySound("LenenShot1",92,0);
                        wait( 5/2 );

                }
}


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

	function ChangeD( sx, sy ){
    		let obj=ObjPrim_Create(OBJ_SPRITE_2D);
    		let img=GCSD~"img/Chang'e.png";
    		ObjPrim_SetTexture(obj,img);
    		ObjSprite2D_SetSourceRect(obj,0,0,80,74);
    		ObjSprite2D_SetDestCenter(obj);
    		Obj_SetRenderPriorityI(obj,42); 
    		ObjRender_SetBlendType(obj,BLEND_ALPHA);
    		ObjRender_SetAlpha(obj,0);							

		ObjRender_SetPosition(obj,sx,sy,0); 
                     	let core = TShotA2( sx, sy, 0, 0, 0, 0, 1, 0 );
		SetShotIntersectionCircle( ObjMove_GetX( core ), ObjMove_GetY( core ), 120 );	
    		ObjRender_SetAlpha(core,0);	
		ObjShot_SetAutoDelete( core, false );
		ObjShot_SetSpellResist( core, true );
		ThisMoonThingyIsTooComplex( obj );
		Fuc( core );
		check( obj );
		return core;

	task ThisMoonThingyIsTooComplex( obj ){
		wait( 80 );
    		ObjRender_SetAlpha(obj,255);	
		}
	task Fuc( core ){
		while( !Obj_IsDeleted( core )){
		ObjRender_SetPosition(obj,ObjMove_GetX( core ),ObjMove_GetY( core ),0); 
		yield;	
		}
		}

	task check( obj ){
	wait( 400 );
	while( IsOnEvent == true ){ yield; };
	wait( 200 );
	Obj_Delete( obj );
	}
	
	}

task Talk{
IntiallizeEvent( 1, 2, 0.4, 0.4, 0.4 );
ObjEvent_SetGraphic( RIGHT, 0, Change );
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "Oh, The Sea of Tranquility...");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "How long has it been                    [r]since the last time I saw this, I wonder..");
Talking( 1, LEFT );
SetText( LEFT, -1, 0, "You're the ringleader of the invasion[r]of the Lunar Capital, huh ?");
Talking( 0, RIGHT );
SetText( RIGHT, 1, 0, "For not one moment did I ever expect          [r]that they would send an earthling to the moon.");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "You can go back now.                  [r]The real culprit was already defeated. [r]Nothing left for you to do.              ");
Talking( 1, LEFT );
SetText( LEFT, -1, 0, "Wha ? What happened ?? and Who are you ???");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "I am Chang'e.                 [r]The master of all Moon Rabbits.");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "The one who was imprisoned[r]because of Hourai Elixir..     ");
Talking( 1, LEFT );
SetText( LEFT, -1, 0, "(muttering) That purple rabbit's true master huh ?..");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "All of this incidences were causing  [r]by someone whom I don't even know.");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "Someone who might have [r]a grudge against me..      ");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "I foresaw that she would kill me.        [r]So I sent an assassin to defeat her first.");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "Now, show yourself!             [r]Seiran, the pale blue Eagle Ravi!");
magiccircle(objBoss,1,-1);
SetCommonData("CircleSize",1);
ObjMove_SetDestAtWeight(objBoss,stgx,200,10,10);
wait( 90 );
Talking( 1, LEFT );
SetText( LEFT, -1, 0, "She ???");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "'Unexpected', right ?");
Talking( 0, RIGHT );
SetText( RIGHT, 1, 0, "Now, as a reward that you can go this far, [r]and to not let your journey gone to waste..");
NotifyEventAll(EV_SET_SONG,1);
Sound(GCSD ~ "Butterfly.mp3");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "I'll let you fight with my assassin!");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "Don't worry. She's now fill with      [r]determination to get revenge on you.");
Talking( 0, RIGHT );
SetText( RIGHT, 0, 0, "So, have fun, you two!");
FinallizeEvent;
}



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

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());
	}