/*#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Toyasatomimi no Miko (Nonspell 3)"]
#Text["knock knock [r] get the door [r] it's religion"]
#System["./system/system/Awalys_System.txt"]
#Background["./system/background/back_miko.dnh"]
#Player["./system/player/Byakuren/Byakuren_A.txt"]*/

#include"./system/shot/CrispBright4/Shotconstants.dnh"
#include"./system/lib/lib_main.dnh"
#include"./system/lib/miko_aura.dnh"

let frame = 0;
let diff = 3;
let time = 0;
let timer = 0;
let move = 0;
let angleInc = 0;
let inc = 0;
let count = 0;
let count2 = 0;
let count3 = 0;

let kunai = false;

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5200);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(45);
	}
	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);
	BossRender;
	BossMarker;
	MagicCircle(objBoss);
	Name("Toyasatomimi no Miko");
	Pattern1;
	//Movement;
}

@MainLoop{
	let ex = ObjMove_GetX(objBoss);
	let ey = ObjMove_GetY(objBoss);

	ObjEnemy_SetIntersectionCircleToShot(objBoss, ex, ey, 32); 
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss, ex, ey, 24);

	SetShotAutoDeleteClip(512, 512, 512, 512);

	ObjEnemy_SetDamageRate(objBoss,1,1);
	if(start){
		ObjEnemy_SetDamageRate(objBoss,100,100);
		angleInc+=1;
	}
	
	Start;

	frame++;

	yield;
}

task Pattern1{
	loop{
		if(start){
			if(kunai){FireKunai;}
			loop(12){FireWorks; wait(20);}
			Movement(objBoss, 1);
			wait(60*2);
			loop(4){FireOrbs; wait(60);}
			kunai = true;
			Movement(objBoss, 1);
			wait(60*2);
		}
		yield;
	}
}

task Start{
	if(frame == 60){
		nTestCharge(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),90,255,200,0);
		PlaySE(ChargeSE);
		Attack = true;
		wait(100);
		Aura;
		wait(60);
		PlaySE(ExpSE2);
		EShockwave(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss), 0.09);
		start=true;
		Attack=false;
		//MagicCircle2;
	}
}	

task FireOrbs{
	let angleT = rand(0,360);
	let rng = rand(-100,100);
	let graph = rand_int(862,869);
	loop(24){
		ascent(i in 2..7){
			CreateShotA2(ObjMove_GetX(objBoss)+rng, ObjMove_GetY(objBoss)+rng/2, i/1.25, angleT+rand(-2,2), -0, i/1.25, graph, 30);
		}
		angleT += 360/24;
	}
	PlaySE(ShotSE2);
}

task FireWorks{
	let angleT = 270+rand(-20,20);
	let shot1 = CreateGravityShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 10, 0.1, angleT, BALL_S_YELLOW, 0);
	PlaySE(FamiliarSE);
	BCommands(shot1);
}
task BCommands(shot){
	wait(60);
	let angleT = GetAngleToPlayer(shot);
	let a = 10;
	//ObjMove_SetSpeed(shot, 0);
	//ObjMove_SetAcceleration(shot, 0);
	if(!Obj_IsDeleted(shot)){
		loop(a){
			ascent(i in 0..7){
				let shot1 = CreateShotA2(ObjMove_GetX(shot)+120*cos(angleT), ObjMove_GetY(shot)+120*sin(angleT), -3, angleT, 0.2, 8, ICE_YELLOW, 10+i*2);
				let shot2 = CreateShotA2(ObjMove_GetX(shot)+40*cos(angleT+360/(a*2)), ObjMove_GetY(shot)+40*sin(angleT+360/(a*2)), -3, angleT+360/(a*2), 0.2, 8, ICE_YELLOW, 10+i*2);
				ObjRender_SetBlendType(shot1, BLEND_ADD_ARGB);
				ObjRender_SetBlendType(shot2, BLEND_ADD_ARGB);
			}
			angleT += 360/a;
		}
		PlaySE(ExpSE2);
		wait(10);
		Obj_Delete(shot);
	}
}

task FireKunai{
	loop(64){
		while(Obj_IsDeleted(objBoss)){yield;}
		loop(12){CreateShotA1(ObjMove_GetX(objBoss)-5, ObjMove_GetY(objBoss)-75, rand(0.75,4), rand(0,360), KUNAI_S_RED, 30);}
		PlaySE(ShotSE1);
		yield;
	}
}

task Movement(obj, mult){
	if(ObjMove_GetX(obj) < 200){
		ObjMove_SetDestAtWeight(obj, ObjMove_GetX(obj)+rand(100*mult,200*mult), ObjMove_GetY(obj)+rand(-10,5), 15,6);
	}
	else if(ObjMove_GetX(obj) > GetStgFrameWidth-200){
		ObjMove_SetDestAtWeight(obj, ObjMove_GetX(obj)-rand(100*mult,200*mult), ObjMove_GetY(obj)+rand(-10,5), 15,6);
	}
	else{
		ObjMove_SetDestAtWeight(obj, ObjMove_GetX(obj)+rand(-100*mult,100*mult), ObjMove_GetY(obj)+rand(-10,5), 15,6);
	}
}