
#Title[アリス３]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_alice.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 80;
	let Step2=false;
	let wIni=60;
let TimeCounter=200*60;
let StandardTimeCounter=TimeCounter;
let ColorRed=255;
let ColorGreen=0;
let ColorBlue=0;
    @Initialize {
	SetCommonData("SetBossLifeArray",[15000]);
	SetCommonData("LifeBerReproduction",true);
	SetX(GetCommonDataDefault("BossX",0));
	SetY(GetCommonDataDefault("BossY",0));
	if(GetCommonDataDefault("ExclusiveBoss",false)==true)
	{
		BossTimer(TimeCounter);
	}
	else
	{
		SetTimer(TimeCounter/60);
	}
//	SetCommonData("BossLastAttackColor",[148,0,211]);
//	SetCommonData("BossLastAttack",true);
//	SetShotAutoDeleteClip(24,24,24,24);
	LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
        SetLife(22000);
 LoadGraphic(GetCurrentScriptDirectory~"..\img\CircleEffect.png");
	InitializeAction();
	SetEnemyMarker(true);
        TMainGrobal;
    }

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

    @DrawLoop {
//DrawText(GetCommonDataDefault("XXX",0),120,452,12,255);
//DrawText(GetCommonDataDefault("XXX2",0),120,402,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",450000);
    }

    // メインタスク
task TMainGrobal
{
	yield;
	GetDamege;
	OutDamageRateZero;
	Collision;
	//Lissajous(148,0,211);
	BossShadowAnimation(imgBoss2,0,255,255,0);
	standBy;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	DamageRate=85;
	shotA;
	}
	wait(29);
	SpellDraw(34,60000);
}

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

	loop
	{
        SetCollisionA(GetX, GetY, 32);
        MSDSetCollisionB(GetX, GetY, 8);
	yield;
	}

}

sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition03(xIni, yIni,30,8);
	wait(90);
	Concentration01(30);
}

task shotM
{
//wait(60);
SetCommonData("AttackPhase",1);
SetAction(ACT_SHOT_A, 60);
DummyCollision;
CreateDoll1;
wait(210);
SetAction(ACT_SHOT_A, 120);
Winder;
wait(900);
SetCommonData("AttackPhase",2);
wait(1200);
SetCommonData("AttackPhase",3);
wait(90);
SetCommonData("AttackPhase",4);
wait(2100);
SetAction(ACT_SHOT_A, 12000);
Shot1;

	task Shot1
	{
		let Chain=3;
		loop
		{
			let angle=rand(-10,10);
			let R=50;
			ascent(i in 2..10)
			{
				CreateShot01(GetX+R*cos(angle+i*15),GetY+R*sin(angle+i*15),2.5,180-(angle+i*15),25,10);
				wait(2);
			}
			wait(30);
			let angle=rand(-10,10);
			descent(i in 2..10)
			{
				CreateShot01(GetX+R*cos(angle+i*15),GetY+R*sin(angle+i*15),2.5,180-(angle+i*15),25,10);
				wait(2);
			}

			wait(30);
		}
	}


	task CreateDoll1
	{
	let color=rand(0,360);
	ascent(i in -3..4)
	{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 90+i*360/7,[i,color+i*360/7]);
	}
	}
	task Winder
	{
		let angle=GetAngleToPlayer;
		let Wangle=7;
		loop(11)
		{
			ascent(i in 0..11)
			{
			CreateShot01(GetX,GetY,2+i*0.5,angle-Wangle+rand(-1,1),30,5);
			CreateShot01(GetX,GetY,2+i*0.5,angle+Wangle+rand(-1,1),30,5);
			}
			Wangle+=5;
			wait(5);
		}
	}

}
///////////////////////////////////////////////////////
task shotE
{
SetCommonData("AttackPhase",1);
SetAction(ACT_SHOT_A, 60);
DummyCollision;
CreateDoll1;
wait(210);
SetAction(ACT_SHOT_A, 120);
Winder;
wait(900);
SetCommonData("AttackPhase",2);
wait(1200);
SetCommonData("AttackPhase",3);
wait(90);
SetCommonData("AttackPhase",4);
wait(2100);
SetAction(ACT_SHOT_A, 12000);
Shot1;

	task Shot1
	{
		loop
		{
			ascent(i in -1..2)
			{
			//CreateShot01(GetX,GetY,2.5,GetAngleToPlayer+i*30,171,15);
			CreateShot02(GetX,GetY,2.0,GetAngleToPlayer+i*30,0.02,5,171,15);
			}
			wait(60);
		}
	}


	task CreateDoll1
	{
	let color=rand(0,360);
	ascent(i in -3..4)
	{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 90+i*360/7,[i,color+i*360/7]);
	}
	}

	task Winder
	{
		let speed=6;
		let angle=GetAngleToPlayer+rand(10,15)*(rand_int(0,1)*2-1);
		let Wangle=50;
		loop(30)
		{
			CreateShot01(GetX,GetY,speed,angle-Wangle,30,5);
			CreateShot01(GetX,GetY,speed,angle+Wangle,30,5);
			Wangle-=1.5;
			speed+=1/30;
			wait(1);
		}
		loop(30)
		{
			CreateShot01(GetX,GetY,speed,angle-Wangle,30,5);
			CreateShot01(GetX,GetY,speed,angle+Wangle,30,5);
			wait(1);
		}
	}
}
/////////////////////////////////////////////////////////////////
task shotA
{
SetCommonData("AttackPhase",1);
SetAction(ACT_SHOT_A, 60);
DummyCollision;
CreateDoll1;
wait(210);
SetAction(ACT_SHOT_A, 120);
wait(900);
SetCommonData("AttackPhase",2);
wait(1200);
SetCommonData("AttackPhase",3);
wait(90);
SetCommonData("AttackPhase",4);
wait(2100);
SetAction(ACT_SHOT_A, 12000);
Shot1;

	task Shot1
	{
		loop
		{
			ascent(i in -2..3)
			{
			CreateShot02(GetX,GetY,2.0,GetAngleToPlayer+i*24,0.02,5,31,15);
			}
			ascent(i in -2..2)
			{
			CreateShot02(GetX,GetY,1.5,GetAngleToPlayer+i*24+12,0.015,3.75,31,15);
			}
			wait(60);
		}
	}


	task CreateDoll1
	{
	let color=rand(0,360);
	ascent(i in -3..4)
	{
        CreateEnemyFromScript("Familiar", GetX, GetY,
                              0, 90+i*360/7,[i,color+i*360/7]);
	}
	}

}

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

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


script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgDoll  = csd ~ "..\lib/dot_alice.png"; 
	let num = GetArgument;
	let DollNum=num[0];
	let DollColor=num[1];
	//let Dollnum=num[1];
	let color=rand_int(9,15);
    @Initialize {
	BombDamageRate=10;
	InitializeActionWithDoll;
//	SetCoordinateType(COODINATE_TYPE_PARENT);
	let num = GetArgument;
        SetLife(100000);
        SetDamageRateEx(100,100,100,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;
	//RoundEffect;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
	case("Moderate")
	{
	shotM;
	}
	case("Extream")
	{
	shotE;
	}
	case("Apocalypse")
	{
	shotA;
	}
	//ZakoEffect(255,0,0);

    }

task move
{
	let Y=GetY;
	let PY=GetY;
	let EndY=GetClipMaxY-30;
	let DisY=EndY-PY;
	let Long=0;
	let Wide=0;
	let MoveAngle=GetAngle;

	let count=0;
	loop(90)
	{
		Y=PY+DisY*count/120+Long*sin(MoveAngle);
		MoveAngle+=4;
		Wide+=150/90;
		Long+=40/90;
		count+=1;
		SetX(GetCenterX+Wide*cos(MoveAngle));
		SetY(Y);
		let DX=GetCommonDataDefault("DollX",[0,0,0,0,0,0,0]);
		DX[DollNum+3]=GetX;
		SetCommonData("DollX",DX);
		let DY=GetCommonData("DollY");
		DY[DollNum+3]=GetY;
		SetCommonData("DollY",DY);
		yield;
	}
	wait(90);
	let Yspeed=-3.9;
	loop(40)
	{
		SetY(GetY+Yspeed);
		let DX=GetCommonData("DollX");
		DX[DollNum+3]=GetX;
		SetCommonData("DollX",DX);
		let DY=GetCommonData("DollY");
		DY[DollNum+3]=GetY;
		SetCommonData("DollY",DY);
		yield;
	}
	loop(45)
	{
		SetY(GetY+Yspeed);
		let DX=GetCommonData("DollX");
		DX[DollNum+3]=GetX;
		SetCommonData("DollX",DX);
		let DY=GetCommonData("DollY");
		DY[DollNum+3]=GetY;
		SetCommonData("DollY",DY);
		Yspeed+=3.9/45;
		yield;
	}
}

task shotM
{
	String;
	wait(120);
	PLaser;
	wait(240);
	alternative(absolute(DollNum))
	case(0)
	{
		CommonShot0;
	}
	case(1)
	{
		MShot1;
	}
	case(2)
	{
		MShot2;
	}
	case(3)
	{
		MShot3;
	}

	task MShot1
	{
		wait(30);
		loop
		{
			let angle=rand(0,360);
			ascent(i in 0..24)
			{
				CreateShot01(GetX,GetY,2.0,angle+i*15,1,5);
			}
			wait(30);
			if(GetCommonData("AttackPhase")==2){break;}
		}

		wait(210);
		let angle=GetAngleToPlayer;
		loop
		{
			CreateShot01(GetX,GetY,3.5,GetAngleToPlayer,171,15);
			wait(45);
			angle+=15*DollNum/2;
			if(GetCommonData("AttackPhase")==3){break;}
		}
		while(GetCommonData("AttackPhase")==3){yield;}
		if(DollNum>0){DollWinder1;}
		if(DollNum<0){DollWinder2;}
	//	VarticalLaser(0);
	}

	task MShot2
	{
		wait(60);
		loop
		{
			let angle=GetAngleToPlayer;
			loop(5)
			{
				CreateShot01(GetX-3*cos(angle+90),GetY-3*sin(angle+90),5.0,angle,81,5);
				CreateShot01(GetX+3*cos(angle+90),GetY+3*sin(angle+90),5.0,angle,81,5);
				wait(3);
			}
			wait(30);
			if(GetCommonData("AttackPhase")==2){break;}
		}

		wait(120);
		let angle=90+DollNum*90;
		loop
		{
			ascent(i in -4..5)
			{
				CreateShot01(GetX,GetY,2.0,angle+i*1.20,86,5);
				CreateShot01(GetX,GetY,2.0,180+angle+i*1.20,86,5);
			}
			wait(15);
			angle+=18*DollNum/2;
			if(GetCommonData("AttackPhase")==3){break;}
		}
		while(GetCommonData("AttackPhase")==3){yield;}
		VarticalLaser(-1*DollNum/2);
		wait(1080);
		let t=0;
		loop
		{
			let angle=rand(0,360);
			ascent(i in 0..24)
			{
				CreateShotA(0,GetX,GetY,5);
				SetShotDataA(0,0,6,angle+i*15,0,-0.4,5,25+t%7);
				SetShotDataA(0,15,0,NULL,0,0.04,4,25+t%7);
				FireShot(0);
			}
			wait(60);
			t+=1;
		}
	}

	task MShot3
	{
		loop
		{
		let angle=rand(-5,5);
		ascent(i in 0..18)
		{
			CreateShot01(GetX,GetY,3,angle,25,5);
			wait(5);
			angle+=10;
		}
		wait(30);
		if(GetCommonData("AttackPhase")==2){break;}
		let angle=rand(175,185);
		ascent(i in 0..18)
		{
			CreateShot01(GetX,GetY,3,angle,25,5);
			wait(5);
			angle-=10;
		}
		wait(30);
		if(GetCommonData("AttackPhase")==2){break;}
		}

		wait(60);
		let angle=90+DollNum*90;
		loop
		{
			ascent(i in -1..2)
			{
				CreateShot01(GetX,GetY,3.0,angle+i*2.5,81,5);
				CreateShot01(GetX,GetY,3.0,180+angle+i*2.5,81,5);
			}
			wait(10);
			angle+=15*DollNum/3;
			if(GetCommonData("AttackPhase")==3){break;}
		}
		while(GetCommonData("AttackPhase")==3){yield;}
		VarticalLaser(1*DollNum/3);
		wait(600);
		wait(15+15*(absolute(DollNum)/DollNum));
		loop
		{
			CreateShot01(GetX,GetY,3,GetAngleToPlayer,171,10);
			wait(60);
		}
	}

}

/////////////////////////////////////////////////////////
task shotE
{
	String;
	wait(120);
	PLaser;
	wait(240);
	alternative(absolute(DollNum))
	case(0)
	{
		CommonShot0;
	}
	case(1)
	{
		EShot1;
	}
	case(2)
	{
		EShot2;
	}
	case(3)
	{
		EShot3;
	}

	task EShot1
	{
		wait(30);
		loop
		{
			let angle=rand(0,360);
			let speed=rand(1.5,2);
			CreateShot01(GetX,GetY,speed,angle,33,5);
			wait(1);
			if(GetCommonData("AttackPhase")==2){break;}
		}
		wait(90+15+15*DollNum);
		loop
		{
			SunnyLaser1(GetX,GetY,6,rand(0,360),1);
			if(GetCommonData("AttackPhase")==3){break;}
			wait(60);
		}
		while(GetCommonData("AttackPhase")==3){yield;}
		if(DollNum>0){DollWinder1;}
		if(DollNum<0){DollWinder2;}

	task SunnyLaser1(x,y,LaserSpeed,LaserAngle,dir)
	{
		let length=20;
		let width=12;
		let obj=Obj_Create(OBJ_SINUATE_LASER);
		Obj_SetX(obj,x);
		Obj_SetY(obj,y);
		Obj_SetSpeed(obj,LaserSpeed);
		Obj_SetAngle(obj,LaserAngle);
		ObjShot_SetBombResist(obj,true);
		Obj_SetAutoDelete(obj,false);
		//ObjShot_SetDelay(obj,delay);
		ObjShot_SetGraphic(obj,242);
		ObjSinuateLaser_SetLength(obj,length);
		ObjSinuateLaser_SetWidth(obj,width);

		let LaserAnglePlus=6;
		let GetAngleToPlayerFromObj=GetAngleToPlayer;
		let MaxChangeAngle=5;
		let AngleGap=0;
		let mo=1;
	//	shot;
		loop(60)
		{
			ShotEffect(Obj_GetX(obj),Obj_GetY(obj),3,255,255,69,30);
			GetAngleToPlayerFromObj=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			loop(4){
			let judgangle=sin(GetAngleToPlayerFromObj-Obj_GetAngle(obj));
			if(judgangle>0)
			{
				Obj_SetAngle(obj,Obj_GetAngle(obj)+mo);
			}
			else
			{
				Obj_SetAngle(obj,Obj_GetAngle(obj)-mo);
			}
			}
			//Obj_SetAngle(obj,GetAngleToPlayerFromObj);
			Obj_SetSpeed(obj,LaserSpeed);
			LaserSpeed-=0.1;
			yield;
		}
		loop(60)
		{
			ShotEffect(Obj_GetX(obj),Obj_GetY(obj),3,255,255,69,30);
			GetAngleToPlayerFromObj=atan2(GetPlayerY-Obj_GetY(obj),GetPlayerX-Obj_GetX(obj));
			loop(1){
			let judgangle=sin(GetAngleToPlayerFromObj-Obj_GetAngle(obj));
			if(judgangle>0)
			{
				Obj_SetAngle(obj,Obj_GetAngle(obj)+mo);
			}
			else
			{
				Obj_SetAngle(obj,Obj_GetAngle(obj)-mo);
			}
			}
			Obj_SetSpeed(obj,LaserSpeed);
			LaserSpeed+=0.15;
			yield;
		}
		loop(60)
		{
			ShotEffect(Obj_GetX(obj),Obj_GetY(obj),3,255,255,69,30);
			yield;
		}
		Obj_Delete(obj);

		task shot
		{
			wait(30);
			let r=40;
			loop(50)
			{
				CreateShot01(Obj_GetX(obj)+r*cos(LaserAngle),Obj_GetY(obj)+r*sin(LaserAngle),2.5,LaserAngle,10,5);
				wait(3);
			}
		}

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=0.8;
		loop(delay)
		{
			ObjEffect_SetScale(obj, Scale, Scale);
			ObjEffect_SetAngle(obj,0,0,Zangle);
			Zangle+=6;
			Scale-=0.8/delay;
			yield;
		}
		Obj_Delete(obj);
}

	}

	}

	task EShot2
	{
		wait(60);
		loop
		{
			let angle=GetAngleToPlayer;
			loop(5)
			{
				CreateShot01(GetX-3*cos(angle+90),GetY-3*sin(angle+90),4.0,angle,81,5);
				CreateShot01(GetX+3*cos(angle+90),GetY+3*sin(angle+90),4.0,angle,81,5);
				wait(3);
			}
			wait(30);
			if(GetCommonData("AttackPhase")==2){break;}
		}

		wait(120);
		loop
		{
			Laser(GetAngleToPlayer+rand(30,60)*DollNum/2,450,40,60,150,159);
			loop(180)
			{
				if(GetCommonData("AttackPhase")==3){break;}
				yield;
			}
			if(GetCommonData("AttackPhase")==3){break;}
		}


		task Laser(angle,length,width,delay,time,gra)
		{
			let lengthmax=length;
			let obj = Obj_Create(OBJ_LASER);
			Obj_SetPosition(obj,GetX,GetY);
			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_SetAlpha(obj,150);
			let dcount=30;
			let lcount=0;
			loop(delay)
			{
				ObjShot_SetGraphic(obj,gra);
				EffectLaser(angle,length*lcount/30,width,0,2,gra);
				Obj_SetPosition(obj,GetX,GetY);
				ObjLaser_SetLength(obj,length*lcount/30);
				if(lcount<30)
				{
					lcount+=1;
				}
				yield;
			}
			loop(time-delay)
			{
				EffectLaser(angle,length,width*2,0,5,gra);
				ObjShot_SetGraphic(obj,gra);
				Obj_SetPosition(obj,GetX,GetY);
				yield;
			}
			Obj_SetCollisionToPlayer(obj,false);
			loop(30)
			{
				EffectLaser(angle,length,width*2*dcount/30,0,2,gra);
				ObjShot_SetGraphic(obj,gra);
				Obj_SetPosition(obj,GetX,GetY);
				ObjLaser_SetWidth(obj,width*dcount/30);
				dcount-=1;
				yield;
			}
			Obj_Delete(obj);
		}

		loop
		{
			wait(15);
			if(GetCommonData("AttackPhase")==3){break;}
		}
		while(GetCommonData("AttackPhase")==3){yield;}
		VarticalLaser(-1*DollNum/2);
		wait(1080);
		let t=0;
		loop
		{
			let angle=GetAngleToPlayer;
			ascent(i in -3..4)
			{
				CreateShot01(GetX,GetY,1.5,angle+i*1,81+t%7,5);
			}
			wait(90);
			t+=1;
		}
	}

	task EShot3
	{
		loop
		{
			let angle=rand(0,360);
			let speed=rand(3.0,3.5);
			CreateShot01(GetX,GetY,speed,angle,38,5);
			wait(2);
			if(GetCommonData("AttackPhase")==2){break;}
		}
		wait(120);
		loop
		{
			Laser(GetAngleToPlayer+rand(25,50)*DollNum/3,450,40,60,150,159);
			loop(180)
			{
				if(GetCommonData("AttackPhase")==3){break;}
				yield;
			}
			if(GetCommonData("AttackPhase")==3){break;}
		}

		task Laser(angle,length,width,delay,time,gra)
		{
			let lengthmax=length;
			let obj = Obj_Create(OBJ_LASER);
			Obj_SetPosition(obj,GetX,GetY);
			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_SetAlpha(obj,150);
			let dcount=30;
			let lcount=0;
			loop(delay)
			{
				ObjShot_SetGraphic(obj,gra);
				EffectLaser(angle,length*lcount/30,width,0,2,gra);
				Obj_SetPosition(obj,GetX,GetY);
				ObjLaser_SetLength(obj,length*lcount/30);
				if(lcount<30)
				{
					lcount+=1;
				}
				yield;
			}
			loop(time-delay)
			{
				EffectLaser(angle,length,width*2,0,5,gra);
				ObjShot_SetGraphic(obj,gra);
				Obj_SetPosition(obj,GetX,GetY);
				yield;
			}
			Obj_SetCollisionToPlayer(obj,false);
			loop(30)
			{
				EffectLaser(angle,length,width*2*dcount/30,0,2,gra);
				ObjShot_SetGraphic(obj,gra);
				Obj_SetPosition(obj,GetX,GetY);
				ObjLaser_SetWidth(obj,width*dcount/30);
				dcount-=1;
				yield;
			}
			Obj_Delete(obj);
		}

		while(GetCommonData("AttackPhase")==3){yield;}
		VarticalLaser(1*DollNum/3);
		wait(600);
		//wait(15+15*(absolute(DollNum)/DollNum));
		let angle=90;
		let dir=DollNum/3;
		let angleplus=0;
		loop
		{
			ascent(i in -1..2)
			{
			CreateShot01(GetX,GetY,2.0,angle+i*20,1,10);
			CreateShot01(GetX,GetY,2.0,angle+i*20+180,1,10);
			}
			angle+=10*dir+sin(angleplus);
			angleplus+=1;
			wait(4);
		}
	}

}
////////////////////////////////////////////////////////////
task shotA
{
	String;
	wait(120);
	PLaser;
	FallShot;
	wait(240);
	alternative(absolute(DollNum))
	case(0)
	{
		CommonShot0;
	}
	case(1)
	{
		AShot1;
	}
	case(2)
	{
		AShot2;
	}
	case(3)
	{
		AShot3;
	}

	task FallShot
	{
		wait(60);
		loop(20)
		{
			CreateShot12(GetX,GetY,rand(-1,1),rand(-2, -3),0,0.05,0,6,14,5);
			wait(3);
		}
	}
	task AShot1
	{
		wait(240);
		loop
		{
			let angle=GetAngleToPlayer;
			loop(6)
			{
			let speed=rand(1.5,2);
			ascent(i in -2..3)
			{
			CreateShot01(GetX,GetY,4,angle+12*i,9,5);
			}
			wait(3);
			}
			wait(180);
			if(GetCommonData("AttackPhase")==2){break;}
		}
		wait(90+30+30*DollNum);
		RoundShot;
		task RoundShot
		{
		loop
		{
			let angle=rand(0,360);
			ascent(i in 0..24)
			{
				CreateShot01(GetX,GetY,1.5,angle+15*i,9,5);
				CreateShot01(GetX,GetY,1.75,angle+15*i+7.5,9,5);
			}
			if(GetCommonData("AttackPhase")==3){break;}
			wait(30);
			if(GetCommonData("AttackPhase")==3){break;}
			wait(30);
			if(GetCommonData("AttackPhase")==3){break;}
			wait(30);
			if(GetCommonData("AttackPhase")==3){break;}
			wait(30);
		}
		}
		while(GetCommonData("AttackPhase")!=4){yield;}
		if(DollNum>0){DollWinder1;}
		if(DollNum<0){DollWinder2;}
	}

	task AShot2
	{
		wait(30);
		loop
		{
			let angle=GetAngleToPlayer+rand(-5,5);
			loop(3)
			{
				ascent(i in -4..4)
				{
				CreateShot01(GetX,GetY,2.25,angle+i*16+8.0,81,5);
				}
				wait(4);
			}
			wait(12);
			if(GetCommonData("AttackPhase")==2){break;}
		}

		wait(120);

		let way=6;
		let angle=90+90/way*DollNum/2+90/way;
		loop
		{
			loop(10)
			{
			ascent(i in 0..way)
			{
				CreateShot01(GetX,GetY,5.0,angle+i*360/way,86,5);
			}
			wait(3);
			angle+=1*DollNum/2;
			}
			
			wait(9);
			angle+=1*DollNum/2*3;
			if(GetCommonData("AttackPhase")==3){break;}
		}
		while(GetCommonData("AttackPhase")==3){yield;}
		VarticalLaser(-1*DollNum/2);
		wait(1080);
		let t=0;
	
		let speed=1;
		let angle=90+10*DollNum/2;
		loop
		{
			let Ra=rand(-0.66,0.66);
			ascent(j in 0..4)
			{
			CreateShot01(GetX,GetY,3.0-0.15*j,angle+Ra,14,5);
			CreateShot01(GetX,GetY,3.0-0.15*j,angle+Ra+180,14,5);
			}
			angle-=20/3*DollNum/2;
			wait(4);
		}
	}

	task AShot3
	{
		wait(90);
		if(DollNum>0)
		{
		wait(60);
		}
		loop
		{
			let angle=GetAngleToPlayer;
			let angle2=GetAngleToPlayer+rand(-5,5);
			ascent(j in -2..2)
			{
			ascent(i in -2..3)
			{
			CreateShot01(GetX,GetY,1.75,angle+18*i+j*2+1,17,5);
			CreateShot01(GetX,GetY,1.20,angle2+24*i+j*2+1,17,5);
			}
			}
			wait(120);
			if(GetCommonData("AttackPhase")==2){break;}
		}
		wait(120);
		wait(60);
		if(DollNum>0)
		{
		wait(30);
		}
		loop
		{
			let angle=GetAngleToPlayer;
			loop(10)
			{
				ascent(i in -1..2)
				{
				CreateShot01(GetX,GetY,5,angle+24*i,17,5);
				}
				wait(2);
			}
			wait(40);
			if(GetCommonData("AttackPhase")==3){break;}
		}

		while(GetCommonData("AttackPhase")==3){yield;}
		VarticalLaser(1*DollNum/3);
		wait(600);
		wait(22.5+22.5*(absolute(DollNum)/DollNum));
		let dir=DollNum/3;
		let angleplus=0;
		loop
		{
			let angle=rand(0,360);
			ascent(i in 0..36)
			{
			ShotA(GetX,GetY,1.5,angle+i*10,9,5);
			}
			wait(90);

			task ShotA(x,y,speed,angle,gra,delay)
			{
				let ms=speed;
				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);
				loop(60)
				{
					yield;
					speed-=ms/60;
					Obj_SetSpeed(obj, speed);
				}
				let SA=atan2(GetPlayerY-y,GetPlayerX-x);
				let adx=150*cos(SA);
				let ady=150*sin(SA);
				let SA2=atan2(GetPlayerY+ady-Obj_GetY(obj),GetPlayerX+adx-Obj_GetX(obj));
				Obj_SetAngle(obj, SA2);
				loop(100)
				{
					yield;
					speed+=0.03;
					Obj_SetSpeed(obj, speed);
				}
			}
		}
	}
}
/////////////////////////////////////////////////////////////////////////

	task CommonShot0
	{
		wait(120);
		loop
		{
			Laser(GetAngleToPlayer,450,40,60,150,159);
			wait(180);
			if(GetCommonData("AttackPhase")==2){break;}
		}
		wait(180);
		loop
		{
			Laser(GetAngleToPlayer,450,40,60,150,159);
			loop(180)
			{
				if(GetCommonData("AttackPhase")==3){break;}
				yield;
			}
			if(GetCommonData("AttackPhase")==3){break;}
		}
		while(GetCommonData("AttackPhase")==3){yield;}
		wait(300);
		loop
		{
			Laser(GetAngleToPlayer,450,40,60,150,159);
			wait(180);
		}

		task Laser(angle,length,width,delay,time,gra)
		{
			let lengthmax=length;
			let obj = Obj_Create(OBJ_LASER);
			Obj_SetPosition(obj,GetX,GetY);
			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_SetAlpha(obj,150);
			let dcount=30;
			let lcount=0;
			loop(delay)
			{
				ObjShot_SetGraphic(obj,gra);
				EffectLaser(angle,length*lcount/30,width,0,2,gra);
				Obj_SetPosition(obj,GetX,GetY);
				ObjLaser_SetLength(obj,length*lcount/30);
				if(lcount<30)
				{
					lcount+=1;
				}
				yield;
			}
			loop(time-delay)
			{
				EffectLaser(angle,length,width*2,0,5,gra);
				ObjShot_SetGraphic(obj,gra);
				Obj_SetPosition(obj,GetX,GetY);
				yield;
			}
			Obj_SetCollisionToPlayer(obj,false);
			loop(30)
			{
				EffectLaser(angle,length,width*2*dcount/30,0,2,gra);
				ObjShot_SetGraphic(obj,gra);
				Obj_SetPosition(obj,GetX,GetY);
				ObjLaser_SetWidth(obj,width*dcount/30);
				dcount-=1;
				yield;
			}
			Obj_Delete(obj);
		}
	}

	task DollWinder1
	{
		let angle=[150,90,30,-30];
		let angle=[235,235,235,-135,-135,-135];
		loop(60)
		{
			ascent(i in 0..6)
			{
				CreateShot01(GetX,GetY,8,angle[i],86,5);
			}
			wait(3);
			angle+=[-30/60,-90/60,-150/60,150/60,90/60,30/60];
		}
		loop(20)
		{
			ascent(i in 0..6)
			{
				CreateShot01(GetX,GetY,8,angle[i],86,5);
			}
			wait(3);
		}
		let angleplus=0.4;
		loop(20)
		{
			ascent(i in 0..6)
			{
				CreateShot01(GetX,GetY,8,angle[i],86,5);
			}
			wait(3);
			ascent(i in 0..6)
			{
				angle[i]=angle[i]+angleplus;
			}
		}
		loop
		{
			angleplus*=-1;
			loop(40)
			{
				ascent(i in 0..6)
				{
					CreateShot01(GetX,GetY,8,angle[i],86,5);
				}
				wait(3);
				ascent(i in 0..6)
				{
					angle[i]=angle[i]+angleplus;
				}
			}
		}
	}

	task DollWinder2
	{
		let angle=[150,90,30,-30];
		let angle=[-55,-55,-55,315,315,315];
		loop(60)
		{
			ascent(i in 0..6)
			{
				CreateShot01(GetX,GetY,8,angle[i],86,5);
			}
			wait(3);
			angle-=[-30/60,-90/60,-150/60,150/60,90/60,30/60];
		}
		loop(20)
		{
			ascent(i in 0..6)
			{
				CreateShot01(GetX,GetY,8,angle[i],86,5);
			}
			wait(3);
		}
		let angleplus=-0.4;
		loop(20)
		{
			ascent(i in 0..6)
			{
				CreateShot01(GetX,GetY,8,angle[i],86,5);
			}
			wait(3);
			ascent(i in 0..6)
			{
			angle[i]=angle[i]+angleplus;
			}
		}
		loop
		{
			angleplus*=-1;
			loop(40)
			{
				ascent(i in 0..6)
				{
					CreateShot01(GetX,GetY,8,angle[i],86,5);
				}
				wait(3);
				ascent(i in 0..6)
				{
				angle[i]=angle[i]+angleplus;
				}
			}
		}
	}

	task VarticalLaser(dir)
	{
		wait(1560);
		let wide=80;
		if(dir!=0){wide=40;}
		let HueCount=DollColor;
		VFire(dir);
		VLaser(90,450,wide,60,150,159,dir);
	}

	task VFire(Fdir)
	{
		let type=1;
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\Fire.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, 0, -64);
		ObjEffect_SetVertexXY(obj, 1,128, -64);
		ObjEffect_SetVertexXY(obj, 2, 128, 64);
		ObjEffect_SetVertexXY(obj, 3, 0, 64);
		
		ObjEffect_SetVertexUV(obj, 0,  0+128*(type%2),  0);
		ObjEffect_SetVertexUV(obj, 1,  128+128*(type%2), 0);
		ObjEffect_SetVertexUV(obj, 2, 128+128*(type%2), 128);
		ObjEffect_SetVertexUV(obj, 3, 0+128*(type%2),  128);

		ObjEffect_SetAngle(obj,0,0,90);

		let scx=1;
		let scy=0;
		let Alpha=0;
		TypeChange;
		let Color=[255,255,255];
		loop(15)
		{
			Obj_SetPosition(obj,GetX,GetY);
			scy+=1/15;
			Alpha+=255/15;
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
			}
			ObjEffect_SetScale(obj, scx, scy);
			yield;
		}
		loop(75)
		{
			Obj_SetPosition(obj,GetX,GetY);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
			}
			ObjEffect_SetScale(obj, scx, scy);
			yield;
		}
		let angle=90;
		loop
		{
			loop(105)
			{
				Obj_SetPosition(obj,GetX,GetY);
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
				}
				ObjEffect_SetScale(obj, scx, scy);
				ObjEffect_SetAngle(obj,0,0,angle);
				angle+=12/105*Fdir;
				yield;
			}
			loop(105)
			{
				Obj_SetPosition(obj,GetX,GetY);
				ascent(let i in 0..4)
				{
					ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
				}
				ObjEffect_SetScale(obj, scx, scy);
				ObjEffect_SetAngle(obj,0,0,angle);
				angle-=12/105*Fdir;
				yield;
			}
		}
		Obj_Delete(obj);

		task TypeChange
		{
			loop
			{
				ObjEffect_SetVertexUV(obj, 0,  256+128*(type%2),  384);
				ObjEffect_SetVertexUV(obj, 1,  384+128*(type%2), 384);
				ObjEffect_SetVertexUV(obj, 2, 384+128*(type%2), 512);
				ObjEffect_SetVertexUV(obj, 3, 256+128*(type%2),  512);

				ObjEffect_SetAngle(obj,0,0,90);

				wait(2);
				type+=1;
			}
		}
	}

	task VLaser(angle,length,width,delay,time,gra,dir)
	{
		let lengthmax=length;
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj,GetX,GetY);
		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_SetAlpha(obj,120);
		let dcount=30;
		let lcount=0;
		loop(delay)
		{
			ObjShot_SetGraphic(obj,gra);
			EffectLaser(angle,length*lcount/30,width,0,2,gra);
			Obj_SetPosition(obj,GetX,GetY);
			ObjLaser_SetLength(obj,length*lcount/30);
			if(lcount<30)
			{
				lcount+=1;
			}
			yield;
		}
		loop(30)
		{
			EffectLaser(angle,length,width*2,0,5,gra);
			ObjShot_SetGraphic(obj,gra);
			Obj_SetPosition(obj,GetX,GetY);
			yield;
		}
		loop
		{
			loop(105)
			{
				EffectLaser(angle,length,width*2,0,5,gra);
				ObjShot_SetGraphic(obj,gra);
				Obj_SetPosition(obj,GetX,GetY);
				Obj_SetAngle(obj,angle);
				angle+=12/105*dir;
				yield;
			}
			loop(105)
			{
				EffectLaser(angle,length,width*2,0,5,gra);
				ObjShot_SetGraphic(obj,gra);
				Obj_SetPosition(obj,GetX,GetY);
				Obj_SetAngle(obj,angle);
				angle-=12/105*dir;
				yield;
			}
		}
		Obj_Delete(obj);
	}

task PLaser
{
	let HueCount=DollColor;
	Fire;
	Laser(90,450,80,60,150,159);
	wait(60);
	wait(90);

	task Fire
	{
		let type=1;
		let Ydir=rand_int(0,1);
  		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj,csd~"..\img\Fire.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
	//	ObjEffect_SetRenderState(obj, ADD);
		ObjEffect_CreateVertex(obj, 4);

		ObjEffect_SetVertexXY(obj, 0, 0, -64);
		ObjEffect_SetVertexXY(obj, 1,128, -64);
		ObjEffect_SetVertexXY(obj, 2, 128, 64);
		ObjEffect_SetVertexXY(obj, 3, 0, 64);
		
		ObjEffect_SetVertexUV(obj, 0,  0+128*(type%2),  0);
		ObjEffect_SetVertexUV(obj, 1,  128+128*(type%2), 0);
		ObjEffect_SetVertexUV(obj, 2, 128+128*(type%2), 128);
		ObjEffect_SetVertexUV(obj, 3, 0+128*(type%2),  128);

		ObjEffect_SetAngle(obj,0,Ydir*180,90);
		ObjEffect_SetLayer(obj,3);
		let scx=1;
		let scy=0;
		let Alpha=0;
		let Color=[255,255,255];
		TypeChange;

		loop(15)
		{
			Obj_SetPosition(obj,GetX,GetY);
			scy+=1/15;
			Alpha+=255/15;
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
			}
			ObjEffect_SetScale(obj, scx, scy);
			yield;
		}
		loop(135)
		{
			Obj_SetPosition(obj,GetX,GetY);
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
			}
			ObjEffect_SetScale(obj, scx, scy);
			yield;
		}
		loop(30)
		{
			Obj_SetPosition(obj,GetX,GetY);
			scy-=1/30;
			Alpha+=255/30;
			ascent(let i in 0..4)
			{
			ObjEffect_SetVertexColor(obj,i,Alpha,Color[0],Color[1],Color[2]);
			}
			ObjEffect_SetScale(obj, scx, scy);
			yield;
		}
		Obj_Delete(obj);
		task TypeChange
		{
			loop
			{
				ObjEffect_SetVertexUV(obj, 0,  256+128*(type%2),  384);
				ObjEffect_SetVertexUV(obj, 1,  384+128*(type%2), 384);
				ObjEffect_SetVertexUV(obj, 2, 384+128*(type%2), 512);
				ObjEffect_SetVertexUV(obj, 3, 256+128*(type%2),  512);

				ObjEffect_SetAngle(obj,0,0,90);

				wait(2);
				Ydir=rand_int(0,1);
				type+=1;
			}
		}
	}

	task Laser(angle,length,width,delay,time,gra)
	{
	let Color=[255,255,255];
	let lengthmax=length;
	let obj = Obj_Create(OBJ_LASER);
	Obj_SetPosition(obj,GetX,GetY);
	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_SetAlpha(obj,150);
	let dcount=30;
	let lcount=0;
	loop(delay)
	{
		ObjShot_SetGraphic(obj,gra);
		EffectLaser(angle,length*lcount/30,width,0,2,gra);
		Obj_SetPosition(obj,GetX,GetY);
		ObjLaser_SetLength(obj,length*lcount/30);
		if(lcount<30)
		{
		lcount+=1;
		}
	yield;
	}
	loop(time-delay)
	{
		EffectLaser(angle,length,width*2,0,5,gra);
		ObjShot_SetGraphic(obj,gra);
		Obj_SetPosition(obj,GetX,GetY);
		yield;
	}
	Obj_SetCollisionToPlayer(obj,false);
	loop(30)
	{
		EffectLaser(angle,length,width*2*dcount/30,0,2,gra);
		ObjShot_SetGraphic(obj,gra);
		Obj_SetPosition(obj,GetX,GetY);
	ObjLaser_SetWidth(obj,width*dcount/30);
	dcount-=1;
	yield;
	}
	Obj_Delete(obj);
	}
}

task EffectLaser(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);
	Obj_SetAlpha(obj,100);
	loop(time)
	{
	Obj_SetPosition(obj,GetX,GetY);
	ObjLaser_SetWidth(obj,width*rand(0.5,1));
	yield;
	}
	Obj_Delete(obj);
}

task String
{
	let Distance;
	let BossAngleFromDoll;
	loop
	{
		Distance=((GetY-GetCommonData("BossY"))^2+(GetX-GetCommonData("BossX"))^2)^0.5;
		BossAngleFromDoll=atan2(GetCommonData("BossY")-GetY,GetCommonData("BossX")-GetX);
		StringLaserEffect(GetX,GetY,Distance,5,BossAngleFromDoll);
		yield;
	}

}

task StringLaserEffect(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, -2);
		ObjEffect_SetVertexXY(obj, 1,length,  -2);
		ObjEffect_SetVertexXY(obj, 2,length, 2);
		ObjEffect_SetVertexXY(obj, 3,  0,  2);
		
		ObjEffect_SetVertexUV(obj, 0,  6,  27);
		ObjEffect_SetVertexUV(obj, 1,  228/10, 27);
		ObjEffect_SetVertexUV(obj, 2, 228/10, 33);
		ObjEffect_SetVertexUV(obj, 3, 6, 33);

		let Alpha=60;

		let R=39;
		let G=64;
		let B=200;


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

		ascent(i in 0..4)
		{
			ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
		}
		loop(1)
		{
		yield;
		}
		Obj_Delete(obj);
}

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

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