e
#Title[AuE~c~ETCNv]
#Text[]
#BackGround[DEFAULT]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	#include_function ".\init.txt"
	#include_function ".\lib\lib_anime_Range.txt"

	@Initialize
	{
		SetLife(900);
		StartSetting(70, 1500000, "AuE~c~ETCNv");
		SetInvincibility(240);
		SetExMode();
		SetHitState(0);

		InitPosition(GetCenterX(), GetClipMinY() + 120);

		LoadGraphic(img_range);

		LoadUserShotData(shot_00);
		SetShotAutoDeleteClip(32, 32, 32, 32);

		InitializeAction();
		InitializeBG();
		DeleteEnemyShot(ALL);
		LoadSE(se_shot1);
		LoadSE(se_shot2);
		LoadSE(se_shot3);

		T_Main();
		T_DamageRate(20, 0, 360, -1);
		T_HitTest(48);
	}

	@Finalize
	{
		CreateItemCircle(GetX(), GetY(), 20, 50);
		DeleteGraphic(img_range);
		DeleteSE(se_shot1);
		DeleteSE(se_shot2);
		DeleteSE(se_shot3);
		ClearBG();
	}

	@DrawLoop
	{
		SetAlpha([255, 128][IsExMode() && OnBomb()]);
		DrawBoss(img_range);
	}

	task T_Main()
	{
		yield;

		SetAction(ACT_SPELL, 60);

		Wait(60);
		SetColor(255, 64, 64);
		Concentration01(60);
		SetColor(255, 255, 255);
		Wait(60);
		SetHitState(1);

		T_Ghost();
	}

	task T_Ghost()
	{
		let k = -1;
		loop{
			PlaySE(se_shot3);
			SetAction(ACT_SHOT_B, 60);
			let angle = rand(0, 360);
			ascent( let i in 0..3 ){
				CreateEnemyFromScript("ghost", GetX(), GetY(), 0, angle + i * 120, k);
			}
			k = -k;
			Wait(600);
		}
	}

	#include_function ".\f_base.txt"
	#include_function ".\f_enemy.txt"
	#include_function ".\f_boss.txt"
	#include_function ".\f_bg_range.txt"
}

script_enemy ghost
{
	#include_function ".\init.txt"

	let arg;
	let type = 1;
	let pattern = 0;
	let anime_count = 0;
	let anime_frame = 5;
	let f_bullet = 0;

	@Initialize
	{
		SetLife(1600);
		SetHitState(1);
		SetInvincibility(120);
		T_HitTest(48);

		LoadGraphic(img_fairy);

		arg = GetArgument();

		T_Main();
	}

	@Finalize
	{
	}

	@DrawLoop
	{
		SetAlpha(255);
		SetRenderState(ADD);
		SetTexture(img_fairy);
		SetGraphicRect(0 + pattern * 64, 320 + type * 64, 64 + pattern * 64, 384 + type * 64);
		DrawGraphic(GetX(), GetY());
		SetRenderState(ALPHA);
	}

	task T_Main()
	{
		yield;

		T_Anime();
		T_Act();
		ascent( let i in 0..(120 + 600) ){
			if( GetLife() <= 1000 ){
				f_bullet = 1;
				SetLife(0);
			}
			if( OnBomb() ){
				SetDamageRateEx(0, 0, 0, 0);
			}
			else{
				SetDamageRateEx(100, 0, 60, 0);
			}
			yield;
		}
		f_bullet = 1;
		SetLife(0);
	}

	task T_Anime()
	{
		loop{
			anime_count ++;
			if( anime_count >= anime_frame ){
				pattern ++;
				if( pattern >= 4 ){
					pattern = 0;
				}
				anime_count = 0;
			}
			yield;
		}
	}

	task T_Act()
	{
		let cx = GetX();
		let cy = GetY();
		let count = 0;
		let angle = GetAngle();
		let d_angle = arg * 90;
		let r = 0;
		let dr = 120 / 30;
		let ddr = -dr / 60;
		dr += ddr / 2;

		loop{
			SetX(cx + r * cos(angle));
			SetY(cy + r * sin(angle));
			if( count < 60 ){
				r += dr;
				dr += ddr;
			}
			angle += arg * 6.35 / 3;
			count ++;
			if( count >= 120 && count % 4 == 0 ){
				PlaySE(se_shot1);
				CreateCircleShotA(GetX(), GetY(), angle - d_angle, 13);
				CreateCircleShotA(GetX(), GetY(), angle + d_angle, 11);
			}
			if( count >= 360 && count % 30 == 0 ){
				CreateShot02(GetX(), GetY(), 1.0, GetAngleToPlayer() - 25, 0.02, 6.0, 206, 0);
				CreateShot02(GetX(), GetY(), 1.0, GetAngleToPlayer(), 0.05, 8.0, 206, 0);
				CreateShot02(GetX(), GetY(), 1.0, GetAngleToPlayer() + 25, 0.02, 6.0, 206, 0);
			}
			yield;
		}
	}

	task CreateCircleShotA(x, y, angle, type)
	{
		CreateShotA(0, x, y, 10);
		SetShotDataA(0, 0, 0, angle, 0, 0, 0, type);
		SetShotDataA(0, 60, NULL, NULL, 0, 0.02, 2.0, type);
		FireShot(0);
	}

	task CreateCircleShotB(x, y, angle, type)
	{
		CreateShotA(0, x, y, 10);
		SetShotDataA(0, 0, 6.0, angle, 0, -0.15, 0, type);
		SetShotDataA(0, 60, NULL, NULL, 0, 0.02, 1.8, type);
		FireShot(0);
	}

	#include_function ".\f_base.txt"
	#include_function ".\f_enemy.txt"
}
