/*#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Toyasatomimi no Miko (Spell 1)"]
#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 angleT = 45;

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(6000/4);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(53);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(999000000/4);
	}
}

@Initialize{
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
    ObjMove_SetDestAtWeight(objBoss, cx, 120, 15,6);


	TFinalizeSpell;
	StartSlow(TARGET_ALL, 60);
	BossRender;
	BossMarker;
	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,25,25);
		angleInc+=1;
	}
	
	Start;

	frame++;

	yield;
}

task Pattern1{
	loop{
		if(start){
			FireLasers(1);
			//FireBalls(2);
			FireBalls2(2);
			wait(60*9.5);
			FireBalls2(1);
			//FireBalls(1);
			FireLasers(2);
			wait(60*9.5);
			//break;
		}
		yield;
	}
}

task Start{
	if(frame == 60){
		Spell("Light Sign \"Teachings of the Tao\"");
		ObjEnemyBossScene_StartSpell(objScene);
		Cutin;
		wait(60);
		//Aura;
		nTestCharge(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),90,255,200,0);
		PlaySE(ChargeSE);
		Attack = true;
		wait(100);
		EShockwave(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss), 0.09);
		PlaySE(ExpSE2);
		start=true;
		//Attack=false;
		//MagicCircle2;
	}
}

task FireLasers(type){
	let angleT = 0;
	loop(60*9.5/5){
		while(Obj_IsDeleted(objBoss)){yield;}
		CreateStraightLaserA1(ObjMove_GetX(objBoss)+90*cos(angleT), ObjMove_GetY(objBoss)+90*sin(angleT), angleT, 500, 20, 30, BEAM_ORANGE, 30);
		CreateStraightLaserA1(ObjMove_GetX(objBoss)+90*cos(angleT+180), ObjMove_GetY(objBoss)+90*sin(angleT+180), angleT+180, 500, 20, 30, BEAM_ORANGE, 30);
		if(type == 1){angleT += 7.3;}
		else if(type == 2){angleT -= 7.3;}
		PlaySE(ShotSE2);
		wait(5);
	}
}

task FireBalls(type){
	let angleT = 0;
	loop(60*9.5/5){
		loop(6){
			while(Obj_IsDeleted(objBoss)){yield;}
			let shot = CreateShotA2(ObjMove_GetX(objBoss)+60*cos(angleT), ObjMove_GetY(objBoss)+60*sin(angleT), 0, angleT, 0.05, rand(2,2.5), RICE_S_YELLOW, 15);
			//ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
			//if(type == 1){ObjMove_SetAngularVelocity(shot, 0.5);}
			//else if(type == 2){ObjMove_SetAngularVelocity(shot, -0.5);}
			angleT += 360/6;
		}
		if(type == 1){angleT += 7.3;}
		else if(type == 2){angleT -= 7.3;}
		wait(5);
	}
}

task FireBalls2(type){
	let angle = 0;
	let a = 0;
	loop(60*9.5/3){
		loop(2){
			while(Obj_IsDeleted(objBoss)){yield;}
			let cx = 120*cos(a)*cos(angle);
			let cy = 120*cos(a)*sin(angle);
			let shot = CreateShotA1(ObjMove_GetX(objBoss)+cx, ObjMove_GetY(objBoss)+cy, 1.5+cos(angle*0.01)*1, angle*0.05, BALL_S_ORANGE, 20);
			//ObjRender_SetBlendType(shot, BLEND_ADD_ARGB);
			if(type == 1){angle -= 360/2;}
			else if(type == 2){angle += 360/2;}
		}
		PlaySE(ShotSE1);
		if(type == 1){angle += 10;}
		if(type == 2){angle -= 10;}
		a++;
		wait(3);
	}
}