#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Dross NS3"]
#Text["Numero 3 -Alas Perturbadoras-"]
#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(3500);}
	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);
SetAutoDeleteObject(true);
InitializeAction(Enemy,DrossDot );
DrawBoss_Task(Enemy);
name("Dross Rotzank",0,10);
//LifeCircleBar_A(Enemy,0.8,0.2,false);
//LifeCircleBar_B(Enemy,0.2,0.0,false);
//LifeCircleBar_Marker(Enemy,0.8);
//LifeStock(1,2);
EnemyMarker(Enemy,Enemy);
TWaveCircle_Shadertask(Enemy,0);
TAura(Enemy,0);
LoadSounds;
//ObjRender_SetPosition(Enemy,GetStgFrameWidth/2, 200,0);
SetAction(Enemy,ACT_MOVE,70);
	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);
nTestCharge(EnemyX,EnemyY,90,255,0,0);
PlaySFX(charge00);
wait(90);
PlaySFX(D3);
let rad = 80;
let angul = 0;
let angul2 = 0;
let spd = 0;
let b_count = [0,3,4,5,6];
let bullets = [0,4,4,4,4];
summonWings;
randMove;
loop{
if(Obj_IsDeleted(Enemy)){break;}
angul = rand(9,-9);
PlaySFX(tan04);
BullTop(-45+angul,2);
BullTop(-135+angul,-2);
wait(300);

}
}

task randMove{
loop{
wait(240);
ObjMove_SetDestAtWeight(Enemy,GetStgFrameWidth/2+rand(60,-60),rand(70,100),30,1);
}
}

task summonWings{

TailWing;
CenterWing;
FaceWing(100,0);
FaceWing(100,180);
//ShootTail;
FaceShoot(100,0);
FaceShoot(100,180);
EmergencyLaser(100,0,0);
EmergencyLaser(100,180,0);
}

task CenterWing{

 let sbobj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    let sbimg = Ala1;
     
    let sbalpha = 0;
    let sbscroll = 0;
	let huehuehue = 0;
     
    LoadTexture(sbimg);
    ObjPrim_SetTexture(sbobj2,sbimg);
	 ObjSprite2D_SetSourceRect(sbobj2,0,0,512,512);
    ObjSprite2D_SetDestCenter(sbobj2);
    //ObjSprite2D_SetDestRect(sbobj2,-256,-256-100,256,256+100);
    Obj_SetRenderPriorityI(sbobj2,39);
    //ObjRender_SetPosition(sbobj2,cx,cy,0);
    
	
	while(!Obj_IsDeleted(Enemy)){
	if(sbalpha<255){sbalpha+=6;}
if(sbalpha>255){sbalpha=255;}
if(sbscroll<0.7){sbscroll+=0.02;}
if(sbscroll>0.7){sbscroll=0.7;}
ObjRender_SetScaleXYZ(sbobj2,sbscroll,sbscroll,sbscroll);
ObjRender_SetAlpha(sbobj2,sbalpha);
    ObjRender_SetPosition(sbobj2,ObjMove_GetX(Enemy),ObjMove_GetY(Enemy),0);
	yield;
	}
	Obj_Delete(sbobj2);
}

task TailWing{

 let sbobj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    let sbimg = Ala2;
     
    let sbalpha = 0;
    let sbscroll = 0;
	let huehuehue = 0;
     
    LoadTexture(sbimg);
    ObjPrim_SetTexture(sbobj2,sbimg);
	 ObjSprite2D_SetSourceRect(sbobj2,0,0,512,512);
    //ObjSprite2D_SetDestCenter(sbobj2);
    ObjSprite2D_SetDestRect(sbobj2,-256,0,256,512);
	
    Obj_SetRenderPriorityI(sbobj2,39);
    //ObjRender_SetPosition(sbobj2,cx,cy,0);
    
	
	while(!Obj_IsDeleted(Enemy)){
	if(sbalpha<255){sbalpha+=6;}
if(sbalpha>255){sbalpha=255;}
if(sbscroll<0.5){sbscroll+=0.02;}
if(sbscroll>0.5){sbscroll=0.5;}
ObjRender_SetScaleXYZ(sbobj2,sbscroll,sbscroll,sbscroll);
ObjRender_SetAlpha(sbobj2,sbalpha);
    ObjRender_SetPosition(sbobj2,ObjMove_GetX(Enemy),ObjMove_GetY(Enemy),0);
	ObjRender_SetAngleZ(sbobj2,0+sin(huehuehue)*30);
	huehuehue+= 1;
	yield;
	}
	Obj_Delete(sbobj2);
}

task FaceWing(range,angle){

 let sbobj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    let sbimg = Ala3;
     
    let sbalpha = 0;
    let sbscroll = 0;
	let huehuehue = 0;
     
    LoadTexture(sbimg);
    ObjPrim_SetTexture(sbobj2,sbimg);
	 ObjSprite2D_SetSourceRect(sbobj2,0,0,256,256);
    ObjSprite2D_SetDestCenter(sbobj2);
    //ObjSprite2D_SetDestRect(sbobj2,-256,-256-100,256,256+100);
    Obj_SetRenderPriorityI(sbobj2,39);
    //ObjRender_SetPosition(sbobj2,cx,cy,0);
    
	
	while(!Obj_IsDeleted(Enemy)){
	if(sbalpha<255){sbalpha+=6;}
if(sbalpha>255){sbalpha=255;}
if(sbscroll<0.5){sbscroll+=0.02;}
if(sbscroll>0.5){sbscroll=0.5;}
ObjRender_SetScaleXYZ(sbobj2,sbscroll,sbscroll,sbscroll);
ObjRender_SetAlpha(sbobj2,sbalpha);
    ObjRender_SetPosition(sbobj2,ObjMove_GetX(Enemy)+range*cos(angle),ObjMove_GetY(Enemy)+range*sin(angle),0);
	yield;
	}
	Obj_Delete(sbobj2);
}

task ShootTail{
wait(70);
let pos = 90;
let angolo = 70;
let rant = 0;
loop{
rant = rand(0,360);
 ShootShapeB(EnemyX+90*cos(pos+sin(angolo)*30),EnemyY+90*sin(pos+sin(angolo)*30),3,rant,3,7,AMULET_BLUE,0);
 ShootShapeB(EnemyX+90*cos(pos+sin(angolo)*30),EnemyY+90*sin(pos+sin(angolo)*30),3,rant,15,3,AMULET_BLUE,0);
 angolo+= 70;
 wait(70);
 }
}

task FaceShoot(range,pos){
let rant = 0;
let C2 = [0,3,5,7];
let C3 = [0,20,25,30];
loop{
if(Obj_IsDeleted(Enemy)){break;}
rant = rand(0,360);
PlaySFX(tan00);
 ShootShapeB(EnemyX+range*cos(pos),EnemyY+range*sin(pos),3,rant,3,C2[GetDifficulty],SMALL_RED,0);
 ascent(i in 0..C3[GetDifficulty]){
  CreateShotA1(EnemyX+range*cos(pos),EnemyY+range*sin(pos),3,rant+i*360/C3[GetDifficulty],SMALL_RED,0);
 }
 wait(70);

}
}

task BullTop(angle,anv){
let topkek = CreateShotA1(EnemyX,EnemyY,4,angle,OVAL_RED,10);
ObjShot_SetSpellResist(topkek,true);
ObjMove_AddPatternA2(topkek,0,NO_CHANGE,NO_CHANGE,-0.05,anv,0);
ObjMove_AddPatternA2(topkek,60,NO_CHANGE,NO_CHANGE,0.2,anv,5);
ObjMove_AddPatternA2(topkek,120,NO_CHANGE,NO_CHANGE,0,0,0);
wait(60);
let C1 = [0,13,10,7];
loop(15){
if(Obj_IsDeleted(topkek)){break;}
PlaySFX(Gtan3);
 ascent(i in 0..8){
 
  CreateShotA2(ObjMove_GetX(topkek),ObjMove_GetY(topkek),0,ObjMove_GetAngle(topkek)+90,0.1,1+i*0.5,AMULET_BLUE,0);
  CreateShotA2(ObjMove_GetX(topkek),ObjMove_GetY(topkek),0,ObjMove_GetAngle(topkek)-90,0.1,1+i*0.5,AMULET_BLUE,0);
  }
 wait(C1[GetDifficulty]);
 }
}

task EmergencyLaser(range,pos,agregado){
while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 1800){
yield;
}
PlaySFX(laser);
let bot = 0;
let laizor = CreateStraightLaserA1(EnemyX+range*cos(pos),EnemyY+range*sin(pos),90,0,40,9999999,ST_LASER_BLUE,60);
loop(60){
ObjLaser_SetLength(laizor,0+bot);
ObjMove_SetPosition(laizor,EnemyX+range*cos(pos),EnemyY+range*sin(pos));
bot+= 700/60;
yield;
}
let tabla = 0;
while(!Obj_IsDeleted(Enemy)){
ObjStLaser_SetAngle(laizor,90+sin(tabla)*10);
ObjMove_SetPosition(laizor,EnemyX+range*cos(pos),EnemyY+range*sin(pos));
tabla+= agregado;
yield;
}
}