#TouhouDanmakufu[Single]
#ScriptVersion[3]
#System["./system/Default_System.txt"]
#Title["Hina Non Spell 1"]
#include"./Effects_Main.txt"

let current = GetCurrentScriptDirectory;
let enm = ID_INVALID;
let GetX = 0;
let GetY = 0;
let EnemyX = 0;
let EnemyY = 0;



let s=1;
let angle2=0;
let c=6; let c2=15; let c3=7;
let ang=0;


let objScene=GetEnemyBossSceneObjectID();
let Sanae;

let HinaName=GetCurrentScriptDirectory~"./img/HinaName.png";

@Event{
	alternative(GetEventType)
	//1;500;2500
	case(EV_REQUEST_LIFE){SetScriptResult(5500*3);}
	case(EV_REQUEST_TIMER){SetScriptResult(45);}
	

}

@Initialize{

		ObjEnemy_SetDamageRate(enm, 100, 100);
	SetAutoDeleteObject(true);
	enm = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(enm);
CreateLifeBar(enm, 60, 55, 41, 0, [255,255,255], "Normal" , [false,false] );
renderHina(enm);
BossIndicator(enm);
TAura(enm, 6);
	

ObjMove_SetPosition(enm, -150 , -150 );
ChargeUp(enm, [320, 160],  -9,3, angle, 50, 20, [255, 0, 0], "DARK");	

//ObjMove_SetDestAtWeight(enm, GetStgFrameWidth/2, GetStgFrameHeight/2-90, 7, 6);

	
	BossActions;
}


@MainLoop{
	GetX = ObjMove_GetX(enm);
	GetY = ObjMove_GetY(enm);
	EnemyX = ObjMove_GetX(enm);
	EnemyY = ObjMove_GetY(enm);
	


	ObjEnemy_SetIntersectionCircleToShot(enm, GetX, GetY, 32);
	ObjEnemy_SetIntersectionCircleToPlayer(enm, GetX, GetY, 24);
	
	
	yield;
}

task BossActions{

	wait(80);
	//renderboss;
	wait(10);
	ObjMove_SetPosition(enm, GetStgFrameWidth/2, 160);
	
	wait(30);
	PerformActions;

	
	while(ObjEnemy_GetInfo(enm, INFO_LIFE) > 0){
		yield;
	}
	
	Obj_Delete(enm);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
		
	yield;
	CloseScript(GetOwnScriptID);
	
	
	task PerformActions{
	
let angle =20;
let angle2 = 0;
let x=0; let y=0; 
if (GetCommonData("rank", "Normal")=="Normal"){c=6; c2=15; c3=3;}
else{c=8; c2=18; c3=5;}

		//ChargeUp(enm, [ObjMove_GetX(enm), ObjMove_GetY(enm)], 6, 3, angle, 90, 40, [13, 123, 150], "DARK");
let ang2=180;
let D=150;
	
let XAngle=1.25;
let YAngle=-2;	

	ChargeUp(enm, [ObjMove_GetX(enm), ObjMove_GetY(enm)], -9,3, angle, 50, 20, [255, 0, 0], "DARK");
	wait(40);
	
	loop{
	Obj_SetValue(enm,"cast",1);
	Pattern1(XAngle,YAngle);
	Pattern2(-XAngle,-YAngle);
	wait(140);
	Pattern3;
	wait(220);
	TMovement(20,30,2);
	wait(65);
	XAngle*=-1;
	YAngle*=-1;
	}
	
}}

task Pattern1(XAngle,YAngle){
	let ang=rand(0,360);
	let x=0;
	let y=0;
	let dir=40;
	ascent(j in 0..60){
		PlaySoundEffect("se_tan01");
	ascent(i in 0..5){
		CreateShotA4(EnemyX+x+dir*cos(ang), EnemyY+y+dir*sin(ang), 3, ang,-0.02,1,AMULET_INV_BLUE, 15);
		ang+=360/5;
	}
		dir+=-1;
		x+=XAngle;
		y+=YAngle;
		ang+=11;
		wait(6);
	}
	
}

task Pattern2(XAngle,YAngle){
	let ang=rand(0,360);
	let x=0;
	let y=0;
	let dir=40;
	ascent(j in 0..60){
	ascent(i in 0..5){
		CreateShotA4(EnemyX+x+dir*cos(ang), EnemyY+y+dir*sin(ang), 3.25, ang,-0.02,2-0.025*j,AMULET_INV_AQUA, 15);
		ang+=360/5;
	}
		dir+=-1;
		x+=XAngle;
		y+=YAngle;
		ang+=-11;
		wait(6);
	}
	
}

task Pattern3{
	let angleset=GetAngleToPlayer(enm);
	let bShot=2;
	ascent(j in 0..5){
		PlaySoundEffect("se_kira00");
	ascent(i in -bShot..bShot+1){
	CreateShotA5(EnemyX,EnemyY,3,angleset+60/bShot*i,-0.018,1-0.2*j,LARGE_RED,15); }
	
	bShot+=1;
	wait(45);
	}
}

	task CreateShotA4(x, y, speed, angle,accel,maxspd,graphic, delay){

DelayShot(x, y, graphic, angle, speed, BLEND_ADD_ARGB, 3, delay);
wait(delay);
let shota1=CreateShotA2(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,accel,maxspd,graphic, 0);
let blurshot=CreateShotA2(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,accel,maxspd,graphic+3, 0);
ObjShot_SetSpellResist(shota1,true);

ObjRender_SetBlendType(blurshot,BLEND_ADD_ARGB);
ObjShot_SetSpellResist(blurshot,true);
ObjRender_SetScaleXYZ(blurshot,1.5,1.5,1.5);
ObjShot_SetIntersectionEnable(blurshot,false);


//ObjRender_SetBlendType(shota1,BLEND_ADD_ARGB);
}

	task CreateShotA5(x, y, speed, angle,accel,maxspd,graphic, delay){
DelayShot(x, y, graphic, angle, speed, BLEND_ADD_ARGB, 3, delay);
wait(delay);
let shota1=CreateShotA2(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,accel,maxspd,graphic, 0);
ObjShot_SetSpellResist(shota1,true);

//ObjRender_SetBlendType(shota1,BLEND_ADD_ARGB);
}


function angleToPlayer {
	let dir = atan2(GetPlayerY-GetY,GetPlayerX-GetX);
	return dir;
}

task BulletCommands(obj){
   
    ObjMove_SetAngle(obj, GetAngleToPlayer(obj));
}

task renderboss{
	loop(60){
		ObjRender_SetAlpha(enm,255);
		yield;
	}
	
}