#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Afro non-spell 04 lunatic"]
#Text["Afro non-spell 04 lunatic"]

#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(300);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(45);
	}
} 

@MainLoop { yield; } 
@Finalize { } 

task mainTask { 
	yield;
	scriptEnding;	
	wait(60);
	beweeg;
	vuur;
	wait(60);
	vuur2;
} 

//beweeg
task beweeg {
	while(!Obj_IsDeleted(bossObj)) {
		ObjMove_RandomPosWeight(bossObj,rand_int(60,90),rand_int(10,30),15,30,GetClipMinX+64,GetClipMinY+64,GetClipMaxX-64,GetCenterY-128);
		wait(240);
	}
}

task vuur {
	let kleur = 134;
	let kleur2 = 195;
	let dir = 0;
	while(!Obj_IsDeleted(bossObj)) {
		wait(5);
		PlaySFX(SFX_TAN00);
		CreateShotA1(GetEnemyX+rand(60,80)*cos(rand(0,360)),GetEnemyY+rand(60,80)*sin(rand(0,360)),rand(1,3),rand(0,360),kleur2,30);
		wait(1);
		CreateShotA1(GetEnemyX+rand(60,80)*cos(rand(0,360)),GetEnemyY+rand(60,80)*sin(rand(0,360)),rand(1,3),rand(0,360),kleur,0);
		CreateShotA1(GetEnemyX+rand(60,80)*cos(rand(0,360)),GetEnemyY+rand(60,80)*sin(rand(0,360)),rand(1,3),rand(0,360),kleur,30);
		wait(1);
		CreateShotA1(GetEnemyX+rand(60,80)*cos(rand(0,360)),GetEnemyY+rand(60,80)*sin(rand(0,360)),rand(1,3),rand(0,360),kleur,0);
		CreateShotA1(GetEnemyX+rand(60,80)*cos(rand(0,360)),GetEnemyY+rand(60,80)*sin(rand(0,360)),rand(1,3),rand(0,360),kleur,30);


		let effy = CreateShotA(GetEnemyX+rand(60,300)*cos(rand(0,360)),GetEnemyY+rand(60,300)*sin(rand(0,360)),70);
		SetShotDataA(effy,0,0,dir,0,0,0,kleur);
		DeleteShotA(effy,0);

		let effy2 = CreateShotA(GetEnemyX+rand(200,300)*cos(rand(0,360)),GetEnemyY+rand(200,300)*sin(rand(0,360)),150);
		SetShotDataA(effy2,0,0,dir,0,0,0,kleur);
		DeleteShotA(effy2,0);

		let effy3 = CreateShotA(GetEnemyX+rand(200,300)*cos(rand(0,360)),GetEnemyY+rand(200,300)*sin(rand(0,360)),150);
		SetShotDataA(effy3,0,0,dir,0,0,0,kleur);
		DeleteShotA(effy3,0);

		let effy4 = CreateShotA(GetEnemyX+rand(200,300)*cos(rand(0,360)),GetEnemyY+rand(200,300)*sin(rand(0,360)),150);
		SetShotDataA(effy4,0,0,dir,0,0,0,kleur);
		DeleteShotA(effy4,0);

		kleur++;
		kleur2++;
		if(kleur == 148){ kleur = 134; }
		if(kleur2 == 200){ kleur2 = 195; }
		dir = 0;
	}
}

task vuur2 {
	let kleur = 229;
	let dir = 0;
	while(!Obj_IsDeleted(bossObj)) {
		ascent(i in 0..24) { 
			CreateShotA1(GetEnemyX+70*cos(dir),GetEnemyY+70*sin(dir),2.0,GetAngleToPlayer(bossObj)+dir,kleur,40);
			CreateShotA1(GetEnemyX+70*cos(dir),GetEnemyY+70*sin(dir),2.0,-GetAngleToPlayer(bossObj)+dir,kleur,40);
			dir+=360/24;
		}
		dir+=4;
		kleur++;
		if(kleur == 235){ kleur = 229; }
		wait(120);
	}
}


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

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

	CloseScript(GetOwnScriptID());
}
 