
script_enemy_main{
	let csd		=GetCurrentScriptDirectory;
	let imgBoss	=csd ~ ".\img\dot_nue.png";
	let shotData	=csd ~ ".\img\shot_all.txt";

	@Initialize {
        	SetLife(2000);
		SetTimer(110);
		SetInvincibility(180);
		InitializeAction();
		LoadUserShotData(shotData);
		SetShotAutoDeleteClip(100,100,100,100);
        	LoadGraphic(imgBoss);
        	Main;
	}
	
	@MainLoop {
        	SetCollisionA(GetX, GetY, 32);
        	SetCollisionB(GetX, GetY, 16);
		if(GetLife>20){SetDamageRate(18,0);}
		else{SetDamageRate(0,0);}
		DeleteEnemyShotImmediatelyInCircle(ALL,0,0,10);
		if(GetTimer==10&&counter==0){
			Timer;
			counter++;
		}
		if(GetMissCount==2&&OnPlayerMissed){VanishEnemy;}
		yield;
	}

	@DrawLoop {
		SetColor(255,255,255);
		SetGraphicScale(1,1);
		DrawBoss(imgBoss);
	}

	sub standBy {
		SetMovePosition03(224, 140, 10, 7);
		SetAction(ACT_MOVE, 60);
		wait(60);
	}

    	task Main {
        	yield;
		BombBarrier;
		standBy;
		CutIn(YOUMU,"|uOʗ̋|v",NULL,0,0,0,0);
		SetScore(80000000);
		SetDurableSpellCard;
		SetAction(ACT_SPELL, 120);
		wait(60);
		SetColor(255,63,63);
		Concentration01(60);
		PlaySE(seCharge1);
		wait(60);
		death;
		attack1;
		loop{if(GetLife<1500||GetTimer<=30){break;}yield;}
		if(GetTimer>30){
			loop(30){DeleteEnemyShotToItem(ALL);wait(1);}
			SetColor(255,63,63);
			if(GetTimer>30){Concentration01(60);}
			PlaySE(seCharge1);
			loop(30){DeleteEnemyShotToItem(ALL);wait(1);}
		}
		attack2;
		loop{if(GetLife<1000||GetTimer<=30){break;}yield;}
		if(GetTimer>30){
			loop(30){DeleteEnemyShotToItem(ALL);wait(1);}
			SetColor(255,63,63);
			if(GetTimer>30){Concentration01(60);}
			PlaySE(seCharge1);
			loop(30){DeleteEnemyShotToItem(ALL);wait(1);}
		}
		attack3;
		loop{if(GetLife<500||GetTimer<=30){break;}yield;}
		if(GetTimer>30){
			loop(30){DeleteEnemyShotToItem(ALL);wait(1);}
			SetColor(255,63,63);
			if(GetTimer>30){Concentration01(60);}
			PlaySE(seCharge1);
			loop(30){DeleteEnemyShotToItem(ALL);wait(1);}
		}
		attack4;
		loop{if(GetTimer<=30){break;}yield;}
		loop(30){DeleteEnemyShotToItem(ALL);wait(1);}
		SetColor(255,63,63);
		Concentration01(60);
		PlaySE(seCharge1);
		loop(30){DeleteEnemyShotToItem(ALL);wait(1);}
		attack5;
	}

	task attack1{
		loop{
			shotA(1500,30);
			loop(100){wait(1);if(GetLife<1500||GetTimer<=30){return;}}
			shotB(3);
			loop(50){wait(1);if(GetLife<1500||GetTimer<=30){return;}}
			shotC(3);
			loop(50){wait(1);if(GetLife<1500||GetTimer<=30){return;}}
			shotB(3);
			loop(50){wait(1);if(GetLife<1500||GetTimer<=30){return;}}
			shotC(3);
			yield;
		}
	}

	task shotA(life,time){
		let randangle=20;
		loop(50){
			loop(2){wait(1);if(GetLife<life||GetTimer<=time){return;}}
			let angle=rand(-randangle,randangle)-90;
			CreateLaserC(1,GetX+40*cos(angle),GetY+40*sin(angle),10,32,15,30);
			SetLaserDataC(1,0,8,angle,0,0,0);
			CreateShotA(2,0,0,30);
			SetShotDataA(2,0,0,0,0,0,0,15);
			SetShotKillTime(2,0);
			CreateShotA(3,0,0,30);
			SetShotDataA(3,0,0,0,0,0,0,15);
			SetShotKillTime(3,0);
			CreateShotA(4,0,0,30);
			SetShotDataA(4,0,0,0,0,0,0,15);
			SetShotKillTime(4,0);
			AddShot(0,1,2,0);
			AddShot(0,1,3,0);
			AddShot(0,1,4,0);
			FireShot(1);
			PlaySE(seShot3);
			randangle+=2;
		}
	}

	task shotB(speed){
		let x=40;
		let angle=90;
		while(x<=384){
			CreateLaser1(x,10,4,angle,40,10,15,speed,48);
			PlaySE(seShot3);
			x+=24;
			angle-=3;
			wait(3);
		}
	}

	task shotC(speed){
		let x=408;
		let angle=90;
		while(x>=56){
			CreateLaser1(x,10,4,angle,40,10,15,speed,48);
			PlaySE(seShot3);
			x-=24;
			angle+=3;
			wait(3);
		}
	}

	task CreateLaser1(x,y,speed,angle,length,width,color,shotspeed,shotcolor) {
		let Obj = Obj_Create(OBJ_SINUATE_LASER);
		let shotx=0;
		let shoty=0;

		Obj_SetPosition(Obj, x, y);
		Obj_SetAngle(Obj, angle);
		Obj_SetSpeed(Obj, speed);
		ObjSinuateLaser_SetLength(Obj,length);
		ObjSinuateLaser_SetWidth(Obj,width);
		ObjShot_SetGraphic(Obj, color);
		Obj_SetAutoDelete(Obj,true);
		ObjShot_SetBombResist(Obj,false);
		ObjShot_SetDelay(Obj, 0);

		wait(40);
		loop(4){
			CreateShot01(Obj_GetX(Obj)-shotx,Obj_GetY(Obj)-shoty,shotspeed+rand(-0.5,0.5),angle+rand(-5,5),shotcolor,10);
			shotx+=length*cos(angle);
			shoty+=length*sin(angle);
		}
		Obj_Delete(Obj);
	}

	task attack2{
		loop{
			shotA(1000,30);
			loop(100){wait(1);if(GetLife<1000||GetTimer<=30){return;}}
			shotD;
			loop(50){wait(1);if(GetLife<1000||GetTimer<=30){return;}}
			shotE;
			loop(50){wait(1);if(GetLife<1000||GetTimer<=30){return;}}
			shotD;
			loop(50){wait(1);if(GetLife<1000||GetTimer<=30){return;}}
			shotE;
			yield;
		}
	}

	task shotD{
		let x=40;
		let angle=90;
		while(x<=384){
			CreateLaser2(x,10,6,angle,30,10,15,2,48);
			x+=24;
			angle-=3;
			PlaySE(seShot3);
			wait(3);
		}
	}

	task shotE{
		let x=408;
		let angle=90;
		while(x>=56){
			CreateLaser2(x,10,6,angle,30,10,15,2,48);
			x-=24;
			angle+=3;
			PlaySE(seShot3);
			wait(3);
		}
	}

	task CreateLaser2(x,y,speed,angle,length,width,color,shotspeed,shotcolor) {
		let Obj = Obj_Create(OBJ_SINUATE_LASER);
		let shotx=0;
		let shoty=0;

		Obj_SetPosition(Obj, x, y);
		Obj_SetAngle(Obj, angle);
		Obj_SetSpeed(Obj, speed);
		ObjSinuateLaser_SetLength(Obj,length);
		ObjSinuateLaser_SetWidth(Obj,width);
		ObjShot_SetGraphic(Obj, color);
		Obj_SetAutoDelete(Obj,true);
		ObjShot_SetBombResist(Obj,false);
		ObjShot_SetDelay(Obj, 0);

		wait(30);
		loop(6){
			CreateShot01(Obj_GetX(Obj)-shotx,Obj_GetY(Obj)-shoty,shotspeed+rand(-0.5,0.5),angle+rand(-5,5),shotcolor,10);
			shotx+=length*cos(angle);
			shoty+=length*sin(angle);
		}
		Obj_Delete(Obj);
	}

	task attack3{
		loop{
			shotA(500,30);
			loop(80){wait(1);if(GetLife<500||GetTimer<=30){return;}}
			shotB(3.5);
			shotG;
			loop(50){wait(1);if(GetLife<500||GetTimer<=30){return;}}
			shotC(3.5);
			shotF;
			loop(50){wait(1);if(GetLife<500||GetTimer<=30){return;}}
			shotB(3.5);
			shotG;
			loop(50){wait(1);if(GetLife<500||GetTimer<=30){return;}}
			shotC(3.5);
			shotF;
			yield;
		}
	}

	task shotF{
		let x=40;
		let angle=90;
		while(x<=416){
			CreateLaser1(x,10,4,angle,40,10,15,3,48);
			x+=24;
			angle+=4;
			PlaySE(seShot3);
			wait(3);
		}
	}

	task shotG{
		let x=408;
		let angle=90;
		while(x>=32){
			CreateLaser1(x,10,4,angle,40,10,15,3,48);
			x-=24;
			angle-=4;
			PlaySE(seShot3);
			wait(3);
		}
	}

	task attack4{
		loop{
			shotA(0,30);
			loop(30){wait(1);if(GetTimer<=30){return;}}
			shotH;
			shotG;
			loop(30){wait(1);if(GetTimer<=30){return;}}
			shotI;
			shotF;
			loop(30){wait(1);if(GetTimer<=30){return;}}
			shotH;
			shotG;
			loop(30){wait(1);if(GetTimer<=30){return;}}
			shotI;
			shotF;
			loop(30){wait(1);if(GetTimer<=30){return;}}
			shotH;
			shotG;
			loop(30){wait(1);if(GetTimer<=30){return;}}
			shotI;
			shotF;
			loop(30){wait(1);if(GetTimer<=30){return;}}
			shotH;
			shotG;
			loop(30){wait(1);if(GetTimer<=30){return;}}
			shotI;
			shotF;
			yield;
		}
	}

	task shotH{
		let x=40;
		let angle=90;
		while(x<=384){
			CreateLaser3(x,10,4,angle,40,10,15,2.5,48);
			x+=24;
			angle-=3;
			PlaySE(seShot3);
			wait(3);
		}
	}

	task shotI{
		let x=408;
		let angle=90;
		while(x>=56){
			CreateLaser3(x,10,4,angle,40,10,15,2.5,48);
			x-=24;
			angle+=3;
			PlaySE(seShot3);
			wait(3);
		}
	}

	task CreateLaser3(x,y,speed,angle,length,width,color,shotspeed,shotcolor) {
		let Obj = Obj_Create(OBJ_SINUATE_LASER);
		let shotx=0;
		let shoty=0;

		Obj_SetPosition(Obj, x, y);
		Obj_SetAngle(Obj, angle);
		Obj_SetSpeed(Obj, speed);
		ObjSinuateLaser_SetLength(Obj,length);
		ObjSinuateLaser_SetWidth(Obj,width);
		ObjShot_SetGraphic(Obj, color);
		Obj_SetAutoDelete(Obj,true);
		ObjShot_SetBombResist(Obj,false);
		ObjShot_SetDelay(Obj, 0);

		wait(40);
		loop(3){
			CreateShot01(Obj_GetX(Obj)-shotx,Obj_GetY(Obj)-shoty,shotspeed+rand(-0.5,0.5),angle+rand(-5,5),shotcolor,10);
			shotx+=length*cos(angle);
			shoty+=length*sin(angle);
		}
		Obj_Delete(Obj);
	}

	task attack5{
		loop{
			shotA(0,0);
			wait(30);
			shotJ;
			shotG;
			wait(30);
			shotK;
			shotF;
			wait(30);
			shotJ;
			shotH;
			wait(30);
			shotK;
			shotI;
			wait(30);
			shotJ;
			shotG;
			wait(30);
			shotK;
			shotF;
			wait(30);
			shotJ;
			shotH;
			wait(30);
			shotK;
			shotI;
			yield;
		}
	}

	task shotJ{
		let x=40;
		let angle=90;
		while(x<=384){
			CreateLaser1(x,10,4,angle,40,10,15,4,48);
			x+=24;
			angle-=3;
			PlaySE(seShot3);
			wait(3);
		}
	}

	task shotK{
		let x=408;
		let angle=90;
		while(x>=56){
			CreateLaser1(x,10,4,angle,40,10,15,4,48);
			x-=24;
			angle+=3;
			PlaySE(seShot3);
			wait(3);
		}
	}

	task death{
		loop{
			if(GetTimer<=0||GetLife<=20){break;}
			yield;
		}
		SetCommonDataEx("Effect","bossx",GetX);
		SetCommonDataEx("Effect","bossy",GetY);
		SetCommonDataEx("Effect","boss",1);
		if(GetTimer>0&&GetLife<=20){
			wait(60);
			AddLife(-20);
		}
	}

	@Finalize{
		DeleteGraphic(imgBoss);
	}

	#include_function ".\lib\lib_anime_Nue.txt"
	#include_function ".\lib\lib_Functions.txt"
}