#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Afro non-spell 05 normal"]
#Text["Afro non-spell 05 normal"]

#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(2);
	setAura(bossObj,64,64,255);
	SetCommonData("bossAttackType",1);
	SetCommonData("bossCircleType",0);
	setInvulnerableTime(bossObj,120);
	
	ObjMove_SetDestAtSpeed(bossObj,192,120,5);
	SetAutoDeleteObject(true);
	mainTask;
} 

@Event { 
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(350);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(49);
	}
} 

@MainLoop { yield; } 
@Finalize { } 


task mainTask { 
	yield;
	scriptEnding;	
	wait(60);
	guruguru;
} 

// Head spinning task 
task guruguru {
	let randMoveLoc = [64,GetCenterX-96,GetCenterX+64,270];
	let randMovePick = 0;
	
	while(!Obj_IsDeleted(bossObj)) { 
		PlaySFX(SFX_POWER0);
		PlaySFX(SFX_CH00);
		exploEffect(bossX,bossY,5.5,0.2);
		headSpeed = 2;
		bossAttack = 2;		
		fire;
		wait(75);
		PlaySFX(SFX_POWER0);
		PlaySFX(SFX_CH00);
		exploEffect(bossX,bossY,5.5,0.2);
		fire2;		
		headSpeed = 2;
		wait(60);
		headSpeed = 0;
		wait(15);
		bossAttack = 0;
		wait(45);	
		randMovePick = rand_int(0,4);
		ObjMove_SetDestAtWeight(bossObj,randMoveLoc[randMovePick],120,10,15);	
		wait(30);
	}
}

// spin shot 1
task fire { 
	let dir = 270;
	let kleur = 47; 
	let kleur2 = 194; 
	ascent(i in 0..60) { 
		PlaySFX(SFX_TAN00);
		let guruShot00 = CreateShotA(bossX+64*cos(dir),bossY+64*sin(dir),30);
		SetShotDataA(guruShot00,0,-0.3,dir,0,0,0,kleur);
		SetShotDataA(guruShot00,60,3.5,dir,0,0,0,kleur2);
		
		let guruShot01 = CreateShotA(bossX-64*cos(dir),bossY-64*sin(dir),30);
		SetShotDataA(guruShot01,0,0.3,dir,0,0,0,kleur);
		SetShotDataA(guruShot01,60,-3.5,dir,0,0,0,kleur2);		
		
		if(headSpeed == 1) { dir+=10; }
		if(headSpeed == 2) { dir-=25; }

		kleur2++;
		if(kleur2 > 200) { kleur2 = 194; } 
		wait(1);
	}
}

// spin shot 2
task fire2 { 
	let dir = 270;
	let kleur = 47; 
	let kleur2 = 194; 
	ascent(i in 0..60) { 
		PlaySFX(SFX_TAN00);
		let guruShot00 = CreateShotA(bossX+64*cos(dir),bossY+64*sin(dir),30);
		SetShotDataA(guruShot00,0,-0.3,dir,0,0,0,kleur);
		SetShotDataA(guruShot00,60,3.5,dir,0,0,0,kleur2);
		
		let guruShot01 = CreateShotA(bossX-64*cos(dir),bossY-64*sin(dir),30);
		SetShotDataA(guruShot01,0,0.3,dir,0,0,0,kleur);
		SetShotDataA(guruShot01,60,-3.5,dir,0,0,0,kleur2);		
		
		if(headSpeed == 1) { dir-=10; }
		if(headSpeed == 2) { dir+=25; }

		kleur2++;
		if(kleur2 > 200) { kleur2 = 194; } 
		wait(1);
	}
}

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

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

	CloseScript(GetOwnScriptID());
}
 