#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Soul Sign \"House of Shining Lanterns\""]

#include"./../../Functions/Effects/Effects.txt"
#include"./../../System/Miyako_Effect.txt"
#include"./LoadGraphics.txt"
#include"./LoadSounds.txt"
#include"./Cutin.txt"

let time = 40;
let bossObj;
let bossX;
let bossY;

#include"./MiyakoDrawBoss.txt"

@Initialize{	
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetCommonData("ForceLifebar",1);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	
	animateBossM;
	LoadShotData;
	TEnemyMarker;
	mainTask;
	TEnd;}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(500);}
	case(EV_REQUEST_TIMER){SetScriptResult(40);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}
	case(EV_GAIN_SPELL){SetScriptResult(10000000);}
	case(EV_REQUEST_IS_DURABLE_SPELL){SetScriptResult(true);}
	case(EV_START_BOSS_SPELL){
		let path = GetCurrentScriptDirectory ~ "./../../System/Miyako_System_MagicCircle.txt";
		let id = LoadScript(path);
		StartScript(id);yield;}}

@MainLoop{
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	ObjEnemy_SetDamageRate(bossObj, 0, 0);
	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	yield;}

@Finalize{}

task mainTask{
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY,8,5);
	TEtama;wait(90);SE(se_spell);
	TSpellBG;SetCommonData("BG",1);TSurvival;
	if(GetCommonData("Replay",0) == 2){
	ObjCutin_SetSpellcardS4("Soul Sign \"House of Shining Lanterns\"", cutin, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(MOKOU, cutin, "Practice");}
	else{
	ObjCutin_SetSpellcardS4("Soul Sign \"House of Shining Lanterns\"", cutin, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cutin, "Extra");}
	wait(60);SE(se_ch2);
	MakeConcentrationB1(bossObj,"SAKURA",255,64,64,75);wait(70);SE(se_enep3);
	MakeExplosionA1(bossObj,"SAKURA",255,64,64);
	ObjRender_SetColor(bossObj,255,64,64);attack=1;
	TAuraFlash;}

task TAuraFlash{
	let obj1 = CreateShotA1(bossX,bossY-210,0,0,357,90);
	let obj2 = CreateShotA1(bossX,bossY-140,0,0,358,90);
	let obj3 = CreateShotA1(bossX,bossY-70,0,0,359,90);
	let obj4 = CreateShotA1(bossX,bossY,0,0,360,90);
	let obj5 = CreateShotA1(bossX,bossY+70,0,0,361,90);
	let obj6 = CreateShotA1(bossX,bossY+140,0,0,362,90);
	let obj7 = CreateShotA1(bossX,bossY+210,0,0,356,90);
	ObjShot_SetSpellResist(obj1,true);
	ObjShot_SetSpellResist(obj2,true);
	ObjShot_SetSpellResist(obj3,true);
	ObjShot_SetSpellResist(obj4,true);
	ObjShot_SetSpellResist(obj5,true);
	ObjShot_SetSpellResist(obj6,true);
	ObjShot_SetSpellResist(obj7,true);
	let circle = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(circle);
	ObjEnemy_SetLife(circle,1);
	ObjPrim_SetTexture(circle,halo);
	Obj_SetRenderPriorityI(circle,50);
	ObjRender_SetAlpha(circle,200);
	ObjRender_SetPosition(circle,bossX,bossY,0);
	ObjRender_SetBlendType(circle,BLEND_ADD_ARGB);
	ObjSprite2D_SetSourceRect(circle,0,0,256,256);
	ObjSprite2D_SetDestCenter(circle);
	TShot;
	wait(90);
		while(time>0){
		if(FActivate(obj1)){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj1),ObjMove_GetY(obj1),10,5);
			ObjRender_SetColor(circle,255,64,255);
			TPurple;SE(se_lgods3);wait(60);}
		if(FActivate(obj2)){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj2),ObjMove_GetY(obj2),10,5);
			ObjRender_SetColor(circle,64,64,255);
			TIndigo;SE(se_lgods2);wait(60);}
		if(FActivate(obj3)){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj3),ObjMove_GetY(obj3),10,5);
			ObjRender_SetColor(circle,64,255,255);
			TBlue;SE(se_lgods1);wait(60);}
		if(FActivate(obj4)){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj4),ObjMove_GetY(obj4),10,5);
			ObjRender_SetColor(circle,64,255,64);
			TGreen;SE(se_lgods2);wait(60);}
		if(FActivate(obj5)){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj5),ObjMove_GetY(obj5),10,5);
			ObjRender_SetColor(circle,255,255,64);
			TYellow;SE(se_lgods3);wait(60);}
		if(FActivate(obj6)){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj6),ObjMove_GetY(obj6),10,5);
			ObjRender_SetColor(circle,255,128,64);
			TOrange;SE(se_lgods2);wait(60);}
		if(FActivate(obj7)){
			ObjMove_SetDestAtWeight(circle,ObjMove_GetX(obj7),ObjMove_GetY(obj7),10,5);
			ObjRender_SetColor(circle,255,64,64);
			TRed;SE(se_lgods1);wait(60);}
		time--;}
	Obj_Delete(circle);
	return;}

let rad = 0;
task TPurple{rad=rand(0,9);ascent(i in 0..40){CreateShotA1(bossX,bossY-210,1,rad+i*9,333,30);}}
task TIndigo{rad=rand(0,9);ascent(i in 0..40){CreateShotA1(bossX,bossY-140,1,rad+i*9,334,30);}}
task TBlue{rad=rand(0,9);ascent(i in 0..40){CreateShotA1(bossX,bossY-70,1,rad+i*9,335,30);}}
task TGreen{rad=rand(0,9);ascent(i in 0..40){CreateShotA1(bossX,bossY,1,rad+i*9,336,30);}}
task TYellow{rad=rand(0,9);ascent(i in 0..40){CreateShotA1(bossX,bossY+70,1,rad+i*9,337,30);}}
task TOrange{rad=rand(0,9);ascent(i in 0..40){CreateShotA1(bossX,bossY+140,1,rad+i*9,338,30);}}
task TRed{rad=rand(0,9);ascent(i in 0..40){CreateShotA1(bossX,bossY+210,1,rad+i*9,332,30);}}

function FActivate(obj){let act = ObjMove_GetY(obj)>=GetPlayerY-35 && ObjMove_GetY(obj)<=GetPlayerY+35;
	return act;}

task TShot{let w = 360;
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
	wait(w);w-=60;
		if(w<=60){w=60;}SE(se_tan2);
		CreateShotA1(bossX,bossY,1,GetAngleToPlayer(bossObj),830,30);}}