
#Title[ルナチャ通常]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "ルナチャ通常";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_lunachild.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
let TimeCounter=25*60;
let StandardTimeCounter=TimeCounter;
let VanishLife=1000;
    @Initialize {
        SetTimer(TimeCounter/60);
        SetLife(2000);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        SetCollisionA(GetX, GetY, 48);
	MSDSetCollisionB(GetX(),GetY(),8);
        yield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @Finalize {
		if(!IsTimeOut)
		{
		SetCommonData("DeleteBulletNum",BulletNum);
		SetCommonData("DeleteBulletX",GetX);
		SetCommonData("DeleteBulletY",GetY);
		}

	SetCommonData("VanishSignal",false);
       DeleteGraphic(imgBoss);
	SetCommonData("TimeBonus",TimeCounter/StandardTimeCounter);
	SetCommonData("BossRate",15000);
    }

    // メインタスク
task TMain 
{
	yield;
	GetDamege;
	OutDamageRateZero;
	Lissajous(255,255,127);
	BossShadowAnimation(imgBoss,0,255,255,127);
	standBy;
//	summon;
	wait(90);
	TMove;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}

	ZakoVanish;
}

task summon
{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 0, 1);
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 0, -1);
}

task TMove
{
loop
{
//	SetMovePosition03(GetX+rand(-10,10), GetY+rand(-10,10), 20,5);
	wait(60);
}
}

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

////////////////////////////////////////////////////////////
task shotM
{
let num=0;
loop(2)
{
	MoonShot(num);
	wait(240+30*num);
	MoonShot2(num);
	wait(240);
	if(num<3)
	{
	num+=1;
	}
}

	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(15)
		{
			CreateShot01(X2+R2*cos(angle2),Y2+R2*sin(angle2),rand(1.5,2.5),GetAngleToPlayer+rand(-15,15),11,10);
			CreateShot01(X2-R2*cos(angle2),Y2+R2*sin(angle2),rand(1.5,2.5),GetAngleToPlayer+rand(-15,15),11,10);
			angle1+=120/15;
			angle2+=144/15;
			wait(1);
		}
		loop(15)
		{
			CreateShot01(X1+R1*cos(angle1),Y1+R1*sin(angle1),rand(1.5,2.5),GetAngleToPlayer+rand(-15,15),11,10);
			CreateShot01(X1-R1*cos(angle1),Y1+R1*sin(angle1),rand(1.5,2.5),GetAngleToPlayer+rand(-15,15),11,10);
			angle1-=120/15;
			angle2-=144/15;
			wait(1);
		}
		ascent(let i in -3..4)
		{
			CreateShot01(GetX,GetY,3,GetAngleToPlayer+i*30,27,10);
		}
	wait(30);
	}
	}



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

	loop(1)
	{
		loop(15)
		{
			ascent(let i in -(1+loopnum)..(2+loopnum))
			{
			CreateShot01(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);
	angle=GetAngleToPlayer+60;
	shotangle=GetAngleToPlayer-15;
		loop(15)
		{
			ascent(let i in -(2+loopnum)..(3+loopnum))
			{
			CreateShot01(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);
	angle=GetAngleToPlayer-60;
	shotangle=GetAngleToPlayer+15;
		loop(15)
		{
			ascent(let i in -(3+loopnum)..(4+loopnum))
			{
			CreateShot01(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);
	angle=GetAngleToPlayer+60;
	shotangle=GetAngleToPlayer-15;
		loop(15)
		{
			ascent(let i in -(4+loopnum)..(5+loopnum))
			{
			CreateShot01(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);
	angle=GetAngleToPlayer-60;
	shotangle=GetAngleToPlayer+15;
		loop(15)
		{
			ascent(let i in -(5+loopnum)..(6+loopnum))
			{
			CreateShot01(X+R*cos(angle),Y+R*sin(angle),7+loopnum,shotangle+18*i,11,10);
			}
			angle+=120/15;
			shotangle-=30/15;
			wait(1);
		}
	}
	}

}
//////////////////////////////////////////////////////////////////////
task shotE
{
let loopnum=0;
loop(3)
{
	MoonFall;
	wait(180);
	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);
		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
{
let loopnum=0;
loop(2)
{
	MoonShot;
	wait(300);
	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..30)
	{
	CreateShot01(x+r*cos(angle+i*12),y+r*sin(angle+i*12),3,angle+i*12,11,10);
	}
	angle+=3*dir;
wait(5);
}
}

task MoonLightShot2(x,y,dir)
{
	let angle=rand(0,360);
	let r=40;
loop(20)
{
	ascent(let i in 0..36)
	{
	CreateShot01(x+r*cos(angle+i*10),y+r*sin(angle+i*10),5,angle+i*10,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);
			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 {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
    @Initialize {
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(300);
        SetDamageRateEx(100,100,0,0);
        SetTexture(imgFam);
        setGraphic;
	TMain;
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
        SetCollisionA(GetX, GetY, 48);
        SetCollisionB(GetX, GetY, 8);
        yield;
    }

    @DrawLoop {
     //  DrawGraphic(GetX, GetY);
    }

        @Finalize
        {
	if(GetEnemyLife>0)
	{
		loop(10)
		{
		FinalizeItemSet(1);
		}
	}
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{

		}
		case("Extream")
		{
			if(!BeVanished && GetEnemyLife>0)
			{
			SetCommonData("DeleteBulletNum",BulletNum);
			SetCommonData("DeleteBulletX",GetX);
			SetCommonData("DeleteBulletY",GetY);
			DeleteEnemyShotToItem(SHOT);
			}
		}
		case("Apocalypse")
		{
			if(!BeVanished && GetEnemyLife>0)
			{
			SetCommonData("DeleteBulletNum",BulletNum);
			SetCommonData("DeleteBulletX",GetX);
			SetCommonData("DeleteBulletY",GetY);
			DeleteEnemyShotToItem(SHOT);
			}
		}
        }

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	ZakoEffect(255,0,0);
	ZakoEnemyLifeDisplay;
	move;

	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}

    }

task move
{
	//SetMovePosition03(100*num, 0, 5,5);
	//wait(60);
	let X=100*num;
	let Y=-4;
	loop
	{
	SetX(X);
	SetY(Y);
	yield;
	}
}

task shotM
{
wait(200);
loop
{
loop(48)
{
CreateShot01(GetX,GetY,3,rand(80,100),14,5);
wait(5);
}
wait(80);
let angle=GetAngleToPlayer;
ascent(let i in 0..18)
{
	CreateShot01(GetX,GetY,4,angle+i*20,14,5);
	CreateShot01(GetX,GetY,3.75,angle+i*20,14,5);
	CreateShot01(GetX,GetY,3.5,angle+i*20,14,5);
}
wait(60);
}
}
/////////////////////////////////////////////////
task shotE
{
wait(200);
loop
{
loop(8)
{
CreateShot01(GetX,GetY,2,GetAngleToPlayer+rand(-15,15),14,5);
wait(30);
}
wait(80);
loop(3)
{
let angle=GetAngleToPlayer;
ascent(let i in 0..18)
{
	CreateShot01(GetX,GetY,4,angle+i*20,14,5);
}
wait(10);
}
wait(30);
}
}
////////////////////////////////////////////////////
task shotA
{
let dir=1;
wait(200);
loop
{
loop(60)
{
CreateShot01(GetX,GetY,3,rand(60,120),14,5);
wait(4);
}
wait(80);
let angle=GetAngleToPlayer;

ascent(let i in 0..18)
{
	ascent(let j in 0..5)
	{
	CreateShot01(GetX,GetY,4-0.25*j,angle+i*20+dir*j,14,5);
	}
}
dir=dir*-1;
wait(60);
}
}
    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\..\txt/StageEnemydata.txt"
}

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