#TouhouDanmakufu[Single]
#ScriptVersion[3]
#System["./system/Default_System.txt"]
#Title["Hina Non Spell 3"]
#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(54);}
	

}

@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(320);	
ObjMove_SetDestAtWeight(enm, GetStgFrameWidth/2, GetStgFrameHeight/2-60, 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=1.5;
	let spd=[1,2];
	
	loop{
	let angleshot=rand(0,360);	
	
	PlaySoundEffect("se_boon01");
	ascent(i in 0..2){		
	ShootShapeA1(EnemyX, EnemyY, spd[0], angleshot+60*i, 3, 5, AMULET_INV_YELLOW, 15,57,D);	
			D*=-1;
		}
	
	wait(440);
	
	D*=-1;
	angleshot=rand(0,360);
	PlaySoundEffect("se_boon01");
	ascent(i in 0..2){	
	ShootShapeA2(EnemyX, EnemyY, spd[1], angleshot+60*i, 3, 5, AMULET_INV_MINT, 15,57,D);	
	D*=-1;
	}
	
	D*=-1;
	wait(420);
	
	}
}}


function ShootShapeA1(spawnX, spawnY, v, angle, num, bside, graphic, delay,delayframe,angspin) {
	 ascent(i in 0..num) {
 		 let sx = spawnX+cos(angle+i*360/num);
  	 	 let sy = spawnY+sin(angle+i*360/num);
 	  	 let sxN = spawnX+cos(angle+(i+1)*360/num);
 		 let syN = spawnY+sin(angle+(i+1)*360/num);
		 
		 let angletoshot=0;
 		 //CreateShotA1(spawnX, spawnY, v*(((sx-spawnX)^2+(sy-spawnY)^2)^0.5), atan2(sy-spawnY,sx-spawnX), graphic, delay);
  		 ascent(j in 0..bside) {
  			 let toAngle = atan2(syN-sy,sxN-sx);
  			 let toDist = (((sxN-sx)^2+(syN-sy)^2)^0.5);
 		     let sx2 = sx+toDist/bside*j*cos(toAngle);
  			 let sy2 = sy+toDist/bside*j*sin(toAngle);
			 
			 angletoshot=atan2(sy2-spawnY,sx2-spawnX);
			 CreateShotA5(spawnX, spawnY, v*(((sx2-spawnX)^2+(sy2-spawnY)^2)^0.4),angletoshot, graphic, delay);
			
			
 		 }
	 }
	 
task CreateShotA5(x, y, speed, angle,graphic, delay){
DelayShot(x, y, graphic, angle, speed, BLEND_ADD_ARGB, 3, delay);
wait(delay);
let shota1=CreateShotA1(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,graphic, 0);
ObjShot_SetSpellResist(shota1,true);
ObjShot_SetAutoDelete(shota1,false);
ObjMove_AddPatternA2(shota1,delayframe,NO_CHANGE,NO_CHANGE,-0.05,0,0);
Speed(shota1,160,angle,angspin);

let blurshot=CreateShotA1(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,graphic+3, 0);
ObjMove_AddPatternA2(blurshot,delayframe,NO_CHANGE,NO_CHANGE,-0.05,0,0);
ObjRender_SetBlendType(blurshot,BLEND_ADD_ARGB);
ObjShot_SetAutoDelete(blurshot,false);
ObjShot_SetSpellResist(blurshot,true);
ObjRender_SetScaleXYZ(blurshot,1.5,1.5,1.5);
ObjShot_SetIntersectionEnable(blurshot,false);		
Speed(blurshot,160,angle,angspin);

Pattern1(shota1,160,blurshot);
}
	 
	 task Speed(obj,t,angle,angspin){
	wait(t);
	ObjShot_SetSpellResist(obj,true);
	PlaySoundEffect("se_kira00");
	ObjRender_SetAlpha(obj,255);
	ObjShot_SetIntersectionEnable(obj,true);
	
		
	let r = GetObjectDistance(obj,enm);
	let a = -90;
	while(!Obj_IsDeleted(obj))
	{
		ObjMove_SetPosition(obj,EnemyX+r*cos(angle),EnemyY+r*sin(angle));
		ObjMove_SetAngle(obj,atan2(ObjMove_GetY(obj)-EnemyY,ObjMove_GetX(obj)-EnemyX));
		angle+=angspin;
		
		yield;
	}
}
	task Pattern1(obj,t,blurshot){
		wait(t);
		let cdr=20;
		let velo=0.2;
		
		ascent(k in 0..20){
			PlaySoundEffect("se_tan01");
			CreateShotA4(ObjMove_GetX(obj), ObjMove_GetY(obj), 2, atan2(ObjMove_GetY(obj)-EnemyY,ObjMove_GetX(obj)-EnemyX), AMULET_INV_YELLOW, 5);

		if (cdr<=8){cdr=8;}
		cdr+=-1;
		wait(cdr);
		}
		ascent(j in 0..2){
		ascent(i in 0..3){
		CreateShotBVelo(ObjMove_GetX(obj), ObjMove_GetY(obj), 1.25, velo,atan2(ObjMove_GetY(obj)-EnemyY,ObjMove_GetX(obj)-EnemyX)+360/3*i, AMULET_INV_MINT, 15);}
		velo*=-1;
		}
		Obj_Delete(obj);
		Obj_Delete(blurshot);
		
	}
} 

	task CreateShotA4(x, y, speed, angle,graphic, delay){
DelayShot(x, y, graphic, angle, speed, BLEND_ADD_ARGB, 3, delay);
wait(delay);
let shota1=CreateShotA1(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,graphic, 0);
//ObjShot_SetSpellResist(shota1,true);

//ObjRender_SetBlendType(shota1,BLEND_ADD_ARGB);
}

	task CreateShotBVelo(x, y, speed, velo,angle,graphic, delay){
DelayShot(x, y, graphic, angle, speed, BLEND_ADD_ARGB, 3, delay);
wait(delay);
let shota1=CreateShotA1(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,graphic, 0);
//ObjShot_SetSpellResist(shota1,true);
ObjMove_SetAngularVelocity(shota1,velo);
//ObjRender_SetBlendType(shota1,BLEND_ADD_ARGB);
}

function ShootShapeA2(spawnX, spawnY, v, angle, num, bside, graphic, delay,delayframe,angspin) {
	 ascent(i in 0..num) {
 		 let sx = spawnX+cos(angle+i*360/num);
  	 	 let sy = spawnY+sin(angle+i*360/num);
 	  	 let sxN = spawnX+cos(angle+(i+1)*360/num);
 		 let syN = spawnY+sin(angle+(i+1)*360/num);
		 
		 let angletoshot=0;
 		 //CreateShotA1(spawnX, spawnY, v*(((sx-spawnX)^2+(sy-spawnY)^2)^0.5), atan2(sy-spawnY,sx-spawnX), graphic, delay);
  		 ascent(j in 0..bside) {
  			 let toAngle = atan2(syN-sy,sxN-sx);
  			 let toDist = (((sxN-sx)^2+(syN-sy)^2)^0.5);
 		     let sx2 = sx+toDist/bside*j*cos(toAngle);
  			 let sy2 = sy+toDist/bside*j*sin(toAngle);
			 
			 angletoshot=atan2(sy2-spawnY,sx2-spawnX);
			 CreateShotA5(spawnX, spawnY, v*(((sx2-spawnX)^2+(sy2-spawnY)^2)^0.4),angletoshot, graphic, delay);
			
			
 		 }
	 }
	 
task CreateShotA5(x, y, speed, angle,graphic, delay){
DelayShot(x, y, graphic, angle, speed, BLEND_ADD_ARGB, 3, delay);
wait(delay);
let shota1=CreateShotA1(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,graphic, 0);
ObjShot_SetSpellResist(shota1,true);
ObjShot_SetAutoDelete(shota1,false);
ObjMove_AddPatternA2(shota1,delayframe,NO_CHANGE,NO_CHANGE,-0.05,0,0);
Speed(shota1,160,angle,angspin);

let blurshot=CreateShotA1(x+speed*delay*cos(angle), y+speed*delay*sin(angle), speed, angle,graphic-3, 0);
ObjMove_AddPatternA2(blurshot,delayframe,NO_CHANGE,NO_CHANGE,-0.05,0,0);
ObjRender_SetBlendType(blurshot,BLEND_ADD_ARGB);
ObjShot_SetAutoDelete(blurshot,false);
ObjShot_SetSpellResist(blurshot,true);
ObjRender_SetScaleXYZ(blurshot,1.5,1.5,1.5);
ObjShot_SetIntersectionEnable(blurshot,false);		
Speed(blurshot,160,angle,angspin);

Pattern1(shota1,160,blurshot);
}
	 
	 task Speed(obj,t,angle,angspin){
	wait(t);
	ObjShot_SetSpellResist(obj,true);
	PlaySoundEffect("se_kira00");
	ObjRender_SetAlpha(obj,255);
	ObjShot_SetIntersectionEnable(obj,true);
	
		
	let r = GetObjectDistance(obj,enm);
	let a = -90;
	while(!Obj_IsDeleted(obj))
	{
		ObjMove_SetPosition(obj,EnemyX+r*cos(angle),EnemyY+r*sin(angle));
		ObjMove_SetAngle(obj,atan2(ObjMove_GetY(obj)-EnemyY,ObjMove_GetX(obj)-EnemyX));
		angle+=angspin;
		
		yield;
	}
}
	task Pattern1(obj,t,blurshot){
		wait(t);
		let cdr=55;
		let velo=0.2;
		angle=21/6*c;
		ascent(k in 0..10){
			PlaySoundEffect("se_tan01");
		ascent(j in 0..2){
			ascent(r in 0..j+1){
				
				CreateShotA4(ObjMove_GetX(obj), ObjMove_GetY(obj), (4-j*0.2), 180+atan2(ObjMove_GetY(obj)-EnemyY,ObjMove_GetX(obj)-EnemyX)-j*1+r*2, AMULET_INV_MINT, 5);}
		}
		if (cdr<=1){cdr=1;}
		cdr+=-5;
		wait(cdr);
		}
		ascent(j in 0..2){
		ascent(i in 0..5){
		CreateShotBVelo(ObjMove_GetX(obj), ObjMove_GetY(obj), -1.25, velo,180+atan2(ObjMove_GetY(obj)-EnemyY,ObjMove_GetX(obj)-EnemyX)+360/5*i, AMULET_INV_YELLOW, 15);}
		velo*=-1;
		}
		Obj_Delete(obj);
		Obj_Delete(blurshot);
		
	}
} 
