
#ScriptVersion[3]
#Title["YoumuS2"]
#Text["YoumuS2"]
#Player[DEFAULT]
#System["./system/Default_System.txt"]
#Background["./BG.txt"]
#Player["./MoF_Reimu/Reimu.txt"]
#include"./Functions/Index.txt"
#include"./SetBoss.txt"
#include"./Shot/AllStarShot_Const.dnh"
#include"./system/Default_Effect.Txt"


let objBoss;
let GCSD=GetCurrentScriptDirectory~"";
let enemy;
let bSpell=false;
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
let atk = false;
let fog = 0;
let action = false;
let objScene=GetEnemyBossSceneObjectID();
let color = [276,277,278];
let color2 = [51,53,55];
let dcolor = [308,309,310];
@Initialize
{
SetCommonData("Scroll",1);
SetBoss("Youmu",true);
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(3500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(36);
	}
		case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(35000000);
	}
}

//----------------------------------------------------
task mainTask{
	magiccircle(objBoss,1,-1);
	DamageRateAtFrame(100,50,180);
	ObjMove_SetDestAtWeight(objBoss,stgx,140,10,7);
	Cutin("\"Polygon Slash\"",15,"YOUMU");
	ObjEnemyBossScene_StartSpell(objScene);
	wait(90);
	TShot1;
	}
//----------------------------------------------------

task TShot1
{
	let count = 4;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	maple;
	attack(60,count*10+45,1);
	wait(60);
	MainPolygon(count);
	wait(150);
	TMovement(20,5,3);
	wait(60);
	if(count<8){count++;}
	}
}

task MainPolygon(num)
{
	let sangle = 0;
	let angle = 360/num;
	let r = 0;
	let objarr = [];
	let plusy = 0;
	let lasercolor = [1030,1027,1025,1021,1019];
	let shotcolor = [14,11,9,5,3];
	if(num==4)
	{
		sangle = 180/num;
		r = 250;
	}
	if(num==5)
	{
		sangle = -90/num;
		r = 200;
		plusy = 20;
	}
	if(num==6)
	{
		//sangle = -90/num;
		r = 205;
	}
	if(num==7)
	{
		sangle = 85/num;
		r = 195;
		plusy = 10;
	}
	if(num==8)
	{
		r = 200;
	}
	ascent(i in 0..num)
	{
		let obj = TShotA1(stgx+r*cos(angle*i+sangle),stgy+plusy+r*1.2*sin(angle*i+sangle),0,0,17,0);
		Obj_SetVisible(obj,false);
		ObjShot_SetIntersectionEnable(obj,false);
		ObjShot_SetSpellResist(obj,true);
		objarr = objarr ~ [obj];
	}
	ascent(i in 0..num)
	{
		Manage(objarr[i],i);
	}
	task Manage(obj,number)
	{
		let dis = 0;
		let dir = 0;
		let nextarr = (number+1)%num;
		let px = ObjMove_GetX(objarr[nextarr]);
		let py = ObjMove_GetY(objarr[nextarr]);
		yield;
		dir = GetAtanAngle(obj,objarr[nextarr]);
		dis = GetDistance(ObjMove_GetX(obj),ObjMove_GetY(obj),px,py)*1.05;
		wait(number*5);
		SLaser(dir,dis,1);
		nextarr = (number+2)%num;
		px = ObjMove_GetX(objarr[nextarr]);
		py = ObjMove_GetY(objarr[nextarr]);
		dir = GetAtanAngle(obj,objarr[nextarr]);
		dis = GetDistance(ObjMove_GetX(obj),ObjMove_GetY(obj),px,py)*1;
		SLaser(dir,dis,0);
		task SLaser(dir,dis,type)
		{
			PlaySound("Eff3",90,0);
			PlaySound("Eff4",90,(num)*5+30);
			let x = ObjMove_GetX(obj);
			let y = ObjMove_GetY(obj);
			let ratio = dis/9;
			let start = rand(80,100);
			let laser = CreateStraightLaserA1(x,y,dir,dis,10,120-number*5,lasercolor[num-4],(num)*5+30);
			let maxi = 11-num;
			let circle = 360/(num*maxi);
			CreateStraightLaserA1(x,y,dir,dis,40,0,lasercolor[num-4],(num)*5+30);
			let dummy = CreateStraightLaserA1(x,y,dir,dis,40,120-number*5,1057,(num)*5+30);
			ObjRender_SetColor(laser,192,192,192);
			ObjShot_SetIntersectionEnable(dummy,false);
			if(num==4){ObjRender_SetColor(dummy,192,192,0);} // yellow
			if(num==5){ObjRender_SetColor(dummy,0,192,0);} // green
			if(num==6){ObjRender_SetColor(dummy,0,192,192);} // aqua
			if(num==7){ObjRender_SetColor(dummy,192,0,192);} // magenta
			if(num==8){ObjRender_SetColor(dummy,192,0,0);} // red
			if(type==1)
			{
			wait((num)*5+30);
			ascent(i in 0..maxi)
			{
				ascent(j in -Level..1+Level)
				{
					ascent(k in 0..2)
					{
						TShotA1(x+ratio*i*cos(dir),y+ratio*i*sin(dir),0.75+k/2.5,dir+j*2+i*circle*2+start,shotcolor[num-4],8);
						TShotA1(x+ratio*i*cos(dir),y+ratio*i*sin(dir),0.75+k/2.5,dir+j*2-i*circle*2+start,shotcolor[num-4],8);
					}
				}
			}
			ascent(i in 0..9)
			{
				ascent(j in 0..4)
				{
					TShotA1(x+ratio*i*cos(dir+rand(-2,2)),y+ratio*i*sin(dir+rand(-3,3)),0.5+j/2,dir-90,shotcolor[num-4],8);
				}
			}
			}
		}
	}
}

//----------------------------------------------------

task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		EndBoss(1);
		yield;
		CloseScript(GetOwnScriptID());
	}