#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Boss Spellcard 1"]
#Background["./Scene/Background.txt"]
#Text[" Cryokinesis - \"Elegant Snowflower's Bloom\" "]
#Player["./Player/Reimu/Reimu.txt"]
#System["./System/Default_System.txt"]

let bossObj;

#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 LettyPath = GetCurrentScriptDirectory ~ "./Img/Boss/Letty Sprite.png"; //Place to select sprite 
	AnimateBossA1_CtC(bossObj,LettyPath);
	
	if(GetCommonData("Is Plural Script",false) == false){
		ObjMove_SetPosition(bossObj,GetStgFrameWidth/2,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(3250);
		}
		case(EV_REQUEST_SPELL_SCORE) {
			SetScriptResult(100000);
		}
		case(EV_REQUEST_TIMER) {
			SetScriptResult(40);
			Timeout;
		}

}

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

}

@Finalize{
}

task mainTask{
	end;	
	if(GetCommonData("Is Plural Script",false) == false){
		wait(30);
		ObjMove_SetDestAtWeight(bossObj,GetStgFrameWidth/2,GetStgFrameHeight/2-72,10,5);
		wait(42);
	}
	else{
		ObjMove_SetDestAtWeight(bossObj,GetStgFrameWidth/2,GetStgFrameHeight/2-72,10,5);
	}
	SetCommonData("Boss Type","LETTY");
	let sceneObj = GetEnemyBossSceneObjectID;
	ObjEnemyBossScene_StartSpell(sceneObj);
	CutIn("Cryokinesis - \"Elegant Snowflower's Bloom\"");
	wait(75);
	SetBossHitbox(32,32);
	ConcentrateA1(bossObj,"Snow","AQUA",300,"Short");
	wait(60);
	Burst(bossObj,"Snow","AQUA","Long");
	loop{
		BossPhase = 2;
		fire;
		wait(90);
		BossPhase = 1;
		wait(20);
		RandMove(bossObj,rand(96,128),rand(32,96), 10, 5, 64, 96, GetStgFrameWidth-64, GetStgFrameHeight/2-64);
		wait(100);
		BossPhase = 2;
		fire2;
		wait(90);
		BossPhase = 1;
		wait(20);
		RandMove(bossObj,rand(96,128),rand(32,96), 10, 5, 64, 96, GetStgFrameWidth-64, GetStgFrameHeight/2-64);
		wait(100);
	}

}

task fire{
	let objarr = [];
	let dir = rand(-90,90);
	PlaySnd("se_lazer01",55);
	ascent(i in 0..7){
		objarr = objarr ~ [CreateDNHCurveLaserA1(BossX,BossY,0,dir,55,16,1025,0)];
		change(objarr[i]);
		fireshots(objarr[i],"AQUA");
		dir+=360/7;
	}
	task change(obj){
		ObjCrLaser_SetTipDecrement(obj,0.1);
		ObjMove_SetAcceleration(obj,0.04);
		ObjMove_SetMaxSpeed(obj,20);
		ObjMove_SetAngularVelocity(obj,1.5);
	}
}

task fire2{
	let objarr = [];
	let dir = rand(-90,90);
	PlaySnd("se_lazer01",55);
	ascent(i in 0..7){
		objarr = objarr ~ [CreateDNHCurveLaserA1(BossX,BossY,0,dir,70,16,1022,0)];
		change(objarr[i]);
		fireshots(objarr[i],"BLUE");
		dir+=360/7;
	}
	task change(obj){
		ObjCrLaser_SetTipDecrement(obj,0.1);
		ObjMove_SetAcceleration(obj,0.04);
		ObjMove_SetMaxSpeed(obj,20);
		ObjMove_SetAngularVelocity(obj,-1.5);
	}
}

task fireshots(obj,colour){
	let s = 87;
	loop(8){
	PlaySnd("se_kira00",40);
	ascent(i in 0..5){
		if(!Obj_IsDeleted(obj)){
			if(colour == "AQUA"){
			CreateDNHShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5+(i/4),ObjMove_GetAngle(obj)+90,89,10);
			CreateDNHShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5+(i/4),ObjMove_GetAngle(obj)+270,89,10);
			}
			if(colour == "BLUE"){
			CreateDNHShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5+(i/4),ObjMove_GetAngle(obj)+90,87,10);
			CreateDNHShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),1.5+(i/4),ObjMove_GetAngle(obj)+270,87,0);
			}
		}
		yield;
	}
	wait(10);
	}
}


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