#東方弾幕風
#Title[夜符「ナイトプラトーン-Lunatic」]
#Text[]
#Image[.]
#BackGround[User]
#Player[FREE]
#ScriptVersion[2]
script_enemy_main {
    let name    = "夜符「ナイトプラトーン-Lunatic」";
let csd = GetCurrentScriptDirectory;
    let imgBoss =csd ~ "..\lib/dot_mystia.png"; 
    let imgFam  = csd ~ "..\img\familiar.png";
    let imgBlind  = csd ~ "..\img\blind.png";
SetRateScoreSystemEnable(false);
    // 初期位置
    let xIni    = GetCenterX;
    let yIni    = GetClipMinY + 128;
	let wIni=60;
	let DrawY=330;
	let count=-wIni;
	let Bonus;
	let DBonusItem;
	alternative(GetCommonDataDefault("SELECTEDDIFFICULT","Normal"))
	case("Easy")
	{
		DBonusItem=1;
	}
	case("Normal")
	{
		DBonusItem=2;
	}
	case("Hard")
	{
		DBonusItem=3;
	}
	case("Lunatic")
	{
		DBonusItem=4;
	}
	let StandardSpellBonus=GetCommonDataDefault("BONUSPOINT",10000)*(20*DBonusItem+20*GetCommonDataDefault("STAGEPROGRESS",2));
	let SpellTimer=50;
	let SpellBonus=StandardSpellBonus/3;

    @Initialize {
    LoadUserShotData(GetCurrentScriptDirectory~".\..\img\shot_All.txt");
	StartSpellHistory(14);
        SetLife(800);
        SetDamageRate(5, 5);
        LoadGraphic(imgBoss);
        LoadGraphic(imgFam);
        LoadGraphic(imgBlind);
        SetTexture(imgBoss);
	InitializeAction();
        TMain;
    }

    @MainLoop {
        SetCollisionA(GetX, GetY, 32);
        SetCollisionB(GetX, GetY, 16);
	Bonus=GetSpellCardBonusScore-(SpellBonus*3)/(SpellTimer*60);
        yield;
    }

    @DrawLoop {
	DrawBoss( imgBoss );
	DrawSpellHistory;
    }

    @Finalize {
        DeleteGraphic(imgBoss);
	EndSpellHistory(14);
	loop(15)
	{
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),1);
		ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),2);
	}
	ItemSet(GetX+rand(-40,40),GetY+rand(-40,40),5);
    }

    // メインタスク
task TMain 
{
	yield;
	standBy;
	spell;
	Trate;
	Blind;
	Shot;
	SubShot;
}

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

task Blind
{
		let x=GetPlayerX;
		let y=GetPlayerY;
		let scax=22;
		let scay=22;

		let obj = Obj_Create(OBJ_EFFECT);
		ObjEffect_SetTexture(obj, imgBlind);
		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_SetVertexUV(obj, 0,    0,    0);
		ObjEffect_SetVertexUV(obj, 1,    0,  448);
		ObjEffect_SetVertexUV(obj, 2,  384,    0);
		ObjEffect_SetVertexUV(obj, 3,  384,  448);
		ObjEffect_SetVertexXY(obj, 0, -192, -224);
		ObjEffect_SetVertexXY(obj, 1, -192,  224);
		ObjEffect_SetVertexXY(obj, 2,  192, -224);
		ObjEffect_SetVertexXY(obj, 3,  192,  224);

		ObjEffect_SetLayer(obj,5);
		ObjEffect_SetRenderState(obj, MULTIPLY);
		ObjEffect_SetScale(obj, scax,scay);

		while(!Obj_BeDeleted(obj))
		{
			Obj_SetPosition(obj,GetPlayerX,GetPlayerY);
			ObjEffect_SetScale(obj, scax,scay);
			if(scax>=4)
			{
			scax-=0.1;
			scay-=0.1;
			}
			yield;
		}
}


sub standBy//初期位置へ
{
	SetAction(ACT_MOVE, 60);
	SetMovePosition02(xIni, yIni, wIni);
	SetInvincibility(wIni);
	wait(wIni);
}

sub spell//発動モーション
{
        CutIn(YOUMU, name, "", 0, 0, 0, 0);
        SetTimer(SpellTimer);
        SetScore(SpellBonus);
	SetAction(ACT_SPELL,90);
	wait(90);
}

task Shot
{
wait(60);
loop
{
	let angle=GetAngleToPlayer;
	ascent(let i in 0..9)
	{
		CreateShot01(GetX,GetY,1.0+i*0.5,angle,PURPLE02,10);
		CreateShot01(GetX,GetY,1.0+i*0.5,angle+25,PURPLE02,10);
		CreateShot01(GetX,GetY,1.0+i*0.5,angle-25,PURPLE02,10);
		wait(15);
	}
	wait(120);
}
}

task SubShot
{
wait(60);
let r=15;
summon;
loop
{
	let angle=GetAngleToPlayer+rand(-3,3);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, angle-45, 1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, angle+45, 1);
	wait(60);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, angle-60, -1);
	CreateEnemyFromScript("Familiar", GetX, GetY,2, angle+60, -1);
	wait(60);
}
}

task summon
{
loop
{
let angle=GetAngleToPlayer+rand(-3,3);
	CreateEnemyFromScript("Familiar2", GetClipMinX, GetClipMinY,2, 90, -1);
	CreateEnemyFromScript("Familiar2", GetClipMaxX, GetClipMinY,2, 90, -1);
	wait(90);
}
}

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


script_enemy Familiar {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "..\img\familiar.png";
	let num = GetArgument;
	let angle=GetAngle;
	let speed=GetSpeed;
	let color1=RED21;
	let color2=BLUE21;
    @Initialize {
        SetLife(2000);
        SetScore(10000);
        SetDamageRate(50, 50);
        SetTexture(imgFam);
        setGraphic;
	SetSpeed(speed);
	SetAngle(angle);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    task TMain {
        yield;
	shot;
    }

task shot
{
wait(5);
	
loop
{
	ascent(let i in -1..2)
	{
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,angle+90,0,0,0,RED02);
		SetShotDataA(1,120+10*i,1.5,NULL,0,0,0,81);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,angle-90,0,0,0,BLUE02);
		SetShotDataA(1,120+10*i,1.5,NULL,0,0,0,86);
		FireShot(1);
	}
wait(20);
}
}


    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
function wait(w) 
{
    loop(w) { yield; }
}
}

script_enemy Familiar2 {
    let csd     = GetCurrentScriptDirectory;
    let imgFam  = csd ~ "img\familiar.png";
	let num = GetArgument;
	let angle=GetAngle;
	let speed=GetSpeed;
	let color1=GREEN21;
	let color2=PURPLE21;
    @Initialize {
        SetLife(2000);
        SetScore(10000);
        SetDamageRate(50, 50);
        SetTexture(imgFam);
        setGraphic;
	SetSpeed(speed);
	SetAngle(angle);
	TMain;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
        DrawGraphic(GetX, GetY);
    }

    task TMain {
        yield;
	shot;
    }

task shot
{
wait(5);
	
loop
{
	ascent(let i in -1..2)
	{
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,angle+90,0,0,0,RED02);
		SetShotDataA(1,120+10*i,1,NULL,0,0,0,84);
		FireShot(1);
		CreateShotA(1,GetX,GetY,30);
		SetShotDataA(1,0,0,angle-90,0,0,0,BLUE02);
		SetShotDataA(1,120+10*i,1,NULL,0,0,0,84);
		FireShot(1);
	}
wait(20);
}
}


    // グラフィックの設定
sub setGraphic{ SetGraphicRect( 0, 48, 48, 96); }
function wait(w) 
{
    loop(w) { yield; }
}
}