/*#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Doremy (Nonspell 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 inc = 0;

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(4300);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(999000000);
	}
}

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

    ObjMove_SetPosition(objBoss, cx, 120);

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

	Pattern1; Pattern2;
	//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, 100, 50);
		inc += 4.1328682;
	}
	
	Start;

	frame++;

	yield;
}

task Pattern1{
	loop{
		if(start){
			/*DSlash;
			wait(60*6);*/

			ascent(i in 1..3){
				Play(ShotSE4, 30);
				DLoop1(i); DLoop2(i);
				wait(60*4);
				Movement(100);
				wait(60*3);
				Movement(100);
				wait(60*2);
				DLoop3;
				wait(60*3);
				Charge(60*1);
				wait(60*1);
			}
		}
		yield;
	}
}
task Pattern2{
	loop{
		if(start){
		
		}
		yield;
	}
}

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

task Start{
	if(frame == 60){
		Charge(90);
		Attack = true;
		wait(100);
		EShockwave(GetBX,GetBY, 0.09);
		Play(ExpSE2, 40);
		start=true;
		Attack=false;
	}
}

task DLoop1(type){
	let angleT = 0;

	let a = 0;
	let b = 0;
	loop(60*6){
		loop(1){
			while(Obj_IsDeleted(objBoss)){ yield; }
			let cx = 90*cos(a+90)*cos(b);
			let cy = 90*cos(a+90)*sin(b);
			let shot = CreateShotA1(GetBX+cx, GetBY+cy, 1+cos(b*0.001)+(a*0.009), b*(a*0.0001), BALL_S_PURPLE, 20);
			//ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
			b += 360/1;
		}
		a++;
		if(type == 1){ b += 20; }
		else if(type == 2){ b -= 15; }
		yield;
	}
}

task DLoop2(type){
	let angleT = 0;

	let a = 0;
	let b = 0;
	loop(60*6){
		loop(1){
			while(Obj_IsDeleted(objBoss)){ yield; }
			let cx = 90*cos(a+90)*cos(b+20);
			let cy = 90*cos(a+90)*sin(b+20);
			let shot = CreateShotA1(GetBX+cx, GetBY+cy, 1.5+cos(b)+(a*0.009), b*(a*0.0001), BALL_BS_PURPLE, 20);
			//ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
			b += 360/1;
		}
		a++;
		if(type == 1){ b += 20; }
		else if(type == 2){ b -= 15; }
		Play(ShotSE1, 30);
		yield;
	}
	Play(ShotSE2, 30);
}

task DSlash{
	let angleT = 0;

	let a = 0;
	let b = 1;

	let cx = 0;
	let cy = 0;
	loop(60*1.75){
		loop(1){
			while(Obj_IsDeleted(objBoss)){ yield; }
			ascent(i in 2..6){
				cx = (i*48)*cos(a+90)*cos(b);
				cy = (i*48)*cos(a+90)*sin(b);
				let shot = CreateShotA2(GetBX+cx, GetBY+cy, 0, b*2, i/250, i, RICE_S_BLUE, 45);
			}
			//ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
			b += 360/1;
		}
		a += 1;
		b ^= 1.00002;
		Play(ShotSE1, 30);
		wait(1);
	}
}

task DLoop3{
	let inc = 0;
	let a = rand(0,360);

	loop(60*3/5){
		while(Obj_IsDeleted(objBoss)){ yield; }
		ascent(i in 4..9){
			let shot1 = CreateShotA2(GetBX+60*cos(inc+a), GetBY+60*sin(inc+a), 0.01*i/8, inc+a/2*i, 0.08*i/8, 6*i/12, BALL_BS_PURPLE, 20);
			let shot2 = CreateShotA2(GetBX+60*cos(-inc+a), GetBY+60*sin(-inc+a), 0.01*i/8, -inc+a*i, 0.08*i/8, 6*i/12, BALL_BS_PINK, 20);
			Play(ShotSE1, 30);
		}
		inc += 24;
		a++;
		wait(5);
	}
}