#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["S1"]
#Text["."]
#System["./System.txt"]
#include"./Functions/Index.txt"

let objScene=GetEnemyBossSceneObjectID();
let objBoss;
let frame=0;
let waterpos;
let charge;
let wsignal=0;
let GCSD=GetCurrentScriptDirectory~"";
let plusangle=-90;

@Initialize{
	mainTask;
}

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){
		SetScriptResult(3000)
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(50)
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(10000)
	}
}

@MainLoop{
	frame++;
	plusangle++;
	if(wsignal!=1){
		ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),24);
		ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	}
	yield;
	
}

task mainTask{
	TLoadSounds;
	objBoss=TDrawBoss;
	TEnemyHitboxStart(objBoss,150);
	wait(30);
	ObjEnemyBossScene_StartSpell(objScene);
	PlaySound(objBoss,23,100,0);
	ObjMove_SetDestAtWeight(objBoss,GetStgFrameWidth/2,GetStgFrameHeight/4,10,5);
	Cutin(objBoss,"Experiment \"Unstable Swamp Water\"");
	TShoot01;
	TEnd;
	yield;
}

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		TExplosionA(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),10,0.5);
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		Obj_Delete(objBoss);
		loop(120){
			DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
			yield;
			}
		CloseScript(GetOwnScriptID());
		return;
	}

task TWater{
	waterpos=TWaterHide(objBoss,"LARGE",true);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),0);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),0);
	while(!Obj_IsDeleted(waterpos)&&wsignal==1){
		ObjRender_SetPosition(waterpos,ObjRender_GetX(objBoss),ObjRender_GetY(objBoss),0);
		yield;
	}
	Obj_Delete(waterpos);
	ObjRender_SetAlpha(objBoss,255);
}

task TShoot01{
	wait(90);
	let n=5;
	let d=3;
	let t=0;
	PlaySound(objBoss,22,100,0);
	charge=TCharge01(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),3,255,255,255);
	wait(60);
	while(!Obj_IsDeleted(objBoss)){
		loop(8){
			let obj=CreateShotB2(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),rand(-3,3),rand(-3,0),0,0.05,0,5,FIRE_BLUE,15);
			TShot(obj);
		}
		PlaySound(objBoss,12,100,0);
		wait(60);
		TCheckHp(objBoss);
		let angleplayer=GetAngleToPlayer(objBoss);
		loop(5){
			let angle=0;
			while(angle<360){
				CreateShotA2(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),5,angle+angleplayer,-0.1,1,SMALL_AQUA,15);
				angle+=360/15;
			}
		PlaySound(objBoss,12,100,0);
		wait(10);
		}
		TCheckHp(objBoss);
		wait(15);
		PlaySound(objBoss,22,100,0);
		charge=TCharge01(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),3,255,255,255);
		wait(60);
	}
	task TShot(obj){
		while(!Obj_IsDeleted(obj)){
			if(ObjMove_GetX(obj)<=0||ObjMove_GetX(obj)>=GetStgFrameWidth||ObjMove_GetY(obj)<=0||ObjMove_GetY(obj)>=GetStgFrameHeight){
			TExplosionA(ObjMove_GetX(obj),ObjMove_GetY(obj),25,0.3);
				let angle=0;
				while(angle<360){
					CreateShotA2(ObjMove_GetX(obj),ObjMove_GetY(obj),6,angle+rand(0,360),-0.25,1,BL_SMALL_RED,0);
					angle+=360/7;
				}
				PlaySound(objBoss,13,100,0);
				Obj_Delete(obj);
			}
			yield;
		}
	}
}