//#東方弾幕風[Single]
#ScriptVersion[3]
#Title["S7K"]
#Text[" "]
#Background["./background/Default_Background.txt"]
#System["./system/Default_System.txt"]
#BGM["./BGM1.mp3"]

#include"./lib/All.txt"

let objEnemy;
let objPlayer;
let objScene = GetEnemyBossSceneObjectID();

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(300);
	}
        case(EV_REQUEST_TIMER)
	{
                SetScriptResult(60);
        }
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(1000000);
	}
}

@Initialize
{
        objPlayer = GetPlayerObjectID();
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	renderKoishiSA(objEnemy);
	SetCommonData("boss", "KOISHI");
	ObjEnemy_SetDamageRate(objEnemy, 0, 0);
	ObjMove_SetDestAtFrame(objEnemy, 192, 100, 60);
	TEnd;
	TSubShot;
}

@MainLoop
{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);

	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 24);

	yield;
}

task TSubShot
{
	loop(60){ yield; }
	ObjEnemyBossScene_StartSpell(objScene);
	SpellStart(objEnemy, "Test \"Ink Splatter\"", GetCurrentScriptDirectory() ~ "./img/CutInImage2.png", 1005, 1020, 0.38);
	loop(60){ yield; }
	Charge(objEnemy);
	loop(30){ yield; }
	ObjEnemy_SetDamageRate(objEnemy, 10, 7);	
	TSubShot1;
	TSubShot2;
	TSubShot3;
	loop(120){ yield; }
	while(ObjEnemy_GetInfo(objEnemy,INFO_LIFE) > 0)
	{
		Charge(objEnemy);
		Target(100, 100, objEnemy);
		loop(60){ yield; }
		ObjMove_SetDestAtFrame(objEnemy, 100, 100, 120);
		loop(120){ yield; }

		Charge(objEnemy);
		Target(100, 348, objEnemy);
		loop(60){ yield; }
		ObjMove_SetDestAtFrame(objEnemy, 100, 348, 120);
		loop(120){ yield; }

		Charge(objEnemy);
		Target(284, 348, objEnemy);
		loop(60){ yield; }
		ObjMove_SetDestAtFrame(objEnemy, 284, 348, 120);
		loop(120){ yield; }

		Charge(objEnemy);
		Target(284, 100, objEnemy);
		loop(60){ yield; }
		ObjMove_SetDestAtFrame(objEnemy, 284, 100, 120);
		loop(120){ yield; }
	}
}

task TSubShot1
{
	let angle = 282;
	let angle1 = -angle;

	loop
	{
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);

		let x = ex + cos(angle) * 100;
		let y = ey + sin(angle) * 20;

		let dis = ((x - ex) ^ 2 + (y - ey) ^ 2) ^ 0.5;
		let ang = atan2(y - ey, x - ex);

		let x1 = ex + cos(angle1) * 100;
		let y1 = ey + sin(angle1) * 20;

		let dis1 = ((x1 - ex) ^ 2 + (y1 - ey) ^ 2) ^ 0.5;
		let ang1 = atan2(y1 - ey, x1 - ex);

		if(!Obj_IsDeleted(objEnemy))
		{
			SEPlay("Shot1", 80);
			let obj = CreateShotA1(ex + cos(ang - 45) * dis, ey + sin(ang - 45) * dis, 0.4, angle - 45 - 270, 22, 10);
			ObjMove_AddPatternA1(obj, 30, 2, NO_CHANGE);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			let obj1 = CreateShotA1(ex + cos(ang1 - 135) * dis, ey + sin(ang1 - 135) * dis, 0.4, angle1 - 135 + 275, 22, 10);
			ObjMove_AddPatternA1(obj1, 30, 2, NO_CHANGE);
			ObjRender_SetBlendType(obj1, BLEND_ADD_ARGB);
			angle += 8;
			angle1 -= 8;
		}
		loop(2){ yield; }
	}
}

task TSubShot2
{
	loop(160){ yield; }
	let angle = 276;
	let angle1 = -angle;
	loop
	{
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);

		let x = ex + cos(angle) * 80;
		let y = ey + sin(angle) * 15;

		let dis = ((x - ex) ^ 2 + (y - ey) ^ 2) ^ 0.5;
		let ang = atan2(y - ey, x - ex);

		let x1 = ex + cos(angle1) * 100;
		let y1 = ey + sin(angle1) * 20;

		let dis1 = ((x1 - ex) ^ 2 + (y1 - ey) ^ 2) ^ 0.5;
		let ang1 = atan2(y1 - ey, x1 - ex);

		if(!Obj_IsDeleted(objEnemy))
		{
			SEPlay("Shot1", 80);
			let obj = CreateShotA1(ex + cos(ang - 20) * dis, ey + sin(ang - 20) * dis, 0.4, angle - 20 - 300, 20, 10);
			ObjMove_AddPatternA1(obj, 30, 2.5, NO_CHANGE);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			let obj1 = CreateShotA1(ex + cos(ang1 - 160) * dis, ey + sin(ang1 - 160) * dis, 0.4, angle1 - 160 + 300, 20, 10);
			ObjMove_AddPatternA1(obj1, 30, 2.5, NO_CHANGE);
			ObjRender_SetBlendType(obj1, BLEND_ADD_ARGB);
			angle += 8;
			angle1 -= 8;
		}
		loop(2){ yield; }
	}
}

task TSubShot3
{
	loop(300){ yield; }
	let angle = 276;
	let angle1 = -angle;
	loop
	{
		let ex = ObjMove_GetX(objEnemy);
		let ey = ObjMove_GetY(objEnemy);

		let x = ex + cos(angle) * 100;
		let y = ey + sin(angle) * 5;

		let dis = ((x - ex) ^ 2 + (y - ey) ^ 2) ^ 0.5;
		let ang = atan2(y - ey, x - ex);

		let x1 = ex + cos(angle1) * 100;
		let y1 = ey + sin(angle1) * 5;

		let dis1 = ((x1 - ex) ^ 2 + (y1 - ey) ^ 2) ^ 0.5;
		let ang1 = atan2(y1 - ey, x1 - ex);

		if(!Obj_IsDeleted(objEnemy))
		{
			SEPlay("Shot1", 80);
			let obj = CreateShotA1(ex + cos(ang - 0) * dis, ey + sin(ang - 0) * dis, 0.4, angle, 23, 10);
			ObjMove_AddPatternA1(obj, 30, 2.5, NO_CHANGE);
			ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
			let obj1 = CreateShotA1(ex + cos(ang1 - 90) * dis, ey + sin(ang1 - 90) * dis, 0.4, angle1 - 90, 23, 10);
			ObjMove_AddPatternA1(obj1, 30, 2.5, NO_CHANGE);
			ObjRender_SetBlendType(obj1, BLEND_ADD_ARGB);
			angle += 8;
			angle1 -= 8;
		}
		loop(2){ yield; }
	}
}

task TEnd
{
	while(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)>0){ yield; }
	Obj_Delete(objEnemy);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT) + ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) != 0)
	{
		NotifyEventAll(EV_USER_SYSTEM, 0);
	}
	loop(20)
	{
		DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
		yield;
	}
	CloseScript(GetOwnScriptID());
}