
#ScriptVersion[3]
#Title["星符「ミッドナイトレヴァリエ」"]
#Text["Exルーミア最初のスペルカード：[r]星符「ミッドナイトレヴァリエ」"]
#Image["./ExRumia(星符「ミッドナイトレヴァリエ」).jpg"]
#Background["script/default_system/Default_Background_IceMountain.txt"]
#BGM[DEFAULT]
#Player[DEFAULT]

#include"script/default_system/Default_ShotConst.txt"
#include"script/default_system/Default_Effect.txt"

#include"./../../img/boss/lib_anime_Sanae.txt"
#include"./../../lib/BossCommon/BossCommon.txt"

@Initialize
{
//	BossInit(GetCommonData("BossPosition",[0,0])[0],GetCommonData("BossPosition",[0,0])[1]);
	BossInit(0,0);
	SetItem(20,2,2);
}

@MainLoop
{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);//当たり判定(自弾)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 12);//当たり判定(体当たり)登録
	SetCommonData("BossPosition",[ex,ey]);
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(6000);//ライフを1500に設定
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(100);//時間制限を60秒に設定
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);//スペルカードボーナスを30000に設定
	}
}

//----------------------------------------------------
//敵動作
//----------------------------------------------------
task BossWork
{
	//座標(cx, 60)へ60フレームかけて移動する
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtWeight(objEnemy, cx, 144, 10,7);
	SetAction(ACT_MOVE, 60);
//	loop(60){yield;}
	CallSpellCard("「客星映しの神風」");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	let WindSpeed=0;
	let WindAngle=90;

	loop(60){yield;}
	C;
	W;
	loop(150){yield;}
	DamageRate=[100,100];


	task W
	{
		wait(120);
		let WindVector=[0,0];
		let WindVector2=[0,0];
		let WindVector3=[0,0];
		let speed=0;
		let Setspeed=2;
		let angle=0;
		let wt=180;
		WindComp;
		WindIntense;


		loop
		{
		speed=Setspeed;
		angle=rand(0,360);
		WindChange(0,speed,angle);
		wait(wt);

		speed=Setspeed;
		angle=rand(0,360);
		WindChange(1,speed,angle);
		wait(wt);

		speed=Setspeed;
		angle=rand(0,360);
		WindChange(2,speed,angle);
		wait(wt);

		}

		task WindChange(num,speed,angle)
		{
		if(num==0)
		{
		WindVector[1]=angle;
		loop(120)
		{
			WindVector[0]=WindVector[0]+speed/120;
			yield;
		}
		wait(30);
		loop(120)
		{
			WindVector[0]=WindVector[0]-speed/120;
			yield;
		}
		}
		else if(num==1)
		{
		WindVector2[1]=angle;
		loop(120)
		{
			WindVector2[0]=WindVector2[0]+speed/120;
			yield;
		}
		wait(30);
		loop(120)
		{
			WindVector2[0]=WindVector2[0]-speed/120;
			yield;
		}
		}
		else if(num==2)
		{
		WindVector3[1]=angle;
		loop(120)
		{
			WindVector3[0]=WindVector3[0]+speed/120;
			yield;
		}
		wait(30);
		loop(120)
		{
			WindVector3[0]=WindVector3[0]-speed/120;
			yield;
		}
		}
		}

		task WindComp
		{
			loop
			{
				let x=0;
				let y=0;
				x+=WindVector[0]*cos(WindVector[1]);
				y+=WindVector[0]*sin(WindVector[1]);
				x+=WindVector2[0]*cos(WindVector2[1]);
				y+=WindVector2[0]*sin(WindVector2[1]);
				x+=WindVector3[0]*cos(WindVector3[1]);
				y+=WindVector3[0]*sin(WindVector3[1]);
				WindSpeed=(x^2+y^2)^0.5;
				WindAngle=atan2(y,x);
				yield;
			}
		}

		task WindIntense
		{
			loop
			{
				Setspeed=(6000-ObjEnemy_GetInfo(objEnemy,INFO_LIFE))*0.001+1.5;
				yield;
			}
		}
	}

	task C
	{
		SetAction(ACT_SHOT_A, 90);
		loop(90)
		{
			let x=rand(0-48,384+48);
			let y=rand(0-48,448+48);
			let dis=((GetPlayerY-y)^2+(GetPlayerX-x)^2)^0.5;
			while(dis<=32)
			{
			x=rand(0-48,384+48);
			y=rand(0-48,448+48);
			dis=((GetPlayerY-y)^2+(GetPlayerX-x)^2)^0.5;
			}
			Shot(x,y);
			wait(1);
		}


		task Shot(x,y)
		{
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
		//	ObjMove_SetSpeed(obj, speed*0);
		//	ObjMove_SetAngle(obj, angle*0);
			ObjShot_SetGraphic(obj, DS_STAR_S_GREEN);
			//ObjShot_SetDelay(obj, delay);

		//	ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
			ObjShot_SetAutoDelete(obj,false);
			ShotEffect(obj);
			let Zangle=0;
			while(!Obj_IsDeleted(obj))
			{
			//ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				ObjRender_SetX(obj,ObjRender_GetX(obj)+WindSpeed*cos(WindAngle));
				ObjRender_SetY(obj,ObjRender_GetY(obj)+WindSpeed*sin(WindAngle));
				if(ObjRender_GetX(obj)<0-48)
				{
					ObjRender_SetX(obj,ObjRender_GetX(obj)+384+96);
				}
				if(ObjRender_GetX(obj)>384+48)
				{
					ObjRender_SetX(obj,ObjRender_GetX(obj)-384-96);
				}
				if(ObjRender_GetY(obj)<0-48)
				{
					ObjRender_SetY(obj,ObjRender_GetY(obj)+448+96);
				}
				if(ObjRender_GetY(obj)>448+48)
				{
					ObjRender_SetY(obj,ObjRender_GetY(obj)-448-96);
				}
				BladeShot(ObjRender_GetX(obj),ObjRender_GetY(obj),Zangle,DS_STAR_S_GREEN);
				Zangle-=3;
				yield;
			}
			Obj_Delete(obj);
		}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 0, 0, gra, 0);//弾を発射
				ObjShot_SetSpellResist(obj,true);
				let scale=1.5-0.5;
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let speed=0.75;
				ObjShot_SetIntersectionEnable(obj,false);
				loop(10)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=1.0/10;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					ObjRender_SetColor(obj,50*scale,150*scale,50*scale);
					yield;
				}
				Obj_Delete(obj);
			}
	}

	task ShotEffect(obj)
	{
		let scale=2.0;
		ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
		ObjShot_SetIntersectionEnable(obj,false);
		loop(15)
		{
			if(Obj_IsDeleted(obj)){break;}
			scale-=1.0/15;
			ObjRender_SetScaleXYZ(obj,scale,scale,scale);
			yield;
		}
		ObjRender_SetBlendType(obj, BLEND_ALPHA);
		ObjShot_SetIntersectionEnable(obj,true);
	}
}