#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Noncard01"]
#Text[""]
#Background["./Background.dnh"]
#System["./System/System Prototype.dnh"]
#Player["./Player/Rin Satsuki/Rin.dnh","./Player/Tokiko/Tokiko.dnh"]

#include"./Shot/ZUNShot_Const.dnh"
#include"./LIB/Function_Misc.dnh"
#include"./LIB/Function_Audio.dnh"
#include"./LIB/Function_Effect.dnh"
#include"./LIB/Function_Enemy.dnh"
#include"./LIB/Function_Shot.dnh"
#include"./LIB/SE_Const.dnh"
#include"./LIB/Animation/lib_anime_Sakuya.txt"

let CSD = GetCurrentScriptDirectory;
let MD = GetModuleDirectory;

let objEnemyMain;
let objScene;
let objList = [];
let Anim_Attack = 0;
let GetCenterX = GetStgFrameWidth/2;
let GetCenterY = GetStgFrameHeight/2;
let GetLife = 0;
let GetTimer = 0;
let GetX = 0;
let GetY = 0;

@Loading {
}

@Event {
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){ SetScriptResult(7000); }
	case(EV_REQUEST_TIMER){	SetScriptResult(40); }
}

@Initialize {
	objEnemyMain = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	objScene = GetEnemyBossSceneObjectID;
	ObjEnemy_Regist(objEnemyMain);

	Obj_SetValue(objEnemyMain,"Boss Name","Sakuya Izayoi");
	Obj_SetValue(objEnemyMain,"Aura Color",[1,10,10]);
	PlayEnemyHitSound(objEnemyMain, 1);
	InitializeAction(objEnemyMain, CSD ~ "LIB/Animation/img/dot_sakuya.png");
	DrawBoss_Task(objEnemyMain);
	
	SetInvincibilityDamageRate(objEnemyMain, 120, 250, 240);
	
	ObjMove_SetPosition(objEnemyMain, GetCenterX, GetCenterY-130);
	
	mainTask;
	End;
	
}

@MainLoop {
	GetX = ObjMove_GetX(objEnemyMain);
	GetY = ObjMove_GetY(objEnemyMain);
	GetLife = ObjEnemy_GetInfo(objEnemyMain,INFO_LIFE);
	GetTimer = ObjEnemyBossScene_GetInfo(objScene,INFO_TIMER);
	
	ObjEnemy_SetIntersectionCircleToShot(objEnemyMain, GetX, GetY, 24);
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemyMain, GetX, GetY, 16);
	
	yield;
}

task mainTask {
	let dir = rand(-30,30);
	let dir1 = dir-90;
	let dir2 = dir+90;
	wait(120);
	loop {
		PlaySoundEffect(charge2,100);
		ConcentrationA1(objEnemyMain,50,7,170,[255,96,96]);
		wait(50);
		let w = 10;
		SetAction(objEnemyMain,ACT_SHOT_B,300);
		wait(10);
		loop(27) {
			PlaySoundEffect(shot,90);
			SpinKnife(dir1,1);
			SpinKnife(dir2,-1);
			SpinKnife(dir1+90,1);
			SpinKnife(dir2+90,-1);
			SpinKnife(dir1+180,1);
			SpinKnife(dir2+180,-1);
			SpinKnife(dir1+270,1);
			SpinKnife(dir2+270,-1);
			dir1+=350/18;
			dir2-=350/18;
			wait(7+w);
			if(w>0) { w-=0.6; }
			else { w = 0; }
		}
		// dir = rand(-30,30);
		// dir1 = dir-90;
		// dir2 = dir+90;
		wait(15);
		let angle = rand(0,360);
		CreateShotRing02(35,GetX,GetY,5,angle,-3/30,2,KNIFE_GRAY,20);
		CreateShotRing02(35,GetX,GetY,5,angle+360/60,-3/30,2,KNIFE_GRAY,45);
		wait(30);
		SetAction(objEnemyMain,ACT_MOVE,60);
		SetMovePositionRandom(objEnemyMain,60,15,10,1.5,GetCenterX-100,GetCenterX+100,GetCenterY-170,GetCenterY-75);
		wait(90);
	}
}
task SpinKnife(dir,rot) {
	let obj = CreateShot01(GetX,GetY,9,dir,KNIFE_BLUE,0);
	ObjMove_SetAcceleration(obj,-9/12);
	ObjMove_SetMaxSpeed(obj,0);
	
	let spin = 0;
	
	loop(60) {
		ObjRender_SetAngleZ(obj,spin);
		spin+=18.0*rot;
		yield;
	}
	ObjRender_SetAngleZ(obj,0);
	ObjMove_SetAngle(obj,ObjMove_GetAngle(obj)+60*rot);
	ObjMove_SetSpeed(obj,3.7);
	ObjMove_SetMaxSpeed(obj,3.7);
	while(!Obj_IsDeleted(obj)) {
		if(ObjMove_GetX(obj)>GetCenterX*2) { ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj)); break; }
		if(ObjMove_GetX(obj)<0) { ObjMove_SetAngle(obj,180-ObjMove_GetAngle(obj)); break; }
		yield;
	}
}
task End {
	while(ObjEnemy_GetInfo(objEnemyMain, INFO_LIFE) > 0) { yield; }
	DeleteShotWave(1,GetX,GetY,15);
	PlaySoundEffect(shot,100);
	Obj_Delete(objEnemyMain);
	yield;
	CloseScript(GetOwnScriptID);
}