
#Title[大妖精通常]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_alice.png"; 
   let imgNuclear =csd~"..\img\s_shot.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let Step2=false;
	let wIni=60;
let TimeCounter=164*60;
let StandardTimeCounter=TimeCounter;
let imgBorderLine = GetCurrentScriptDirectory~"..\img\SampleEC01a.png";
    @Initialize {
	SetCommonData("BombOffset",true);
	SetCommonData("SetBossLifeArray",[0]);
	SetCommonData("LifeBerReproduction",true);
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
	SetShotAutoDeleteClip(16,16,16,32);
        SetLife(13500);
	InitializeAction();
	SetEnemyMarker(true);
	SetX(GetCommonDataDefault("BossX",0));
	SetY(GetCommonDataDefault("BossY",0));
        TMainGrobal;
    }

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

    @DrawLoop {
//DrawText(GetLife,120,382,12,255);//起動時間の表示
	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);
		}

	SetCommonData("VanishSignal",false);
	SetCommonData("TimeBonus",TimeCounter/StandardTimeCounter);
	SetCommonData("BossRate",500000);
    }

    // メインタスク
task TMainGrobal
{
	yield;
	GetDamege;
	OutDamageRateZero;
	Collision;
	//Lissajous(0,250,154);
	BossShadowAnimation(imgBoss2,0,255,255,0);
	standBy;
	BombOffSet;
	BombBarrier;
	shotA;

}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(GetCenterX, GetCenterY, 20,5);
	wait(60);
//	summon;
	Concentration01(30);
	//Concentration03(GetX,GetY,60,0,64,255);
}

task Collision
{
	SetCommonData("NoCollision",true);
	wait(120);
	SetCommonData("NoCollision",false);

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

task BombOffSet
{
loop
{
	BombDamageRate=0;
	while(!GetCommonDataDefault("OnDtypeBomb",false)){yield;}
	if(GetCommonDataDefault("OnDtypeBomb",false))
	{
		AchievementSet(86);
		BombDamageRate=100;
		ArtfulSacrifice;
		SpellDraw(45,135);
	}
	while(GetCommonDataDefault("OnDtypeBomb",false)){yield;}
}
}


task ArtfulSacrifice
{
	let OpX=[GetPlayerX-30,GetPlayerX+30,GetPlayerX-60,GetPlayerX+60];
	let OpY=[GetPlayerY+5,GetPlayerY+5,GetPlayerY+10,GetPlayerY+10];
	let TargetX=GetCommonDataDefault("TargetX",[0,0,0,0]);
	let TargetY=GetCommonDataDefault("TargetY",[0,0,0,0]);
	let ShotAngle=[267.5,272.5,265,275,260,280];
	ascent(i in 0..4)
	{
	ArtfulSacrificeEffect(i);
	}


task ArtfulSacrificeEffect(num)
{
	//let ShotAngleAdjust=atan2(TargetY[num]-GetPlayerY,TargetX[num]-GetPlayerX);
	let BombStartX=OpX[num];
	let BombEndX=TargetX[num];
	let BombStartY=OpY[num];
	let BombEndY=TargetY[num];

	if(TargetX[num]==-1)
	{
		BombEndX=OpX[num]+300*cos(ShotAngle[num]);
	}
	if(TargetY[num]==-1)
	{
		BombEndY=OpY[num]+300*sin(ShotAngle[num]);
	}

	let EndX=(BombEndX+BombStartX)/2;
	let EndY=(BombEndY+BombStartY)/2;

	let obj = Obj_Create(OBJ_EFFECT);
	ObjEffect_SetTexture(obj, imgBoss);
	ObjEffect_SetRenderState(obj, ADD);
	ObjEffect_SetLayer(obj,3);
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	ObjEffect_CreateVertex(obj, 4);

	ObjEffect_SetVertexXY(obj, 0, -16, -16);
	ObjEffect_SetVertexXY(obj, 1, 16,  -16);
	ObjEffect_SetVertexXY(obj, 2, 16, 16);
	ObjEffect_SetVertexXY(obj, 3,  -16,  16);

	ObjEffect_SetVertexUV(obj, 0,  768,  0);
	ObjEffect_SetVertexUV(obj, 1,  800, 0);
	ObjEffect_SetVertexUV(obj, 2, 800,  32);
	ObjEffect_SetVertexUV(obj, 3, 768, 32);

	let speed=15;
	let angle=atan2(EndY-GetY,EndX-GetX);
	Obj_SetSpeed(obj,speed);
	Obj_SetAngle(obj,angle);
	ObjEffect_SetScale(obj,1.5,1.5);
	Obj_SetPosition(obj, GetX, GetY);
	let count=0;
	let Zangle=0;
	while(!Obj_BeDeleted(obj))
	{
		ObjEffect_SetAngle(obj,0,0,Zangle);
		Zangle+=30;
	//	if(TargetX[num]==-1 && count>=10){break;}
		if(count%3==0)
		{
	//	BorderEffect(Obj_GetX(obj),Obj_GetY(obj));
		}
		if(((Obj_GetX(obj)-EndX)^2+(Obj_GetY(obj)-EndY)^2)^0.5<=48)
		{
			break;
		}
		if(Obj_GetY(obj)<GetClipMinY)
		{
			break;
		}
		if(Obj_GetY(obj)>GetClipMaxY)
		{
			break;
		}
		count+=1;
		yield;
	}
	Border(Obj_GetX(obj),Obj_GetY(obj));
	DollExplode(Obj_GetX(obj),Obj_GetY(obj));
	Obj_Delete(obj);
}

task Border(BombX,BombY)
{
let r1=-25;
let r2=25;
let angle=0;
let Alpha=100;
	loop(15)
	{
		BorderEffect(BombX,BombY,r1,r2,angle,Alpha);
		if(r1<45)
		{
			r1+=3*4;
			r2+=3*4;
		}
		angle+=8;
		wait(4);
	}
	loop(15)
	{
		BorderEffect(BombX,BombY,r1,r2,angle,Alpha);
		r1-=0.75*4;
		r2-=0.75*4;
		angle+=8;
		Alpha-=100/60;
		wait(4);
	}
}

task BorderEffect(BombX,BombY,r1,r2,angle,Alpha)
{
		let randvertex=rand_int(0,5);
		let VertexNum=16;
		let Radius=[r1,r2];
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,imgBorderLine);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj,VertexNum);
		ascent(let i in 0+randvertex..VertexNum+randvertex)
		{
			ObjEffect_SetVertexXY(obj, i-randvertex, Radius[i%2]*cos(360/(VertexNum-2)*i), Radius[i%2]*sin(360/(VertexNum-2)*i));
		}
		ascent(let i in 0+randvertex..VertexNum+randvertex)
		{	
			ObjEffect_SetVertexUV(obj, i-randvertex,  256/(VertexNum)*i,  16*(i%2));
		}


		ObjEffect_SetLayer(obj,3);

		let Scale=1;
		let Zangle=0;
		ObjEffect_SetScale(obj,Scale,Scale);
		Obj_SetPosition(obj,BombX,BombY);
	//	let Alpha=100;
		//let angle=0;

		let StandardX=GetCenterX;
		let StandardY=GetCenterY+32;

		loop(2)
		{
		if(r1<40)
		{
			r1+=2.0;
			r2+=2.0;
			Radius=[r1,r2];
		}
		ascent(let i in 0..VertexNum)
		{
			ObjEffect_SetVertexXY(obj, i, Radius[i%2]*cos(360/(VertexNum-2)*i+angle), Radius[i%2]*sin(360/(VertexNum-2)*i+angle));
		}
		ascent(let i in 0..VertexNum)
		{			
			ObjEffect_SetVertexColor(obj, i,Alpha,255,0,0);
		}
		ObjEffect_SetScale(obj,Scale,Scale);
		angle+=2;
		Alpha-=20;
		Scale+=0.01;
		yield;
		}
		Obj_Delete(obj);
}

task DollExplode(x,y)
{
		let sc=0.0;

  		let obj = Obj_Create(OBJ_EFFECT);
		Obj_SetPosition(obj,x,y);
		ObjEffect_SetTexture(obj,imgNuclear);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_SetScale(obj, sc,sc);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -128, -128);
		ObjEffect_SetVertexXY(obj, 1,  128, -128);
		ObjEffect_SetVertexXY(obj, 2,  128,  128);
		ObjEffect_SetVertexXY(obj, 3, -128,  128);
		
		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128,  128);
		ObjEffect_SetVertexUV(obj, 3, 0, 128);

		ObjEffect_SetLayer(obj,5);

		loop(90)
		{	
			if(sc<0.75)
			{
			sc+=0.75/15;
			}
		//	Obj_SetPosition(obj,GetX,GetY);
			ObjEffect_SetScale(obj, sc,sc);
			wait(1);
		}
		loop(30)
		{	
			if(sc>0)
			{
			sc-=0.75/30;
			}
		//	Obj_SetPosition(obj,GetX,GetY);
			ObjEffect_SetScale(obj, sc,sc);
			wait(1);
		}
}
}


task BombBarrier
{
loop
{
	//while(!OnBomb || GetTimeOfPlayerInvincibility==0){yield;}
	while( GetTimeOfPlayerInvincibility==0){yield;}
	DamageRate=0;
	BombDamageRate=0;
	BarrierEffect(1);
	BarrierEffect(0);	
	//while(OnBomb || GetTimeOfPlayerInvincibility>0){yield;}
	while(GetTimeOfPlayerInvincibility>0){yield;}
	wait(30);
	DamageRate=100;
	BombDamageRate=100;
}

task BarrierEffect(type)
{
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\CircleLine.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -64, -64);
		ObjEffect_SetVertexXY(obj, 1,64,  -64);
		ObjEffect_SetVertexXY(obj, 2,64, 64);
		ObjEffect_SetVertexXY(obj, 3,  -64,  64);
		
		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128, 128);
		ObjEffect_SetVertexUV(obj, 3, 0, 128);

		let Alpha=10;
		let R=255;let G=255;let B=255;

		alternative(GetPlayerInfo(PLAYER_SPEED_HIGH))
		case(4){R=100;G=100;B=255;}
		case(4/2){R=100;G=100;B=255;}
		case(5/2){R=255;G=100;B=100;}
		case(5){R=255;G=100;B=100;}
		case(5.5){R=255;G=100;B=255;}
		case(5.5/5){R=255;G=100;B=255;}
		case(4.5){R=50;G=205;B=50;}
		case(4.5/2){R=50;G=205;B=50;}

		let color;
		color=AnimeHueDifine(GlobalHueCount);
		R=color[0];G=color[1];B=color[2];
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}

		ObjEffect_SetLayer(obj,4);

		let X=GetCenterX;
		let Y=GetCenterY;
		Obj_SetPosition(obj,GetX,GetY);

		let Scale=0;

		let Xangle=0;
		let Yangle=0;
		let Zangle=0;

		if(type)
		{
		}
		else
		{
			Yangle+=90;
		}

		while(OnBomb || GetTimeOfPlayerInvincibility>0)
		{
		color=AnimeHueDifine(GlobalHueCount);
		R=color[0];G=color[1];B=color[2];
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
			Obj_SetPosition(obj,GetX,GetY);
			if(Scale<1)
			{
			Scale+=1/30;
			}
			if(type)
			{
			if(Xangle%90>5 && Xangle%90<85)
			{
			BombEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			}
			}
			else
			{
			if(Yangle%90>5 && Yangle%90<85)
			{
			BombEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			}
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			if(type)
			{
			Xangle+=3;
			}
			else
			{
			Yangle+=3;
			}
			yield;
		}

		loop(30)
		{
		color=AnimeHueDifine(GlobalHueCount);
		R=color[0];G=color[1];B=color[2];
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
			Scale-=1/30;
			BombEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B);
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			if(type)
			{
			Xangle+=3;
			}
			else
			{
			Yangle+=3;
			}
			yield;
		}
		Obj_Delete(obj);
}

task BombEffectBlur(X,Y,Alpha,Scale,Xangle,Yangle,Zangle,R,G,B)
{
		let obj = Obj_Create(OBJ_EFFECT);

		ObjEffect_SetTexture(obj, csd~"..\img\CircleLine.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -64, -64);
		ObjEffect_SetVertexXY(obj, 1,64,  -64);
		ObjEffect_SetVertexXY(obj, 2,64, 64);
		ObjEffect_SetVertexXY(obj, 3,  -64,  64);
		
		ObjEffect_SetVertexUV(obj, 0,  0, 0);
		ObjEffect_SetVertexUV(obj, 1,  128, 0);
		ObjEffect_SetVertexUV(obj, 2, 128, 128);
		ObjEffect_SetVertexUV(obj, 3, 0, 128);

		ObjEffect_SetLayer(obj,4);

		Obj_SetPosition(obj,GetX,GetY);

		ObjEffect_SetScale(obj, Scale,Scale);
		ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);

		let BAlpha=Alpha;

		loop(60)
		{
			ascent(i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			ObjEffect_SetAngle(obj,Xangle,Yangle,Zangle);
			ObjEffect_SetScale(obj, Scale,Scale);
			Alpha-=BAlpha/60;
			yield;
		}
		Obj_Delete(obj);
}

}

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


task shotM
{

}
/////////////////////////////////////////////////////////////////////////////
task shotE
{

}
//////////////////////////////////////////////////////////////////////
task shotA
{
loop
{
wait(60);
SetAction(ACT_SHOT_B, 120);
SpellDraw(43,1440);
Summon;
wait(120);
SetAction(ACT_MOVE, 60);
SetMovePosition03(xIni, yIni, 20,5);
wait(120);
Summon2;
wait(1170);
Concentration01(30);
wait(30);
SetMovePosition03(xIni, yIni, 20,5);
SetAction(ACT_SHOT_A, 660);
Shot1;
wait(660);
SetMovePosition03(xIni, yIni, 20,5);
SetAction(ACT_SHOT_B, 60);
Summon3;
wait(120);
loop(4)
{
wait(120);
SetAction(ACT_MOVE, 60);
SetMovePosition03(rand(GetCenterX-120,GetCenterX+120), rand(GetCenterY-60,GetCenterY-150), 20,4);
}
wait(120);
SetAction(ACT_MOVE, 60);
SetMovePosition03(xIni, yIni, 20,5);
wait(120);
SpellDraw(46,960);
Summon4;
wait(960);
SetAction(ACT_MOVE, 60);
SetMovePosition03(xIni, yIni-60, 20,5);
wait(150);
Summon5;
wait(750);
SetAction(ACT_MOVE, 60);
SetMovePosition03(GetCenterX, GetCenterY, 20,5);
wait(60);
}

	task Summon5
	{
	DummyCollision;
	SetAction(ACT_SHOT_B, 60);
	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	ascent(i in -5..6)
	{
        CreateEnemyFromScript("Familiar5", GetX, GetY,
                              0, angle+360/7*i, [i,dir]);
	}	
	}


task DummyCollision
{
SetCommonData("DollX",[0,0,0,0,0,0,0,0,0,0,0]);
SetCommonData("DollY",[0,0,0,0,0,0,0,0,0,0,0]);
yield;
loop(21*24+120+90)
{
let DX=GetCommonData("DollX");
let DY=GetCommonData("DollY");
ascent(i in 0..7)
{
	SetDummySkyCollision(DX[i],DY[i],36);}
yield;
}
}

	task Summon4
	{
	Shot;
	let dir=rand_int(0,1)*2-1;
	loop(4)
	{
	SetAction(ACT_SHOT_B, 60);
	let angle=rand(0,360);
	ascent(i in 0..3)
	{
        CreateEnemyFromScript("Familiar4", GetX, GetY,
                              0, angle+120*i, [i,dir]);
	}
	dir*=-1;
	wait(210);
	}

		task Shot
		{
		wait(60);
		let dir=rand_int(0,1)*2-1;
		let way=30;
		loop(16)
		{
			let Rangle=rand(0,360);
			loop(3)
			{
			ascent(i in 0..way)
			{
			let Sangle=Rangle+90+i*360/way;
			ascent(j in -1..2)
			{
				CreateShotA(0,GetX,GetY,5);
				SetShotDataA(0,0,3-0.393*absolute(j), Sangle+5*j,0,-0.05+0.00655*absolute(j),-5,83);
				//SetShotDataA(0,60,NULL,90+i*18+5*j+0+180+30,0,0.05-0.005*absolute(j),5+0.05*absolute(j),83);
				SetShotDataA(0,60,NULL,Sangle+180+60*dir,0,0.06-0.00025*absolute(j)*0,6+0.025*absolute(j)*0,83);
				FireShot(0);
			}
			}
			wait(6);
			}
			wait(32);
			dir*=-1;
			way+=1
		}
		}
	}

	task Summon3
	{
	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	ascent(i in 0..7)
	{
        CreateEnemyFromScript("Familiar3", GetX, GetY,
                              0, angle+i*360/7, [i,dir]);
	}
	}

	task Shot1
	{
	let angle=rand(0,360);
	let Wave=30;
	loop(80)
	{
		ascent(i in 0..15)
		{
			CreateShotA(0,GetX,GetY,5);
			SetShotDataA(0,0,5,angle+i*24,0,-0.2,0.2,9);
			SetShotDataA(0,60,NULL,angle+i*24+Wave,0,0.25,6.0,9);
			FireShot(0);

			CreateShotA(0,GetX,GetY,5);
			SetShotDataA(0,0,5,angle+i*24+12,0,-0.2,0.2,14);
			SetShotDataA(0,60,NULL,angle+i*24+Wave+12,0,0.25,6.0,14);
			FireShot(0);

		}
		angle+=1.1;
		Wave+=5;
		wait(7);

	}
	}

	task Summon2
	{
	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	ascent(i in 0..3)
	{
        CreateEnemyFromScript("Familiar2", GetX, GetY,
                              0, angle+i*360/3, [i,dir]);
	}
	wait(240);
	SetAction(ACT_SHOT_A, 60);
	loop(2)
	{
	wait(300);
	SetAction(ACT_SHOT_A, 60);
	}
	}

	task Summon
	{
	let angle=rand(0,360);
	let dir=rand_int(0,1)*2-1;
	ascent(i in 0..16)
	{
        CreateEnemyFromScript("Familiar1", GetX, GetY,
                              0, angle+i*360/16, [i,dir]);
	wait(5);
	}
	}
}

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

script_enemy Familiar1 {
    let csd     = GetCurrentScriptDirectory;
    let imgDoll  = csd ~ "..\lib/dot_alice.png"; 

	let num = GetArgument[0];
	let DollDir=GetArgument[1];
	let color=rand_int(9,15);
	let DollAngle;
    @Initialize {
	BombDamageRate=10;
	InitializeActionWithDoll;
	//SetCoordinateType(COODINATE_TYPE_PARENT);
        SetLife(50000);
        SetDamageRateEx(100,100,0,0);
	TMain;
    }

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

    @DrawLoop {
     DrawDoll( imgDoll, GetX, GetY );
    }

        @Finalize
        {
	SpecialBreak=true;
	MagicCircleBreak(GetX,GetY,1000,0.3);
	}

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
//	ZakoEnemyLifeDisplay;
	move;

	//shotA;

    }

task move
{
	let angle=GetAngle;
	let anglePlus=0;
	let anglePlusAngle=0;
	let dir=DollDir;
	let R1=390;
	let R2=224;
	SetMovePosition03(GetCenterX+R1*cos(GetAngle),GetCenterY+R2*sin(GetAngle),20,4);
	wait(210-num*5);
	shotA;
	//let angle=atan2(GetY-GetCenterY,GetX-GetCenterX);
	loop(240)
	{
		SetX(GetCenterX+R1*cos(angle));
		SetY(GetCenterY+R2*sin(angle));
		SetAngle(angle);
		angle+=anglePlus;
		DollAngle=angle;
		if(anglePlus<0.5)
		{
		anglePlus+=0.0025;
		}
		yield;
	}
	loop(90)
	{
		SetX(GetCenterX+R1*cos(angle));
		SetY(GetCenterY+R2*sin(angle));
		SetAngle(angle);
		angle+=anglePlus;
		DollAngle=angle;
		anglePlus-=0.007;
		yield;
	}
	loop(150)
	{
		SetX(GetCenterX+R1*cos(angle));
		SetY(GetCenterY+R2*sin(angle));
		SetAngle(angle);
		angle+=anglePlus;
		DollAngle=angle;
		if(anglePlus<0.5)
		{
		anglePlus+=0.005;
		}
		yield;
	}
	loop(420)
	{
		SetX(GetCenterX+R1*cos(angle));
		SetY(GetCenterY+R2*sin(angle));
		SetAngle(angle);
		angle+=anglePlus;
		DollAngle=angle;
		if(anglePlus>-0.5)
		{
		anglePlus-=0.00275;
		}
		yield;
	}
	loop(125)
	{
		SetX(GetCenterX+R1*cos(angle));
		SetY(GetCenterY+R2*sin(angle));
		SetAngle(angle);
		angle+=anglePlus;
		DollAngle=angle;
		anglePlus+=0.004;
		yield;
	}
	wait(60);
	//SetMovePosition02(GetCommonData("BossX"),GetCommonData("BossY"),90);
	//wait(90);

	VanishEnemy;

}

////////////////////////////////////////////////////////////
task shotA
{
wait(60);

loop(27)
{
	loop(3)
	{
		if(sin(DollAngle)>0.8)
		{
		ReflectShot(GetX,GetY,2.0,270,9,5);
		}
		else if(sin(DollAngle)<-0.8)
		{
		ReflectShot(GetX,GetY,2.0,90,9,5);
		}

		if(cos(DollAngle)>0)
		{
		ReflectShot(GetX,GetY,2.0,180,9,5);
		}
		if(cos(DollAngle)<0)
		{
		ReflectShot(GetX,GetY,2.0,0,9,5);
		}
	wait(3);
	}
	wait(25);
}

		task ReflectShot(x,y,speed,angle,gra,delay)
		{
			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);
			//ObjShot_SetBombResist(obj,true);
			Obj_SetAutoDelete(obj,false);
	
			let Rcount=1;
			wait(300);
			Obj_Delete(obj);
		}

}

#include_function ".\..\txt/StageEnemydata.txt"
#include_function ".\..\lib/lib_anime_Alice.txt"
#include_function ".\..\lib/lib_anime_doll.txt"
}


script_enemy Familiar2 {
    let csd     = GetCurrentScriptDirectory;
    let imgDoll  = csd ~ "..\lib/dot_alice.png"; 
	let num = GetArgument[0];
	let DollDir=GetArgument[1];
	let color=rand_int(9,15);
	let DollAngle;
    @Initialize {
	BombDamageRate=10;
	InitializeActionWithDoll;
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(100,100,50,0);
	TMain;
    }

    @MainLoop {
      //  SetCollisionA(GetX, GetY, 48);
      //  MSDSetCollisionB(GetX, GetY, 8);
        yield;
    }

    @DrawLoop {
    // DrawDoll( imgDoll, GetX, GetY );
    }

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,1000,0.3);

	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(5)
		{
			FinalizeItemSet(1);
		}
	}
	}

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	//ZakoEnemyLifeDisplay;
	move;

	shotA;

let layer;
loop
{
	if(sin(DollAngle)>0){layer=3;}
	else{layer=1;}
	EffectDrawDoll( imgDoll, GetX, GetY ,layer);
yield;
}
    }

task move
{
	let angle=GetAngle;
	let dir=DollDir;
	let R1=0;
	let R2=0;
	loop(1140)
	{
		if(R1<40)
		{
			R1+=30/30;
			R2+=10/30;
		}
		SetX(R1*cos(angle));
		SetY(R2*sin(angle));
		SetAngle(angle);
		angle+=3;
		DollAngle=angle;
		yield;
	}
	loop(30)
	{
		R1-=40/30;
		R2-=20/30;
		SetX(R1*cos(angle));
		SetY(R2*sin(angle));
		SetAngle(angle);
		angle+=3;
		DollAngle=angle;
		yield;
	}
	VanishEnemy;
}

task shotM
{

}
/////////////////////////////////////////////////////////
task shotE
{
}
////////////////////////////////////////////////////////////
task shotA
{

wait(240);
loop(3)
{
Laser(GetX,GetY,GetPlayerX,GetPlayerY,600,20,60,180,159);
wait(300);
}

task Laser(x,y,Px,Py,length,width,delay,time,gra)
{
	let angle=GetAngleToPlayer;
	let lengthmax=length;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,x,y);
	Obj_SetAngle(obj,angle);
	ObjShot_SetGraphic(obj,gra);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetDelay(obj,delay);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
	let dcount=30;
	let lcount=0;
	loop(delay)
	{
		StarLaserEffect(GetX,GetY,length*lcount/30,width,angle);
		angle=atan2(Py-GetY,Px-GetX);
		Obj_SetAngle(obj,angle);
		Obj_SetPosition(obj,GetX,GetY);
		EffectLaser(x,y,Px,Py,length*lcount/30,width,0,1,gra);
		ObjLaser_SetLength(obj,length*lcount/30);
		if(lcount<30)
		{
		lcount+=1;
		}
	yield;
	}
	EffectLaser(x,y,Px,Py,length,width,0,time-delay,gra);
	loop(time-delay)
	{
		StarLaserEffect(GetX,GetY,length*lcount/30,width,angle);
		angle=atan2(Py-GetY,Px-GetX);
	Obj_SetAngle(obj,angle);
		Obj_SetPosition(obj,GetX,GetY);
		yield;
	}
	Obj_SetCollisionToPlayer(obj,false);
	loop(30)
	{
		StarLaserEffect(GetX,GetY,length*lcount/30,width*dcount/30,angle);
		angle=atan2(Py-GetY,Px-GetX);
		Obj_SetPosition(obj,GetX,GetY);
	Obj_SetAngle(obj,angle);
		EffectLaser(x,y,Px,Py,length,width*dcount/30,0,2,gra);
	ObjLaser_SetWidth(obj,width*dcount/30);
	dcount-=1;
	yield;
	}
	Obj_Delete(obj);
}

task EffectLaser(x,y,Px,Py,length,width,delay,time,gra)
{
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,x,y);
	Obj_SetAngle(obj,atan2(Py-GetY,Px-GetX));
	ObjShot_SetGraphic(obj,gra);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width*rand(0.5,1));
	ObjLaser_SetSource(obj,false);
	ObjShot_SetDelay(obj,delay);
	ObjShot_SetBombResist(obj,true);
	loop(time)
	{
	Obj_SetPosition(obj,GetX,GetY);
	Obj_SetAngle(obj,atan2(Py-GetY,Px-GetX));
	ObjLaser_SetWidth(obj,width*rand(0.5,1));
	yield;
	}
	Obj_Delete(obj);
}

task StarLaserEffect(x,y,length,width,angle)
{
		let imgBer=csd~"..\img\ber.png";
		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBer);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjShot_SetBombResist(obj,true);
		ObjEffect_SetVertexXY(obj, 0, -0, -3);
		ObjEffect_SetVertexXY(obj, 1,length,  -3);
		ObjEffect_SetVertexXY(obj, 2,length, 3);
		ObjEffect_SetVertexXY(obj, 3,  -0,  3);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  228, 27);
		ObjEffect_SetVertexUV(obj, 2, 228, 33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);

		let Alpha=100*width/20;
		let R=255;
		let G=255;
		let B=255;

		R=160;
		G=32;
		B=240;


		ObjEffect_SetLayer(obj,3);
		Obj_SetPosition(obj,x,y);
		Obj_SetAngle(obj,angle);
		ObjEffect_SetAngle(obj,0,0,angle);

		if(GetCommonDataDefault("LightMode_SpecialEffect",0)==1){Obj_Delete(obj);return;}

		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		loop(15)
		{
		//Obj_SetPosition(obj,GetX,GetY);
		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		Alpha-=100/15;
		//if(OnPlayerMissed){Alpha=0;}
		yield;
		}
		Obj_Delete(obj);
}

}

#include_function ".\..\txt/StageEnemydata.txt"
#include_function ".\..\lib/lib_anime_Alice.txt"
#include_function ".\..\lib/lib_anime_doll.txt"
}

script_enemy Familiar3 {
    let csd     = GetCurrentScriptDirectory;
    let imgDoll  = csd ~ "..\lib/dot_alice.png"; 
	let num = GetArgument[0];
	let DollDir=GetArgument[1];
	let color=rand_int(9,15);
	let DollAngle;
    @Initialize {
	BombDamageRate=10;
	InitializeActionWithDoll;
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(100,100,50,0);
	TMain;
    }

    @MainLoop {
    //   SetCollisionA(GetX, GetY, 48);
     //   MSDSetCollisionB(GetX, GetY, 8);
        yield;
    }

    @DrawLoop {
     DrawDoll( imgDoll, GetX, GetY );
    }

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,1000,0.3);

	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(5)
		{
			FinalizeItemSet(1);
		}
	}
	}

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	//ZakoEnemyLifeDisplay;
	move;

	shotA;
    }

task move
{
	let R=0;
	let angle=GetAngle;
	let angleplus=12;
	loop(750)
	{
		SetX(R*cos(angle));
		SetY(R*sin(angle));
		if(R<75)
		{
			R+=1;
			angleplus-=0.10;
		}
		angle+=angleplus;
		yield;
	}
	loop(75)
	{
		SetX(R*cos(angle));
		SetY(R*sin(angle));
		R-=1;
		angle+=angleplus;
		yield;
	}
	VanishEnemy;
}

task shotM
{

}
/////////////////////////////////////////////////////////
task shotE
{

}
////////////////////////////////////////////////////////////
task shotA
{
wait(90);
ShotB;
let Bangle=GetAngleToPlayer;
let Sangle=90;
let SangleTheta=0;
let speed=2;
loop(300)
{
	Bangle=GetAngleToPlayer;
	CreateShot01(GetX,GetY,speed,Bangle+Sangle,9,5);
	Sangle=90*sin(SangleTheta)+rand(-5,5);
	SangleTheta+=11;
	//speed+=0.01;
	wait(2);
}

task ShotB
{
wait(60);
let grad=5;
let dir=DollDir;
let Bangle=0;
let Bdis=400;
let speed=3;
loop(30)
{
loop(7)
{
	let TX=GetCommonData("BossX")+Bdis*cos(Bangle);
	let TY=GetCommonData("BossY")+Bdis*sin(Bangle);
	let angle=atan2(TY-GetY,TX-GetX);
	let dis=((TY-GetY)^2+(TX-GetX)^2)^0.5;
	speed=dis/100;
	//ascent(i in 0..12)
	//{
		CreateShot01(GetX,GetY,speed,angle,14,5);
	//}
Bangle+=360/7;
}

wait(20);
Bangle+=9.3;
}
}

}

#include_function ".\..\txt/StageEnemydata.txt"
#include_function ".\..\lib/lib_anime_Alice.txt"
#include_function ".\..\lib/lib_anime_doll.txt"
}

script_enemy Familiar4 {
    let csd     = GetCurrentScriptDirectory;
    let imgDoll  = csd ~ "..\lib/dot_alice.png"; 
	let num = GetArgument[0];
	let DollDir=GetArgument[1];
	let color=rand_int(9,15);
	let DollAngle;
    @Initialize {
	BombDamageRate=10;
	InitializeActionWithDoll;
	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(100,100,50,0);
	TMain;
    }

    @MainLoop {
    //   SetCollisionA(GetX, GetY, 48);
    //    MSDSetCollisionB(GetX, GetY, 8);
        yield;
    }

    @DrawLoop {
	SetAlpha(180);
     DrawDoll( imgDoll, GetX, GetY );
    }

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,1000,0.3);

	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(5)
		{
			FinalizeItemSet(1);
		}
	}
	}

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	//ZakoEnemyLifeDisplay;
	move;

	shotA;
    }

task move
{
	let angle=GetAngle;
	let R=0;
	loop
	{
		SetX(R*cos(angle));
		SetY(R*sin(angle));
		R+=2;
		angle+=0.66*DollDir;
		SetAngle(angle);
		yield;
	}
}

task shotM
{

}
/////////////////////////////////////////////////////////
task shotE
{

}
////////////////////////////////////////////////////////////
task shotA
{
wait(15);
Shot;


task Shot
{
let Lleng=30;
let angle=GetAngle+30+num*120;
let GGG=4;
let Ccount=0;
loop(9)
{
let angle=GetAngle+120;
	ascent(i in 3..5)
	{
	Laser(GetX,GetY,angle+i*120,Lleng*2,12,60,180,153+Ccount%7);
	Laser(GetX,GetY,angle+i*120+180,Lleng,12,60,180,153+Ccount%7);
	}
	if(num==0 && Ccount<7)
	{
	//CircleShot(Lleng*3^0.5,GetAngle,GGG*DollDir,Ccount);
	}
	//angle+=3*DollDir;
	Lleng+=30+10;
	GGG+=4;
	Ccount+=1;
	wait(20);
}
wait(211);
VanishEnemy;
}

task CircleShot(R,Cangle,grad,color)
{
	wait(45);
	let SSangle;
	ascent(i in 0..90)
	{
	let x=GetCommonData("BossX")+R*cos(Cangle+i*4);
	let y=GetCommonData("BossY")+R*sin(Cangle+i*4);
	SSangle=atan2(GetCommonData("BossY")-y,GetCommonData("BossX")-x)+grad;
	ResistShot(x,y,0,SSangle,9+color,18,i%2);
	}
}

		task ResistShot(x,y,speed,angle,gra,delay,num)
		{
			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);
			//ObjShot_SetBombResist(obj,true);
			Obj_SetAutoDelete(obj,false);
	
			loop(195)
			{
				if(speed<1.5+num*0.5)
				{
				speed+=0.01;
				}
				Obj_SetSpeed(obj, speed);	
				yield;
			}
			Obj_SetAutoDelete(obj,true);
		}

task Laser(x,y,angle,length,width,delay,time,gra)
{
	let lengthmax=length;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,x,y);
	Obj_SetAngle(obj,angle);
	ObjShot_SetGraphic(obj,gra);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width);
	ObjLaser_SetSource(obj,false);
	ObjShot_SetDelay(obj,delay);
	ObjShot_SetBombResist(obj,true);
	Obj_SetAutoDelete(obj,false);
	let dcount=30;
	let lcount=0;
	Obj_SetCollisionToPlayer(obj,false);
	loop(delay)
	{
	//	EffectLaser(x,y,angle,length*lcount/30,width,0,1,gra);
		ObjLaser_SetLength(obj,length*lcount/30);
		if(lcount<30)
		{
		lcount+=1.25;
		}
	yield;
	}
	Obj_SetCollisionToPlayer(obj,true);
//	EffectLaser(x,y,angle,length,width,0,time-delay,gra);
	loop(time-delay)
	{
		yield;
	}
	Obj_SetCollisionToPlayer(obj,false);
	loop(30)
	{
	//	EffectLaser(x,y,angle,length*lcount/30,width*dcount/30,0,1,gra);
		ObjLaser_SetLength(obj,length*lcount/30);
		ObjLaser_SetWidth(obj,width*dcount/30);
		Obj_SetAngle(obj,angle);
		dcount-=1;
		yield;
	}
	Obj_Delete(obj);
}

task EffectLaser(x,y,angle,length,width,delay,time,gra)
{
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,x,y);
	Obj_SetAngle(obj,angle);
	ObjShot_SetGraphic(obj,gra);
	ObjLaser_SetLength(obj,length);
	ObjLaser_SetWidth(obj,width*rand(0.5,1));
	ObjLaser_SetSource(obj,false);
	ObjShot_SetDelay(obj,delay);
	ObjShot_SetBombResist(obj,true);
	loop(time)
	{
	ObjLaser_SetWidth(obj,width*rand(0.5,1));
	yield;
	}
	Obj_Delete(obj);
}

}

#include_function ".\..\txt/StageEnemydata.txt"
#include_function ".\..\lib/lib_anime_Alice.txt"
#include_function ".\..\lib/lib_anime_doll.txt"
}


script_enemy Familiar5 {
    let csd     = GetCurrentScriptDirectory;
    let imgDoll  = csd ~ "..\lib/dot_alice.png"; 
	let DollNum = GetArgument[0];
	let num = GetArgument[0];
	let DollDir=GetArgument[1];
	let color=rand_int(9,15);
	let DollAngle;
    @Initialize {
	BombDamageRate=10;
	InitializeActionWithDoll;
	//SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(50000);
        SetDamageRateEx(100,100,50,0);
	TMain;
    }

    @MainLoop {
        SetServantSkyCollision(GetX, GetY, 36);
        yield;
    }

    @DrawLoop {
     DrawDoll( imgDoll, GetX, GetY );
    }

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,1000,0.3);

	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(5)
		{
			FinalizeItemSet(1);
		}
	}
	}

    task TMain {
        yield;
	GetDamege;
	OutDamageRateZero;
	//ZakoEnemyLifeDisplay;
	move;

	shotA;
    }

task move
{
	let R=210;
	let R1=240;
	let R2=50;
	SetMovePosition03(GetCenterX+R*cos(90+num*5),GetClipMinY-100+R*sin(90+num*5),20,4);
	loop
	{
		let DX=GetCommonDataDefault("DollX",[0,0,0,0,0,0,0,0,0,0,0]);
		DX[DollNum+5]=GetX;
		SetCommonData("DollX",DX);
		let DY=GetCommonData("DollY");
		DY[DollNum+5]=GetY;
		SetCommonData("DollY",DY);
		yield;
	}
}

task shotM
{

}
/////////////////////////////////////////////////////////
task shotE
{


}
////////////////////////////////////////////////////////////
task shotA
{
let grad=0;
let kind=0;
let wave=0;
if(num==0)
{
	wave=rand(2,5)*(rand_int(0,1)*2-1);
	kind=rand_int(0,9)+10;
	grad=rand(-3.5,3.5);
	SetCommonData("Wave",wave);
	SetCommonData("Grad",grad);
	SetCommonData("Kind",kind);
}
wait(90);
grad=GetCommonDataDefault("Grad",15);
kind=GetCommonDataDefault("Kind",0);
//ShotB;
let Bangle=0;
let Sangle=90;
let SangleTheta=0;
let speed=4.0;

let count=0;

loop(240)
{
	if(kind<=2)
	{
	wait(15);
	Sangle=atan2(GetClipMinY-100-GetY,GetCenterX-GetX)+180+Bangle;
	ascent(i in -6..7)
	{
	ascent(j in -1..2)
	{
	CreateShot01(GetX,GetY,4.5+j*0.9,GetAngleToPlayer+grad+i*8+j*wave,9+(i+7)%7,5);
	}
	}
	count+=36;
	wait(36);
	}
	else
	{
	Sangle=atan2(GetClipMinY-100-GetY,GetCenterX-GetX)+180+Bangle*0;
	ascent(i in -1..2)
	{
	ascent(j in 0..4)
	{
	CreateShot01(GetX,GetY,speed+j*0.20,Sangle+(grad+18.5)*i,9+(num+i*2+7+7)%7,5);
	}
	}
	count+=6;
	wait(6);
	}

	if(num==0)
	{
	wave=rand(2,5)*(rand_int(0,1)*2-1);
	kind=rand_int(0,9);
	speed=rand(3.5,3.75);
	grad=rand(-3.5,3.5);
	//grad=rand(18,25);
	Bangle=rand(-5,5)+GetAngleToPlayer-90;
	}
	count+=12;
	wait(12);
	if(num==0)
	{
	SetCommonData("Wave",wave);
	SetCommonData("Kind",kind);
	SetCommonData("Grad",grad);
	SetCommonData("Speed",speed);
	SetCommonData("Bangle",Bangle);
	}
	count+=12;
	wait(12);
	wave=GetCommonDataDefault("Wave",0);
	kind=GetCommonDataDefault("Kind",0);
	grad=GetCommonDataDefault("Grad",0);
	speed=GetCommonDataDefault("Speed",5);
	Bangle=GetCommonDataDefault("Bangle",5);
	if(count>=504){break;}
}
wait(564-count);
SetMovePosition02(GetCommonData("BossX"),GetCommonData("BossY"),60);
wait(60);
VanishEnemy;
}

#include_function ".\..\txt/StageEnemydata.txt"
#include_function ".\..\lib/lib_anime_Alice.txt"
#include_function ".\..\lib/lib_anime_doll.txt"
}


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