
script_enemy_main
{
	#include_script".\..\..\EnemyBossSystem.txt";
	#include_script".\Chen_AnimeLib.txt";
	
	tex_enemy=filedir~"Chen_Main.png";
	tex_spellbg=filedir~"Chen_SpellBG.png";
	
	bg_rect=[0,0,512,512];
	
	@Initialize
	{
		point=360;
		SetLife(800);
		SetTimer(50);
		EnemyBossInitialize;
		SetAnimetion(tex_enemy);
		SetShotAutoDeleteClip(120,32,120,32);
	}
	@MainLoop{EnemyBossMainLoopSystem(50,invincible);yield;}
	@DrawLoop{EnemyBossDrawLoop;}
	@Finalize{EnemyBossFinalize;}
	
	
	
	task MainThread_Standard
	{
		yield;
		SetSpellCard("阿吽「義覚義玄の護法陣」",33);
		local
		{
			let wt=40;
			let x=[180,-120];
			let y=[100,180];
			ascent(a in 0..2)
			{
				Explosion01(GetX,GetY,5,0.1,60);
				SetMovePositionHermite(cenX+x[a],y[a],0,0,0,0,wt);
				SetAction(ACT_MOVE,wt);
				SetRoll(wt);
				wait(wt);
			}
			Explosion01(GetX,GetY,5,0.1,60);
			SetMovePositionHermite(cenX,cenY,0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			SetRoll(wt);
			wait(wt);
		}
		local
		{
			ascent(a in 0..2)
			{
				SetFamilier(a);
			}
			
			let wt=90;
			SetMovePositionHermite(cenX,minY+90,0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			SetRoll(wt);
			wait(wt);
		}
		SetAction(ACT_SHOT_A,180);
		wait(180);
		let r=1;
		if(rand_int(0,1)){r=-r;}
		let lp=0;
		loop
		{
			local
			{
				let p=GetAngleToPlayer;
				let way=7;
				let wide=21;
				
				let speed=2;
				let speedB=1.8;
				let angleA=p;
				let gra=[129,134];
				let delay=10;
				while(angleA<p+360)
				{
					let angleB=angleA-wide/2;
					while(angleB<=angleA+wide/2+1)
					{
						CreateShotA(1,GetX,GetY,delay);
						SetShotDataA(1,0,0,angleB,0,speed/120,speed,gra[lp%length(gra)]);
						let cnt=60;
						local
						{
							CreateShotA(2,0,0,0);
							SetShotDataA(2,0,0,angleB+180,0,speedB/60,speedB,gra[lp%length(gra)]);
							AddShot(cnt,1,2,0);
						}
						FireShot(1);
						angleB+=3;
					}
					angleA+=360/way;
				}
			}
			
			
			let wt=120;
			SetMovePositionHermite(cenX+rand(-60,60),minY+rand(80,100),0,0,0,0,wt);
			SetAction(ACT_MOVE,wt);
			SetRoll(wt);
			wait(wt);
			lp++;
		}
		
		task SetFamilier(let type)
		{
			let sx=cenX;
			let sy=cenY;
			let rot=30+180*type;
			Move;
			wait(140);
			loop
			{
				let px=GetPlayerX;
				let py=GetPlayerY;
				if(!type)
				{
					SetTargeting(px,py,0.5,180,1);
				}
				wait(30);
				loop(50)
				{
					let p=atan2(py-sy,px-sx);
					
					let speed=2;
					let angle=p;
					let gra=[67,68];
					let delay=0;
					
					CreateShot02(sx,sy,0,angle,speed/60,speed,gra[type],delay);
					wait(2);
				}
				wait(90);
			}
			task Move
			{
				let lengmax=220;
				let leng=0;
				loop
				{
					sx=cenX+(leng*1.2)*cos(rot);
					sy=cenY+(leng*0.9)*sin(rot);
					let del=240;
					let gra=[43,44];
					if(leng<lengmax){leng+=lengmax/100;del=40;}
					SetLaserEffect(sx,sy,40,40,rot+90,gra[type],del);
					rot+=1.2;
					yield;
				}
			
			}
			
		}
	}
	
	task MainThread_Advanced{}
	task MainThread_Unlimited{}
	
}