
#Title[大妖精通常]
#Text[]
#Image[.]
#BackGround[User] 
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_daiyousei.png"; 
    let imgBoss2 =csd ~ "..\lib/dot_daiyousei2.png";
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
let TimeCounter=21*60;
let StandardTimeCounter=TimeCounter;
let StrongLine=2200/11;
let StrongLineNoBomb=2200/7.5;
let BombUsed=0;
    @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;
	if(OnBomb){BombUsed=1;}
    }

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

/*	let DefeatTime=StandardTimeCounter-TimeCounter;
	if(DefeatTime<StrongLine && BombUsed==1)
	{
		SetCommonData("StrongPlayer",true);
	}
	else if(DefeatTime<StrongLineNoBomb && BombUsed==0)
	{
		SetCommonData("StrongPlayer",true);
	}
*/
    }

    // メインタスク
task TMain 
{
	yield;
	Particle;
	GetDamege;
	OutDamageRateZero;
	//Lissajous(0,250,154);
	BossShadowAnimation(imgBoss2,0,0,250,154);
	standBy;
	Collision;
	DamageRateChange;
	summon;

	wait(30);
/*
	NewCharge(30,4,0.5,0,250,154);
	NewCharge(30,4,0.5,(255+0)/2,(255+250)/2,(255+154)/2);
	NewCharge(30,4,0.5,255,255,255);
*/
	wait(30);
//	SetColor(0,250,154);

	Concentration01(30);

//	SetColor(255,255,255);
/*
	NewChargeShrink(150,4,0.5,255,200,100);
	NewChargeShrink(150,4,0.5,255,100,100);
	NewChargeShrink(150,4,0.5,255,255,255);
*/



	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;
	}
}

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

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

task DamageRateChange
{
loop
{
	if(GetEnemyNum==3){DamageRate=100;}
	else if(GetEnemyNum==2){DamageRate=110;}
	else if(GetEnemyNum==1){DamageRate=120;}
yield;
}
}

task Particle
{
loop
{
ParticleEffect;
wait(5);
}
}

task ParticleEffect
{
		let obj=Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, csd~"..\img\ParticleEffect.png");
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
		ObjEffect_SetRenderState(obj, ADD); 
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexXY(obj, 0, -8, -8);
		ObjEffect_SetVertexXY(obj, 1, 8,  -8);
		ObjEffect_SetVertexXY(obj, 2, 8, 8);
		ObjEffect_SetVertexXY(obj, 3,  -8,  8);

		ObjEffect_SetVertexUV(obj, 0,  0,  0);
		ObjEffect_SetVertexUV(obj, 1,  16, 0);
		ObjEffect_SetVertexUV(obj, 2, 16,  16);
		ObjEffect_SetVertexUV(obj, 3, 0, 16);
		let Alpha=100;
		let StandardAlpha=Alpha;
		let R;let G;let B;
		R=0;G=255;B=0;
		ObjEffect_SetLayer(obj,1);
		Obj_SetPosition(obj,GetX+rand(-20,20),GetY+rand(-20,20));
		let speed=rand(0.5,1.0);
		let angle=rand(88,92);
		let Scale=0.5;
		let StandardScale=Scale;
		if(GetCommonDataDefault("LightMode_BossBlur",0)==1){Obj_Delete(obj);return;}
		loop(30)
		{
			Alpha-=StandardAlpha/30;
			Scale-=StandardScale/30;
			Obj_SetPosition(obj,Obj_GetX(obj)+speed*cos(angle),Obj_GetY(obj)+speed*sin(angle));
			ObjEffect_SetScale(obj,Scale,Scale);
			ascent(let i in 0..4)
			{
				ObjEffect_SetVertexColor(obj,i,Alpha,R,G,B);
			}
			yield;
		}
		Obj_Delete(obj);
}

////////////////////////////////////////////////////////////
task shotM
{
let loopnum=0;
loop(2)
{
	SetAction(ACT_SHOT_A,120);
	loop(2)
	{
	kunaishot(GetAngleToPlayer,73);
	wait(20);
	kunaishot(GetAngleToPlayer,78);
	wait(20);
	}
	kunaishot(GetAngleToPlayer,73);
	wait(60);
	SetAction(ACT_SHOT_B,180);
	kunaishot2;
	wait(240);
}
	let angle=rand(0,360);
	SetAction(ACT_SHOT_B,240);
	kunaishot3(angle,73,1);
	wait(60);
	kunaishot3(angle+19,78,-1);
	wait(60);
	kunaishot3(angle,73,1);
	wait(60);
	kunaishot3(angle+19,78,-1);

task kunaishot(let angle,let color)
{
	ascent(let j in 0..5)
	{
	ascent(let i in -2..3)
	{
	CreateShot01(GetX,GetY,3+0.5*j,angle+i*20,color,5);
	}
	wait(5);
	}
}

task kunaishot2
{
let angle=rand(0,360);
let dir=rand_int(0,1)*2-1;
loop(40)
{
	loop(3)
	{
		CreateShot01(GetX,GetY,3.5,angle,78,5);
		CreateShot01(GetX,GetY,3.5,angle+90,73,5);
		CreateShot01(GetX,GetY,3.5,angle+180,78,5);
		CreateShot01(GetX,GetY,3.5,angle+270,73,5);
		angle+=1.5*dir;
		yield;
	}
	angle+=9*dir;
yield;
}
}

task kunaishot3(let angle,let color,let dir)
{
loop(20)
{
	ascent(let i in 0..20)
	{
	CreateShot01(GetX,GetY,4,angle+i*20,color,5);
	}
	wait(3);
	angle+=1*dir;
}
}

}
//////////////////////////////////////////////////////////////////////
task shotE
{
let loopnum=0;
loop(2)
{
	SetAction(ACT_SHOT_A,120);
	loop(2)
	{
	kunaishot(GetAngleToPlayer,73,1);
	wait(20);
	kunaishot(GetAngleToPlayer,78,-1);
	wait(20);
	}
	kunaishot(GetAngleToPlayer,73,1);
	wait(60);
	SetAction(ACT_SHOT_B,180);
	kunaishot2;
	wait(240);
}
	let angle=rand(0,360);
	SetAction(ACT_SHOT_B,240);
	kunaishot3(angle,73,1);
	wait(60);
	kunaishot3(angle+19*1.5,78,-1);
	wait(60);
	kunaishot3(angle,73,1);
	wait(60);
	kunaishot3(angle+19*1.5,78,-1);


task kunaishot(let angle,let color,dir)
{
	ascent(let j in 0..5)
	{
	ascent(let i in -2..3)
	{
	CreateShot01(GetX,GetY,2+0.5*j,angle+i*20+j*2*dir,color,5);
	}
	wait(5);
	}
}

task kunaishot2
{
let r=0;
let angle=90+rand(-10,10);
let dir=rand_int(0,1)*2-1;
loop(40)
{
	loop(3)
	{
		CreateShot01(GetX+r*cos(angle),GetY+r*sin(angle),3.0,angle,78,5);
		CreateShot01(GetX+r*cos(angle+2.5),GetY+r*sin(angle+2.5),3.0,angle+2.5,78,5);
		CreateShot01(GetX+r*cos(angle+1.25),GetY+r*sin(angle+1.25),3.0,angle+1.25,78,5);
		CreateShot01(GetX+r*cos(180-angle),GetY+r*sin(180-angle),2.0,180-angle,73,5);
		CreateShot01(GetX+r*cos(180-angle+2.5),GetY+r*sin(180-angle+2.5),2.0,180-angle+2.5,73,5);
		CreateShot01(GetX+r*cos(180-angle+1.25),GetY+r*sin(180-angle+1.25),2.0,180-angle+1.25,73,5);
		angle+=3.75*dir;
		r+=1.0;
		yield;
	}
	angle+=9*dir;
yield;
}
}

task kunaishot3(let angle,let color,let dir)
{
loop(20)
{
	ascent(let i in 0..20)
	{
	CreateShot01(GetX,GetY,3,angle+i*20,color,5);
	}
	wait(3);
	angle+=1.5*dir;
}
}

}
///////////////////////////////////////////////////////////////////////////
task shotA
{
let loopnum=0;
loop(2)
{
	SetAction(ACT_SHOT_A,120);
	loop(2)
	{
	kunaishot(GetAngleToPlayer,73);
	wait(20);
	kunaishot(GetAngleToPlayer,78);
	wait(20);
	}
	kunaishot(GetAngleToPlayer,73);
	wait(60);
	SetAction(ACT_SHOT_B,180);
	loop(2)
	{
	ReflectShot(GetX,GetY,4,rand(-15,-20),9,5);
	wait(30);
	ReflectShot(GetX,GetY,4,rand(195,200),14,5);
	wait(30);
	}
	wait(120);
}
	let angle=rand(0,360);
	SetAction(ACT_SHOT_B,240);
	kunaishot3(angle,73,1);
	wait(60);
	kunaishot3(angle+19*2.25,78,-1);
	wait(60);
	kunaishot3(angle,73,1);
	wait(60);
	kunaishot3(angle+19*2.25,78,-1);



task kunaishot(let angle,let color)
{
	ascent(let j in 0..8)
	{
	ascent(let i in -8..9)
	{
	CreateShot01(GetX,GetY,4+0.8*j,angle+i*6,color,5);
	}
	wait(5);
	}
}

task ReflectShot(x,y,speed,angle,graphic,delay)
{
	let obj = Obj_Create(OBJ_SHOT);
	Obj_SetPosition(obj, x, y,);
	Obj_SetSpeed(obj, speed);
	Obj_SetAngle(obj, angle);
	ObjShot_SetGraphic(obj, graphic);
	ObjShot_SetDelay(obj, delay);
	DropShot(obj, graphic);
	ObjShot_SetBombResist(obj,true);
	//Obj_SetAlpha(obj,0);

	while(!Obj_BeDeleted(obj))
	{
	if(Obj_GetX(obj)<GetClipMinX){
            Obj_SetX(obj, GetClipMinX*2 - Obj_GetX(obj));
            Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
        }
        if(Obj_GetX(obj)>GetClipMaxX){
            Obj_SetX(obj, GetClipMaxX*2 - Obj_GetX(obj));
            Obj_SetAngle(obj, 180 - Obj_GetAngle(obj));
        }
		yield;
	}

	task DropShot(obj, graphic)
	{
	wait(10);
	loop
	{
		loop(5)
		{
			if(graphic==9)
			{
		//	ShotEffect(Obj_GetX(obj),Obj_GetY(obj),5,150,255,0,0);
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),7.0,90,73,0);
			}
			if(graphic==14)
			{
		//	ShotEffect(Obj_GetX(obj),Obj_GetY(obj),5,150,0,0,255);
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),7.0,90,78,0);
			}
		wait(2);
		}
		wait(5);
	}
	}
}

task kunaishot3(let angle,let color,let dir)
{
loop(30)
{
	ascent(let i in 0..20)
	{
	CreateShot01(GetX,GetY,5,angle+i*20,color,5);
	}
	wait(2);
	angle+=2.25*dir;
}
}

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 ZakoVanish
{
	wait(300);
	//SetCommonData("VanishSignal",true);
}
#include_function ".\..\txt\data.txt"
#include_function ".\..\lib/lib_anime_Daiyousei.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);
	TMain;
    }

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

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

        @Finalize
        {
	MagicCircleBreak(GetX,GetY,10,0.3);
//	if(GetEnemyLife>0)
	if(GetCommonDataDefault("BossLife",0)>0)
	{
		loop(5)
		{
		FinalizeItemSet(1);
		}
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			if(!BeVanished && GetCommonDataDefault("BossLife",0)>0)
			{
			SetCommonData("DeleteBulletNum",BulletNum);
			SetCommonData("DeleteBulletX",GetX);
			SetCommonData("DeleteBulletY",GetY);
			DeleteEnemyShotToItem(SHOT);
			}
		}
		case("Extream")
		{
			if(!BeVanished && GetCommonDataDefault("BossLife",0)>0)
			{
			SetCommonData("DeleteBulletNum",BulletNum);
			SetCommonData("DeleteBulletX",GetX);
			SetCommonData("DeleteBulletY",GetY);
			DeleteEnemyShotToItem(SHOT);
			}
		}
		case("Apocalypse")
		{
			if(!BeVanished && GetCommonDataDefault("BossLife",0)>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);
}
}

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

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