
#ScriptVersion[3]
#Title["Spellcard 2"]
#Text[" Jealousy Sign [r]\"Fragments of a Broken Heart\" "]
#System["./System.txt"]
#Background["./Background.dnh"]

let bossObj;
let BossX = 0;
let BossY = 0;
let shot = GetCurrentScriptDirectory ~ "se/shot.wav";
let wave = GetCurrentScriptDirectory ~ "se/wave.wav";
let wave3 = GetCurrentScriptDirectory ~ "se/wave3.wav";
let um2 = GetCurrentScriptDirectory ~ "se/um2.wav";
let imgBoss = GetCurrentScriptDirectory ~ "img/Parsee.png";

#include "./shot/Parsee_ShotConst.dnh"
#include "./Render.dnh"

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

	//  Defines a Boss and Registers it.
	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(bossObj);
	
	Render;
	
	
	//Textures the Boss and Indicates the Boss's True Center.
	ObjPrim_SetTexture(bossObj,imgBoss);
	ObjSprite2D_SetDestCenter(bossObj);
	
	// Moves Boss to XY Location at wanted Speed (Parameters:Obj,X,Y,V)
	ObjMove_SetDestAtWeight(bossObj,GetScreenWidth/2,GetScreenHeight/2,15,10);
	
	mainTask; //Runs Maintask
	
}

@Event{
	// Event: Sets the Boss's Specs
	
		// Sets Boss's Life and Timer
		alternative(GetEventType() )
		case(EV_REQUEST_LIFE) {
			SetScriptResult(6000);
		}
		case(EV_REQUEST_TIMER) {
			SetScriptResult(50);
		}

}

@MainLoop{
	// MainLoop: Runs throughout the script.
	
	// Indicates that BossX = GetEnemyX and BossY = GetEnemyY
	BossX = ObjMove_GetX(bossObj);
	BossY = ObjMove_GetY(bossObj);
	
	// Sets the Boss's Collision Circle(Hitbox) For the Shots and Player.
	ObjEnemy_SetIntersectionCircleToShot(bossObj,BossX,BossY,20);
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,BossX,BossY,20);
	
	yield;

}

@Finalize{


}

// Your best friend. FOREVER!!! The Wait Function
function wait(w) { loop(w){ yield;} }

task mainTask{
	wait(80);
	let sceneObj = GetEnemyBossSceneObjectID;
	ObjEnemyBossScene_StartSpell(sceneObj);
	CutIn("Jealousy Sign - \"Fragments of a Broken Heart\"");
	wait(240);
	ConcentrationQ;
	wait(120);
	fire;
	end;
}

task fire{

	task sound{
		wait(30);
		Play(wave3);
	}

	task sound2{
		wait(330);
		while(!Obj_IsDeleted(bossObj)){
		ascent(i in 0..10){
		Play(shot);
		wait(5);
		}
		wait(100);
		}
	}

	let obj = CreateShotA1(BossX+21,BossY,3,270,384,30);
	ObjShot_SetSpellResist(obj,true);
	ObjRender_SetAngleY(obj,180);
	ObjMove_AddPatternA3(obj,0,-5,90,0.1,0,0,384);
	ObjMove_AddPatternA3(obj,220,5,0,-0.075,0,0,384);
	ObjRender_SetScaleXYZ(obj,3,3,3);
	
	let obj1 = CreateShotA1(BossX-21,BossY,3,270,384,30);
	ObjShot_SetSpellResist(obj1,true);
	ObjMove_AddPatternA3(obj1,0,-5,90,0.1,0,0,384);
	ObjMove_AddPatternA3(obj1,220,5,180,-0.075,0,0,384);
	ObjRender_SetScaleXYZ(obj1,3,3,3);
	
	uhoh;
	fire2;
	
	
	task uhoh{
	sound;
			let crap = 0;
		loop(6){
			ascent(i in 0..10){
				ObjRender_SetColor(obj,255,255*i,255*i);
				ObjRender_SetColor(obj1,255,255*i,255*i);
				wait(10-i*2);
			}
		}
		Play(um2);
		loop(51){
				ObjRender_SetColor(obj,255-crap,255-crap,255-crap);
				ObjRender_SetColor(obj1,255-crap,255-crap,255-crap);
				crap+=5;
				yield;
		}
	}
	
	task bossfire{
		let x = 0;
		let dir = 0;
		let spin = 0;
		loop{
			while(x<12 && !Obj_IsDeleted(bossObj)){
				Play(shot);
				let zobj = CreateShotA1(BossX,BossY,3,dir,46,30);
				ObjMove_AddPatternA3(zobj,0,-5,spin*2+dir,0.1,0,-1,3844);
				ObjRender_SetScaleXYZ(zobj,0.35,0.35,0.35);
				ObjRender_SetColor(zobj,128,0,0);
						
				let zobj1 = CreateShotA1(BossX,BossY,3,dir,46,30);
				ObjMove_AddPatternA3(zobj1,0,-5,-spin*2+dir,0.1,0,-1,3844);
				ObjRender_SetScaleXYZ(zobj1,0.35,0.35,0.35);
				ObjRender_SetColor(zobj1,128,0,0);
						
				spin+=0.05;
				dir+=360/12;
				x++;
			}
			x = 0;
			dir = 0;
			wait(60);
		}
	}	
	
	task fire2{
		sound2;
		wait(300);
		bossfire;
		let spin = 0;
		let dir = 0;
		let x = 0;
		loop{
			ascent(i in 0..10){
				while(x<16){
					let zobj = CreateShotA1(ObjRender_GetX(obj),ObjRender_GetY(obj),3,dir,46,30);
					ObjMove_AddPatternA3(zobj,0,-5,spin*2+dir,0.1,0,-2,3844);
					ObjRender_SetScaleXYZ(zobj,0.75,0.75,0.75);
					ObjRender_SetColor(zobj,255,0,0);
					
					
					let zobj1 = CreateShotA1(ObjRender_GetX(obj1),ObjRender_GetY(obj1),3,dir,46,30);
					ObjMove_AddPatternA3(zobj1,0,-5,-spin*2+dir,0.1,0,-2,3844);
					ObjRender_SetScaleXYZ(zobj1,0.75,0.75,0.75);
					ObjRender_SetColor(zobj1,255,0,0);
					
					spin+=0.05;
					dir+=360/16;
					x++;
				}
				x = 0;
				dir = 0;
				wait(5);
			}
		wait(120);
		}
	}
}

task end{
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){ yield;}
	let ex = ObjMove_GetX(bossObj);
	let ey = ObjMove_GetY(bossObj);
	Death(ex,ey);
	Obj_Delete(bossObj);
	
	SetAutoDeleteObject(true);
	
	loop(220){
	SetAutoDeleteObject(true);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	yield;
	}
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	

	CloseScript(GetOwnScriptID());
}