
#ScriptVersion[3]
#Title["Spellcard 1"]
#Text[" Envy Sign [r]\"The Ritual of Corrupt Nature\" "]
#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(40);
		}

}

@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("Envy Sign - \"The Ritual of Corrupt Nature\"");
	wait(240);
	ConcentrationQ;
	move;
	fire;
	fire2;
	end;
}

task move{
	loop{
	ObjMove_SetDestAtWeight(bossObj,GetPlayerX,GetPlayerY,10,1);
	yield;
	}
}

task fire{
	let x = 0;
	let dir = 0;
	let spin = 0;
	loop{
	sound;
		while(x<4 && !Obj_IsDeleted(bossObj)){
				
			let obj1 = CreateShotA1(BossX,BossY,3,dir+spin,3844,30);
			ObjMove_AddPatternA3(obj1,0,2,dir+spin,-0.1,0,2,46);
			ObjRender_SetColor(obj1,255,0,0);
			ObjRender_SetScaleXYZ(obj1,0.75,0.75,0.75);
					
			let obj2 = CreateShotA1(BossX,BossY,3,dir-spin,3844,30);
			ObjMove_AddPatternA3(obj2,0,2,dir-spin,-0.1,0,2,46);
			ObjRender_SetColor(obj2,255,0,0);
			ObjRender_SetScaleXYZ(obj2,0.75,0.75,0.75);
			dir+=360/4;
			x++;
			spin+=1;
		}
		x = 0;
		dir = 0;
		wait(20);
	}
	
}

task fire2{
	wait(1207);
	let x = 0;
	let dir = 0;
	let spin = 0;
	loop{
		while(x<4 && !Obj_IsDeleted(bossObj)){
				
			let obj1 = CreateShotA1(BossX,BossY,3,dir+spin,3844,30);
			ObjMove_AddPatternA3(obj1,0,2,dir+spin*2,-0.1,0,2,3844);
			ObjRender_SetColor(obj1,128,0,0);
			ObjRender_SetScaleXYZ(obj1,0.75,0.75,0.75);
					
			let obj2 = CreateShotA1(BossX,BossY,3,dir-spin,3844,30);
			ObjMove_AddPatternA3(obj2,0,2,dir-spin*2,-0.1,0,2,3844);
			ObjRender_SetColor(obj2,128,0,0);
			ObjRender_SetScaleXYZ(obj2,0.75,0.75,0.75);
			dir+=360/4;
			x++;
			spin+=1;
		}
		x = 0;
		dir = 0;
		sound2;
		wait(25);
	}
	
}

task sound{
	wait(30);
 while(!Obj_IsDeleted(bossObj)){
 Play(shot);
 wait(20);
 }
}

task sound2{
	wait(30);
 while(!Obj_IsDeleted(bossObj)){
 Play(wave);
 wait(20);
 }
}

task end{
	while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){ yield;}
	
	Obj_Delete(bossObj);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	

	CloseScript(GetOwnScriptID());
}