#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Dross NS2"]
#Text["Numero 5 "]
#System[".\system\Default_System.txt"]


#include"./lib/AllStarShot_Const.dnh"
#include"./lib/TheFunctions.txt"
#include"./BGTask.txt"
#include"./Animation_lib_satori.txt"

let Enemy = ID_INVALID;
let EnemyX = 0;
let EnemyY = 0;

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){SetScriptResult(2400);}
	case(EV_REQUEST_TIMER){SetScriptResult(50);}
//case(EV_REQUEST_SPELL_SCORE){SetScriptResult(90000);}
}

@Initialize{
	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
SetDamageRateAtFrame(Enemy,60,10,120);
ObjRender_SetPosition(Enemy,GetStgFrameWidth/2, 100,0);
SetAutoDeleteObject(true);
InitializeAction(Enemy,DrossDot);
DrawBoss_Task(Enemy);
name("Dross Rotzank",0,10);
//LifeCircleBar_A(Enemy,0.8,0.2,true);
//LifeCircleBar_B(Enemy,0.2,0.0,true);
//LifeCircleBar_Marker(Enemy,0.8);
//LifeStock(2,1);
EnemyMarker(Enemy,Enemy);
TWaveCircle_Shadertask(Enemy,0);
TAura(Enemy,0);
LoadSounds;

	//ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 100, 10,5);
	BossActions;
}

@MainLoop{

	yield;
}

task BossActions{
	ShootBullets;
//Texto;
	while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 0){
		EnemyX = ObjMove_GetX(Enemy);
		EnemyY = ObjMove_GetY(Enemy);
		ObjEnemy_SetIntersectionCircleToShot(Enemy, EnemyX, EnemyY, 40);
		ObjEnemy_SetIntersectionCircleToPlayer(Enemy, EnemyX, EnemyY, 30);
                                          
		yield;
	}
DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(Enemy);
			if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_PLAYER_SHOOTDOWN_COUNT) == 0 && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_PLAYER_SPELL_COUNT) == 0 ){
	SetCommonData("Perfects_Bombs",GetCommonData("Perfects_Bombs",perfectsB)+1);
	}
	if(GetCommonData("Perfects_Bombs",perfectsB) == 5){SetPlayerSpell(GetPlayerSpell+1); SetCommonData("Perfects_Bombs",0);NotifyEventAll(EV_USER+998,0)}
	loop(60){yield;}

	CloseScript(GetOwnScriptID);
}
function wait(t){loop(t){yield;}}

task ShootBullets{
wait(60);
PlaySFX(charge00);
nTestCharge(EnemyX,EnemyY,90,255,0,0);
wait(90);
PlaySFX(D5);
let rad = 80;
let angul = 0;
let angul2 = 0;
let spd = 0;
attack2;
let C1 = [0,15,18,21];
loop{

if(Obj_IsDeleted(Enemy)){break;}
PlaySFX(tan04);
ascent(i in 0..C1[GetDifficulty]){
OndaBullet(EnemyX,EnemyY,4,angul+i*360/C1[GetDifficulty],SMALL_RED,0);
OndaBullet(EnemyX,EnemyY,5,angul+i*360/C1[GetDifficulty],SMALL_RED,0);
OndaBullet(EnemyX,EnemyY,3,angul+i*360/C1[GetDifficulty],SMALL_RED,0);
OndaBullet(EnemyX,EnemyY,6,angul+i*360/C1[GetDifficulty],SMALL_RED,0);
OndaBullet(EnemyX,EnemyY,7,angul+i*360/C1[GetDifficulty],SMALL_RED,0);
OndaBullet(EnemyX,EnemyY,8,angul+i*360/C1[GetDifficulty],SMALL_RED,0);
}
angul+= 8.12313;
wait(120);
ObjMove_SetDestAtWeight(Enemy,GetStgFrameWidth/2+rand(60,-60),rand(30,100),20,4);
spd = 0;


}
}

task OndaBullet(x,y,speed,angle,graphic,delay){
let ola = CreateShotA2(x,y,speed,angle,-0.1,0,graphic,delay);
while(!Obj_IsDeleted(ola)){
if(Obj_IsDeleted(Enemy)){break;}
if(ObjMove_GetSpeed(ola) == 0){ 
  ObjMove_SetAcceleration(ola,0.1);
  ObjMove_SetMaxSpeed(ola,speed);
  wait(30);
  ObjMove_SetAcceleration(ola,-0.1);
  ObjMove_SetMaxSpeed(ola,0);
  }
 yield;
 }
}

task attack2{

loop{
if(Obj_IsDeleted(Enemy)){break;}
PlaySFX(laser);
CheetoLaser(EnemyX,EnemyY,3,-90,70,20,C_LASER_YELLOW,3);
CheetoLaser(EnemyX,EnemyY,3,-90,70,20,C_LASER_YELLOW,-3);
wait(120);
}
}

task CheetoLaser(x,y,speed,angle,l,w,graphic,anv){
let obj = CreateCurveLaserA1(x,y,speed,angle,l,w,graphic,0);
ObjCrLaser_SetTipDecrement(obj,0);
ObjMove_SetAngularVelocity(obj,anv);
wait(60);
ObjMove_SetAngularVelocity(obj,0);
speed = 6;
	let a = 90;
	let a_spd = 3; // rate of angle change
	loop(30){
		let angle_to = GetAngleToPlayer(obj);

		// choose to increase or decrease angle depending on which is closer
		let da = [a_spd, -a_spd][((a - angle_to) % 360) < 180]; 

		// if the angles are close enough, just snap instead
		if( (|a - angle_to|) < a_spd){
			a = angle_to;
		}else{
			a = (a + da) % 360;
		}

		ObjMove_SetAngle(obj, a);

		// optionally scale speed so it slows down to adjust angle
		let scale = (|(a - angle_to) % 360 - 180|) / 180; // ranges [0,1]; is 1 when angles are equal
		ObjMove_SetSpeed(obj, speed * scale); // squaring also optional, increases slowdown
		yield;
	}
}