
#Title[大妖精通常]
#Text[]
#Image[.]
#BackGround[User] 
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_daiyousei.png"; 
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
let TimeCounter=21*60;
let StandardTimeCounter=TimeCounter;
    @Initialize {
        SetTimer(TimeCounter/60);
        SetLife(2200);
	InitializeAction();
	SetEnemyMarker(true);
        TMain;
    }

    @MainLoop {
	BulletNum=GetEnemyShotCount;
	TimeCounter-=1;
        yield;
    }

    @DrawLoop {
//DrawText(GetLife,120,382,12,255);//起動時間の表示
	DrawBoss( imgBoss );
    }

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

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

    // メインタスク
task TMain 
{
	yield;
	GetDamege;
	OutDamageRateZero;
	//Lissajous(0,250,154);
	BossShadowAnimation(imgBoss,0,0,250,154);
	standBy;
	Collision;
	DamageRateChange;
	summon;
	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, 8);
	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 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)
			{
			CreateShot01(Obj_GetX(obj),Obj_GetY(obj),7.0,90,73,0);
			}
			if(graphic==14)
			{
			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 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, 48);
        MSDSetCollisionB(GetX, GetY, 8);
        yield;
    }

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

        @Finalize
        {
	if(GetEnemyLife>0)
	{
		loop(10)
		{
		FinalizeItemSet(1);
		}
	}
		alternative(GetCommonDataDefault("SELECTEDDIFFICULT","None"))
		case("Moderate")
		{
			if(!BeVanished && GetEnemyLife>0)
			{
			SetCommonData("DeleteBulletNum",BulletNum);
			SetCommonData("DeleteBulletX",GetX);
			SetCommonData("DeleteBulletY",GetY);
			DeleteEnemyShotToItem(SHOT);
			}
		}
		case("Extream")
		{
			if(!BeVanished && GetEnemyLife>0)
			{
			SetCommonData("DeleteBulletNum",BulletNum);
			SetCommonData("DeleteBulletX",GetX);
			SetCommonData("DeleteBulletY",GetY);
			DeleteEnemyShotToItem(SHOT);
			}
		}
		case("Apocalypse")
		{
			if(!BeVanished && GetEnemyLife>0)
			{
			SetCommonData("DeleteBulletNum",BulletNum);
			SetCommonData("DeleteBulletX",GetX);
			SetCommonData("DeleteBulletY",GetY);
			DeleteEnemyShotToItem(SHOT);
			}
		}
        }

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

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

    }

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

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

ascent(let i in 0..18)
{
	ascent(let j in 0..5)
	{
	CreateShot01(GetX,GetY,4-0.25*j,angle+i*20+dir*j,14,5);
	}
}
dir=dir*-1;
wait(60);
}
}

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

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