/*#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Doremy (Nonspell 3)"]
#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(3000);
	}
	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, 120, 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){
			DLoop1; DLoop2;
			wait(60*4);
			Movement(100);
			wait(60*2);
			Movement(100);
			BRing;
			wait(60*3);
			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, 50);
		start=true;
		Attack=false;
	}
}

task DLoop1{
	let angle = 0;
	let a = 0;
	let w = 2;

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

task DLoop2{
	let angle = 0;
	let a = 0;
	let w = 2;

	loop(60*6/w){
		loop(2){
			while(Obj_IsDeleted(objBoss)){ yield; }
			let cx = 90*cos(a)*cos(angle);
			let cy = 90*cos(a)*sin(angle);
			let shot = CreateShotA1(GetBX+cx, GetBY+cy, 3.5+cos(angle*0.1), w*(angle*0.03), BALL_S_PURPLE, 20);
			//ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
			angle += 360/2;
		}
		angle += 10;
		a++;
		wait(w);
	}
}

task BRing{
	let angleT = rand(0,360);
	loop(32){
		ascent(i in 1..9){
			let shot = CreateShotA1(GetBX, GetBY, 5-i/2, angleT+rand(-2,2), RICE_M_PINK, 10);
		}
		angleT += 360/32;
	}
}