e
#Title[́uXiCvn[gR[Xv]
#Text[]
#BackGround[DEFAULT]
#Player[FREE]
#ScriptVersion[2]

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

	@Initialize
	{
		StartPlural();

		SetLife(600);
		StartSetting(45, 1000000, "́uXiCvn[gR[Xv");
		SetInvincibility(210);

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

		LoadGraphic(img_mystia);

		LoadUserShotData(shot_00);
		SetShotAutoDeleteClip(24, 24, 24, 24);

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

		SetEffectForZeroLife(60, 0, 0);

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

	@Finalize
	{
		if( GotSpellCardBonus() ){
			SetCommonData("mid_item", 1);
		}
		if( GetLife() <= 0 ){
			CreateItemCircle(GetX(), GetY(), 20, 50);
			if( GetCommonDataDefault("mid_item", 0) ){
				CreateItem(ITEM_1UP, GetX(), GetY());
			}
		}
		DeleteSE(se_shot1);
		DeleteSE(se_shot2);
		DeleteGraphic(img_mystia);
		ClearBG();
	}

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

	task T_Main()
	{
		yield;

		SetAction(ACT_SPELL, 60);

		Wait(210);
		SetCommonData("Back7_State", 1);

		T_Shot();

		loop{
			if( GetEnemyLife() <= 0 || GetTimer() <= -1 ){
				break;
			}
			yield;
		}
		PlaySE(se_destroy2);
		Wait(20);
		PlaySE(se_destroy2);
		Wait(20);
		PlaySE(se_destroy2);
		Wait(19);
		PlaySE(se_destroy);
	}

	function MoveAct()
	{
		let x;
		let y;
		let direction = 0;

		if( GetX() < GetClipMinX() + 140 ){
			direction = 1;
		}
		else if( GetX() > GetClipMaxX() - 140 ){
			direction = -1;
		}
		else if( GetX() < GetPlayerX() ){
			direction = 1;
		}
		else{
			direction = -1;
		}
		x = GetX() + direction * rand(70, 140);
		y = GetY();
		SetAction(ACT_MOVE, 30);
		SetMovePositionDC(x, y, 30);
	}

	task T_Shot()
	{
		loop{
			SetAction(ACT_SHOT_A, 60);
			ascent( let i in 0.. 6 ){
				PlaySE(se_shot1);
				let angle = GetAngleToPlayer();
				CreateBirdShot(GetX(), GetY(), angle + rand(-5, 5), 7);
				Wait(3);
			}
			Wait(60);
			//MoveAct();
			Wait(75);
		}
	}

	task CreateBirdShot(x, y, angle, f)
	{
		let obj = Obj_Create(OBJ_SHOT);

		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 136);

		let count = 0;
		let v = 2.0;
		let s_count = rand_int(0, 10);
		while( !Obj_BeDeleted(obj) ){
			Obj_SetSpeed(obj, v);
			v += 0.1;
			if( count >= 20 && count % 10 == s_count ){
				PlaySE(se_shot1);
				CreateBombShot(Obj_GetX(obj), Obj_GetY(obj), angle, f);
			}
			count ++;
			yield;
		}
	}

	task CreateBombShot(x, y, angle, f)
	{
		let obj = Obj_Create(OBJ_SHOT);

		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		ObjShot_SetGraphic(obj, 45);
		Wait(60);

		if( !Obj_BeDeleted(obj) ){
			PlaySE(se_shot1);
			let s_angle = GetSnipeAngle(x, y);
			ascent( let j in 0..3 ){
				ascent( let i in 0..6 ){
					let type = 100 + f;
					if( rand_int(0, 10) == 0 ){
						type = 171;
					}
					CreateShot01(x, y, 1.15 + i * 5.05 / 5, s_angle + (j - 1) * 50, type, 0);
				}
			}
			Obj_Delete(obj);
		}
	}

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