
#ScriptVersion[3]
#Title["u~bhiCg@Gv"]
#Text["Ex[~Aŏ̃XyJ[hF[r]u~bhiCg@Gv"]
#Image["./ExRumia(u~bhiCg@Gv).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_Youmu.txt"
#include"./../../lib/BossCommon/BossCommon.txt"

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

@MainLoop
{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);//蔻(e)o^
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 12);//蔻(̓)o^
	SetCommonData("BossPosition",[ex,ey]);
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(2000);//Ct1500ɐݒ
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(100);//Ԑ60bɐݒ
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);//XyJ[h{[iX30000ɐݒ
	}
}

//----------------------------------------------------
//G
//----------------------------------------------------
task BossWork
{
	//W(cx, 60)60t[Ĉړ
	let cx = GetStgFrameWidth() / 2;//STGV[̒SxW擾
	ObjMove_SetDestAtWeight(objEnemy, cx, 144, 10,7);
	SetAction(ACT_MOVE, 60);
	loop(60){yield;}
//	CallSpellCard("u鮓jMv");
/*
	SetAction(ACT_SPELL, 60);
	loop(12){yield;}
*/

	let dir=floor(rand(0,2-0.001))*2-1;
	T_Slash(dir,0);
	loop(60){yield;}
	CallSpellCard("u鮓jMv");

	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	loop
	{
	wait(90);
	A(dir);
	DamageRate=[100,100];

	wait(840);
	ObjMove_SetDestAtWeight(objEnemy, cx, 144, 10,7);
	SetAction(ACT_MOVE, 60);
	loop(60){yield;}
	dir*=-1;
	T_Slash(dir,1);
	wait(60);
	}

	task T_Slash(dir,slow)
	{
		SetAction(ACT_CHARGE, 60);
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let R=60;
		ascent(i in 0..8)
		{	
		let x=ex+R*cos(i*45)-384*cos(i*45+90)*dir;
		let y=ey+R*sin(i*45)-384*sin(i*45+90)*dir;

		NoticeLaser(x,y,1,i*45+90*dir,768,5,153,60);
		LaserSlash(x,y,i*45+90*dir);
		}

		task LaserSlash(sx,sy,angle)
		{
			if(slow){StartSlow(TARGET_ALL,30);}
			wait(60);
			StartSlow(TARGET_ALL,60);
			SetAction(ACT_SLASH_V, 60);
			ascent(i in 0..48)
			{
				L(i);
			}

			task L(num)
			{
				let obj=CreateLooseLaserA1(sx,sy,2.5+num*0.5+rand(-0.5,0.5),angle+rand(-1,1),45,15,81,0);
				ObjShot_SetAutoDelete(obj,false);
				wait(60);
				ObjShot_SetAutoDelete(obj,true);
			}
		}

		task NoticeLaser(x,y,Lspeed,Langle,Slength,width,graphic,delay)
		{
			let obj = CreateStraightLaserA1(x, y, Langle, Lspeed, width, Slength, graphic, 0);
			ObjLaser_SetLength(obj,Slength);
			ObjShot_SetIntersectionEnable(obj,false);
			ObjShot_SetAutoDelete(obj,false);
			wait(delay);
			Obj_Delete(obj);
		}
	}

	task A(dir)
	{
		if(dir==1)
		{
		ObjMove_SetDestAtWeight(objEnemy, 12, 112, 10,7);
		wait(60);
		SetAction(ACT_CHARGE, 60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,0,768,5,158,30);
		wait(30);
		StartSlow(TARGET_ALL,60);
		SetAction(ACT_SLASH_H, 30);
		ObjMove_SetDestAtFrame(objEnemy,372,112,10);
		Shot;

		wait(120);

		ObjMove_SetDestAtWeight(objEnemy, 340, 12, 10,7);
		wait(60);
		SetAction(ACT_CHARGE, 60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,90,768,5,158,30);
		wait(30);
		StartSlow(TARGET_ALL,60);
		SetAction(ACT_SLASH_V, 30);
		ObjMove_SetDestAtFrame(objEnemy,340,444,10);
		Shot2;

		wait(120);
		let y=400;
		ObjMove_SetDestAtWeight(objEnemy, 372, y, 10,7);
		wait(60);
		SetAction(ACT_CHARGE, 60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,180,768,5,158,30);
		wait(30);
		StartSlow(TARGET_ALL,60);
		SetAction(ACT_SLASH_H, 30);
		ObjMove_SetDestAtFrame(objEnemy,12,y,10);
		Shot3(y);

		wait(120);
		let x=28;
		ObjMove_SetDestAtWeight(objEnemy, x, 444, 10,7);
		wait(60);
		SetAction(ACT_CHARGE, 60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,270,768,5,158,30);
		wait(30);
		StartSlow(TARGET_ALL,60);
		SetAction(ACT_SLASH_V, 30);
		ObjMove_SetDestAtFrame(objEnemy,x,12,10);
		Shot4(x);

		task Shot
		{
			let angle=rand(0,360);
			ascent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(12+j*10,112,5-4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(12+j*10,112,rand(0,360));
			}
			yield;
			}
		}

		task Shot2
		{
			let angle=rand(0,360);
			ascent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(340,12+j*12,5-4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(340,12+j*12,rand(0,360));
			}
			yield;
			}
		}

		task Shot3(y)
		{
			let angle=rand(0,360);
			descent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(12+j*10,y,1+4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(12+j*10,y,rand(0,360));
			}
			yield;
			}
		}

		task Shot4(x)
		{
			let angle=rand(0,360);
			descent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(x,12+j*12,1+4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(x,12+j*12,rand(0,360));
			}
			yield;
			}
		}

		}
		else
		{
		ObjMove_SetDestAtWeight(objEnemy, 372, 112, 10,7);
		wait(60);
		SetAction(ACT_CHARGE, 60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,180,768,5,158,30);
		wait(30);
		StartSlow(TARGET_ALL,60);
		SetAction(ACT_SLASH_H, 30);
		ObjMove_SetDestAtFrame(objEnemy,12,112,10);
		Shot;

		wait(120);

		ObjMove_SetDestAtWeight(objEnemy, 28, 12, 10,7);
		wait(60);
		SetAction(ACT_CHARGE, 60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,90,768,5,158,30);
		wait(30);
		StartSlow(TARGET_ALL,60);
		SetAction(ACT_SLASH_V, 30);
		ObjMove_SetDestAtFrame(objEnemy,28,444,10);
		Shot2;

		wait(120);
		let y=400;
		ObjMove_SetDestAtWeight(objEnemy, 12, y, 10,7);
		wait(60);
		SetAction(ACT_CHARGE, 60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,0,768,5,158,30);
		wait(30);
		StartSlow(TARGET_ALL,60);
		SetAction(ACT_SLASH_H, 30);
		ObjMove_SetDestAtFrame(objEnemy,372,y,10);
		Shot3(y);

		wait(120);
		let x=340;
		ObjMove_SetDestAtWeight(objEnemy, x, 444, 10,7);
		wait(60);
		SetAction(ACT_CHARGE, 60);
		StartSlow(TARGET_ALL,30);
		NoticeLaser(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1,270,768,5,158,30);
		wait(30);
		StartSlow(TARGET_ALL,60);
		SetAction(ACT_SLASH_V, 30);
		ObjMove_SetDestAtFrame(objEnemy,x,12,10);
		Shot4(x);

		task Shot
		{
			let angle=rand(0,360);
			descent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(12+j*10,112,1+4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(12+j*10,112,rand(0,360));
			}
			yield;
			}
		}

		task Shot2
		{
			let angle=rand(0,360);
			ascent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(28,12+j*12,5-4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(28,12+j*12,rand(0,360));
			}
			yield;
			}
		}

		task Shot3(y)
		{
			let angle=rand(0,360);
			ascent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(12+j*10,y,5-4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(12+j*10,y,rand(0,360));
			}
			yield;
			}
		}

		task Shot4(x)
		{
			let angle=rand(0,360);
			descent(j in 0..36)
			{
			ascent(i in 0..12)
			{
				S(x,12+j*12,1+4*j/36,angle+i*30);
			}
			angle+=10;
			if(j%4==1)
			{
			HomingShot(x,12+j*12,rand(0,360));
			}
			yield;
			}
		}

		}

		task S(x,y,speed,angle)
		{
			let obj = ObjShot_Create(OBJ_SHOT);
			ObjShot_Regist(obj);
			ObjMove_SetPosition(obj, x, y);
			ObjMove_SetSpeed(obj, speed);
			ObjMove_SetAngle(obj, angle);
			ObjShot_SetGraphic(obj, 86);
			//ObjShot_SetDelay(obj, delay);
			//ObjShot_SetAutoDelete(obj,false);
			loop(60)
			{
				angle+=360/60;
				ObjMove_SetAngle(obj, angle);
				yield;
			}
		}

		task HomingShot(x,y,angle)
		{
			let LaserSpeed=3;
			loop(30)
			{
				Homing;
				Homing;

				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				LaserSpeed-=2.5/30;
				BladeShot(x,y,angle,81);
				yield;
			}
			loop(105)
			{
				Homing;
				Homing;

				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				BladeShot(x,y,angle,81);
				yield;
			}
			loop(75)
			{
				Homing;

				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				if(y<-32){break;}
				LaserSpeed+=9/60;
				BladeShot(x,y,angle,81);
				yield;
			}
			loop(75)
			{
				x+=LaserSpeed*cos(angle);
				y+=LaserSpeed*sin(angle);
				if(x<-64){break;}
				if(x>448){break;}
				if(y<-32){break;}
				LaserSpeed+=6/60;
				BladeShot(x,y,angle,81);
				yield;
			}
			function Homing
			{
				let ToPlayerAngle=atan2(GetPlayerY-y,GetPlayerX-x);
				let judgangle=sin(ToPlayerAngle-angle);
				let ShiftAngle=absolute(ToPlayerAngle-angle);
				if(judgangle>0)
				{
					angle+=1.0;
				}
				else
				{
					angle-=1.0;
				}
			}

			task BladeShot(x,y,angle,gra)
			{
				let obj = CreateShotA2(x, y, 0, angle, 0, 0, gra, 0);//e𔭎
				ObjShot_SetSpellResist(obj,true);
				let scale=2.5;
				ObjRender_SetBlendType(obj, BLEND_ADD_RGB);
				let speed=0.75;
				loop(10)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.5/15;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					ObjShot_SetIntersectionCircleA1(obj,scale*3);
					yield;
				}
				ObjShot_SetIntersectionEnable(obj,false);
				loop(5)
				{
					if(Obj_IsDeleted(obj)){break;}
					scale-=2.5/15;
					ObjRender_SetScaleXYZ(obj,scale,scale,scale);
					yield;
				}
				Obj_Delete(obj);
			}

		}

		task NoticeLaser(x,y,Lspeed,Langle,Slength,width,graphic,delay)
		{
			let obj = CreateStraightLaserA1(x, y, Langle, Lspeed, width, Slength, graphic, 0);
			ObjLaser_SetLength(obj,Slength);
			ObjShot_SetIntersectionEnable(obj,false);
			ObjShot_SetAutoDelete(obj,false);
			wait(delay);
			Obj_Delete(obj);
		}
	}

	task FreezeShot(x,y,speed)
	{
	let angle=90;
	let obj = ObjShot_Create(OBJ_SHOT);
	ObjShot_Regist(obj);
	ObjMove_SetPosition(obj, x, y);
	ObjMove_SetSpeed(obj, speed);
	ObjMove_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, 29);
	ObjShot_SetAutoDelete(obj,true);
	ShotEffect(obj);
	}

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

	task B
	{
		loop(240){yield;}
		WShot;
		loop(30){yield;}
		loop
		{
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);
		let mx= ex+rand(-120,120);
		let my= ey+rand(-20,20);
		while(mx<64 || mx>320){mx=ex+rand(-120,120);}
		while(my<80 || my>160){my=ey+rand(-20,20);}
		ObjMove_SetDestAtWeight(objEnemy,mx, my, 30,2.0);
		SetAction(ACT_MOVE, 75);
		loop(120){yield;}
		WShot;
		loop(30){yield;}
		}

		task WShot
		{

			let angle=GetAngleToPlayer(objEnemy);
			let life=ObjEnemy_GetInfo(objEnemy,INFO_LIFE);
			let way=floor((4000-life)/500)+4;
			ascent(i in -way..way+1)
			{
			let obj=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),1.25,angle+i*2.5,21,0);
			ShotEffect(obj);
			}

		}
	}


}