/*#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Doremy (Spell 1)"]
#Text["pink blob girl"]
#System["./data/system/Awalys_System.dnh"]
#Player["./data/player/Sanae by Awalys/player.dnh"]
#Background["./data/background/Boss_BG.dnh"]*/

#include"./data/shot/CrispBright4/Shotconstants.dnh"
#include"./data/lib/lib_main.dnh"
#include"./data/lib/Boss_Anim.dnh"
#include"./data/lib/shot_lib.dnh"

let frame = 0;
let time = 0;
let timer = 0;
let move = 0;
let angleInc = 0;

let id = "spell1";

let rad = 0;
let dir = false;

let fam;

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(6000/5);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(90);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(999000000);
	}
}

@Initialize{
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);

	fam = CreateFamiliarA2(cx, 190, 0);

    ObjMove_SetDestAtWeight(objBoss, cx, 190, 15, 6);

	TFinalizeSpell(id);
	StartSlow(TARGET_ALL, 60);
	BossMarker;
	MagicCircle(objBoss);
	BossRender;
	Name("Doremy Sweet");

	Pattern1; Pattern2;
	//Radius;
	//MovementLoop(100, 180);
}

@MainLoop{
	SetShotAutoDeleteClip(256, 256, 256, 256);

	ObjEnemy_SetIntersectionCircleToPlayer(objBoss, GetBX, GetBY, 16);
	ObjEnemy_SetIntersectionCircleToShot(objBoss, GetBX, GetBY, 24);

	ObjEnemy_SetDamageRate(objBoss, 1, 1);
	if(start){
		ObjEnemy_SetDamageRate(objBoss, 20, 10);
	}
	
	Start;

	frame++;

	yield;
}

task Pattern1{
	loop{
		if(start){
			Attack = false;
			ObjMove_SetDestAtFrame(fam, cx, 190, 120);
			loop(60*10){
				if(rad < 320){ rad += 1; }
				yield;
			}

			Charge(90); wait(60*2);
			FireAimed; Play(ShotSE4, 30); 

			wait(60*6);
			Charge(90); wait(60*1.5);
			ObjMove_SetDestAtFrame(fam, GetPlayerX, GetPlayerY, 120);
			Play(ChargeSE2, 40); Attack = true;

			loop(60*4){
				if(rad > 0){ rad -= 0.5; }
				yield;
			}
			Charge(60*2); 
			loop(60*2){
				if(rad > 0){ rad -= 0.5; }
				yield;
			}
			EShockwave(GetBX, GetBY, 0.1); Play(ExpSE2, 50);
			dir = !dir;
		}
		yield;
	}
}
task Pattern2{
	loop{
		if(start){
			DLoop1;
			break;
		}
		yield;
	}

}

task Charge(frame){
	nTestCharge(GetBX, GetBY, frame, 200, 0, 255);
	Play(ChargeSE, 40);
}

task Start{
	if(frame == 60){
		Spell("Dreamy Embrace \"Into the Jaws of the Dream World\"", id);
		ObjEnemyBossScene_StartSpell(objScene);
		Cutin;
		wait(60);
		Charge(90);
		Play(ChargeSE, 40);
		Attack = true;
		wait(100);
		EShockwave(GetBX,GetBY, 0.09);
		Play(ExpSE2, 40);
		start=true;
		Attack=false;
	}
}

task DLoop1{
	let a = 0;
	let b = 0;
	loop{
		while(Obj_IsDeleted(objBoss)){ yield; }
		loop(2){
			ascent(i in 1..3){
				//let shot2 = CreateShotA2(GetBX+rad*cos(-a+b),GetBY+rad*sin(-a+b), 0, a+b, i/50, 6, RICE_M_PURPLE_INV, 30);
				let shot = CreateShotA2(ObjMove_GetX(fam)+rad*cos(-a+b),ObjMove_GetY(fam)+rad*sin(-a+b), 0, a+b+180, i/75, 5, RICE_M_PURPLE_INV, 45);
				//ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
			}
			a += 7;
			b += 1.25;
		}
			Play(ShotSE1, 30);
		wait(5);
	}
}

task FireAimed{
	let angleT;
	if(!dir){ angleT = GetAngleToPlayer(objBoss)-130; }
	else{ angleT = GetAngleToPlayer(objBoss)+130; }

	loop(60*6/2){
		while(Obj_IsDeleted(objBoss)){ yield; }
		loop(2){
			let shot = CreateShotA2(GetBX+40*cos(angleT), GetBY+40*sin(angleT), 0, angleT, 0.1, 8, RICE_S_PINK_INV, 15);
			angleT += 360/2;
		}
		if(!dir){ angleT += 2; }
		else{ angleT -= 2; }
		Play(ShotSE2, 30);
		wait(2);
	}
}

/*task Radius{
	loop{
		if(start){
			if(rad < 320 && !exp){ rad += 0.5; }
			//if(rad > -1 && exp){ rad--; }

			//if(rad == 250){ rad = 250-1; WaitRChange1; }
			//if(rad == -1){ rad = 0; WaitRChange2; }
		}
		yield;
	}
}
task WaitRChange1{
	wait(60*8);
	if(rad == 280-1){ Charge(60); }
	rad = 280-2;
	wait(60); 
	exp = true; 
}
task WaitRChange2{
	exp = false; 
}*/