
#ScriptVersion[3]
#Title["TsubakuraS8"]
#Text["TsubakuraS8"]
#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",2);
}

@MainLoop
{
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(1);
	}
                case(EV_REQUEST_IS_DURABLE_SPELL)
	{
		SetScriptResult(true);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(65);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(80000000);
	}
}

//----------------------------------------------------
task mainTask{
	StartCountDown;
	SetCommonData("ForceLifebar",1);
	PlaySound("SpellStart",100,0);
	ObjMove_SetDestAtWeight(objBoss,stgx,stgy,10,7);
	Cutin("Wild Art 'Painting of Disaster'",15,"SHINKI");
	ObjEnemyBossScene_StartSpell(objScene);
	wait( 180 );
	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;
	Warning1;
	wait( 60 );
	PatternBrush;
	DelaySound( 125 );
	wait( 980 );
	Warning2;
	wait( 60 );
	PatternBrush2;
	DelaySound( 90 );
	wait( 1200 );
	Warning3;
	wait( 60 );
	PatternBrush3;
	DelaySound( 90 );
}

let warn = GCSD~"img/warning.png";

task Warning3{
loop( 50 ){
loop( 5 ){
Warn1( rand( 0, GetStgFrameWidth ), rand( 0, GetStgFrameHeight ) );
PlaySound("LenenBulletWave",100,0);
}
wait( 2 );
}
}

task Warning2{
loop( 50 ){
loop( 4 ){
let r = rand( 0, 150 );
let angle = rand( 0, 360 );
Warn1( ObjMove_GetX( objBoss ) + r*cos( angle ), ObjMove_GetY( objBoss ) + r*sin( angle ) );
PlaySound("LenenBulletWave",100,0);
}
wait( 2 );
}
}

task Warning1{
let count = 0;
let r = 100;
let x;
let y;
loop( 50 ){
    loop( 6 ){

        x = rand(0,GetStgFrameWidth);
        y = rand(0,GetStgFrameHeight);
        while(GetDistance(x,y,GetEnemyX,GetEnemyY)<r){

            x = rand(0,GetStgFrameWidth);
            y = rand(0,GetStgFrameHeight);
        }
Warn1( x, y );
PlaySound("LenenBulletWave",100,0);
    }
    wait(2);
}
}

task Warn1( x, y ){ 
	let value = 0;
	let obj=ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,25);
	ObjPrim_SetTexture(obj,warn);
	ObjSprite2D_SetSourceRect(obj,0,0,50,51);
	ObjSprite2D_SetDestRect(obj,-50,-51,50,51);
	ObjSprite2D_SetDestCenter( obj );
	//ObjRender_SetScaleXYZ(obj,2,2,0);
	ObjRender_SetBlendType(obj,BLEND_ADD_ARGB);
	ObjRender_SetPosition(obj,x,y,0);
	Sizing( obj );
	//Appearing( obj );
	dDelete( obj, 75 );
	ObjRender_SetAlpha( obj, 255 );
	while( !Obj_IsDeleted(objBoss) && bSpell == false){
	//descent( i in 0..20 ){
	//ObjRender_SetScaleXYZ(obj,i,i,0);	
	yield;
	}
	//yield;
	//}
}
	task Sizing( obj ){
	descent( i in 5..10 ){
	ObjRender_SetScaleXYZ(obj,i/5,i/5,0);	
	yield;
	}
	}

	task Appearing( obj ){
	descent( i in 1..2*10 ){
	ObjRender_SetAlpha( obj, i/10 );
	yield;
	}
	}

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

task DelayRotation2( obj, time, target, rstart, rmax, angle, ad, av, aad, aav, avmax ){
wait( time );
ObjectRotation2( obj, target, rstart, rmax, angle, ad, av, aad, aav, avmax );
}

task ObjectRotation2( obj, target, rstart, rmax, angle, ad, av, aad, aav, avmax ){

   let ox;
   let oy;
   let r = rstart;
   while(!Obj_IsDeleted(obj)){

      ox = ObjMove_GetX( target ) + r*cos( angle );
      oy = ObjMove_GetY( target ) + r*sin( angle );

      ObjMove_SetPosition(obj,ox,oy);
      ObjStLaser_SetAngle(obj,angle);

      if(r < rmax){
      r += ad;
      ad += aad; }

      if(r > rmax){
      r -= ad;
      ad += aad; }

      if( av < avmax ){
      angle -= av;
      av += aav;
}

      if( av > avmax ){
      angle -= avmax;
      }

      yield;

      
 
   }
}

task DelayRotation( obj, time, target, rstart, rmax, angle, ad, av, aad, aav, avmax ){
wait( time );
ObjectRotation( obj, target, rstart, rmax, angle, ad, av, aad, aav, avmax );
}

task ObjectRotation( obj, target, rstart, rmax, angle, ad, av, aad, aav, avmax ){

   let ox;
   let oy;
   let r = rstart;
   while(!Obj_IsDeleted(obj)){

      ox = ObjMove_GetX( target ) + r*cos( angle );
      oy = ObjMove_GetY( target ) + r*sin( angle );

      ObjMove_SetPosition(obj,ox,oy);
      ObjStLaser_SetAngle(obj,angle);

      if(r < rmax){
      r += ad;
      ad += aad; }

      if(r > rmax){
      r -= ad;
      ad += aad; }

      if( av < avmax ){
      angle += av;
      av += aav;
}

      if( av > avmax ){
      angle += avmax;
      }

      yield;

      
 
   }
}

              task PatternBrush{ 
              loop( 1 ){

              			let angle = 270;
	                                	let way = 1;
                                                	let shote = 1032;
			let delay = 125;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss ) - 10;
				
				let a = CreateStraightLaserA1( sx, sy, angle, 300, 100, 700, shote, delay );
				Obj_SetRenderPriorityI( a, 60 );
				DelayRotation( a, 150, objBoss, 10, 10, angle, 0, 0, 0, 0.005, 1 );
				ClosingCurtain( a, 60 + 700, 100 );
				PatternTrail( a );

				let b = CreateStraightLaserA1( sx, sy, angle, 30, 20, 700, shote, delay );
				ObjRender_SetAlpha( b, 0 );
				DelayRotation( b, 150, objBoss, 10, 10, angle, 0, 0, 0, 0.005, 1 );
				ClosingCurtain( b, 60 + 700, 20 );

				angle += 360 / way;

			}
			PlaySound("LenenLaserDelayLong",100,0);
                        		if( wait( 1 ) ){ return; }
	}
   }

              task PatternBrush2{ 
              loop( 1 ){

              			let angle = 270;
	                                	let way = 1;
                                                	let shote = 1032;
			let delay = 90;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss )-10;
				
				let a = CreateStraightLaserA1( sx, sy, angle, 300, 100, 600, shote, delay );
				Obj_SetRenderPriorityI( a, 60 );
				DelayRotation2( a, 105, objBoss, 10, 10, angle, 0, 0, 0, 0.005, 1 );
				ClosingCurtain( a, 60 + 565, 100 );
				PatternTrail2( a );

				let b = CreateStraightLaserA1( sx, sy, angle, 30, 20, 600, shote, delay );
				ObjRender_SetAlpha( b, 0 );
				DelayRotation( b, 105, objBoss, 10, 10, angle, 0, 0, 0, 0.005, 1 );
				ClosingCurtain( b, 60 + 565, 20 );

				angle += 360 / way;

			}
			PlaySound("LenenLaserDelayLong",100,0);
                        		if( wait( 1 ) ){ return; }
	}
   }
              task PatternBrush3{ 
              loop( 1 ){

              			let angle = 270;
	                                	let way = 1;
                                                	let shote = 1032;
			let delay = 90;

			loop( way ){

                      	                	let sx = ObjMove_GetX( objBoss );
                        		let sy = ObjMove_GetY( objBoss )-10;
				
				let a = CreateStraightLaserA1( sx, sy, angle, 300, 100, 6000, shote, delay );
				Obj_SetRenderPriorityI( a, 60 );
				DelayRotation( a, 105, objBoss, 10, 10, angle, 0, 0, 0, 0.03, 0.8 );
				PatternTrail3( a );

				let b = CreateStraightLaserA1( sx, sy, angle, 30, 20, 6000, shote, delay );
				ObjRender_SetAlpha( b, 0 );
				DelayRotation( b, 105, objBoss, 10, 10, angle, 0, 0, 0, 0.03, 0.8 );

				angle += 360 / way;

			}
			PlaySound("LenenLaserDelayLong",100,0);
                        		if( wait( 1 ) ){ return; }
	}
   }

	
task ClosingCurtain( obj, t, width ){
wait( t );
descent(i in 0..width){
ObjLaser_SetRenderWidth( obj, i );
ObjLaser_SetIntersectionWidth( obj, i );
yield;
}
}
	task DelaySound( t ){
	wait( t );
	PlaySound("LenenLaserLong",100,0);
	}	

	function HLaser( sx, sy, angle, length, width, duration, shote, delay ){
	ProperLaserDelay( sx, sy, angle, length, delay, shote );
	wait( delay );
	PlaySound("LenenLaserLong",92,0);
	ProperLaser( sx, sy, angle, length, width, duration, shote );
	}

	task ProperLaserDelay( sx, sy, angle, length, delay, shote ){
	let sht0 = CreateStraightLaserA1( sx, sy, angle, length, 4, delay, shote, 0 );
	ObjShot_SetIntersectionEnable( sht0, false );
	wait( delay );
	Obj_Delete( sht0 );
	}

	task ProperLaser( sx, sy, angle, length, width, duration, shote ){
	let sht1 = CreateStraightLaserA1( sx, sy, angle, length, width, duration, shote, 0 );
	ObjLaser_SetGrazeInvalidFrame( sht1, 5 );
	wait( duration );

	ObjShot_SetIntersectionEnable( sht1, false );
	descent( i in 0..width ){
	ObjLaser_SetRenderWidth( sht1, i );
	wait( 2 );
	}

	Obj_Delete( sht1 );
	}

task DelayDeletes( time, obj ){
wait( time );
ObjShot_FadeDelete( obj );
}

	task PatternTrail( obj ){ 
	wait( 150 );
	let t = 0;
	while( !Obj_IsDeleted( obj )){
	let r = 10;
	loop( 10 ){
	                                	let way = 1;
                                                	let shote = 97;				
			let angle = ObjStLaser_GetAngle( obj );
			loop( way ){

                        		let sx = ObjMove_GetX( objBoss ) + r*cos( angle );
                        		let sy = ObjMove_GetY( objBoss ) + r*sin( angle );
				
				let sht1 = TShotA2( sx, sy, 0, angle, 0, 0, shote, 0 );
				ObjMove_AddPatternA2( sht1, 740 - t, 0, angle, 0.015, 0.25, 2 );
				ObjShot_SetSpellResist( sht1, true );

				angle += 360 / way;

			}
			r += 30;
			}
			t += 8;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 8 ) ){ return; }
		}
   }

	task PatternTrail2( obj ){ 
	wait( 135 );
	let t = 0;
	while( !Obj_IsDeleted( obj )){
	let r = 10;
	loop( 8 ){
	                                	let way = 1;
                                                	let shote = 97;				
			let angle = ObjStLaser_GetAngle( obj );
			loop( way ){

                        		let sx = ObjMove_GetX( objBoss ) + r*cos( angle );
                        		let sy = ObjMove_GetY( objBoss ) + r*sin( angle );
				
				let sht1 = TShotA2( sx, sy, 0, angle+90, 0, 0, shote, 0 );
				ObjMove_AddPatternA2( sht1, 640 - t, 0, angle+90, 0.002, 0, 1 );
				let sht2 = TShotA2( sx, sy, 0, angle-90, 0, 0, shote, 0 );
				ObjMove_AddPatternA2( sht2, 800 - t, 0, angle-90, 0.0025, 0, 1.5 );
				ObjShot_SetSpellResist( sht1, true );
				ObjShot_SetSpellResist( sht2, true );

				angle += 360 / way;

			}
			r += 40;
			}
			t += 9;
			PlaySound("LenenShot1",92,0);
                        		if( wait( 9 ) ){ return; }
		}
   }

	task PatternTrail3( obj ){ 
	wait( 90 );
	while( !Obj_IsDeleted( obj )){
	let r = 10;
	loop( 8 ){
			let a = rand( 0, 360 );
	                                	let way = 1;
                                                	let shote = 97;				
			let angle = ObjStLaser_GetAngle( obj );
			loop( way ){

                        		let sx = ObjMove_GetX( objBoss ) + r*cos( angle );
                        		let sy = ObjMove_GetY( objBoss ) + r*sin( angle );
				
				let sht1 = TShotA2( sx, sy, 0, angle+a, 0, 0, shote, 0 );
				ObjMove_AddPatternA2( sht1, 90, 0, angle+a, 0.012, 0, 2.6 );
				ObjShot_SetSpellResist( sht1, true );

				angle += 360 / way;

			}
			r += 35;
			}
			PlaySound("LenenShot1",92,0);
                        		if( wait( 7 ) ){ return; }
		}
   }

	task StartCountDown
	{
		wait((65*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());
	}