#TouhouDanmakufu
#Title["Personalized Indoctrination"]
#Text[Invitae arcanum.]
#Image[snapshot\personalizedindoctrination.bmp]
#Player[player\ProcellaPlayers\EmilyA\EmilyA.dnh, player\ProcellaPlayers\EmilyB\EmilyB.dnh, player\ProcellaPlayers\FeliciaA\FeliciaA.dnh, player\ProcellaPlayers\FeliciaB\FeliciaB.dnh]
#PlayLevel[Normal]
#BGM[bgm\Night Falls ~ Evening Star.mp3]
#ScriptVersion[2]

script_enemy_main {
	#include_function "lib\SHOT_REPLACE\shot_replace.dnh"
	let ImgBoss = "script\img\stg8enm.png";
	let bg = "script\img\desdemona_bg.png";
	let MagicCircle = "script\img\mccircle.png";
	let mca = 0;

	let frame = -120;
	let trig = 0;
	let r = 0;
	@Initialize {
		SetLife(800);
		SetInvincibility(240);
		SetDamageRate(20, 5);
		SetTimer(51);
		SetScore(555555);
		CutIn(KOUMA, ""\""Personalized Indoctrination"\", "script\img\alexandaqua.png", 0, 0, 0, 0);

		LoadGraphic(ImgBoss);
		SetTexture(ImgBoss);
		SetGraphicRect(6,195,70,285);
		LoadGraphic(bg);
		LoadGraphic(MagicCircle);
		psrand(747030);
		shotinit;

		SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
	}
	function IsOffScreen {
		return GetX < GetClipMinX || GetX > GetClipMaxX || GetY < GetClipMinY || GetY > GetClipMaxY;
	}
	@MainLoop {
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		if(frame%120 == 1) {
			ascent(a in 0..36) {
				ascent(v in 4..8) {
					CreateShotA(0, GetX, GetY, 0);
					SetShotDataA(0, 0, v / 2, a * 10, 0, -0.05, 0, WHITE21);
					SetShotDataA(0, 60, v / 2, a * 10 - 100, 0, -0.05, 0, PURPLE21);
					SetShotDataA(0, 120, NULL, a * 10 + 100, 0, 0.1, v / 3, RED21);
					FireShot(0);
				}
			}
		}
		else if(frame%60 == 1) {
			ascent(a in 0..36) {
				ascent(v in 4..8) {
					CreateShotA(0, GetX, GetY, 0);
					SetShotDataA(0, 0, v / 2, a * 10, 0, -0.05, 0, WHITE21);
					SetShotDataA(0, 60, v / 2, a * 10 + 100, 0, -0.05, 0, RED21);
					SetShotDataA(0, 120, NULL, a * 10 - 100, 0, 0.1, v / 3, PURPLE21);
					FireShot(0);
				}
			}
		}
		if(frame%120 == 1 && frame > 121) {
			Slow(1);
			Concentration01(60);
			MotionBlur(ALL, 60, 60);
		}
		else if(frame%120 == 61 || OnPlayerMissed || OnBomb) {
			Slow(0);
			if(frame%120 == 61 && frame > 181) {
				TrailShot(GetX, GetY, 1, 4, GetAngleToPlayer, PURPLE03, PURPLE02, PURPLE01, 0);
			}
		}
		yield;
		frame++;
	}
	function TrailShot(x, y, v1, v2, angle, headshot, bodyshot, tailshot, delay) {
		CreateShot01(GetX, GetY, v2, angle, headshot, delay);
		loop(8) {
			CreateShot01(GetX, GetY, rand(v1 + 0.5, v2), angle + rand(-2.5, 2.5), bodyshot, delay);
			CreateShot01(GetX, GetY, rand(v1, v2 - 0.5), angle + rand(-2.5, 2.5), tailshot, delay);
		}
	}
	@DrawLoop {
		SetRenderState(ALPHA);
		SetTexture(ImgBoss);
		SetAlpha(255);
		SetGraphicRect(6,195,70,285);
		SetGraphicAngle(0, 0, 0);
		DrawGraphic(GetX, GetY);
	}
	@Finalize {
		DeleteGraphic(ImgBoss);
		DeleteGraphic(bg);
		DeleteGraphic(MagicCircle);
	}
	task CreateShot03(x, y, v, angle, graphic, delay) {
		let obj = Obj_Create(OBJ_SHOT);
		let lifecounter = 10;
		Obj_SetPosition(obj, x, y);
		Obj_SetSpeed(obj, v);
		Obj_SetAngle(obj, angle);
		Obj_SetAutoDelete(obj, false);
		ObjShot_SetGraphic(obj, graphic);
		ObjShot_SetBombResist(obj, true);
		ObjShot_SetDelay(obj, delay);
		while(Obj_BeDeleted(obj) == false) {
			lifecounter--;
			if(lifecounter <= 0) {
				Obj_SetAutoDelete(obj, true);
			}
			yield;
		}
	}
}