#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["SpellML"]

#include"./functions2.txt"

timer = 30;

@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy,0,0);
	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID());
	
	TEnemyWork;
	ObjEnemy_Render;
	TLife(objEnemy,180,20,20,2.5,2.5,15,7.5);
	TEnd;
}

@MainLoop
{
	timer-=1/60;
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
		{
		SetScriptResult(500);
		}
	case(EV_REQUEST_TIMER)
		{
		SetScriptResult(timer);
		}
	case(EV_REQUEST_SPELL_SCORE)
		{
		SetScriptResult(30000);
		}
	case(EV_START_BOSS_SPELL)
		{
		SetScriptResult(true);
		}
}

task TEnemyWork
{
	TSpellName("Splash Sign \"Kero-chan at the Bottom of a Well\"");
	TXY;
	ObjMove_SetDestAtWeight(objEnemy,GetStgFrameWidth/2,GetStgFrameHeight/2-75,15,5);
	EnemySpell = true;
	loop(60){yield;}
	ObjEffect_Shadow;
	EnemySpell2 = true;
	let dist = 72;
	ascent(i0 in 0..64)
		{
		ascent(i1 in 0..2)
			{
			i1 = i1*2-1;
			let obj = CreateShotA1(GetStgFrameWidth/2+i1*(GetStgFrameWidth/2+32),i0*(GetStgFrameHeight+32)/64-16,0,0,DS_RICE_S_GREEN,0);
			ObjShot_SetSpellResist(obj,true);
			ObjMove_SetDestAtWeight(obj,GetStgFrameWidth/2+i1*dist,ObjMove_GetY(obj),30,5);
			}
		loop(1){yield;}
		}
	loop(30){yield;}
	TSpam;
	loop(30){yield;}
	loop
		{
		let angle = GetAngleToPlayer(objEnemy);
		ascent(i0 in 0..5)
			{
			ascent(i1 in 0..5)
				{
				TShot(i1*360/5+angle);
				}
			PlaySound(se_DeepShotHigh,80);
			loop(6){yield;}
			}
		loop(64){yield;}
		}
				
		
	task TSpam
		{	
		loop
			{
			ascent(i1 in 0..2)
				{
				i1 = i1*2-1;
				ascent(i0 in 0..3)	
					{
					CreateShotA2(GetStgFrameWidth/2+i1*(dist+16+i0*(GetStgFrameWidth/2-dist)/3)+i1*rand(0,1)*(GetStgFrameWidth/2-dist+16)/3,-32,2,90+rand(-2,2),0.05,10,DS_FIRE_SKY-round(rand(0,1))*6,0);
					}
				PlaySound(se_CuteShotLong,77.5);		
				loop(round(rand(2,4))){yield;}	
				}
			}
		}
	task TShot(angle)	
		{
		let obj = CreateShotOA1(objEnemy,3,angle,DS_BALL_BS_WHITE,16);
		loop(16)
			{
			while(!Obj_IsDeleted(obj) && ObjMove_GetX(obj) > GetStgFrameWidth/2-dist && ObjMove_GetX(obj) < GetStgFrameWidth/2+dist){yield;}
			if(Obj_IsDeleted(obj)){return;}
			if(ObjMove_GetX(obj) <= GetStgFrameWidth/2-dist)
				{
				ObjShot_SetGraphic(obj,DS_BALL_BS_SKY);
				}
			else
				{
				ObjShot_SetGraphic(obj,DS_BALL_BS_BLUE);
				}
			ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));			
			yield;
			}
		ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj));
		ObjShot_FadeDelete(obj);
		}

}
task TMovement
{
	let distM = 25;
	let distm =distM/2;
	let numb = round(rand(0,1))*2-1;
		if(ObjMove_GetX(objEnemy) < 175)
			{
			numb =1;	
			}
		else if (ObjMove_GetX(objEnemy) > GetStgFrameWidth-175)
			{	
			numb = -1;
			}
	ObjMove_SetDestAtWeight(objEnemy,ObjMove_GetX(objEnemy)+numb*rand(distm,distM),rand(120,170),30,5);
		
}