
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Aya_AnimeLib.txt";
	
	tex_enemy=filedir~"Aya_Main.png";
	tex_spellbg=filedir~"Aya_SpellBG.png";
	
	bg_rect=[0,0,512,512];
	
	@Initialize
	{
		point=375;
		SetLife(750);
		SetTimer(45);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetMovePositionHermite(cenX,minY+120,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("天楼「金翅鳥の居処」",9);
		wait(100);
		Sub;
		let i=0;
		let random=rand(0,360);
		loop
		{
			let way=3;
			let sx=[maxX-10,minX+10];
			let sy=minY+10;
			let gra=83;
			let delay=10;
			let ad=0.7;
			let w=3;
			loop(6)
			{
				ascent(x in 0..2)
				{
					let speed=[4,1.4];
					let angle=0;
					let ag=[-random-i,random+i];
					while(angle<360)
					{
						ascent(a in 0..2)
						{
							ascent(s in 0..length(speed))
							{
								CreateShot02(sx[x],sy,0,angle+ag[a],speed[s]/120,speed[s],gra,delay);
							}
						}
						angle+=360/way;
					}
				}
				i+=ad;
				wait(w);
			}
			loop(6)
			{
				ascent(x in 0..2)
				{
					let angle=0;
					let gra=83;
					let delay=15;
					while(angle<360)
					{
						CreateShotA(1,sx[x],sy,delay);
						SetShotDataA(1,0,0,0,0,0,0,gra);
						SetShotKillTime(1,0);
						FireShot(1);
						angle+=360/way;
					}
				}
				i+=ad;
				wait(w);
			}
		}
		
		task Sub
		{
			wait(70);
			let mv=rand_int(2,3);
			let r=1;
			if(rand_int(0,1)){r=-r;}
			loop
			{
				let movepos=[rand(-120,-90),rand(-90,-50),rand(-50,0),rand(0,50),rand(50,90),rand(90,120)];
				let cmp=mv;
				while(mv!=cmp){mv+=rand_int(-2,2);}
				if(mv<=-1){mv=1;}
				if(mv>=6){mv=4;}
				let wt=20;
				SetAction(ACT_MOVE,wt);
				SetMovePosition02(cenX+movepos[mv],minY+rand(110,130),wt);
				
				let lp=0;
				let p=rand(0,360);
				loop(5)
				{
					let way=20;
					let speed=4;
					let angle=p;
					let gra=[137,144];
					let delay=10;
					while(angle<p+360)
					{
						CreateShot01(GetX,GetY,speed,angle,gra[lp%length(gra)],delay);
						angle+=360/way;
					}
					lp++;
					wait(5);
				}
				
				loop(3)
				{
					let p=rand(0,360);
					let way=45;
					let speed=2.5;
					let angle=p;
					let gra=25;
					let delay=10;
					while(angle<p+360)
					{
						CreateShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
						angle+=360/way;
					}
					wait(30);
				}
				wait(120);
			}
		}
	}
	
	
	
	
	task MainThread_Advanced
	{
		yield;
		SetMovePositionHermite(cenX,minY+90,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("開風「天上の道標」",10);
		wait(100);
		Sub;
		let i=0;
		let random=rand(0,360);
		let sy=GetY;
		loop
		{
			let ad=0.7;
			let w=3;
			let sx=[cenX+120,cenX-120];
			ascent(x in 0..2)
			{
				loop(6)
				{
					let delay=15;
					let gra=115;
					let way=7;
					loop(9)
					{
						let speed=[5,2];
						let angle=0;
						let ag=[-random-i,random+i];
						ascent(a in 0..2)
						{
							ascent(s in 0..length(speed))
							{
								let angle=ag[a];
								while(angle<ag[a]+360)
								{
									CreateShot02(sx[x],sy,0,angle,speed[s]/60,speed[s],gra,delay);
									angle+=360/way;
								}
							}
						}
						wait(w);
						i+=ad;
					}
					loop(9)
					{
						let angle=0;
						while(angle<360)
						{
							CreateShotA(1,sx[x],sy,delay);
							SetShotDataA(1,0,0,0,0,0,0,gra);
							SetShotKillTime(1,0);
							FireShot(1);
							angle+=360/way;
						}
						i+=ad;
						wait(w);
					}
				}
			}
		}
		
		task Sub
		{
			wait(80);
			loop
			{
				SetAction(ACT_SHOT_A,80);
				Concentration01(80);
				let px_=GetPlayerX;
				let py_=GetPlayerY;
				SetTargeting(px_,py_,0.5,120,0);
				wait(80);
				SetAction(ACT_SHOT_B,90);
				local
				{
					let px=[px_,maxX+(maxX-(px_-20)),minX-(px_-20)];
					SetShot(0);
					wait(40);
					Concentration01(30);
					ascent(a in 1..3){SetShot(a);}
					
					task SetShot(let a)
					{
						let speed=5;
						if(a){speed=8;}
						let angle=atan2(py_-GetY,px[a]-GetX);
						let gra=25;
						let delay=10;
						while(speed>=2.5)
						{
							ReflectShot(GetX,GetY,speed,angle,1,true,false,true,false,gra,delay);
							speed/=1.05;
						}
					}
				}
				wait(90);
				SetMove(cenX+rand(-100,100),minY+rand(80,90),200);
				wait(200);
			}
		}
	}
	
	
	
	
	task MainThread_Unlimited
	{
		yield;
		SetMovePositionHermite(cenX,minY+70,0,0,0,0,100);
		SetAction(ACT_MOVE,100);
		SetSpellCard("地獄「外法天狗の大魔縁」",11);
		wait(100);
		local
		{
			local
			{
				let speed=5;
				let angle=10;
				let gra=119;
				let delay=30;
				while(angle<370)
				{
					BaseShot(GetX,GetY,speed,angle,15,gra,delay);
					angle+=20;
				}
			}
			wait(20);
			Concentration01(60);
			wait(60);
			local
			{
				let speed=[6,3.7];
				let angle=0;
				let gra=[86,81];
				let delay=0;
				let a=0;
				while(angle<360)
				{
					BaseShot(GetX,GetY,speed[a%2],angle,15,gra[a%2],delay);
					a++;
					angle+=10;
				}
			}
			Concentration01(100);
			wait(70);
			function BaseShot(let sx,let sy,let speed,let angle,let max,let gra,let delay)
			{
				let wide=0;
				while(wide<=max)
				{
					if(wide==0)
					{
						CreateShot01(sx,sy,speed,angle,gra,delay);
					}
					else
					{
						let ag=angle-wide/2;
						while(ag<=angle+wide/2+0.5)
						{
							CreateShot01(sx,sy,speed,ag,gra,delay);
							ag+=wide;
						}
					}
					wide+=1;
					speed/=1.02;
				}
			}
		}
		
		SetShot;
		let i=rand(0,360);
		SetAction(ACT_SHOT_A,60*45);
		loop
		{
			let way=15;
			let ag=[i,-i/1.8];
			
			let speed=[4,4.65];
			let gra=115;
			let delay=2;
			ascent(s in 0..length(speed))
			{
			
				ascent(a in 0..2)
				{
					let angle=ag[a];
					while(angle<ag[a]+360)
					{
						let leng=20;
						let sx=GetX+leng*cos(angle);
						let sy=GetY+leng*sin(angle);
						CreateShot01(sx,sy,speed[s],angle,gra,delay);
						angle+=360/way;
					}
				}
			}
			wait(11);
			i+=1.6;
		}
		
		task SetShot
		{
			wait(60);
			loop
			{
				let p=rand(0,360);
				loop(5)
				{
					let way=18;
					let speed=4.5;
					let angle=p;
					let gra=30;
					let delay=5;
					while(angle<p+360)
					{
						CreateShot02(GetX,GetY,0,angle,speed/60,speed,gra,delay);
						angle+=360/way;
					}
					
					p+=(360/way)/2;
					wait(2);
				}
				wait(50);
			}
		}
	}
	
}