#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Red Thread \"The Flax Yarn Flashes Forward\""]

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

let bossObj;
let bossX;
let bossY;
let damage = 0;

#include"./MiyakoDrawBoss.txt"

@Initialize{	
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	SetAutoDeleteObject(true);
	ObjEnemy_Regist(bossObj);
	LoadShotData;
	animateBossT;
	TEnemyMarker;
	mainTask;
	TEnd;}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(500);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(1000000);}
	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);

	if(damage==0){ObjEnemy_SetDamageRate(bossObj, 0, 0);}
	if(damage==1){ObjEnemy_SetDamageRate(bossObj, 10, 10);}

	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,32);
	yield;}

@Finalize{}

task mainTask{
	ObjMove_SetDestAtWeight(bossObj,CenterX,CenterY-100,5,3);
	TEtama;wait(90);SE(se_spell);
	if(GetCommonData("Replay",0) == 2){
	ObjCutin_SetSpellcardS4("Red Thread \"The Flax Yarn Flashes Forward\"", cutin2, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(MOKOU, cutin2, "Practice");}
	else{
	ObjCutin_SetSpellcardS4("Red Thread \"The Flax Yarn Flashes Forward\"", cutin2, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cutin2, "Extra");}
	TSpellBGMID;SetCommonData("BG",1);
		wait(150);damage=1;attack=1;
		MakeConcentrationB1(bossObj,"HEART",255,25,25,120);SE(se_ch);wait(120);
		MakeExplosionA1(bossObj,"HEART",255,25,25);SE(se_enep3);
	TCircle;
	let t = 0;
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
		let r = rand(0,60);attack=1;SE(se_enep4);
		TExplosionA(bossX,bossY,0,3,1,1);
		ascent(i in 0..6){TRedThread(i*60+r,90,t);}
		wait(30);attack=0;t+=1;
	ObjMove_SetDestAtWeight(bossObj,CenterX+rand(-50,50),CenterY-rand(80,120),5,1);
	wait(120);}}

task TCircle{let ang = 0;
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){ ascent(a in 0..5){
			CreateShotA1(bossX+20,bossY,2+a/10,180+ang,32,15);
			CreateShotA1(bossX-20,bossY,2+a/10,-ang,32,15);}
	wait(2);SE(se_tan3);ang+=25;}}

task TRedThread(ang,nak,typ){ let delay = 120;
	let main = CreateShotA1(bossX,bossY,4,ang,823,30);
	ObjShot_SetIntersectionEnable(main,false);
	if(typ==0){Obj_SetVisible(main,true);}
	if(typ>=1){Obj_SetVisible(main,false);}
	wait(30);
	loop(8){
	if(Obj_IsDeleted(main)){break;}
		let x = ObjMove_GetX(main);
		let y = ObjMove_GetY(main);
		let angle = ObjMove_GetAngle(main);
		let a = CreateStraightLaserA1(x,y,angle+nak,380,10,60,1003,delay);
		let b = CreateStraightLaserA1(x,y,angle-nak,380,10,60,1003,delay);
	wait(15);delay-=15;}}