#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Noncard02"]
#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);
	SetAction(objEnemyMain,ACT_MOVE,60);
	ObjMove_SetDestAtWeight(objEnemyMain, GetCenterX, GetCenterY-90, 10, 5);
	
	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 = 0;
	wait(150);
	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);
		PlaySoundEffect(effect2,100);
		loop(8) {
			SpinKnife(dir,1);
			SpinKnife(dir+360/16,-1);
			dir+=360/8;
		}
		wait(50);
		SetAction(objEnemyMain,ACT_MOVE,60);
		SetMovePositionRandom(objEnemyMain,60,15,10,1.5,GetCenterX-100,GetCenterX+100,GetCenterY-160,GetCenterY-70);
		wait(150);
	}
}
task SpinKnife(dir,rot) {
	let obj = CreateShot01(GetX,GetY,9,dir,KNIFE_BLUE,0);
	ObjShot_SetSpellResist(obj, true);
	ObjMove_SetAcceleration(obj,-9/12);
	ObjMove_SetMaxSpeed(obj,0);
	
	let spin = 0;
	
	loop(60) {
		ObjRender_SetAngleZ(obj,spin);
		spin+=18.0*rot;
		yield;
	}
	PlaySoundEffect(shot,100);
	ObjRender_SetAngleZ(obj,0);
	ObjMove_SetSpeed(obj,5);
	ObjMove_SetMaxSpeed(obj,5);
	ObjMove_SetAngularVelocity(obj,1.3*rot);
	
	let count = 0;
	
	while(!Obj_IsDeleted(obj)) {
		if(count==8) {
			PlaySoundEffect(wave,90);
			CreateShot02(ObjMove_GetX(obj),ObjMove_GetY(obj),0,ObjMove_GetAngle(obj)+20,2.3/45,2.3,KNIFE_GREEN,15);
			CreateShot02(ObjMove_GetX(obj),ObjMove_GetY(obj),0,ObjMove_GetAngle(obj)-20,2.3/45,2.3,KNIFE_GREEN,15);
			CreateShot02(ObjMove_GetX(obj),ObjMove_GetY(obj),0,ObjMove_GetAngle(obj)+20+180,2.3/45,2.3,KNIFE_GREEN,15);
			CreateShot02(ObjMove_GetX(obj),ObjMove_GetY(obj),0,ObjMove_GetAngle(obj)-20+180,2.3/45,2.3,KNIFE_GREEN,15);
			count = 0;
		}
		count++;
		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);
}