/*#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Toyasatomimi no Miko (Nonspell 2)"]
#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;

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(3750);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(43);
	}
	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;
	BossRender;
	StartSlow(TARGET_ALL, 60);
	BossMarker;
	Name("Toyasatomimi no Miko");
	MagicCircle(objBoss);
	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){
			FireShot1(1); FireShot1(2);
			wait(60*2);
			FireShot2;
			Movement(objBoss);
			wait(60*2);
			FireShot2;
			FireShot3;
			Movement(objBoss);
			wait(60*2);
			FireShot2;
			Movement(objBoss);
			//FireShot1(0.005);
			wait(60*4);
		}
		yield;
	}
}

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

task FireShot1(type){
	let angleT = 160;
	let a = 0;
	if(type == 1){a = 0;}
	else if(type == 2){a = -0;}
	loop(72){
		while(Obj_IsDeleted(objBoss)){yield;}
		loop(8){
			let shot = CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 8, angleT, -0.3, 0, ARROW_BLUE, 10);
			ObjMove_AddPatternA2(shot, 20, 1, ObjMove_GetAngle(shot), 0.1, a, 6);
			angleT += 360/8;
		}
		//CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 8, rand(0,360), -0.3, 2, BALL_S_BLUE, 15);
		if(type == 1){angleT += 5;}
		else if(type == 2){angleT -= 1;}
		PlaySE(ShotSE1);
		wait(7);
	}
}

task FireShot2{
	let angleT = GetAngleToPlayer(objBoss);
	PlaySE(ShotSE2);
	ascent(i in 5..10){
		ascent(j in 0..19){
			CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), i/1.5, angleT+j*10, ARROW_RED, 15);
			CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), i/1.5, angleT-j*10, ARROW_RED, 15);
		}
	}
}

task FireShot3{
	let angleT = rand(0,360);
	PlaySE(ShotSE2);
	loop(72){
		CreateShotA2(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), 7, angleT, -0.1, 1.5, ARROW_GREEN, 30);
		angleT += 360/72;
	}
}

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