
#ScriptVersion[3]
#Title["Spellcard 1"]
#Text[" Faith Sign - \" Beliefs of the Transient\""]
#System["./System.txt"]
#Background["./Background.dnh"]

let bossObj;
let BossX = 0;
let BossY = 0;
let shot = GetCurrentScriptDirectory ~ "se/Shot1.wav";
let wave = GetCurrentScriptDirectory ~ "se/BulletWave.wav";
let barrage = GetCurrentScriptDirectory ~ "se/barrage.wav";
let spelloff = GetCurrentScriptDirectory ~ "se/SpellOff.wav";
let imgBoss = GetCurrentScriptDirectory ~ "img/Kanako.png";

#include "./shot/Default_ShotConst.txt"
#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;
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	
	//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(20);
		}
		case(EV_REQUEST_TIMER) {
			SetScriptResult(40);
		}
		case(EV_REQUEST_IS_DURABLE_SPELL) {
			SetScriptResult(true);
		}

}

@MainLoop{
	// MainLoop: Runs throughout the script.
	
	// Indicates that BossX = GetEnemyX and BossY = GetEnemyY
	BossX = ObjMove_GetX(bossObj);
	BossY = ObjMove_GetY(bossObj);
	
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,BossX,BossY,20);
	
	yield;

}

@Finalize{
	Play(spelloff);
}

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

task mainTask{
	end;
	wait(80);
	CutIn("Faith Sign - \"Beliefs of the Transient\"");
	let sceneObj = GetEnemyBossSceneObjectID;
	ObjEnemyBossScene_StartSpell(sceneObj);
	wait(80);
	ConcentrationQ;
	wait(70);
	ObjRender_SetColor(bossObj,0,0,255);
	Split;
	wait(500);
}

task Split{

	let imgBoss2 = CSD ~ "img/Aura.png";
	let spin = 0;
	let slide = 0;
	Play(barrage);
	let auraObj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(auraObj,imgBoss2);
	ObjSprite2D_SetSourceRect(auraObj,0,0,256,256);
	ObjSprite2D_SetDestCenter(auraObj);
	ObjRender_SetColor(auraObj,255,128,128);
	Obj_SetRenderPriorityI(auraObj,30);
	
	let auraObj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(auraObj2,imgBoss2);
	ObjSprite2D_SetSourceRect(auraObj2,0,0,256,256);
	ObjSprite2D_SetDestCenter(auraObj2);
	ObjRender_SetColor(auraObj2,128,255,128);
	Obj_SetRenderPriorityI(auraObj2,30);
	
	let auraObj3 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(auraObj3,imgBoss2);
	ObjSprite2D_SetSourceRect(auraObj3,0,0,256,256);
	ObjSprite2D_SetDestCenter(auraObj3);
	ObjRender_SetColor(auraObj3,128,128,255);
	Obj_SetRenderPriorityI(auraObj3,30);
	
	movement;
	loop(250){	
		ObjRender_SetPosition(auraObj,(GetStgFrameWidth/2)+slide*cos(spin),(GetStgFrameHeight/2)+slide*sin(spin),0);
		ObjRender_SetPosition(auraObj2,(GetStgFrameWidth/2)+slide*cos(spin+360/3),(GetStgFrameHeight/2)+slide*sin(spin+360/3),0);
		ObjRender_SetPosition(auraObj3,(GetStgFrameWidth/2)+slide*cos(spin+360/1.5),(GetStgFrameHeight/2)+slide*sin(spin+360/1.5),0);
		slide+=1;
		spin+=0.5;
		yield;
	}
	fire2;
	fire;
	fire3;
	while(!Obj_IsDeleted(bossObj)){
		ObjRender_SetPosition(auraObj,(GetStgFrameWidth/2)+slide*cos(spin),(GetStgFrameHeight/2)+slide*sin(spin),0);
		ObjRender_SetPosition(auraObj2,(GetStgFrameWidth/2)+slide*cos(spin+360/3),(GetStgFrameHeight/2)+slide*sin(spin+360/3),0);
		ObjRender_SetPosition(auraObj3,(GetStgFrameWidth/2)+slide*cos(spin+360/1.5),(GetStgFrameHeight/2)+slide*sin(spin+360/1.5),0);
		spin+=0.5;
		yield;
	}
	Obj_Delete(auraObj);
	Obj_Delete(auraObj2);
	Obj_Delete(auraObj3);
	
	task movement{
		let spin = 0;
		let spin2 = 0;
		wait(120);
		loop(120){
			spin+=0.00025;
			spin2+=spin;
			ObjMove_SetDestAtSpeed(bossObj,ObjMove_GetX(bossObj),-256,spin2);
		}
	}
	
	task fire{
		let dir = 0;
		let x = 0;
		let i = 0;
		let a = 3;
		let spin = 0;
		loop(20){
			ascent(i in 0..3){
				while(x<a){
					Play(shot);
					let obj = CreateShotA1(ObjRender_GetX(auraObj)+0*cos(dir),ObjRender_GetY(auraObj)+0*sin(dir),3,dir,41,30);
					ObjMove_AddPatternA3(obj,0,4,dir+spin*i+120,-0.1,i/15,2,41);
					
					let obj1 = CreateShotA1(ObjRender_GetX(auraObj2)+0*cos(dir),ObjRender_GetY(auraObj2)+0*sin(dir),3,dir,44,30);
					ObjMove_AddPatternA3(obj1,0,4,dir+spin*i+240,-0.1,i/15,2,44);
					
					let obj2 = CreateShotA1(ObjRender_GetX(auraObj3)+0*cos(dir),ObjRender_GetY(auraObj3)+0*sin(dir),3,dir,46,30);
					ObjMove_AddPatternA3(obj2,0,4,dir+spin*i,-0.1,i/15,2,46);
					
					x++;
					dir+=360/a;
					spin+=0.1;
				}
				wait(5);
				x = 0;
				dir = 0;
			}
			wait(25);
		}
	}
	
	task fire2{
		wait(830);
		ConcentrationQ;
		wait(70);
		let dir = 0;
		let x = 0;
		let i = 0;
		let a = 1;
		let spin2 = 0;
		loop{
			while(x<a){
					Play(wave);
					let obj = CreateShotA1(ObjRender_GetX(auraObj)+0*cos(dir),ObjRender_GetY(auraObj)+0*sin(dir),3,dir,41,30);
					ObjMove_AddPatternA3(obj,0,4,dir+spin2+300,-0.1,i/15,0,65);
					ObjMove_AddPatternA3(obj,60,4,dir+spin2+280,-0.1,i/15,2,65);
					
					let obja = CreateShotA1(ObjRender_GetX(auraObj)+0*cos(dir),ObjRender_GetY(auraObj)+0*sin(dir),3,dir,41,30);
					ObjMove_AddPatternA3(obja,0,4,dir+spin2+300,-0.1,i/15,0,65);
					ObjMove_AddPatternA3(obja,60,4,dir+spin2+320,-0.1,i/15,2,65);
					
					let obj1 = CreateShotA1(ObjRender_GetX(auraObj2)+0*cos(dir),ObjRender_GetY(auraObj2)+0*sin(dir),3,dir,44,30);
					ObjMove_AddPatternA3(obj1,0,4,dir+spin2+420,-0.1,i/15,0,68);
					ObjMove_AddPatternA3(obj1,60,4,dir+spin2+400,-0.1,i/15,2,68);
					
					let objb = CreateShotA1(ObjRender_GetX(auraObj2)+0*cos(dir),ObjRender_GetY(auraObj2)+0*sin(dir),3,dir,44,30);
					ObjMove_AddPatternA3(objb,0,4,dir+spin2+420,-0.1,i/15,0,68);
					ObjMove_AddPatternA3(objb,60,4,dir+spin2+440,-0.1,i/15,2,68);
					
					let obj2 = CreateShotA1(ObjRender_GetX(auraObj3)+0*cos(dir),ObjRender_GetY(auraObj3)+0*sin(dir),3,dir,46,30);
					ObjMove_AddPatternA3(obj2,0,4,dir+spin2+180,-0.1,i/15,0,70);
					ObjMove_AddPatternA3(obj2,60,4,dir+spin2+160,-0.1,i/15,2,70);
					
					let objc = CreateShotA1(ObjRender_GetX(auraObj3)+0*cos(dir),ObjRender_GetY(auraObj3)+0*sin(dir),3,dir,46,30);
					ObjMove_AddPatternA3(objc,0,4,dir+spin2+180,-0.1,i/15,0,70);
					ObjMove_AddPatternA3(objc,60,4,dir+spin2+200,-0.1,i/15,2,70);
					
					let obj23 = CreateShotA1(ObjRender_GetX(auraObj)+0*cos(dir),ObjRender_GetY(auraObj)+0*sin(dir),3,dir,41,30);
					ObjMove_AddPatternA3(obj23,0,4,dir+spin2+120,-0.1,i/15,0,65);
					ObjMove_AddPatternA3(obj23,60,4,dir+spin2+100,-0.1,i/15,2,65);
					
					let obj2a = CreateShotA1(ObjRender_GetX(auraObj)+0*cos(dir),ObjRender_GetY(auraObj)+0*sin(dir),3,dir,41,30);
					ObjMove_AddPatternA3(obj2a,0,4,dir+spin2+120,-0.1,i/15,0,65);
					ObjMove_AddPatternA3(obj2a,60,4,dir+spin2+140,-0.1,i/15,2,65);
					
					let obj21 = CreateShotA1(ObjRender_GetX(auraObj2)+0*cos(dir),ObjRender_GetY(auraObj2)+0*sin(dir),3,dir,44,30);
					ObjMove_AddPatternA3(obj21,0,4,dir+spin2+240,-0.1,i/15,0,68);
					ObjMove_AddPatternA3(obj21,60,4,dir+spin2+220,-0.1,i/15,2,68);
					
					let obj2b = CreateShotA1(ObjRender_GetX(auraObj2)+0*cos(dir),ObjRender_GetY(auraObj2)+0*sin(dir),3,dir,44,30);
					ObjMove_AddPatternA3(obj2b,0,4,dir+spin2+240,-0.1,i/15,0,68);
					ObjMove_AddPatternA3(obj2b,60,4,dir+spin2+260,-0.1,i/15,2,68);
					
					let obj22 = CreateShotA1(ObjRender_GetX(auraObj3)+0*cos(dir),ObjRender_GetY(auraObj3)+0*sin(dir),3,dir,46,30);
					ObjMove_AddPatternA3(obj22,0,4,dir+spin2,-0.1,i/15,0,70);
					ObjMove_AddPatternA3(obj22,60,4,dir+spin2-20,-0.1,i/15,2,70);
					
					let obj2c = CreateShotA1(ObjRender_GetX(auraObj3)+0*cos(dir),ObjRender_GetY(auraObj3)+0*sin(dir),3,dir,46,30);
					ObjMove_AddPatternA3(obj2c,0,4,dir+spin2,-0.1,i/15,0,70);
					ObjMove_AddPatternA3(obj2c,60,4,dir+spin2+20,-0.1,i/15,2,70);
					
				x++;
				dir+=360/a;
				spin2+=12;
			}
			wait(10);
			x = 0;
			dir = 0;
		}
	}
	
	task fire3{
	wait(1280);
	ConcentrationQ;
	wait(80);
	let x = 0;
	let a = 14;
	let dir = 0;
	let spin = 0;
		loop{
			ascent(i in 0..3){
				while(x<a){
					let obj = CreateShotA1((GetStgFrameWidth/2)+0*cos(dir),(GetStgFrameHeight/2)+0*sin(dir),3,dir,41,60);
					ObjMove_AddPatternA3(obj,0,4,dir-spin*2,-0.1,i/15,2,41);
					
					let obj1 = CreateShotA1((GetStgFrameWidth/2)+0*cos(dir),(GetStgFrameHeight/2)+0*sin(dir),3,dir,44,70);
					ObjMove_AddPatternA3(obj1,0,4,dir-spin,-0.1,i/15,2,44);
					
					let obj2 = CreateShotA1((GetStgFrameWidth/2)+0*cos(dir),(GetStgFrameHeight/2)+0*sin(dir),3,dir,46,80);
					ObjMove_AddPatternA3(obj2,0,4,dir-spin/2,-0.1,i/15,2,46);
					
					x++;
					dir+=360/a;
					spin+=0.1;
				}
				Play(shot);
				wait(2);
				x = 0;
				dir = 0;
			}
			wait(80);
		}
	}
	
}

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

	Play(spelloff);
	wait(5);
	
	Obj_Delete(bossObj);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	

	CloseScript(GetOwnScriptID());
}