
#ScriptVersion[3]
#Title["TsubakuraS6"]
#Text["TsubakuraS6"]
#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"


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 action = false;
let objScene=GetEnemyBossSceneObjectID();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetBoss("Doremy",true);
SetCommonData("Life",1);
SetCommonData("Bomb",1);
}

@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(1250);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(90);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(60000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	PlaySound("SpellStart",100,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,7);
	Cutin("Psyche Card 'ID-Resisting Talisman'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait( 170 );
	TShot1;
	}
//----------------------------------------------------

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;
	wait( 10 );

	PatternOpen;

	wait( 10 );

	let sha1 = Shadow( stgx + 150, 200 );
	let sha2 = Shadow( stgx - 150, 200 );
	let shaa1 = TShotA2( stgx + 150, 200, 0, 90, 0, 0, 1, 0 );
	let shaa2 = TShotA2( stgx - 150, 200, 0, 90, 0, 0, 1, 0 );
	ObjShot_SetSpellResist( shaa1, true );
	ObjShot_SetSpellResist( shaa2, true );
	ObjShot_SetIntersectionEnable( shaa1, false );
	ObjShot_SetIntersectionEnable( shaa2, false );

	wait( 90 );

	Id( sha1, stgx - 150, 200 );
	Es( sha2, stgx + 150, 200 );
	Ego( ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ) );
	SuperEgo;

	PlaySound("LenenLaserDelayLong",92,0);
	wait( 160 );

	DamageRateAtFrame(11.5,0,0);
	PatternShotId( shaa1, 0.65 );
	PatternShotEs( shaa2, 0.65 );
	PatternShotEgo( 0.8 );
	PatternShotSuperEgo( 0.5 );
}

	function GetDotAngle(x1,y1,x2,y2){
	let angle=atan2(y1-y2,x1-x2);
	return angle;
}

             task PatternOpen{ 
             let Wait = 100;
             loop( 1 ){
             loop( 1 ){

		            let angle = GetDotAngle( stgx + 150, 200, ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ));
                                                    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 ] );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);

	}
	
             loop( 1 ){

		            let angle = GetDotAngle( stgx - 150, 200, ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ));
                                                    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 ] );

				angle += 360 / way;

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

	}
	}

   }


function Shadow( sx, sy ){ 
	let blind = GCSD~"img/turu_dot.png";
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,50);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,0,0,65,94);
	ObjSprite2D_SetDestRect(obj,-384,-448,384,448);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetPosition(obj,sx,sy,0);
	ObjRender_SetColor(obj,0,0,0);
	dDelete( obj );
	return blind;
}

task Id( sha, sx, sy ){ 
	let blind = GCSD~"img/Id.png";
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,49);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,0,0,493,493);
	ObjSprite2D_SetDestRect(obj,-493,-493,493,493);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha( obj, 255/4 );
	dDelete( obj );
	let size = 0.65;
	ObjRender_SetScaleXYZ(obj,size, size, 0);
	yield;
	while( !Obj_IsDeleted(objBoss) && bSpell == false){
	ObjRender_SetPosition(obj,sx,sy,0);
	yield;
	}
	Obj_Delete(obj);
}
task Es(  sha, sx, sy ){ 
	let blind = GCSD~"img/Es.png";
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,49);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,0,0,493,493);
	ObjSprite2D_SetDestRect(obj,-493,-493,493,493);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha( obj, 255/4 );
	dDelete( obj );
	let size = 0.65;
	ObjRender_SetScaleXYZ(obj,size, size, 0);
	yield;
	while( !Obj_IsDeleted(objBoss) && bSpell == false){
	ObjRender_SetPosition(obj,sx,sy,0);
	yield;
	}
	Obj_Delete(obj);
}
task Ego( sx, sy ){ 
	let blind = GCSD~"img/Ego.png";
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,49);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,0,0,493,493);
	ObjSprite2D_SetDestRect(obj,-493,-493,493,493);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha( obj, 255/4 );
	dDelete( obj );
	let size = 0.8;
	ObjRender_SetScaleXYZ(obj,size, size, 0);
	yield;
	while( !Obj_IsDeleted(objBoss) && bSpell == false){
	ObjRender_SetPosition(obj,sx,sy,0);
	yield;
	}
	Obj_Delete(obj);
}
task SuperEgo{ 
	let blind = GCSD~"img/Superego.png";
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,49);
	ObjPrim_SetTexture(obj,blind);
	ObjSprite2D_SetSourceRect(obj,0,0,493,493);
	ObjSprite2D_SetDestRect(obj,-493,-493,493,493);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha( obj, 255/4 );
	dDelete( obj );
	let size = 0.5;//rand( 0.4, 0.5 );
	ObjRender_SetScaleXYZ(obj,size, size, 0);
	while( !Obj_IsDeleted(objBoss) && bSpell == false){
	ObjRender_SetPosition(obj,GetPlayerX,GetPlayerY,0);
	yield;
	}
	Obj_Delete(obj);
}

	task dDelete( obj ){
	while( !Obj_IsDeleted( objBoss )){ yield; }
	Obj_Delete( obj );
	}

task UpDown( obj, size ){
while( !Obj_IsDeleted( objBoss ) && bSpell == false ){ 
let a = 0;
loop( 240 ){
ObjRender_SetScaleXYZ(obj,size + a, size + a, 0);
a += 0.0005;
yield;
}
loop( 240 ){
ObjRender_SetScaleXYZ(obj,size + a, size + a, 0);
a -= 0.0005;
yield;
}
}
}

	task PatternShotId( obj, size ){ 
	loop( 1200 ){

              			let speed = 0.9;
			let angle = rand( 0, 360 );
	                                	let way = 48;
                                                	let shote = 97;
			let delay = 10;			
			let z = rand( -120, 120 );
			if( GetDistance( GetPlayerX, GetPlayerY, ObjMove_GetX( obj ), ObjMove_GetY( obj ) ) < size* 240 ){ z = 180; }

			loop( way ){

			let r = size*240;
                        		let sx = ObjMove_GetX( obj )  + r*cos( angle + z );
                        		let sy = ObjMove_GetY( obj ) + r*sin( angle + z );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );

				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                        		if( wait( 75 ) ){ return; }
		}
   }
	task PatternShotEs( obj, size ){ 
	loop( 1200 ){

              			let speed = 0.9;
			let angle = rand( 0, 360 );
	                                	let way = 48;
                                                	let shote = 97;
			let delay = 10;			
			let z = rand( -120, 120 );
			if( GetDistance( GetPlayerX, GetPlayerY, ObjMove_GetX( obj ), ObjMove_GetY( obj ) ) < size* 240 ){ z = 180; }

			loop( way ){

			let r = size*240;
                        		let sx = ObjMove_GetX( obj )  + r*cos( angle + z );
                        		let sy = ObjMove_GetY( obj ) + r*sin( angle + z );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );

				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

			}
			PlaySound("LenenShot1",92,0);
                        		if( wait( 75 ) ){ return; }
		}
   }
	task PatternShotEgo( size ){ 
	loop( 1200 ){

              			let speed = 0.9;
			let angle = rand( 0, 360 );
	                                	let way = 55;
                                                	let shote = 97;
			let delay = 10;			
			let z = rand( -120, 120 );
			if( GetDistance( GetPlayerX, GetPlayerY, ObjMove_GetX( objBoss ), ObjMove_GetY( objBoss ) ) < size* 240 ){ z = 180; }

			loop( way ){

			let r = size*240;
                        		let sx = ObjMove_GetX( objBoss ) + r*cos( angle + z );
                        		let sy = ObjMove_GetY( objBoss )  + r*sin( angle + z );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );

				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

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

	task PatternShotSuperEgo( size ){ 
	loop( 1200 ){

              			let speed = 0.9;
			let angle = rand( 0, 360 );
	                                	let way = 35;
                                                	let shote = 97;
			let delay = 10;			
			let z = rand( -120, 120 );

			loop( way ){

			let r = size*240;
                        		let sx = GetPlayerX + r*cos( angle + z );
                        		let sy = GetPlayerY + r*sin( angle + z );
				
				let sht1 = TShotA2( sx, sy, speed, angle, 0, speed, shote, delay );
				ObjShot_SetSpellResist( sht1, true );

				NotifyEventAll( EV_USER + 40, [ sht1, delay ] );

				angle += 360 / way;

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


	task Deletee( sht1 ){
              	while( ObjMove_GetY( sht1 ) < GetStgFrameHeight ){ yield; }
	Obj_Delete( sht1 );
	}

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

	}




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

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