
#Title[サニー１]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_yuka.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 140;
	let wIni=60;
let TimeCounter=45*60;
let StandardTimeCounter=TimeCounter;
    @Initialize {
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
        SetLife(4000);
	InitializeAction();
	SetEnemyMarker(true);
	BombDamageRate=10;
        TMain;
    }

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

    @DrawLoop {
	DrawBoss( imgBoss );
    }

    @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
		{
			SetCommonDataEx(NsScore,NsAchievement[92],1);
		}
	SetCommonData("VanishSignal",false);
	SetCommonData("TimeBonus",TimeCounter/StandardTimeCounter);
	SetCommonData("BossRate",30000);
    }

    // メインタスク
task TMain 
{
	yield;
	GetDamege;
	OutDamageRateZero;
	//Lissajous(255,255,127);
	BossShadowAnimation(imgBoss2,0,0,255,255);
	standBy;
	Collision;
	wait(60);
	Concentration01(30);
	wait(30);
	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
{
	SetAction(ACT_SHOT_A, 60);
	summon;
	wait(90);
	SetAction(ACT_SHOT_A, 360);
	Shot1;

	wait(560);

	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	let time=210;
	DamageRate=80;
	BombDamageRate=100;
SetAction(ACT_SHOT_B, 3600);
SpellDraw(30,3600);
loop
{
	ascent(i in 0..5)
	{
		YukaShot(GetX,GetY,0,angle+i*72,225.5+dir*0.5,5,dir);
	}
	angle=rand(0,360);
	dir*=-1;
	wait(time);
	time-=10;
}

/*
	loop
	{
	ascent(j in 0..5)
	{
		let X=GetX+(50+Radius*cos(RadiusAngle))*cos(angle+j*72);
		let Y=GetY+(50+Radius*cos(RadiusAngle))*sin(angle+j*72);
		ascent(i in 0..5)
		{
			CreateShot01(X,Y,3,angle/7+i*72,42,2);
		}
	}

		angle+=10;
		RadiusAngle+=3;
		if(cos(RadiusAngle)<0){RadiusAngle+=180;}
		wait(5);
	}
*/

	task YukaShot(x,y,speed,angle,gra,delay,dir)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, gra);
		ObjShot_SetDelay(obj, delay);
		Obj_SetAutoDelete(obj,false);
		Obj_SetAlpha(obj,0);
		Obj_SetCollisionToPlayer(obj,false);
		ObjShot_SetBombResist(obj,true);

		let Radius=120;
		let RadiusAngle=90;
		let Maxspeed=2;
		let count=0;

		loop(240)
		{
			ObjShot_SetDelay(obj, 10);
			Obj_SetX(obj,x+Radius*cos(RadiusAngle)*cos(angle));
			Obj_SetY(obj,y+Radius*cos(RadiusAngle)*sin(angle));
			if(count%10==0)
			{
			ascent(i in 0..5)
			{
				CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2.5,angle+i*72+10,42.5+0.5*dir,0);
			}
			}
			RadiusAngle+=0.75;
			angle+=3*dir;
			count+=1;
			yield;
		}
		Obj_Delete(obj);
	}


	task Shot1
	{
		let speed=2.2;
		let angle=rand(0,360);
		loop(85)
		{
		ascent(i in 0..12)
		{
			let sangle=angle+i*30;
			CreateShot01(GetX+30*cos(sangle),GetY+30*sin(sangle),speed,sangle,42,5);
		}
		speed+=0.04;
		angle+=7*1.25;
		wait(4);
		}
	}
	task summon
	{
        CreateEnemyFromScript("Familiar", GetX, GetY,0, 0, 0);
        CreateEnemyFromScript("Familiar", GetX, GetY,0, 0, 1);
        CreateEnemyFromScript("Familiar", GetX, GetY,0, 0, 2);
        CreateEnemyFromScript("Familiar", GetX, GetY,0, 0, 3);
	}
}
//////////////////////////////////////////////////////////////////////
task shotE
{
	SetAction(ACT_SHOT_A, 60);
	summon;
	wait(60);
	SetAction(ACT_SHOT_A, 360);
	Shot1;

	wait(560);

	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	let time=180;
	DamageRate=80;
	BombDamageRate=100;

	SetAction(ACT_SHOT_B, 3600);
SpellDraw(31,3600);
	Shot2;
loop
{
	ascent(i in 0..18)
	{
		YukaShot(GetX,GetY,0,angle+i*20,225.5+dir*0.5,5,dir);
	}
	angle=rand(0,360);
	dir*=-1;
	wait(time);
	time-=5;
}

	task YukaShot(x,y,speed,angle,gra,delay,dir)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 43);
		ObjShot_SetDelay(obj, delay);
		Obj_SetAutoDelete(obj,false);
		Obj_SetAlpha(obj,0);
		Obj_SetCollisionToPlayer(obj,false);
		ObjShot_SetBombResist(obj,true);

		let Radius=60;
		let RadiusAngle=90;
		let speed=2;
		let count=0;

		loop(60)
		{
			ObjShot_SetDelay(obj, 10);
			Obj_SetX(obj,x+Radius*cos(RadiusAngle)*cos(angle));
			Obj_SetY(obj,y+Radius*cos(RadiusAngle)*sin(angle));
			RadiusAngle+=1.5;
			angle+=0.5*dir;
			count+=1;
			yield;
		}

		let sangle=0;
		loop(90)
		{
			ObjShot_SetDelay(obj, 10);
			Obj_SetX(obj,x+Radius*cos(RadiusAngle)*cos(angle));
			Obj_SetY(obj,y+Radius*cos(RadiusAngle)*sin(angle));
			if(count%5==0)
			{
				CreateShot01(Obj_GetX(obj),Obj_GetY(obj),4.5,180+angle+sangle,43,0);
			}
			sangle-=0.9*dir;
			RadiusAngle+=0.2;
			angle+=0.5*dir;
			count+=1;
			yield;
		}
		Obj_Delete(obj);
	}

	task Shot2
	{
		let count=0;
		let angle=GetAngleToPlayer;
		let angle2=angle;
		loop
		{
			if(count%20==0)
			{
				S1;
			}
			angle+=0.5;
			angle2-=0.5;
			count+=1;
			yield;
		}

		task S1
		{

			loop(5)
			{
				ascent(i in 0..8)
				{
				CreateShot01(GetX,GetY,2,angle+i*45,41,5);
				CreateShot01(GetX,GetY,2,angle2+i*45,41,5);
				}
				wait(3);
			}
		}
	}

	task Shot1
	{
	let dir=rand_int(0,1)*2-1;
loop(4)
{
	let angle=GetAngleToPlayer;
	let way=5;
	loop(10)
	{
	ascent(i in -1..2)
	{
		CreateShot01(GetX,GetY,5,angle+15*i,10,5);
	}
	angle+=dir;
	wait(3);
	}
	dir*=-1;
	wait(60);
}
	}

	task FlowerShot(x,y,angle,dir)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
	//	Obj_SetSpeed(obj, speed);
	//	Obj_SetAngle(obj, angle);
	//	ObjShot_SetGraphic(obj, gra);
	//	ObjShot_SetDelay(obj, delay);
		Obj_SetAutoDelete(obj,false);
		Obj_SetAlpha(obj,0);
		Obj_SetCollisionToPlayer(obj,false);
		ObjShot_SetBombResist(obj,true);

		let Radius=0;
		let RadiusAngle=90;
		let speed=2;
		let count=0;

		loop(40)
		{
			ObjShot_SetDelay(obj, 10);
			Obj_SetX(obj,x+Radius*cos(angle));
			Obj_SetY(obj,y+Radius*sin(angle));
			if(count%3==0)
			{
			ascent(i in 0..1)
			{
				CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2.5*0,angle+30,42.5+0.5*dir,0);
			}
			}
			Radius+=3.1;
			angle+=2.75*dir;
			count+=1;
			yield;
		}
		Obj_Delete(obj);
	}

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

}
///////////////////////////////////////////////////////////////////////////
task shotA
{
	SetAction(ACT_SHOT_A, 30);
	summon;

	wait(680);

	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	let time=210;
	DamageRate=80;
	BombDamageRate=100;
	SetAction(ACT_SHOT_B, 3600);
SpellDraw(32,3600);
	loop
	{
	Shot2;
	wait(60);
	Shot3;
	wait(60);
	}

	task Shot2
	{
		let angle=rand(0,360);
		let angle2=rand(0,360);
		ascent(i in 0..48)
		{
		YukaShot(GetX,GetY,5,angle+i*9,angle2-6*i,9,5,1);
		}
	}

	task Shot3
	{
		let angle=rand(0,360);
		let angle2=rand(0,360);
		ascent(i in 0..48)
		{
		YukaShot(GetX,GetY,3,angle+i*9,angle2-6*i,10,5,1);
		}
	}

	task YukaShot(x,y,speed,angle,angle2,gra,delay,dir)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
		Obj_SetSpeed(obj, speed);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, gra);
		ObjShot_SetDelay(obj, delay);
	//	Obj_SetAutoDelete(obj,false);
		Obj_SetCollisionToPlayer(obj,false);
		ObjShot_SetBombResist(obj,true);
		let MaxSpeed=speed;
		//while(!Obj_BeDeleted(obj))
		loop(60)
		{
			speed-=MaxSpeed/60;
			Obj_SetSpeed(obj, speed);
			yield;
		}
		ascent(i in 0..6)
		{
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2.75,angle2+i*60,gra+32,5);
		}
		Obj_Delete(obj);

	task FShot
	{
	wait(delay);
	while(!Obj_BeDeleted(obj))
	{
		//let angle=rand(0,360);
		ascent(i in 0..1){
			CreateShotA(1, Obj_GetX(obj), Obj_GetY(obj), 0);
			SetShotDataA(1, 0, 0,angle+i*72+80*dir, 0, 0.01, 10, 41);
			FireShot(1);
		}
		wait(8);
	}
	}

	}

	task FlowerShot(x,y,angle,dir)
	{
		let obj = Obj_Create(OBJ_SHOT);
		Obj_SetPosition(obj, x,y);
	//	Obj_SetSpeed(obj, speed);
	//	Obj_SetAngle(obj, angle);
	//	ObjShot_SetGraphic(obj, gra);
	//	ObjShot_SetDelay(obj, delay);
		Obj_SetAutoDelete(obj,false);
		Obj_SetAlpha(obj,0);
		Obj_SetCollisionToPlayer(obj,false);
		ObjShot_SetBombResist(obj,true);

		let Radius=0;
		let RadiusAngle=90;
		let speed=2;
		let count=0;

		loop(40)
		{
			ObjShot_SetDelay(obj, 10);
			Obj_SetX(obj,x+Radius*cos(angle));
			Obj_SetY(obj,y+Radius*sin(angle));
			if(count%3==0)
			{
			ascent(i in 0..1)
			{
				CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2.5*0,angle+30,42.5+0.5*dir,0);
			}
			}
			Radius+=3.1;
			angle+=2.75*dir;
			count+=1;
			yield;
		}
		Obj_Delete(obj);
	}

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

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

#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_sunnymilk.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(250);
        SetDamageRateEx(100,100,0,0);
	TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 36);
        MSDSetCollisionB(GetX, GetY, 12);
        yield;

    }

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

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,10,0.3);
	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(10)
		{
		FinalizeItemSet(1);
		}
	}
        }

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	ZakoEnemyLifeDisplay;
	move;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
	ZakoEffect(255,0,0);

    }

task move
{
	alternative(num)
	case(0){SetMovePosition02(130, -10, 30);}
	case(1){SetMovePosition02(-130, -10, 30);}
	case(2){SetMovePosition02(-70, -50, 30);}
	case(3){SetMovePosition02(70, -50, 30);}
	wait(390);
	SetAngle(90);
	let speed=0;
	loop
	{
		SetSpeed(speed);
		speed+=0.1;
		yield;
		if(GetY>GetClipMaxY+32){VanishEnemy;}
	}

}

task shotM
{
wait(30);
loop(3)
{
loop(10)
{
let angle=GetAngleToPlayer;
ascent(let i in -1..2)
{
CreateShot01(GetX,GetY,5,GetAngleToPlayer+i*15,14,5);
}
wait(5);
}
wait(70);
}
wait(30);
ascent(let j in 0..15)
{
	let angle=rand(0,360);
		ascent(i in 0..5){
			CreateShotA(1, GetX, GetY, 5);
			SetShotDataA(1, 0, 1.4,angle+i*72, 0, -0.1, 0, 41);
			SetShotDataA(1, 60, 0,angle+i*72, 0, -0.01, -3.0, 41);
			FireShot(1);
		}
	wait(6);
}

}
/////////////////////////////////////////////////////////
task shotE
{
wait(30+num*15);
loop(4)
{
let dir=rand_int(0,1)*2-1;
let angle=rand(80,100);
ascent(j in 0..5)
{
	ascent(i in -4..5)
	{
		CreateShot01(GetX,GetY,3,angle+i*15,45,5);
	}
		wait(3);
}
wait(60);

}
wait(90-num*15);
ascent(let j in 0..18)
{
	let angle=rand(0,360);
	//if(num<=1){angle=GetAngleToPlayer+180;}
		ascent(i in 0..5){
			CreateShotA(1, GetX, GetY, 5);
			SetShotDataA(1, 0, 1.4,angle+i*72, 0, -0.1, 0, 41);
			SetShotDataA(1, 60, 0,angle+i*72, 0, -0.01, -3.0, 41);
			FireShot(1);
		}
	wait(5);
}

}
////////////////////////////////////////////////////////////
task shotA
{
wait(30);
	Shot1;
	Shot2;
	Shot3;
	task Shot1
	{
	let angle=0;
	let anglewide=0;
	loop(75)
	{
	angle=atan2(GetPlayerY-GetCommonData("BossY"),GetPlayerX-GetCommonData("BossX"))+rand(-anglewide,anglewide);
	CreateShot01(GetX,GetY,3,angle,9,5);
	anglewide+=0.5;
	wait(4);
	}
	}

	task Shot2
	{
	wait(30+num*30);
	loop(2)
	{
		loop(5)
		{
		ascent(i in -3..4)
		{
			CreateShot01(GetX,GetY,5,GetAngleToPlayer+i*10,10,5);
		}
		wait(3);
		}
	wait(105);
	}
wait(120-num*30);
ascent(let j in 0..18)
{
	let angle=rand(0,360);
		ascent(i in 0..5){
			CreateShotA(1, GetX, GetY, 5);
			SetShotDataA(1, 0, 1.4,angle+i*72, 0, -0.1, 0, 41);
			SetShotDataA(1, 60, 0,angle+i*72, 0, -0.01, -3.0, 41);
			FireShot(1);
		}
	wait(5);
}

}

	task Shot3
	{
	while(GetY<GetClipMaxY){yield;}
	ascent(i in 0..36)
	{
		CreateShot01(GetX,GetY,1.5,GetAngleToPlayer+i*10,9,15);
	}

	}
}

#include_function ".\..\txt/StageEnemydata.txt"
}

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