#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Afro spell 01 hard"]
#Text["Afro spell 01 hard"]

#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 {
	SetCommonData("spellScriptID",GetOwnScriptID);
	
	renderBoss(2);
	setAura(bossObj,64,64,255);
	SetCommonData("bossCircleType",2);
	SetCommonData("bossAttackType",2);
	SetCommonData("bossBgType",2);
	if(GetAreaCommonData("system","gameLang",0) == 0) { SetCommonData("cardName","tB[o[ ufBXR O[v"); } 
	if(GetAreaCommonData("system","gameLang",0) == 1) { SetCommonData("cardName","Fever uDisco Groovesv"); } 		
	setInvulnerableTime(bossObj,120);
	
	concenEffect(bossObj,15,4,64,64,255);
	concenEffect(bossObj,15,4,255,64,64);
	concenEffect(bossObj,15,4,64,255,64);
	concenEffect(bossObj,15,4,255,255,64);

	concenEffect(bossObj,30,3,155,32,255);
	concenEffect(bossObj,30,3,255,255,255);
	concenEffect(bossObj,30,3,255,255,64);	

	ObjMove_SetDestAtSpeed(bossObj,192,GetCenterY-128,3);
	SetShotAutoDeleteClip(16,16,16,16);
	SetAutoDeleteObject(true);
	mainTask;
} 

@Event { 
	alternative(GetEventType()) 
	case(EV_REQUEST_LIFE) { 
		SetScriptResult(380);
	}
	case(EV_REQUEST_TIMER) { 
		SetScriptResult(43);
	}
	case(EV_REQUEST_SPELL_SCORE) {
	    let spellCardBonus = calculateAndGetSpellCardBonus();
		SetScriptResult(spellCardBonus);
	}	
	case(EV_USER+9999) {
		SetCommonData("spellcardID","tenji01hard");
	}	
} 

@MainLoop { yield; } 
@Finalize { } 


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

// Movement 
task beweeg { 
	while(!Obj_IsDeleted(bossObj)) { 
		ObjMove_SetDestAtWeight(bossObj,rand_int(GetClipMinX+64,GetClipMaxX-64),GetEnemyY,15,15);
		wait(90);
		vuur;
		wait(240);
	}
}

// Fever attack with lasers and stars
task vuur {
	let dir = 0;
	let dir2 = 0;
	let kleur = 134;

	// wind up animation
	bossAttack = 1;	
	quakeCam2D(15,55);
	PlaySFX(SFX_POWER0);
	concenEffect(bossObj,40,3,255,128,255);
	concenEffect(bossObj,40,3,128,128,255);
	concenEffect(bossObj,40,3,255,128,128);
	concenEffect(bossObj,40,3,128,255,128);
	concenEffect(bossObj,15,4,255,128,128);
	concenEffect(bossObj,15,4,128,255,128);
	wait(60);
	bossAttack = 2;

	// lasers from hands
	ascent(i in 0..32) {
		wait(2);
		
		// effect
		let effShot = CreateShotA(GetEnemyX-20,GetEnemyY+10,30);
		let effShot2 = CreateShotA(GetEnemyX+20,GetEnemyY+10,30);
		SetShotDataA(effShot,0,0,0,0,0,0,4);
		SetShotDataA(effShot2,0,0,0,0,0,0,6);
		DeleteShotA(effShot,0);
		DeleteShotA(effShot2,0);
		
		// lasers
		PlaySFX(SFX_LAZER01);
		CreateLooseLaserA1(GetEnemyX-20,GetEnemyY+10,3,GetAngleToPlayer(bossObj)-4+dir,300,10,4,20);
		CreateLooseLaserA1(GetEnemyX+20,GetEnemyY+10,3,GetAngleToPlayer(bossObj)+4-dir,300,10,6,20);
		CreateLooseLaserA1(GetEnemyX-20,GetEnemyY+10,3,GetAngleToPlayer(bossObj)-160-dir,300,10,2,20);
		CreateLooseLaserA1(GetEnemyX+20,GetEnemyY+10,3,GetAngleToPlayer(bossObj)-200+dir,300,10,3,20);
		dir+=10;
	}
	dir = 0;
	bossAttack = 0;
	
	ascent(i in 0..36) {
		PlaySFX(SFX_KIRA00);
		ascent(j in 0..4) { 
			CreateShotA1(bossX-25,bossY-60,2.5,dir,kleur,10);
			CreateShotA1(bossX-25,bossY-60,2.6,dir,kleur,10);
			CreateShotA1(bossX-25,bossY-60,2.7,dir,kleur,10);
			CreateShotA1(bossX-25,bossY-60,2.8,dir,kleur,10);
			dir+=360/4;
			dir++;
		}
		kleur++;
		if(kleur == 148) { kleur=134; }
		dir+=8;
		wait(2);
	}
}


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

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

	CloseScript(GetOwnScriptID());
}
 