#TouhouDanmakufu[Stage]
#Title["Deep Sea"]
#Text["Difficulty: Lukewarm"]
#ScriptVersion[3]
//#System["./default_system/Default_SystemFullScreen.txt"]
#System["./default_system/Default_System.txt"]
#include "./default_system/MS_Index.txt"

@Initialize{
LoadCommonDataAreaA2("HighScore",GetCurrentScriptDirectory ~ "./default_system/score.dat");
SetCommonData("IsStage", true);

OxigenController;
WorldBG;

BGM;
LoadAssets;
STAGE;
Difficulty(1);
}

@MainLoop{
if(GetPlayerState()==STATE_END){
	loop(60){yield;}
	CloseStgScene();
}

yield;
}

@Finalize{}


task BGM{
wait(60);
	let obj	= ObjSound_Create();
	ObjSound_Load(obj,GetCurrentScriptDirectory ~ "Default_System/se/bgm.ogg");
	ObjSound_SetSoundDivision(obj,SOUND_BGM);
	ObjSound_SetVolumeRate(obj,85);
	ObjSound_SetLoopEnable(obj,true);
	ObjSound_SetLoopTime(obj, 13.012, 60*4+07.583);
	ObjSound_Play(obj);
}

task STAGE{
    let obj=ObjEnemyBossScene_Create();
    ObjEnemyBossScene_Add(obj,1,GetCurrentScriptDirectory ~ "./NS1.txt");
	ObjEnemyBossScene_Add(obj,1,GetCurrentScriptDirectory ~ "./SP1.txt");
	ObjEnemyBossScene_Add(obj,2,GetCurrentScriptDirectory ~ "./NS2.txt");
	ObjEnemyBossScene_Add(obj,2,GetCurrentScriptDirectory ~ "./SP2.txt");
	ObjEnemyBossScene_Add(obj,3,GetCurrentScriptDirectory ~ "./NS3.txt");
	ObjEnemyBossScene_Add(obj,3,GetCurrentScriptDirectory ~ "./SP3.txt");
	ObjEnemyBossScene_Add(obj,4,GetCurrentScriptDirectory ~ "./NS4.txt");
	ObjEnemyBossScene_Add(obj,4,GetCurrentScriptDirectory ~ "./SP4.txt");
	ObjEnemyBossScene_Add(obj,5,GetCurrentScriptDirectory ~ "./SP5.txt");
	ObjEnemyBossScene_Add(obj,6,GetCurrentScriptDirectory ~ "./SP6.txt");
	ObjEnemyBossScene_LoadInThread(obj);
	ObjEnemyBossScene_Regist(obj);
	BossIsDed;
	RipNon;
	RipSpell;
	TimerCountdown(obj);
	
    while(!Obj_IsDeleted(obj)){
        yield;
    }
	
	wait(120);
	StageClear(1000000);
	wait(90);
	if(GetCommonData("GotHighScore", 0) == 1){Highscore;}
	wait(90);
	SaveCommonDataAreaA2("HighScore",GetCurrentScriptDirectory ~ "./default_system/score.dat");
	wait(30);
	CloseStgScene;
}

task RipNon{
	loop{
	while(GetCommonData("RipNon",0) < 1){yield;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/explode.wav", 90, 1);
	ExplodeCircleT(GetCommonData("bossx", 0), GetCommonData("bossy", 0), 60, 12, 0);
	SetCommonData("RipNon",0);
	yield;
	}
}

task RipSpell{
	loop{
	while(GetCommonData("RipSpell",0) < 1){yield;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/cardbreak.wav", 90, 1);
	loop(60){ParticleT(GetCommonData("bossx", 0), GetCommonData("bossy", 0), rand(0.5, 10), rand(0,360), 0.6, rand(0,360), "Cherry", [255, 10, 10], 4);}
	loop(40){CreateItemU1(1, GetCommonData("bossx", 0)+rand(-100, 100), GetCommonData("bossy", 0)+rand(-100, 100), 1000);}
	SetCommonData("RipSpell",0);
	yield;
	}
}

task BossIsDed{
	loop{
	while(GetCommonData("BossIsDed",0) < 1){yield;}
	PlaySound(GetCurrentScriptDirectory ~ "Default_System/se/death.ogg", 90, 1);
	ScreenShake(120,15);
	Slowdown;
	loop(120){ParticleT(GetCommonData("bossx", 0), GetCommonData("bossy", 0), rand(0.5, 10), rand(0,360), 0.6, rand(0,360), "Cherry", [255, 10, 10], 4);}
	ascent(i in 0..6){ExplodeCircleT(GetCommonData("bossx", 0), GetCommonData("bossy", 0), 60, i*12, 0);}
	loop(40){CreateItemU1(1, GetCommonData("bossx", 0)+rand(-100, 100), GetCommonData("bossy", 0)+rand(-100, 100), 1000);}
	SetCommonData("BossIsDed",0);
	yield;
	}
}

task Slowdown{
StartSlow(TARGET_ALL, 15);
wait(20);
StopSlow(TARGET_ALL);
}