#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Midboss Nonspell 1"]
#Background["./Scene/Background.txt"]
#Text["  Kogasa Nonspell 1 "]
#Player["./Player/Reimu/Reimu.txt"]
#System["./System/Default_System.txt"]

let bossObj;
SetCommonData("Switch to Phase 2?",false);
#include "./Lib/AllStarShot_Const.dnh"
#include "./Functions/Functions_Index.dnh"

@Initialize{
	// Initialize: Works when starting up Danmakufu PH3

	//  Defines a Boss and Registers it.
	bossObj = CreateBoss;
	
	let KogasaPath = GetCurrentScriptDirectory ~ "./Img/Boss/Kogasa Sprite.png"; //Place to select sprite 
	AnimateBossA2_ZUN(bossObj,KogasaPath,64,96);
	
	if(GetCommonData("Is Plural Script",false) == false){
		ObjMove_SetPosition(bossObj,GetStgFrameWidth/2,128);
	}
	else{
		ObjMove_SetPosition(bossObj,0,-128);
	}
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	
	
	mainTask; //Runs Maintask
	
}

@Event{
	// Event: Sets the Boss's Specs
	
		// Sets Boss's Life and Timer
		alternative(GetEventType() )
		case(EV_REQUEST_LIFE) {
			SetScriptResult(2000);
		}
		case(EV_REQUEST_SPELL_SCORE) {
			SetScriptResult(false);
		}
		case(EV_REQUEST_TIMER) {
			SetScriptResult(21);
			Timeout;
		}

}

@MainLoop{
	// MainLoop: Runs throughout the script.
	
	yield;

}

@Finalize{
	ObjRender_SetColor(bossObj,255,255,255);
}

task mainTask{
	end;	
	wait(20);
	ObjMove_SetDestAtWeight(bossObj,GetStgFrameWidth/2,GetStgFrameHeight/2-72,8,10);
	wait(42);
	ConcentrateA1(bossObj,"Cherry","PURPLE",240,"Short");
	wait(60);
	SetBossHitbox(0,32);
	Burst(bossObj,"Cherry","PURPLE","Short");
	ObjRender_SetColor(bossObj,255,120,255);
	fire;
}

task fire{
	let count = 0;
	loop{
		fireleft;
		wait(72-count);
		fireright;
		wait(72-count);
		count+=3;
	}
}

task fireleft{
	let x = 0;
	let a = 19;
	let dir = rand(-30,30);
			Swipe("LEFT");
	while(x<a){
		ascent(i in 0..8){
			change;
			let shot = CreateDNHShotA1(BossX,BossY,7,dir-16+i*4,20,5+i*5);
			ObjMove_SetAcceleration(shot,-0.2);
			ObjMove_SetMaxSpeed(shot,0.1);
			ObjMove_AddPatternA3(shot,30,0.1,dir-16+i*4,0.1,0,5.25-i/3,21);
		}
		
		x++;
		dir+=360/a;
		yield;
	}
}

task fireright{
	let x = 0;
	let a = 19;
	let dir = 180-rand(-30,30);
			Swipe("RIGHT");
	while(x<a){
		ascent(i in 0..8){
			change;
			let shot = CreateDNHShotA1(BossX,BossY,7,dir+16-i*4,20,5+i*5);
			ObjMove_SetAcceleration(shot,-0.2);
			ObjMove_SetMaxSpeed(shot,0.1);
			ObjMove_AddPatternA3(shot,30,0.1,dir+16-i*4,0.1,0,5.25-i/3,21);
		}
		
		x++;
		dir-=360/a;
		yield;
	}
}

task Swipe(side){
	if(side == "LEFT"){
		BossPhase = 2;
		wait(18);
		BossPhase = 1;
	}
	if(side == "RIGHT"){
		BossPhase = 3;
		wait(18);
		BossPhase = 1;
	}
}

task change{
	PlaySnd("se_tan01",40);
	wait(30);
	PlaySnd("se_kira00",45);
}


task end{
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){ yield;}
	SetCommonData("Is Spell?",false);
	Obj_Delete(bossObj);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	
	CloseScript(GetOwnScriptID());
}