#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["South Sea \"Souvenier for Colour Lovers\" - Ultra"]

#include"./Cutin.txt"
#include"./../../Functions/Effects/Effects.txt"
#include"./LoadGraphics.txt"
#include"./LoadSounds.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);
	SetCommonData("ForceLifebar",1);
	ObjEnemy_Regist(bossObj);
	SetAutoDeleteObject(true);

	animateBossM;
	LoadShotData;
	TEnemyMarker;
	mainTask;
	TEnd;}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(500);}
	case(EV_REQUEST_TIMER){SetScriptResult(50);}
	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,120,8,3);
	TEtama;wait(90);SE(se_spell);
	if(GetCommonData("Replay",0) == 2){
	ObjCutin_SetSpellcardS4("South Sea \"Souvenier for Colour Lovers\"", cutin, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(MOKOU, cutin, "Practice");}
	else{
	ObjCutin_SetSpellcardS4("South Sea \"Souvenier for Colour Lovers\"", cutin, NAZRIN, 240, 104, 104);
	ObjCutin_LaunchS3(NAZRIN, cutin, "Ultra");}
	TSpellBG;TSurvival;
	SetCommonData("BG",1);
	wait(90);damage=1;ScaryWater;
	SE(se_ch);MakeConcentrationB1(bossObj,"SAKURA",64,200,255,120);
	wait(110);
	ObjRender_SetColor(bossObj,64,100,255);
	ObjMove_SetDestAtWeight(bossObj,CenterX,400,8,3);
	wait(120);SE(se_enep3);MakeExplosionA1(bossObj,"SAKURA",64,200,255);
	ascent(i in -7..8){TWater(330+i*6);}
	ascent(i in -7..8){TWater(210+i*6);}}

task ScaryWater{
	waterLine(-10,448,0);wait(30);
	waterLine(394,438,180);wait(30);
	waterLine(-10,428,0);wait(30);
	waterLine(394,418,180);wait(30);

	task waterLine(x,y,ang){
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){
		CreateShotA1(x,y,1,ang,334,0);
	wait(20);}}}

task TWater(ang){
	let move = 0;
	while(ObjEnemy_GetInfo(bossObj,INFO_LIFE) > 0){ SE(se_water);
		let obj = CreateShotA1(bossX,bossY,2,ang+40*sin(move),334,30);
		reflect(obj);wait(10);move+=5;}}

task reflect(object){
	while(ObjMove_GetY(object) > 0){yield;}
	if(ObjMove_GetY(object) <= 0){
		ObjMove_AddPatternB2(object,0,0,0,rand(0.2,-0.2),0.01,rand(0.4,-0.4),2);
		ObjShot_SetDelay(object,15);
		ObjShot_SetGraphic(object,rand(371,378));}}