/*#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Doremy (Nonspell 2)"]
#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(3250);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(999000000);
	}
}

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

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

	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 += 1;
	}
	
	Start;

	frame++;

	yield;
}

task Pattern1{
	loop{
		if(start){
			ascent(i in 1..3){
				DLoop1(i); DLoop2(i);
				wait(60*4);
				Movement(100);
				wait(60*2);
				Movement(100);
				wait(60*2);
				DLoop3;
				wait(60*2);
				Charge(60);
				wait(60);
			}
		}
		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, 30); 
		start=true;
		Attack=false;
	}
}

task DLoop1(type){
	let angle = 0;
	let a = 0;
	let b = 0;
	let gr;
	if(type == 1){ b = 480; gr = BALL_S_BLUE; }
	else if(type == 2){ b = 512; gr = BALL_S_CYAN; }

	loop(60*6/2){
		loop(2){
			while(Obj_IsDeleted(objBoss)){ yield; }
			let cx = 100*cos((a)*0.35)*cos(angle);
			let cy = 100*cos((a)*0.35)*sin(angle);
			let shot = CreateShotA1(GetBX+cx, GetBY+cy, 2.5+cos(angle*0.01), 2*(angle*(b*0.00001)), gr, 20);
			//ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
			angle += 360/2;
		}
		Play(ShotSE1, 30); 
		angle += 20;
		a++;
		b += 1.21;
		wait(2);
	}
	Play(ShotSE2, 30);
}

task DLoop2(type){
	let angle = 0;
	let a = 0;
	let b = 0;
	let gr;
	if(type == 1){ b = 480; gr = BALL_M_BLUE; }
	else if(type == 2){ b = 512; gr = BALL_M_CYAN; }

	loop(60*6/2){
		loop(2){
			while(Obj_IsDeleted(objBoss)){ yield; }
			let cx = 100*cos((a)*0.35)*cos(angle);
			let cy = 100*cos((a)*0.35)*sin(angle);
			let shot = CreateShotA1(GetBX+cx, GetBY+cy, 2.5+cos(angle*0.02), 2*(angle*(b*0.00001))+180, gr, 20);
			//ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
			angle += 360/2;
		}
		angle -= 20;
		a++;
		b += 1.21;
		wait(2);
	}
}

task DLoop3{
	let inc = 0;
	let a = 45;
	let b = 80;

	loop(60*3/3){
		while(Obj_IsDeleted(objBoss)){ yield; }
		Play(ShotSE1, 30);
		ascent(i in 3..8){
			let shot1 = CreateShotA2(GetBX+100*cos(inc+a), GetBY+100*sin(inc+a), 0.01*i/8, inc+a+b, 0.08*i/8, 6*i/10, BALL_BS_GREEN, 20);
			let shot2 = CreateShotA2(GetBX+100*cos(-inc+a), GetBY+100*sin(-inc+a), 0.01*i/8, -inc+a-b, 0.08*i/8, 6*i/10, BALL_BS_CYAN, 20);
		}
		inc += 24;
		a -= 4.23;
		//b += 2;
		wait(3);
	}
}