
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Yuka_AnimeLib.txt";
	
	tex_enemy=filedir~"Yuka_Main.png";
	tex_spellbg=filedir~"Yuka_SpellBG.png";
	
	bg_rect=[0,0,768,512];
	
	@Initialize
	{
		point=300;
		SetLife(750);
		SetTimer(43);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+100,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("円舞「雪月花の舞」",15);
		wait(100);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			SetAction(ACT_SHOT_A,100);
			local
			{
				let way=3;
				let gra=[88,83,81];
				let p=rand(0,360);
				ascent(a in 0..way)
				{
					SetShot1(GetPlayerX,GetPlayerY,p+(360/way)*a,gra[a%length(gra)],0);
				}
				
				way=4;
				ascent(a in 0..way)
				{
					SetShot1(GetPlayerX,GetPlayerY,p+(360/way)*a,87,1);
				}
			}
			wait(120);
			SetMove(cenX+rand(-100,100),minY+rand(110,140),140);
			wait(250);
			r=-r;
			task SetShot1(let px,let py,let ag,let gra,let type)
			{
				let flg=0;
				let ip=6;
				let leng=160;
				let rb=r;
				if(type){rb=-r;leng=120;}
				Effect;
				
				let wt=1;
				let speed=4.5;
				let v=-90;
				loop(120)
				{
					let sx=px+leng*cos(ag);
					let sy=py+leng*sin(ag);
					let angle=ag;
					if(type){angle=ag+v*rb;}
					CreateShot02(sx,sy,0,angle,speed/20,speed,gra,0);
					wait(wt);
					px=GetPlayerX;
					py=GetPlayerY;
				}
				loop
				{
					let sx=px+leng*cos(ag);
					let sy=py+leng*sin(ag);
					let angle=ag;
					if(type){angle=ag+v*rb;}
					CreateShot02(sx,sy,0,angle,speed/20,speed,gra,0);
					
					leng-=2;
					if(type){leng+=4;}
					if(leng<0||type)
					{
						if(sx<=minX||sx>=maxX||sy<=minY||sy>=maxY){break;}
					}
					wait(wt);
				}
				local
				{
					if(!type)
					{
						let way=24;
						let col=(gra-1)%8;
						let p=rand(0,360);
						
						let sx=px+leng*cos(ag);
						let sy=py+leng*sin(ag);
						let speed=1.4;
						let angle=p;
						let delay=25;
						gra=41+col;
						while(angle<p+360)
						{
							CreateShot02(sx,sy,0,angle,speed/100,speed,gra,delay);
							angle+=360/way;
						}
					}
					else
					{
						let col=(gra-1)%8;
						
						let sx=px+leng*cos(ag);
						let sy=py+leng*sin(ag);
						let p=atan2(py-sy,px-sx);
						let speed=2;
						let angle=p;
						let delay=60;
						gra=49+col;
						CreateShotA(1,sx,sy,delay);
						SetShotDataA(1,0,0,0,0,0,0,gra);
						SetShotKillTime(1,0);
						FireShot(1);
						wait(30);
						CreateShot02(sx,sy,0,angle,speed/120,speed,gra,0);
					}
				}
				flg=1;
				
				task Effect
				{
					while(!flg)
					{
						let sx=px+leng*cos(ag);
						let sy=py+leng*sin(ag);
						let delay=10;
						CreateShotA(1,sx,sy,delay);
						SetShotDataA(1,0,0,0,0,0,0,gra);
						SetShotKillTime(1,0);
						FireShot(1);
						ag+=ip*rb;
						ip/=1.01;
						yield;
					}
				}
			}
		}
	}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+70,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("儚花「散華の宝冠」",16);
		wait(100);
		
		let r=1;
		if(rand_int(0,1)){r=-r;}
		loop
		{
			SetAction(ACT_SHOT_A,100);
			local
			{
				let way=5;
				let gra=82;
				let p=rand(0,360);
				ascent(a in 0..way)
				{
					SetShot1(GetPlayerX,GetPlayerY,p+(360/way)*a,gra);
				}
				
			}
			wait(120);
			SetMove(cenX+rand(-100,100),minY+rand(70,80),140);
			wait(200);
			SetAction(ACT_SHOT_B,100);
			local
			{
				let wide=100;
				let way=7;
				let p=atan2(GetPlayerY-(GetY+20),GetPlayerX-GetX);
				let speed=4.2;
				let angle=p-wide/2;
				let gra=51;
				let delay=20;
				while(angle<=p+wide/2+1)
				{
					CreateShot02(GetX,GetY+20,0,angle,speed/120,speed,gra,delay);
					angle+=wide/(way-1);
				}
			}
			let wide=15;
			let p=atan2(GetPlayerY-(GetY+20),GetPlayerX-GetX);
			loop(7)
			{
				let speed=6;
				let angle=p-wide/2;
				let gra=41;
				while(angle<=p+wide/2+1)
				{
					SetShot2(GetX,GetY+20,speed,angle,gra);
					angle+=wide;
				}
				wide+=20;
				wait(1);
			}
			wait(210);
			r=-r;
			
			task SetShot2(let sx,let sy,let speed,let angle,let gra)
			{
				let flg=0;
				let count=0;
				loop
				{
					let del=50;
					let size=20;
					/*
					if(count>35&&count<95)
					{
						let toAngle=atan2(GetPlayerY-sy,GetPlayerX-sx);
						let dangle=7;
						let ret=toAngle-angle;
						if((ret>0&&ret<=180)||(ret<0&&ret<=-180)){angle+=dangle;}
						else if((ret>0&&ret>180)||(ret<0&&ret>-180)){angle+=-dangle;}
						if(angle>=180){angle+=-360;}
						if(angle<-180){angle+=360;}
					}
					*/
					SetLaserEffect(sx,sy,size*(speed/3),size,angle,gra,del);
					sx+=speed*cos(angle);
					sy+=speed*sin(angle);
					if(sx<=minX||sx>=maxX||sy<=minY||sy>=maxY){break;}
					speed+=0.1;
					count++;
					yield;
				}
				flg=1;
			}
			
			task SetShot1(let px,let py,let ag,let gra)
			{
				let flg=0;
				let ip=1.5;
				let leng=120;
				let rb=r;
				Effect;
				
				let wt=2;
				let speed=1.5;
				let v=-90;
				loop(130)
				{
					let sx=px+leng*cos(ag);
					let sy=py+leng*sin(ag);
					let angle=ag-170*rb;
					let limit=60;
					let sch=6*rb;
					
					CreateShotA(1,sx,sy,0);
					SetShotDataA(1,0,speed,angle,0,-speed/limit,0.5,gra);
					SetShotDataA(1,limit,NULL,NULL,sch,0,0,gra);
					SetShotDataA(1,limit+floor(240/absolute(sch)),NULL,NULL,0,speed/60,speed,NULL);
					FireShot(1);
					wait(wt);
					let v=1.5;
					if(px<cenX){px+=v;}
					if(px>cenX){px-=v;}
					if(py<cenY){py+=v;}
					if(py>cenY){py-=v;}
					speed+=0.04;
					leng+=0.7;
				}
				wait(100);
				local
				{
					let way=16;
					let col=(gra-1)%8;
					let p=rand(0,360);
					
					let sx=px+leng*cos(ag);
					let sy=py+leng*sin(ag);
					let speed=[1,0.9];
					let angle=p;
					let delay=25;
					gra=25+col;
					while(angle<p+360)
					{
						ascent(a in 0..length(speed))
						{
							CreateShot02(sx,sy,0,angle,speed[a]/100,speed[a],gra,delay);
						}
						angle+=360/way;
					}
				}
				flg=1;
				
				task Effect
				{
					while(!flg)
					{
						let sx=px+leng*cos(ag);
						let sy=py+leng*sin(ag);
						let delay=15;
						CreateShotA(1,sx,sy,delay);
						SetShotDataA(1,0,0,0,0,0,0,gra);
						SetShotKillTime(1,0);
						FireShot(1);
						ag+=ip*rb;
						yield;
					}
				}
			}
		}
	}
	
	
	
	
	task MainThread_Unlimited
	{
		yield;
		SetMovePositionHermite(cenX,minY+130,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("魔力「緑を統べる波動」",17);
		wait(100);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		
		let lp=270;
		let i=rand(0,360);
		let sp=0;
		let wide=5;
//		State;
		Sub;
		task State
		{
			let wp=0.5;
			loop
			{
				wide+=0.5;
				i+=0.3*cos(lp/2)*r;
				sp+=0.005*cos(lp);
				lp++;
				yield;
			}
		}
		SetAction(ACT_SHOT_B,60*60);
		loop
		{
			local
			{
				let p=rand(0,360);
				let way=28;
				let limit=60;
				let leng=20;
				let speed=[1,1.2];
				let sch=[0.1*r,-0.25*r];
				let angle=p;
				let gra=[28,32];
				if(lp%2){gra=[32,28];}
				let delay=10;
				while(angle<p+360)
				{
					let sx=GetX;
					let sy=GetY+20;
					ascent(a in 0..length(sch))
					{
						ascent(s in 0..length(speed))
						{
							SetShot(sx,sy,speed[s],angle,sch[a],gra[a],delay);
						}
					}
					angle+=360/way;
				}
				lp++;
			}
			wait(100);
			
			task SetShot(let sx,let sy,let speed,let angle,let sch,let gra,let delay)
			{
				let flame=0;
				let leng=0;
				let o=Obj_Create(OBJ_SHOT);
				Obj_SetX(o,sx);
				Obj_SetY(o,sy);
				Obj_SetSpeed(o,0);
				Obj_SetAngle(o,angle);
				ObjShot_SetGraphic(o,gra);
				ObjShot_SetDelay(o,delay);
				Obj_SetAutoDelete(o,false);
				ObjShot_SetBombResist(o,false);
				
				while(!Obj_BeDeleted(o))
				{
					Obj_SetX(o,sx+leng*cos(angle));
					Obj_SetY(o,sy+leng*sin(angle));
					
					if(flame>=delay)
					{
						angle+=sch;
						leng+=speed;
					}
					if(leng>=500){Obj_Delete(o);}
					flame++;
					yield;
				}
			}
			r=-r;
		}
		task Sub
		{
			wait(180);
			loop
			{
				let wide=60;
				let way=4;
				let p=GetAngleToPlayer;
				let ag=p;
				while(ag<p+360)
				{
					let speed=1;
					let angle=ag-wide/2;
					let gra=123;
					let delay=20;
					while(angle<=ag+wide/2+1)
					{
						CreateShot01(GetX,GetY+25,speed,angle,gra,delay);
						angle+=2;
					}
					ag+=360/way;
				}
				wait(240);
			}
		}
	}
	
}
