
#Title[ルナチャ]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_lunachild.png"; 
    let imgBoss2 =csd ~ "..\lib/dot_lunachild2.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
let TimeCounter=25*60;
let StandardTimeCounter=TimeCounter;
    @Initialize {
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
        SetLife(2200);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
    }

    @MainLoop {
	SetCommonData("BossX",GetX);
	SetCommonData("BossY",GetY);
	SetCommonData("BossLife",GetLife);
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        yield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
//DrawText(TimeCounter,120,382,12,255);//起動時間の表示
    }

    @Finalize {
	DeleteAllEnemyWithoutBoss;
	SetCommonData("BossX",GetX);
	SetCommonData("BossY",GetY);
	SetCommonData("BossLife",GetLife);
	DeleteEnemyShotToItem(ALL);
		if(!IsTimeOut)
		{
		SetCommonData("DeleteBulletNum",BulletNum);
		SetCommonData("DeleteBulletX",GetX);
		SetCommonData("DeleteBulletY",GetY);
		}
		if(!OnBomb)
		{
			ExtendItemSet(GetX,GetY,2);
		}
		else
		{
			AchievementSet(93);
		}
	SetCommonData("VanishSignal",false);
	SetCommonData("TimeBonus",TimeCounter/StandardTimeCounter);
	SetCommonData("BossRate",100000);
    }

    // メインタスク
task TMain 
{
	yield;
	GetDamege;
	OutDamageRateZero;
	//Lissajous(255,255,127);
	BossShadowAnimation(imgBoss2,0,255,255,127);
	standBy;
	Collision;
	wait(60);
	Concentration01(30);
	wait(15);
	if(GetCommonDataDefault("SELECTEDDIFFICULT","None")=="Apocalypse")
	{
        CreateEnemyFromScript("Familiar", GetCenterX+120, GetClipMinY+64,
                              0, 90, 1);
        CreateEnemyFromScript("Familiar", GetCenterX-120, GetClipMinY+64,
                              0, 90, -1);
	}
	wait(15);
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}

	ZakoVanish;
}

task Collision
{
	loop(90)
	{
        SetCollisionA(GetX, GetY, 48);
	yield;
	}
	loop
	{
        SetCollisionA(GetX, GetY, 48);
        MSDSetCollisionB(GetX, GetY, 16);
	yield;
	}
}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni, 20,5);
}

////////////////////////////////////////////////////////////
task shotM
{
SpellDraw(3,6000);
let num=0;
loop(2)
{
	SetAction(ACT_SHOT_A,120+num*60);
	MoonShot(num);
	wait(240+30*num);
	SetAction(ACT_SHOT_B,210);
	MoonShot2(num);
	wait(240);
	if(num<3)
	{
	num+=1;
	}
}
	SetAction(ACT_SHOT_A,120+num*60);
	MoonShot(num);


	task MoonShot(loopnum)
	{
		let X1=GetX;
		let Y1=GetY-170;
		let R1=200;
		let angle1=30;

		let X2=GetX;
		let Y2=GetY-100;
		let R2=180;
		let angle2=18;

	loop(2+loopnum)
	{
		loop(12)
		{
			MoonCreateShot01(X2+R2*cos(angle2),Y2+R2*sin(angle2),rand(1.5,2.5),GetAngleToPlayer+rand(-15,15),11,10);
			MoonCreateShot01(X2-R2*cos(angle2),Y2+R2*sin(angle2),rand(1.5,2.5),GetAngleToPlayer+rand(-15,15),11,10);
			angle1+=120/12;
			angle2+=144/12;
			wait(1);
		}
		loop(12)
		{
//ShotEffect(X1+R1*cos(angle1),Y1+R1*sin(angle1),10,100,255,255,0);
//ShotEffect(X1-R1*cos(angle1),Y1+R1*sin(angle1),10,100,255,255,0);
			MoonCreateShot01(X1+R1*cos(angle1),Y1+R1*sin(angle1),rand(1.5,2.5),GetAngleToPlayer+rand(-15,15),11,10);
			MoonCreateShot01(X1-R1*cos(angle1),Y1+R1*sin(angle1),rand(1.5,2.5),GetAngleToPlayer+rand(-15,15),11,10);
			angle1-=120/12;
			angle2-=144/12;
			wait(1);
		}
		ascent(let i in -3..4)
		{
//ShotEffect(GetX,GetY,10,100,255,255,0);
			CreateShot01(GetX,GetY,3,GetAngleToPlayer+i*30,27,10);
		}
	wait(36);
	}
	}



	task MoonShot2(loopnum)
	{
		let X=GetX-50*cos(GetAngleToPlayer);
		let Y=GetY-50*sin(GetAngleToPlayer);
		let R=80;
		let angle=GetAngleToPlayer-60;
		let shotangle=GetAngleToPlayer+15;

	loop(1)
	{
		loop(15)
		{
		ShotEffect(X+R*cos(angle),Y+R*sin(angle),10,255,255,255,0);
			ascent(let i in -(1+loopnum)..(2+loopnum))
			{
			Moon2CreateShot01(X+R*cos(angle),Y+R*sin(angle),3+loopnum,shotangle+18*i,11,10);
			}
			angle+=120/15;
			shotangle-=30/15;
			wait(1);
		}
	wait(30);
	X=GetX-50*cos(GetAngleToPlayer);
	Y=GetY-50*sin(GetAngleToPlayer);
	angle=GetAngleToPlayer+60;
	shotangle=GetAngleToPlayer-15;
		loop(15)
		{
		ShotEffect(X+R*cos(angle),Y+R*sin(angle),10,255,255,255,0);
			ascent(let i in -(2+loopnum)..(3+loopnum))
			{
			Moon2CreateShot01(X+R*cos(angle),Y+R*sin(angle),4+loopnum,shotangle+18*i,11,10);
			}
			angle-=120/15;
			shotangle+=30/15;
			wait(1);
		}
	wait(30);
	X=GetX-50*cos(GetAngleToPlayer);
	Y=GetY-50*sin(GetAngleToPlayer);
	angle=GetAngleToPlayer-60;
	shotangle=GetAngleToPlayer+15;
		loop(15)
		{
		ShotEffect(X+R*cos(angle),Y+R*sin(angle),10,255,255,255,0);
			ascent(let i in -(3+loopnum)..(4+loopnum))
			{
			Moon2CreateShot01(X+R*cos(angle),Y+R*sin(angle),5+loopnum,shotangle+18*i,11,10);
			}
			angle+=120/15;
			shotangle-=30/15;
			wait(1);
		}
	wait(30);
	X=GetX-50*cos(GetAngleToPlayer);
	Y=GetY-50*sin(GetAngleToPlayer);
	angle=GetAngleToPlayer+60;
	shotangle=GetAngleToPlayer-15;
		loop(15)
		{
		ShotEffect(X+R*cos(angle),Y+R*sin(angle),10,255,255,255,0);
			ascent(let i in -(4+loopnum)..(5+loopnum))
			{
			Moon2CreateShot01(X+R*cos(angle),Y+R*sin(angle),6+loopnum,shotangle+18*i,11,10);
			}
			angle-=120/15;
			shotangle+=30/15;
			wait(1);
		}
	wait(30);
	X=GetX-50*cos(GetAngleToPlayer);
	Y=GetY-50*sin(GetAngleToPlayer);
	angle=GetAngleToPlayer-60;
	shotangle=GetAngleToPlayer+15;
		loop(15)
		{
		ShotEffect(X+R*cos(angle),Y+R*sin(angle),10,255,255,255,0);
			ascent(let i in -(5+loopnum)..(6+loopnum))
			{
			Moon2CreateShot01(X+R*cos(angle),Y+R*sin(angle),7+loopnum,shotangle+18*i,11,10);
			}
			angle+=120/15;
			shotangle-=30/15;
			wait(1);
		}
	}
	}

	task MoonCreateShot01(x,y,speed,angle,gra,delay)
	{
		ShotEffect(x,y,delay,255,255,255,0);
		wait(delay);
		CreateShot01(x,y,speed,angle,gra,0);
	}

	task Moon2CreateShot01(x,y,speed,angle,gra,delay)
	{
		wait(delay);
		CreateShot01(x,y,speed,angle,gra,0);
	}

task ShotEffect(x,y,delay,Alpha,R,G,B)
{
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\Light.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, -32, -32);
		ObjEffect_SetVertexXY(obj, 1,32, -32);
		ObjEffect_SetVertexXY(obj, 2, 32, 32);
		ObjEffect_SetVertexXY(obj, 3, -32, 32);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  64, 0);
		ObjEffect_SetVertexUV(obj, 2, 64, 64);
		ObjEffect_SetVertexUV(obj, 3, 0,  64);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}

		Obj_SetPosition(obj,x,y);

		ObjEffect_SetLayer(obj,2);

		let Zangle=rand(0,360);
		ObjEffect_SetAngle(obj,0,0,Zangle);

		let Scale=1.0;
		loop(delay)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=6;
			Scale-=1.0/delay;
			yield;
		}
		Obj_Delete(obj);
}
}
//////////////////////////////////////////////////////////////////////
task shotE
{
SpellDraw(4,6000);
let loopnum=0;
loop(3)
{
	SetAction(ACT_SHOT_A,180);
	MoonFall;
	wait(180);
	SetAction(ACT_SHOT_B,240);
	MoonRain;
	wait(240);
	if(loopnum<2)
	{
	loopnum+=1;
	}
}



	task MoonFall
	{
		loop(3+loopnum)
		{
		let X1=GetClipMinX;
		let Y1=GetClipMinY;
		let X2=GetClipMaxX;
		let Y2=GetClipMinY;
		CentralMoonFallShot(X1,Y1,atan2(GetPlayerY-Y2,GetPlayerX-X1),4);
		wait(20-5*loopnum);
		CentralMoonFallShot(X2,Y2,atan2(GetPlayerY-Y2,GetPlayerX-X2),4);
		//CentralMoonFallShot(X,GetClipMinY,atan2(GetPlayerY-GetClipMinY,GetPlayerX-X),4);
		wait(20-5*loopnum);
		}
	}

	task CentralMoonFallShot(x,y,angle,speed)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 9);
		ObjShot_SetDelay(obj, 0);
		Obj_SetAutoDelete(obj,false);
		Obj_SetAlpha(obj,0);
		Obj_SetCollisionToPlayer(obj,false);

		let moonangle=rand(0,360);
		let moonR1=80;
		let moonR2=90;
		let moonR3=120;

		CentralMoonFallShot2(obj,moonR3,moonR2,moonangle);

		ascent(let i in -15..15)
		{
			MoonFallShot1(obj,moonR1,i*6,0,moonangle);
		}
		loop(300)
		{

		yield;
		}
		Obj_Delete(obj);
	}

	task CentralMoonFallShot2(Cobj,moonR1,moonR2,moonangle)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, Obj_GetX(Cobj)+moonR2*cos(180+moonangle),Obj_GetY(Cobj)+moonR2*sin(180+moonangle));
	//	Obj_SetSpeed(obj, speed);
	//	Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 9);
		ObjShot_SetDelay(obj, 0);
		Obj_SetAutoDelete(obj,false);
		Obj_SetAlpha(obj,0);
		Obj_SetCollisionToPlayer(obj,false);

		ascent(let i in -11..11)
		{
			MoonFallShot1(obj,moonR1,i*4.0,0,moonangle);
		}
		while(!Obj_BeDeleted(Cobj))
		{
			Obj_SetPosition(obj, Obj_GetX(Cobj)+moonR2*cos(180+moonangle),Obj_GetY(Cobj)+moonR2*sin(180+moonangle));
			moonangle+=2;
			yield;
		}
		Obj_Delete(obj);
	}


	task MoonFallShot1(Cobj,moonR,angle,dis,moonangle)
	{
		let obj = Obj_Create(OBJ_SHOT);
	//	Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 243);
		ObjShot_SetDelay(obj, 10);
		Obj_SetAutoDelete(obj,false);

		Obj_SetPosition(obj, Obj_GetX(Cobj)+moonR*cos(angle+moonangle),Obj_GetY(Cobj)+moonR*sin(angle+moonangle));
//ShotEffect(Obj_GetX(obj),Obj_GetY(obj),10,100,255,255,0);
		while(!Obj_BeDeleted(Cobj))
		{
			Obj_SetPosition(obj, Obj_GetX(Cobj)+moonR*cos(angle+moonangle),Obj_GetY(Cobj)+moonR*sin(angle+moonangle));
			angle+=2;
			yield;
		}
		Obj_Delete(obj);
	}

	task MoonRain
	{
		RainLaser(GetCenterX-80,GetClipMinY+32);
		wait(15);
		RainLaser(GetCenterX+80,GetClipMinY+32);
	}

	task RainLaser(x,y)
	{
	let speed=4;
	let waittime=35;
	loop(5)
	{
		let angle=rand(0,360);
		ascent(let i in 0..360/(8-loopnum*2))
		{
		CreateLaser01(x,y,speed,angle+i*(8-loopnum*2),120,7,243,5);
		}
		wait(waittime);
		speed+=0.5;
		waittime-=1;
	}
	}
}
///////////////////////////////////////////////////////////////////////////
task shotA
{
SpellDraw(5,6000);
let loopnum=0;
loop(2)
{
	SetAction(ACT_SHOT_A,240);
	MoonShot;
	wait(300);
	SetAction(ACT_SHOT_B,330);
	MoonCycle;
	wait(420);
}

task MoonShot
{
	MoonLightShot1(GetCenterX-120,GetClipMinY+64,1);
	MoonLightShot2(GetCenterX+120,GetClipMinY+64,1);
	wait(120);
	MoonLightShot2(GetCenterX-120,GetClipMinY+64,-1);
	MoonLightShot1(GetCenterX+120,GetClipMinY+64,-1);
}

task MoonLightShot1(x,y,dir)
{
	let angle=rand(0,360);
	let r=40;
loop(20)
{
	ascent(let i in 0..24)
	{
	CreateShot01(x+r*cos(angle+i*15),y+r*sin(angle+i*15),2.75,angle+i*15,11,10);
	}
	angle+=3.5*dir;
wait(5);
}
}

task MoonLightShot2(x,y,dir)
{
	let angle=rand(0,360);
	let r=40;
loop(20)
{
	ascent(let i in 0..30)
	{
	CreateShot01(x+r*cos(angle+i*12),y+r*sin(angle+i*12),5,angle+i*12,67,10);
	}
wait(5);
angle+=0.5*dir;
}
}

task MoonCycle
{
let dir=rand_int(0,1)*2-1;
	loop(5)
	{
	MoonCycleShot(dir);
	wait(60);
	dir=dir*-1;
	}
}

task MoonCycleShot(dir)
{
		let X=GetX;
		let Y=GetY;
		let ShotX;
		let ShotY;
		let R=80;
		let angle=rand(0,360);
		let shotangle=angle+180;
		loop(30)
		{
			ShotX=X+R*cos(angle);
			ShotY=Y+R*sin(angle);
//ShotEffect(ShotX,ShotY,10,100,255,255,0);
			ascent(let i in 0..3)
			{
				CreateShot01(ShotX,ShotY,3.25,shotangle+i*120,11,10);
			}
			angle+=6*dir;
			shotangle-=6*dir;
		//	R-=2;
			wait(1);
		}
		loop(30)
		{
			ShotX=X+R*cos(angle);
			ShotY=Y+R*sin(angle);
			ascent(let i in 0..3)
			{
				CreateShot01(ShotX,ShotY,3.25,shotangle+i*120,11,10);
			}
			angle+=6*dir;
			shotangle-=6*dir;
		//	R+=2;
			wait(1);
		}
}

}
////////////////////////////////////////////////////////////////////////
task ZakoVanish
{
	wait(300);
	SetCommonData("VanishSignal",true);
}

#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Lunachild.txt"
}

script_enemy Familiar {

    @Initialize {
	SetLife(1);
	SetColor(255,255,127);
	Concentration01(30);
	SetColor(255,255,255);
	T;
    }
    @MainLoop {
	yield;
	}
task T
{
loop(30){yield;}
VanishEnemy;
}

}


#include_script ".\..\txt/EnemyShotData.txt"
