#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Fifi-chan spell 01 lunatic"]
#Text["Fifi-chan spell 01 lunatic"]

let cutFifi = "script/thdcs/system/face/fifichan.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"
#include "script/thdcs/functions/function_cutin.txt"

@Initialize {
	SetCommonData("spellScriptID",GetOwnScriptID);
	
	renderBoss(11);	
	setAura(bossObj,255,64,64);
	SetCommonData("bossCircleType",0);
	SetCommonData("bossAttackType",2);
	SetCommonData("bossBgType",1);
	if(GetAreaCommonData("system","gameLang",0) == 0) { SetCommonData("cardName","J u~ǂȓv"); } 
	if(GetAreaCommonData("system","gameLang",0) == 1) { SetCommonData("cardName","Peaceful day uInnocent Animalv"); } 	
	setInvulnerableTime(bossObj,120);
	
	concenEffect(bossObj,60,2,255,64,128);
	ObjMove_SetDestAtSpeed(bossObj,192,120,5);
	SetShotAutoDeleteClip(16,16,16,16);
	SetAutoDeleteObject(true);

	mainTask;
} 

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

@MainLoop { yield; } 
@Finalize { }  

task mainTask {
	yield;
	wait(120);
	scriptEnding;
	movement; 
			
}

task movement {
	let r = 0;
	let v = 3;
	let dir = 0;
	let vx = v*cos(dir);
	let vy = v*sin(dir);	
	let x = 0;
	let y = 0;
	ObjMove_SetDestAtSpeed(bossObj,GetClipMinX-64,100,5);
	while(ObjMove_GetSpeed(bossObj) > 0) { yield; }
	x = ObjMove_GetX(bossObj);
	y = ObjMove_GetY(bossObj);
	fire;
	fire2;
	while(!Obj_IsDeleted(bossObj)) {
		ObjMove_SetSpeed(bossObj,1);
		
		// right side move
		loop(180) {
			ObjMove_SetPosition(bossObj,x+r*cos(dir),y+25*sin(dir));
			dir+=8;
			ObjMove_SetAngle(bossObj,dir);
			x += vx;
			y += vy;
			y = absolute(y);
			yield;
		}
		
		// reposition and update
		ObjMove_SetPosition(bossObj,GetClipMaxX+64,GetCenterY+32);
		x = ObjMove_GetX(bossObj);
		y = ObjMove_GetY(bossObj);
		
		// left side move
		loop(180) { 
			ObjMove_SetPosition(bossObj,x+r*cos(dir),y+25*sin(dir));
			dir+=8;
			ObjMove_SetAngle(bossObj,dir);
			x -= vx;
			y -= vy;
			y = absolute(y);
			yield;
		}	
		
		// reposition and update
		ObjMove_SetPosition(bossObj,GetClipMinX-64,100);
		x = ObjMove_GetX(bossObj);
		y = ObjMove_GetY(bossObj);		
	}
}

// hopping shot
task fire {
	let dir = 0;
	while(!Obj_IsDeleted(bossObj)) {
		ascent(i in 0..7) {
			let fifiShot00 = CreateShotA1(bossX,bossY+48,0,ObjMove_GetAngle(bossObj),13,5);
			ObjMove_AddPatternA2(fifiShot00,30+(i*10),0,NO_CHANGE,0.1,0,2+(i/3));
		}
		wait(3);
	}
}

// flower petals 
task fire2 { 
	let speed = 0;
	while(!Obj_IsDeleted(bossObj)) {
		PlaySFX(SFX_TAN00);
		ascent(i in 0..12) {
			speed = rand(2,4);
			CreateShotB2(bossX,bossY,speed*cos(rand(265,275)),speed*sin(rand(265,275)),0,0.05,0,rand(1,3.5),55,5);
			CreateShotB2(bossX,bossY,speed*cos(rand(255,285)),speed*sin(rand(255,285)),0,0.05,0,rand(1,3),55,5);
		}
		wait(60);
	}
}

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

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

	CloseScript(GetOwnScriptID());
}



