#TouhouDanmakufu[Single]
#ScriptVersion[3]
#System["./system/Default_System.txt"]
#Title["Hina Non Spell 4"]
#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(5900*3);}
	case(EV_REQUEST_TIMER){SetScriptResult(39);}
	

}

@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);
Invincible(460);	
ObjMove_SetDestAtWeight(enm, GetStgFrameWidth/2, GetStgFrameHeight/2-80, 6, 4);

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

	
	BossActions;
}

	task Invincible(frame){
		SetInvincibility(enm, frame);
		
	}

@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);
	
	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");

	ChargeUp(enm, [ObjMove_GetX(enm), ObjMove_GetY(enm)], -9,3, angle, 50, 20, [255, 0, 0], "DARK");
	wait(40);
	TCharge01(EnemyX,EnemyY,4,30,182, 3, 252);
	wait(30);
	PlaySoundEffect("se_enep02");
	MapleExplode(50,2,2,8);
	ExplosionA2(enm, "purple");
	IJNFlag;
	Obj_SetValue(enm,"cast",1);
	let D=0.75;
	PatternA1;

}}

task PatternA1{
	
	loop{
	let ang=rand(0,360);
	let angle=rand(0,360);
	let dir=10;
	let dir2=60;
	let AngleAccel=1;
	let cdr=16;
	let velo= 0.35;
	let spd=2;
	
	ascent(j in 0..60){
		PlaySoundEffect("se_tan01");
		ascent(k in 0..2){
			ascent(i in 0..5){
		CreateShotA4(EnemyX+dir*cos(angle), EnemyY+dir*sin(angle), spd, ang,0,0,0,AMULET_BLUE+3*k, 15);
		ang+=360/5;
		}
		angle+=360/2;
		}
	spd+=0.015;
	if(dir>=60){dir=60;}
	if(cdr<=5){cdr=5;}
	cdr+=-1;
	dir+=4;
	ang+=AngleAccel;
	AngleAccel++;
	angle+=8;
	wait(cdr);
	}
	
	ascent(j in 0..60){
		PlaySoundEffect("se_tan01");
		ascent(k in 0..2){
			ascent(i in 0..5){
		CreateShotA4(EnemyX+dir*cos(angle), EnemyY+dir2*sin(angle), spd+0.015*j, ang,0,0,0,AMULET_BLUE+3*k, 15);
		ang+=360/5;
		}
		angle+=360/2;
		}
	if(dir>=120){dir=120;}
	if(dir2<=30){dir2=30;}
	dir+=6;
	dir2+=-2;
	ang+=AngleAccel;
	AngleAccel++;
	angle+=-8;
	wait(5);
	}
	
	let graph=[ICE_BLUE,ICE_PURPLE];
	let directPos=0;
	
	ascent(j in 0..3){
		PlaySoundEffect("se_kira00");
		TMovement(60,30,2);
	ascent(i in 0..4){
		ascent(k in 0..35){
		CreateShotA4(EnemyX+directPos, EnemyY+directPos, 4, ang+rand(-3,3)*j,-0.2,0,2-0.5*i,graph[i%2], 5);
		ang+=360/35;
		}
	}
		directPos+=rand(-5,5);
		wait(30);
	}
	wait(60);
	
	ObjMove_SetDestAtWeight(enm, GetStgFrameWidth/2, GetStgFrameHeight/2-80, 6, 2);
	wait(90);
	
	}
}

	task CreateShotA4(x, y, speed, angle,accel,velo,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);
ObjMove_SetAngularVelocity(shota1,velo);

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

}

