script_enemy_main {
	#include_function ".\includeKoishi.txt"
	task TMain {
		SetDamageRate(65, 0);
		SetMovePosition03(GetCenterX+32, GetCenterY-75, 10, 9);
		SetInvincibility(180);
		while(OnPlayerMissed || OnBomb) { SetInvincibility(180); yield; }
		wait(120);
		TCharge(GetX, GetY);
		PlaySE2("charge");
		wait(60);
		attack1;
		attack2;
		attack3;
		attack4;
	}
	task attack1 {
		TCharge(GetX, GetY);
		PlaySE2("charge");
		let a = 0;
		let r = 90-45;
		loop {
			let x1 = GetX; let y1 = GetY;
			PlaySE2("tan00");
			ascent(i in 0..2) {
				let x = 100*cos(a+i*360/2); let y = 35*sin(a+i*360/2);
				CreateShot01(x1+x*cos(r)-y*sin(r), y1+y*cos(r)+x*sin(r), 2, 90+a, 47, 10);
			}
			a+=16; a%=360; r+=3/2; r%=360;
			wait([5, 5, 3, 3][GetDifficulty]);
		}
	}
	task attack2 {
		while(GetCommonDataDefault("Life Master", 0) > 4000 && GetCommonDataDefault("Boss Timer", 0)/60 > 100) { yield; }
		DeleteEnemyShotToItemInCircle(ALL, GetX, GetY, 1000);
		TCharge(GetX, GetY);
		PlaySE2("charge");
		let a = 0;
		let b = 50;
		while(GetCommonDataDefault("Life Master", 0) > 1500 && GetCommonDataDefault("Boss Timer", 0)/60 > 45) {
			PlaySE2("tan01");
			CreateShot01(GetCenterX+70*cos(90+a), GetY+70*sin(90+a), 3, 90+b, 204, 15);
			a-=24; a%=360;
			b+=18; a%=360;
			wait([7, 5, 7, 5][GetDifficulty]);
		}
	}
	task attack3 {
		while(GetCommonDataDefault("Life Master", 0) > 3000 && GetCommonDataDefault("Boss Timer", 0)/60 > 80) { yield; }
		DeleteEnemyShotToItemInCircle(ALL, GetX, GetY, 1000);
		TCharge(GetX, GetY);
		PlaySE2("charge");
		loop {
			let a = GetAngleToPlayer;
			ascent(i in 0..20) {
				PlaySE2("tan00");
				ascent(j in -2..3) { CreateShot01(GetX, GetY, 2+i/20*3, a+j*23-10-i/2, 17, 5); }
				wait(2);
			}
			wait([45, 30, 20, 10][GetDifficulty]);
			wait(40);
			wait([45, 30, 20, 10][GetDifficulty]);
		}
	}
	task attack4 {
		while(GetCommonDataDefault("Life Master", 0) > 1500 && GetCommonDataDefault("Boss Timer", 0)/60 > 45) { yield; }
		DeleteEnemyShotToItemInCircle(ALL, GetX, GetY, 1000);
		TCharge(GetX, GetY);
		PlaySE2("charge");
		task Algorithm {
			let obj_ = Obj_Create(OBJ_SHOT);
			Obj_SetPosition(obj_, GetX, GetY);
			Obj_SetSpeed(obj_, 3/2);
			Obj_SetAngle(obj_, GetAngleToPlayer);
			ObjShot_SetGraphic(obj_, 1);
			Obj_SetAlpha(obj_, 0);
			Obj_SetCollisionToPlayer(obj_, false);
			ObjShot_SetBombResist(obj_, true);
			Obj_SetAutoDelete(obj_, false);
			task AlgorithmBullet(ang) {
				let obj = Obj_Create(OBJ_SHOT);
				Obj_SetAngle(obj, GetAngleToPlayer);
				ObjShot_SetGraphic(obj, 70);
				ObjShot_SetBombResist(obj, true);
				Obj_SetAutoDelete(obj, false);
				let a = ang; let r = 0;
				loop(600) { 
					Obj_SetPosition(obj, Obj_GetX(obj_)+r*cos(a), Obj_GetY(obj_)+r*sin(a));
					if(r < 100) { r+=4; }
					a+=[1, 3/4, 3/4, 1/2][GetDifficulty]; a%=360;
				yield; }
				Obj_Delete(obj);
			}
			let angle = rand(0,360);
			let num = [10, 15, 15, 18][GetDifficulty];
			ascent(i in 0..num) { AlgorithmBullet(angle+i*360/num); }
			loop(600) { yield; } Obj_Delete(obj_);
		}
		loop {
			Algorithm;
			wait(150);
			wait(150);
		}
	}
}