#e
#Title[u҂̎΁v]
#Text[]
#Image[.]
#BackGround[User]
#ScriptVersion[2]
script_enemy_main {
    let name    = "u҂̎΁v";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "lib/patchouli_dot.png"; 
    let imgFam  = csd ~ "img\familiar.png";
SetRateScoreSystemEnable(false);
SetCommonData("SPELL",0);
    // ʒu
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let judg1=0;
	let judg2=0;
	let judg3=0;
	let judg4=0;
	let judg5=0;
	let judg6=0;
	let judg7=0;
	let judg8=0;
	let judg9=0;
	let judg10=0;
	let judg11=0;
	let judg12=0;
	let judg13=0;
	let judg14=0;
	let judg15=0;
	let countc=0;
    @Initialize {

        SetLife(2000);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        SetTexture(imgBoss);
	InitializeAction();
	SetAlpha(255);
        TMain;
    }

    @MainLoop {

        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
	DrawBoss( imgBoss );
    }
    @Finalize {
        DeleteGraphic(imgBoss);
	CreateItem(ITEM_BOMB,GetX,GetY);
	if(GetCommonData("LifeF")<GetCommonData("LifeW"))
	{
		judg1=1;
	}
	if(judg1==0)
	{
		if(GetCommonData("LifeW")<GetCommonData("LifeM"))
		{
			judg2=1;
		}
		if(judg2==0)
		{
			if(GetCommonData("LifeM")<GetCommonData("LifeE"))
			{
				judg3=1;
			}
			if(judg3==0)
			{
				if(GetCommonData("LifeE")<GetCommonData("LifeT"))
				{
					judg4=1;
				}
				if(judg4==0)
				{
					SetCommonData("SPELL",5);
				}
				else
				{
					SetCommonData("SPELL",4);
				}
			}
			else
			{
				if(GetCommonData("LifeM")<GetCommonData("LifeT"))
				{
					judg5=1;
				}
				if(judg5==0)
				{
					SetCommonData("SPELL",5);
				}
				else
				{
					SetCommonData("SPELL",3);
				}
			}				
		}
		else
		{
			if(GetCommonData("LifeW")<GetCommonData("LifeE"))
			{
				judg6=1;
			}
			if(judg6==0)
			{
				if(GetCommonData("LifeE")<GetCommonData("LifeT"))
				{
					judg7=1;
				}
				if(judg7==0)
				{
					SetCommonData("SPELL",5);
				}
				else
				{
					SetCommonData("SPELL",4);
				}
			}
			else
			{
				if(GetCommonData("LifeW")<GetCommonData("LifeT"))
				{
					judg8=1;
				}
				if(judg8==0)
				{
					SetCommonData("SPELL",5);
				}
				else
				{
					SetCommonData("SPELL",2);
				}
			}				
		}		
	}

	else
	{
		if(GetCommonData("LifeF")<GetCommonData("LifeM"))
		{
			judg9=1;
		}
		if(judg9==0)
		{
			if(GetCommonData("LifeM")<GetCommonData("LifeE"))
			{
				judg10=1;
			}
			if(judg10==0)
			{
				if(GetCommonData("LifeE")<GetCommonData("LifeT"))
				{
					judg11=1;
				}
				if(judg11==0)
				{
					SetCommonData("SPELL",5);
				}
				else
				{
					SetCommonData("SPELL",4);
				}
			}
			else
			{
				if(GetCommonData("LifeM")<GetCommonData("LifeT"))
				{
					judg12=1;
				}
				if(judg12==0)
				{
					SetCommonData("SPELL",5);
				}
				else
				{
					SetCommonData("SPELL",3);
				}
			}				
		}
		else
		{
			if(GetCommonData("LifeF")<GetCommonData("LifeE"))
			{
				judg13=1;
			}
			if(judg13==0)
			{
				if(GetCommonData("LifeE")<GetCommonData("LifeT"))
				{
					judg14=1;
				}
				if(judg14==0)
				{
					SetCommonData("SPELL",5);
				}
				else
				{
					SetCommonData("SPELL",4);
				}
			}
			else 
			{
				if(GetCommonData("LifeF")<GetCommonData("LifeT"))
				{
					judg15=1;
				}
				if(judg15==0)
				{
					SetCommonData("SPELL",5);
				}
				else
				{
					SetCommonData("SPELL",1);
				}
			}				
		}		
	}
}

    

    // C^XN
task TMain 
{
	yield;
	standBy;
        spell;
	Trate;
	Summon;
	move;
}


task Trate
{
	wait(120);
        SetDamageRate(50, 50);
}

sub spell//[V
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(50);
        SetScore(22000000/3);
	SetAction(ACT_SPELL,90);
	wait(90);
}

sub move 
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition02(GetCenterX, GetClipMinY-320,60);
}

sub standBy//ʒu
{
	SetAction(ACT_MOVE, 60);
	let wIni = 60;
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}


task Summon
{
        CreateEnemyFromScript("Familiar", GetX-120, GetY,
                              0, 0, 1);
        CreateEnemyFromScript("Familiar", GetX-60, GetY,
                              0, 0, 2);
        CreateEnemyFromScript("Familiar", GetX-0, GetY,
                              0, 0, 3);
        CreateEnemyFromScript("Familiar", GetX+60, GetY,
                              0, 0, 4);
        CreateEnemyFromScript("Familiar", GetX+120, GetY,
                              0, 0, 5);
}
task Shot
{
	let dir=1;
	loop
	{
		let angle=GetAngleToPlayer;
		loop(4)
		{
		CreateShot01(GetX,GetY,5,angle,BLUE03,0);
		wait(3);
		}
		ascent(let i in 1..17)
		{
			shot(GetX,GetY,5,angle+i*22.5*dir,BLUE03,0);
			wait(3);
		}
		wait(180);
		dir=-dir;
		yield;
	}
}


task shot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let count=0;
	let count1=0;
	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);
	while(!Obj_BeDeleted(obj))
	{
		if(Obj_GetX(obj)<=GetClipMinX || Obj_GetX(obj)>=GetClipMaxX || Obj_GetY(obj)<=GetClipMinY || Obj_GetY(obj)>=GetClipMaxY)//[ł̋
		{
		ascent(let i in 0..8)
		{
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,i*45,BLUE05,0);
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1.5,i*45,BLUE05,0);
		CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1,i*45,BLUE05,0);
        	}
		Obj_Delete(obj);
		}
		yield;
    	}

}

    function moveToPlayer(xMove, yAdd, frame, left, top, right, bottom) {
        let x;
        let y;

        if(GetPlayerX < GetX)
	{
            x = GetX - xMove;

            if(x < left) {
                x = GetX + xMove;
            }
        } else {
            x = GetX + xMove;

            if(right < x) {
                x = GetX - xMove;
            }
        }

        y = GetY + yAdd;
        if(y < top) {
            y = top;
        } else if(bottom < y) {
            y = bottom;
        }

        SetMovePosition02(x, y, frame);
SetAction(ACT_MOVE,60);
    }

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

script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "img\familiar.png";
let num = GetArgument;

    @Initialize {
        SetLife(8000);
        SetScore(10000);
        SetDamageRateEx(100,100,100,20);
	let num = GetArgument;
        SetTexture(imgFam);
        setGraphic;
	SetAngle(GetAngleToPlayer+num*45);
	TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    task TMain {
        yield;
	if(num==1)
	{
		ShotF;
	}
	if(num==2)
	{
		ShotW;
	}
	if(num==3)
	{
		ShotM;
	}
	if(num==4)
	{
		ShotE;
	}
	if(num==5)
	{
		ShotT;
	}
	Life;
    }

task Life
{
loop
{
	if(num==1)
	{
		SetCommonData("LifeF",GetLife);
	}
	if(num==2)
	{
		SetCommonData("LifeW",GetLife);
	}
	if(num==3)
	{
		SetCommonData("LifeM",GetLife);
	}
	if(num==4)
	{
		SetCommonData("LifeE",GetLife);
	}
	if(num==5)
	{
		SetCommonData("LifeT",GetLife);
	}
yield;
}
}

task ShotF
{
wait(30);
let angle=rand(0,360);
loop
{
CreateShot01(GetX,GetY,3,angle,RED01,30);
CreateShot01(GetX,GetY,3,-angle,RED01,30);
CreateShot01(GetX,GetY,3,angle+180,RED01,30);
CreateShot01(GetX,GetY,3,-angle+180,RED01,30);
angle+=5;
wait(10);
}
}


task ShotW
{
loop
{
CreateShot01(GetX,GetY,4,GetAngleToPlayer,BLUE03,10);
CreateShot01(GetX,GetY,3.5,GetAngleToPlayer,BLUE03,10);
CreateShot01(GetX,GetY,3,GetAngleToPlayer,BLUE03,10);
wait(120);
}
}

task ShotM
{
loop
{
let angle=GetAngleToPlayer;
let angle2=GetAngleToPlayer+rand(60,300);
loop(3)
{
shot(GetX,GetY,2,angle,YELLOW02,30);
shot(GetX,GetY,2,angle2,YELLOW02,30);
wait(10);
}
wait(60);
let angle2=rand(0,120);
let angle3=rand(120,240);
let angle4=rand(240,360);
loop(3)
{
shot(GetX,GetY,2,angle2,YELLOW02,30);
shot(GetX,GetY,2,angle3,YELLOW02,30);
shot(GetX,GetY,2,angle4,YELLOW02,30);
wait(10);
}
wait(60);
}
}

task ShotE
{
loop
{
		let angle=GetAngleToPlayer;
		ascent(let i in 0..20)
		{
		CreateShotA(1,GetX+rand(-50,50),GetY+rand(-50,50),30);
		SetShotDataA(1,0,0,0,0,0,3,YELLOW01);
		SetShotDataA(1,60-i*3,0,angle+rand(-30,30),0,0.05,3,YELLOW21);
		FireShot(1);
		wait(3);
		}
wait(180);
}
}

task ShotT
{
let w=90;
let dir=1;
	loop
	{
		loop(1)
		{
			CreateShot01(GetX+rand(-50,50), GetY+rand(-50,50),rand(2,3),w,GREEN11,30);
		}
		if(w<=170 && dir==1)
		{
			w+=2;
		}
		if(w>=10 && dir==-1)
		{
			w-=2;
		}
		if(w>=170)
		{
			dir=-1;
			wait(30);
		}
		if(w<=10)
		{
			dir=1;
			wait(30);
		}
	wait(3);
	}
}

task shot(let x, let y, let speed,let angle, let graphic, let delay)
{
	let count=0;
	let count1=0;
	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);
	while(!Obj_BeDeleted(obj))
	{
		if(Obj_GetX(obj)<GetClipMinX && count==0)//[ł̋
		{
			Obj_SetX(obj, GetClipMinX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-Obj_GetAngle(obj));
			count=1;
        	}
		if(Obj_GetX(obj)>GetClipMaxX && count==0)//E[ł̋
		{
			Obj_SetX(obj, GetClipMaxX*2-Obj_GetX(obj));
			Obj_SetAngle(obj,180-Obj_GetAngle(obj));
			count=1;
        	}
		if(Obj_GetY(obj)<GetClipMinY)//[ł̋
		{
			Obj_SetY(obj, GetClipMinY*2-Obj_GetY(obj));
			Obj_SetAngle(obj,360-Obj_GetAngle(obj));
        	}
		yield;
    	}
}
    // OtBbN̐ݒ
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
#include_function ".\data.txt"
}
