#TouhouDanmakufu
#ScriptVersion[3]
#System["./../tricky_system/TrickySystem.dnh"]
#Title["Shokora Midboss Spell 1"]
#Background["./NamelessPath.dnh"]
#Player["./../lib/Okina_player_by_Python/Okina Matara/Okina.dnh"]

#include "../lib/UNL_Shot/lib_ShotConstants.dnh"
#include "./../lib/includes/BossIncludes.dnh"
#include "./../lib/includes/EffectFunctions.dnh"

@Event{
	alternative(GetEventType())
		case(EV_REQUEST_LIFE){ SetScriptResult(1000); }
		case(EV_REQUEST_TIMER){ SetScriptResult(999); }
		case(EV_REQUEST_SPELL_SCORE){ SetScriptResult(1000000); }
		case(EV_GAIN_SPELL){ AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE)); }
		case(EV_REQUEST_IS_DURABLE_SPELL) { SetScriptResult(true); }
}

@Initialize{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjMove_SetPosition(objEnemy, -1500, -1500);
	SetAutoDeleteObject(true);
	delayedstart;
	End;
}

task End {
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0) { yield; }
	SetShotAutoDeleteClip(32, 40, 32, 32);
	NotifyEventAll(EV_SPELLBGEND, 1);
	//DeleteShotWave(1,GetX,GetY,20);
	CreateItems02(22, ITEM_POINT_S, GetStgFrameWidth/2, -40, 0, -50, 150, 35, 10000);
	DeleteShotAll(TYPE_ALL,TYPE_ITEM);
	//PlaySoundEffect("end",60,GetCenterX);
	//NotifyEventAll(EV_SPAWN_ENEMY,[99.1,GetEnemyX,GetEnemyY]);
	Obj_Delete(objEnemy);
	CloseScript(GetOwnScriptID);
}

task delayedstart{
	ObjEnemyBossScene_StartSpell(objScene);
	ObjEnemyBossScene_SetSpellTimer(objScene, 60*13);
	PlaySoundEffect("cardcall", 90, GetCenterX);
	
	let lbcut = GetCurrentScriptDirectory~"sprites/shokorasprite.png";
	ObjCutin_SetSpellcardS4("Light Tome &quot;Purge&quot;", lbcut, "AYA", "196", "214", "151");
	ObjCutin_LaunchS3("AYA", "0", "Hard");
	NotifyEventAll(EV_SPELLBG, 1);
	
	attack1;
}

task attack1{
	wait(90);
	let color = 0;
	angle = 270;
	let time = 115;
	let radius = 35;
	let offset = 0;
	let x = 0;
	let y = 0;
	loop(1){
		//AlertSound;
		angle = rand(0, 360);
		x = GetCenterX;
		y = 120;
		PlaySoundEffect("sagecast", 90, GetCenterX);
		loop(6){ 
			Indicator(x+radius*cos(angle)+rand(-0, 0), y+radius*sin(angle)+rand(-0, 0), 90);
			angle+=360/6;
			wait(4);
		}
		wait(time);
		time-=15;
	}
	loop(4){
		//AlertSound;
		angle = rand(0, 360);
		x = GetPlayerX;
		y = GetPlayerY;
		PlaySoundEffect("sagecast", 90, GetCenterX);
		loop(6){ 
			Indicator(x+radius*cos(angle)+rand(-0, 0), y+radius*sin(angle)+rand(-0, 0), 90);
			angle+=360/6;
			wait(4);
		}
		wait(time);
		time-=15;
	}
}

task AlertSound {
		loop(5) {
			PlaySoundEffect("alert", 100, GetStgFrameWidth/2);
			wait(8);
		}
	}

task Indicator(x, y, duration){
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj, GetCurrentScriptDirectory~"../Sprites/Target.png");
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestCenter(obj);
	//ObjRender_SetBlendType(obj, BLEND_ADD_ARGB);
	Obj_SetRenderPriorityI(obj, 40);
	ObjRender_SetPosition(obj,x,y,0);
	let angle = 270;
	let angle2 = AngleBetweenPoints(x, y, GetPlayerX, GetPlayerY);
	let diroffset = 0;
	let variance = 0;
	let scale = 1;
	let alpha = 255;
	ascent(i in 0..duration){
		ObjRender_SetAngleXYZ(obj,0,0,angle);
		ObjRender_SetScaleXYZ(obj,scale,scale,scale);
		angle+=4;
		if(scale>0.3){ scale-=0.025; }
		yield;
	}
	PlaySoundEffect("se_enep02", 80, x);
		loop(16){
			CreateDNHShotA2(x, y, 4, angle2+rand(-3, 3), -0.06, 2, CIRCLE_S[GRAY], 10);
			angle2+=360/16;
		}
			angle2+=360/16/2;
		loop(16){
			CreateDNHShotA2(x, y, 4, angle2+rand(-3, 3), -0.06, 1, CIRCLE_S[GRAY], 10);
			angle2+=360/16;
		}
	
	loop(30){
		ObjRender_SetAngleXYZ(obj,0,0,angle);
		angle+=4;
		alpha-=255/30;
		ObjRender_SetAlpha(obj, alpha);
		yield;
		}
	Obj_Delete(obj);	
}	
