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

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

#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,240);
	
	ObjMove_SetDestAtSpeed(bossObj,192,120,5);
	SetAutoDeleteObject(true);
	mainTask;
} 

@Event { 
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(360);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(45);
	}
} 

@MainLoop { yield; } 
@Finalize { } 


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

// Movement
task beweeg { 
	while(!Obj_IsDeleted(bossObj)) { 
		bossAttack = 3;
		vuurLeft;
		wait(45);
		bossAttack = 4;
		vuurRight;	
		wait(45);
		bossAttack = 2;
		fountainFam(GetPlayerX-60,GetClipMaxY,0.1);
		fountainFam(GetPlayerX+60,GetClipMaxY,-0.1);
		wait(75);
		bossAttack = 0;
		wait(75);
		ObjMove_SetDestAtWeight(bossObj,rand_int(GetClipMinX+32,GetClipMaxX-64),GetEnemyY,5,5);
		wait(120);
		ObjMove_SetDestAtWeight(bossObj,GetPlayerX,GetEnemyY,5,5);
	}
}

// Left fountain
task vuurLeft { 
	let speed = 0;
	ascent(i in 0..24) {
		PlaySFX(SFX_TAN01);
		speed = rand_int(5,9);
		CreateShotB2(GetClipMinX+32,GetClipMaxY,speed*cos(rand(265,275)),speed*sin(rand(265,275)),0,0.05,0,rand(0.3,3),207,15);
		CreateShotB2(GetClipMinX+32,GetClipMaxY,speed*cos(rand(265,275)),speed*sin(rand(265,275)),0,0.05,0,rand(0.3,3),52,15);
		wait(3);		
	}
}

// Right fountain
task vuurRight { 
	let speed = 0;
	ascent(i in 0..24) {
		PlaySFX(SFX_TAN01);
		speed = rand_int(5,9);
		CreateShotB2(GetClipMaxX-32,GetClipMaxY,speed*cos(rand(265,275)),speed*sin(rand(265,275)),0,0.05,0,rand(0.3,3),207,15);
		CreateShotB2(GetClipMaxX-32,GetClipMaxY,speed*cos(rand(265,275)),speed*sin(rand(265,275)),0,0.05,0,rand(0.3,3),52,15);
		wait(3);
	}
}

// Middle fountains as fams
task fountainFam(x,y,sidev) {
	let obj = ObjEnemy_Create(OBJ_ENEMY); 
	
	let famSpin = 0;
	let c = 0;
	
	ObjEnemy_Regist(obj);
	ObjPrim_SetTexture(obj,famTex); 
	ObjRender_SetScaleXYZ(obj,1.2,1.2,0);
	ObjSprite2D_SetSourceRect(obj,64,0,96,32); 
	ObjSprite2D_SetDestCenter(obj);
	ObjMove_SetPosition(obj,x,y);
	
	concenEffect(obj,8,4,64,64,255);
	concenEffect(obj,8,4,255,64,64);
	concenEffect(obj,8,4,64,255,64);	
	
	PlaySFX(SFX_OPTION);
	fountainFamShot(obj); 
	
	while(!Obj_IsDeleted(bossObj)) {
		if(c > 30) { ObjMove_SetPosition(obj,ObjMove_GetX(obj)+sidev,ObjMove_GetY(obj)); }
		c++;
		
		ObjRender_SetAngleZ(obj,famSpin);
		famSpin+=10;
		yield;
	}
	Obj_Delete(obj);
}

// Fountain shots
task fountainFamShot(obj) {
	let speed = 0;
	wait(30);
	ascent(i in 0..24) { 
		PlaySFX(SFX_TAN00);
		speed = rand_int(5,9);
		CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),speed*cos(rand(265,275)),speed*sin(rand(265,275)),0,0.04,0,rand(0.3,3),205,15);
		CreateShotB2(ObjMove_GetX(obj),ObjMove_GetY(obj),speed*cos(rand(265,275)),speed*sin(rand(265,275)),0,0.04,0,rand(0.3,3),46,15);
		wait(3);
	}
	Obj_Delete(obj);
}

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

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

	CloseScript(GetOwnScriptID());
}
 