#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Toyasatomimi no Miko (Extra Spell)"]
#Text["I decided to cut this out [r] from the script [r] at the last minute."]
#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(2500/4);
	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(999000000*2);
	}
}

@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);
	Name("Toyasatomimi no Miko");
	//Movement;
	Pattern;
}

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

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

	SetShotAutoDeleteClip(256, 256, 256, 256);

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

	frame++;

	yield;
}

task Pattern{
	loop{
		if(start){
			loop(3){Pattern1; wait(60+90);}
			wait(30);
			PlaySE(ChargeSE);
			nTestCharge(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),60,175,150,0);
			wait(60);
			Pattern2(1); wait(160); Pattern2(2);
			wait(270);
		}
		yield;
	}
}

task Pattern1{
	//wait(60);
	FireRing3;
	//ObjMove_SetDestAtWeight(objBoss, GetPlayerX+rand(-30,30), GetPlayerY+rand(-30,30), 15, 7);
	ObjMove_SetSpeed(objBoss, 10);
	ObjMove_SetAcceleration(objBoss, -0.2);
	ObjMove_SetMaxSpeed(objBoss, 0);
	ObjMove_SetAngle(objBoss, GetAngleToPlayer(objBoss)+rand(-10,10));
	wait(90);
	FireRing(1, 1);
}
task Pattern2(type){
	ObjMove_SetSpeed(objBoss, 5);
	ObjMove_SetAcceleration(objBoss, -0.05);
	ObjMove_SetMaxSpeed(objBoss, 0);
	ObjMove_SetAngle(objBoss, GetAngleToPlayer(objBoss)+rand(-30,30));
	FireRing(2, type);
	FireRing2;
}

task Start{
	if(frame == 60){
		Spell("Light Sign \"Shichiseiken\"");
		ObjEnemyBossScene_StartSpell(objScene);
		Cutin;
		wait(60);
		nTestCharge(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),90,175,150,0);
		PlaySE(ChargeSE);
		Attack = true;
		wait(100);
		FireRing(3, 1);
		wait(30);
		FireRing(3, 2);
		wait(45);
		EShockwave(ObjMove_GetX(objBoss),ObjMove_GetY(objBoss), 0.09);
		PlaySE(ExpSE2);
		start=true;
		Attack=false;
		//MagicCircle2;
	}
}	

task FireRing(type, type2){ //type1 is for the duration and length of the slash. type2 is for the direction.
	let angleT = 0;
	let inc = 30;
	let ln = 0;
	let r = 0;
	let frame = 0;
	let a = 0;
	if(type == 1){ln = 10*2; frame = 30; r = 240; a = 100;}
	else if(type == 2){ln = 10*2; frame = 120; r = 360; a = 150;}
	else if(type == 3){ln = 6*2; frame = 30; r = 360; a = 100;}

	if(type2 == 1){angleT = GetAngleToPlayer(objBoss)-a;}
	else if(type2 == 2){angleT = GetAngleToPlayer(objBoss)+a;}
	PlaySE(SlashSE);
	loop(frame){
		while(Obj_IsDeleted(objBoss)){yield;}
		ascent(i in 2..ln){
			let shot1 = CreateShotA2(ObjMove_GetX(objBoss)+(inc*i/2)*cos(angleT), ObjMove_GetY(objBoss)+(inc*i/2.5)*sin(angleT), 1, angleT, 0.015, 1000, MIKO_ORB_ORANGE, 0);
			ObjShot_SetSpellResist(shot1, true);
			//ObjShot_SetDeleteFrame(shot1, 15);
			//ObjRender_SetBlendType(shot1, BLEND_ADD_RGB);
			//ObjMove_AddPatternA1(shot1, 90, 5, ObjMove_GetAngle(shot1));
			if(type == 1){inc-=0.07/2;}
			else if(type == 2){inc += 0.01/2;}
			else if(type == 3){inc -= 0.07/2;}
			BCommands(shot1);
		}
		if(type2 == 1){angleT += r/frame;}
		else if(type2 == 2){angleT -= r/frame;}
		yield;
	}
}
task FireRing2{
	let angleT = GetAngleToPlayer(objBoss)+45;
	loop(12){
		ascent(i in 6..16){
			let shot1 = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), i/3, angleT, KNIFE_ORANGE, 0);
			ObjRender_SetBlendType(shot1, BLEND_ADD_ARGB);
			//ReflectSides(shot1, 1);
		}
		angleT += 360/12;
	}
	PlaySE(ShotSE1);
}
task FireRing3{
	let angleT = GetAngleToPlayer(objBoss);
	let a = 2;
	loop(9){
		ascent(i in 8..16){
			let shot1 = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), i/2, angleT+a, KNIFE_ORANGE, 0);
			let shot2 = CreateShotA1(ObjMove_GetX(objBoss), ObjMove_GetY(objBoss), i/2, angleT-a, KNIFE_ORANGE, 0);
			ObjRender_SetBlendType(shot1, BLEND_ADD_ARGB);
			ObjRender_SetBlendType(shot2, BLEND_ADD_ARGB);
			ReflectSides(shot1, 1);
			ReflectSides(shot2, 1);
		}
		angleT += 360/9;
	}
	PlaySE(ShotSE1);
}

task BCommands(shot){ wait(2); ObjShot_FadeDelete(shot); }