#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Dj non-spell 02 hard"]
#Text["Dj non-spell 02 hard"]

let famTex = "script/thdcs/system/effects/fammer.png";
let dummyTex = "";

#include "script/thdcs/system/shotlibrary.txt"
#include "script/thdcs/functions/function_common.txt"
#include "script/thdcs/functions/function_global.txt"
#include "script/thdcs/functions/function_bosseff.txt"

@Initialize {
	renderBoss(3);
	setAura(bossObj,64,255,128);
	SetCommonData("bossAttackType",1);
	SetCommonData("bossCircleType",0);
	setInvulnerableTime(bossObj,120);
	
	ObjMove_SetDestAtSpeed(bossObj,192,120,5);
	SetAutoDeleteObject(true);
	SetShotAutoDeleteClip(16,16,16,16);
	
	mainTask;
} 

@Event { 
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(300);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(66);
	}
} 

@MainLoop { yield; } 
@Finalize { } 

task mainTask { 
	yield;
	scriptEnding;
	beweeg;
}

task beweeg { 
	while(!Obj_IsDeleted(bossObj)) { 
		ObjMove_SetDestAtSpeed(bossObj,GetCenterX,GetCenterY-140,3);	
		wait(120);
		summonRecords;
		wait(240);
		ObjMove_SetDestAtSpeed(bossObj,GetClipMinX+64,GetClipMaxY-64,3);	
		wait(120);
		summonRecords;
		wait(240);		
		ObjMove_SetDestAtSpeed(bossObj,GetCenterX,GetCenterY-160,3);	
		wait(120);
		summonRecords;
		wait(180);		
		ObjMove_SetDestAtSpeed(bossObj,GetClipMaxX-64,GetClipMaxY-64,3);
		wait(120);
		summonRecords;
		wait(240);			
	}
}

sub summonRecords {	
	let dir = 270;
	PlaySFX(SFX_OPTION);
	ascent(i in 0..3) { 
		recordBullet(GetEnemyX,GetEnemyY,2,dir,251,30);
		dir+=360/3;
	}

}
task recordBullet(x,y,v,dir,kleur,delay) {
	let obj = ObjShot_Create(OBJ_SHOT);
	let obj2 = ObjEnemy_Create(OBJ_ENEMY); 	
	
	// shot overlapping the fam
	ObjShot_Regist(obj);
	ObjMove_SetPosition(obj,x,y);
	ObjMove_SetSpeed(obj,v);
	ObjMove_SetAngle(obj,dir);
	ObjShot_SetGraphic(obj,kleur);
	ObjShot_SetDelay(obj,delay);
	ObjShot_SetSpellResist(obj,true);
	Obj_SetRenderPriorityI(obj,30);
	
	// invis familiar
	ObjEnemy_Regist(obj2);
	ObjPrim_SetTexture(obj2,dummyTex); 
	ObjRender_SetScaleXYZ(obj2,1,1,0);
	ObjEnemy_SetLife(obj2,50);
	ObjMove_SetPosition(obj2,x,y);	
	Obj_SetValue(obj2,"isFamiliar",true); 
	recordHandle(obj,obj2);
	
	while(!Obj_IsDeleted(obj)) {	
		while(ObjEnemy_GetInfo(obj2, INFO_LIFE) <= 0) {
			PlaySFX(SFX_ENEP00);
			Obj_Delete(obj); Obj_Delete(obj2);
			break;
		}	
		
		ObjShot_SetIntersectionCircleA1(obj,25);
		ObjEnemy_SetIntersectionCircleToShot(obj2,ObjMove_GetX(obj2),ObjMove_GetY(obj2),25);

		ObjMove_SetPosition(obj,ObjMove_GetX(obj),ObjMove_GetY(obj));
		ObjMove_SetPosition(obj2,ObjMove_GetX(obj),ObjMove_GetY(obj));
		ObjRender_SetPosition(obj2,ObjMove_GetX(obj),ObjMove_GetY(obj),0);

		yield;
	}
	Obj_Delete(obj); Obj_Delete(obj2);
	Obj_DeleteValue(obj2,"isFamiliar");
}


task recordHandle(obj,obj2) {
	let dir = 0;
	wait(60);
	ObjMove_SetSpeed(obj,0);
	ascent(i in 0..20) {
		PlaySFX(SFX_TAN00);
		if(!Obj_IsDeleted(obj)) { 
			let recordShot = CreateShotA(ObjMove_GetX(obj),ObjMove_GetY(obj),10);
			SetShotDataA(recordShot,0,2,dir,0,0,2,109);
			SetShotDataA(recordShot,30,0,dir,0,0,0,108);
			SetShotDataA(recordShot,120,0,dir,0,0.1,2,116);

			let recordShot2 = CreateShotA(ObjMove_GetX(obj),ObjMove_GetY(obj),10);
			SetShotDataA(recordShot2,0,2,dir+120,0,0,2,109);
			SetShotDataA(recordShot2,30,0,dir+120,0,0,0,108);
			SetShotDataA(recordShot2,120,0,dir+120,0,0.1,2,116);

			let recordShot3 = CreateShotA(ObjMove_GetX(obj),ObjMove_GetY(obj),10);
			SetShotDataA(recordShot3,0,2,dir+240,0,0,2,109);
			SetShotDataA(recordShot3,30,0,dir+240,0,0,0,108);
			SetShotDataA(recordShot3,120,0,dir+240,0,0.1,2,116);		
			dir+=6;
			wait(3);
		}
	}
	ObjMove_SetSpeed(obj,2);
	PlaySFX(SFX_KIRA00);
	while(!Obj_IsDeleted(obj)) {	
		ascent(i in 0..5) { 
			CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),2,dir,221,10);
			dir+=360/5;
		}	
		PlaySFX(SFX_TAN00);
		ascent(i in 0..24) { 
			CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1,dir,100,10);
			CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1.1,dir+24,100,10);
			dir+=360/24;
		}	
		dir+=33;
		wait(90);	
	}
}

task scriptEnding {
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0) {
		yield;
	}

	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(bossObj);

	CloseScript(GetOwnScriptID());
}
 