#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Dross S2"]
#Text[""]
#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;
//those Min and Max x y are taken from Shadow's Raimoo, Edited for full screen by Me(i am too honest :))
//if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}  my god "function"
let MinX = 0;
let MaxX = 640;
let MinY = 0;
let MaxY = GetStgFrameHeight*1.8;
let cutinImg = DrossCutin;
let Diff = ["none","Easy","Normal","Hard","Abnormal"];
let Spellname = ["Number 4 -Case of the &quot;Danmaku Killer&quot; (REAL)-","Shape Magic -Magical Oval-"];

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}
	case(EV_REQUEST_LIFE){SetScriptResult(1800);}
	case(EV_REQUEST_TIMER){SetScriptResult(56);}

}

@Initialize{

	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
SetShotAutoDeleteClip(500,500,500,500);
SetAutoDeleteObject(true);
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
SetDamageRateAtFrame(Enemy,25,10,120);
name("Dross Rotzank",0,10);
//LifeCircleBar_A(Enemy,0.2,0.0,false);
//LifeCircleBar_B(Enemy,0.2,0.0,false);
//LifeCircleBar_Marker(Enemy,0.8);
//LifeCircleBar_MarkerEx(Enemy,0.8,1200);
//LifeStock(1,1);
TWaveCircle_Shadertask(Enemy,0);
TAura(Enemy,0);
LoadSounds;
PlaySFX(spell);
EnemyMarker(Enemy,Enemy);
SpellBGoverlay;
st3SpellBG2;	
st3SpellBG1;
st3SpellBG3;			
ObjCutin_SetSpellcardS4(Spellname[GetLanguage], cutinImg, NAZRIN, 104, 104, 240);
ObjCutin_LaunchS3(BYAKUREN, cutinImg, Diff[GetDifficulty]);
InitializeAction(Enemy,DrossDot);
DrawBoss_Task(Enemy);
SetAction(Enemy,ACT_MOVE,70);
	ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 110, 20,4);
	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);
	//loop(60){yield;}
		if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_PLAYER_SHOOTDOWN_COUNT) +ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_PLAYER_SPELL_COUNT) == 0)
		{AddScore(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID,INFO_SPELL_SCORE));}
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_PLAYER_SHOOTDOWN_COUNT) == 0 && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_PLAYER_SPELL_COUNT) == 0 ){
	SetCommonData("Perfects",GetCommonData("Perfects",perfects)+1);
	}
	if(GetCommonData("Perfects",perfects) == 5){SetPlayerLife(GetPlayerLife+1); SetCommonData("Perfects",0);NotifyEventAll(EV_USER+999,0)}
		loop(60){yield;}
	CloseScript(GetOwnScriptID);
}
function wait(t){loop(t){yield;}}

task ShootBullets{
let angul = rand(0,360);
let angul2 = 0;
wait(150);
PlaySFX(D4);
let Count1 = [0,20,30,40];
let Count2 = [0,3,4,5,5];
let as = 0;
let taim = 120;
let posx = 0;
let posy = 0;
movement;
loop{
loop(3){
if(Obj_IsDeleted(Enemy)){break;}
PlaySFX(tan04);	
posx = EnemyX;
posy = EnemyY;

ascent(i in 0..Count1[GetDifficulty]){
OndaBullet2(posx,posy,4,angul+i*360/Count1[GetDifficulty],KNIFE_RED,0); 
OndaBullet2(posx,posy,5,angul+i*360/Count1[GetDifficulty]  +5,KNIFE_RED,0); 
OndaBullet2(posx,posy,6,angul+i*360/Count1[GetDifficulty]  +10,KNIFE_RED,0); 
OndaBullet2(posx,posy,7,angul+i*360/Count1[GetDifficulty]  +15,KNIFE_RED,0); 
OndaBullet2(posx,posy,8,angul+i*360/Count1[GetDifficulty]  +20,KNIFE_RED,0); 
 }
wait(300);
posx = EnemyX;
posy = EnemyY;
angul = rand(0,360);
if(Obj_IsDeleted(Enemy)){break;}
ascent(i in 0..Count1[GetDifficulty]){
OndaBullet(posx,posy,4,angul+i*360/Count1[GetDifficulty],KNIFE_BLUE,0); 
OndaBullet(posx,posy,5,angul+i*360/Count1[GetDifficulty]  +5,KNIFE_BLUE,0); 
OndaBullet(posx,posy,6,angul+i*360/Count1[GetDifficulty]  +10,KNIFE_BLUE,0); 
OndaBullet(posx,posy,7,angul+i*360/Count1[GetDifficulty]  +15,KNIFE_BLUE,0); 
//OndaBullet(posx,posy,8,angul+i*360/40  +20,KNIFE_BLUE,0); 
 }
  }
  DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
  blackout(30);
  posx = ObjMove_GetX(Player);
posy = ObjMove_GetY(Player);
if(Obj_IsDeleted(Enemy)){break;}
  ascent(i in 0..Count1[GetDifficulty]){
//OndaBullet2(posx+20*cos(angul+i*360/40),posy+20*sin(angul+i*360/40),4,angul+i*360/40,KNIFE_RED,0); 
//OndaBullet2(posx+20*cos(angul+i*360/40),posy+20*sin(angul+i*360/40),5,angul+i*360/40  +5,KNIFE_RED,0); 
OndaBullet3(posx+20*cos(angul+i*360/Count1[GetDifficulty]),posy+20*sin(angul+i*360/Count1[GetDifficulty]),6,angul+i*360/Count1[GetDifficulty]  +10,KNIFE_RED,0); 
OndaBullet3(posx+20*cos(angul+i*360/Count1[GetDifficulty]),posy+20*sin(angul+i*360/Count1[GetDifficulty]),7,angul+i*360/Count1[GetDifficulty]  +15,KNIFE_RED,0); 
OndaBullet3(posx+20*cos(angul+i*360/Count1[GetDifficulty]),posy+20*sin(angul+i*360/Count1[GetDifficulty]),8,angul+i*360/Count1[GetDifficulty]  +20,KNIFE_RED,0); 
 }
 wait(60);
  yield;
  }
}
function angleToPlayer{
let angle=atan2(GetPlayerY-EnemyY,GetPlayerX-EnemyX);
return angle;
}

task Dankness{

 let sbobj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    let sbimg = imgDarkness;
     
    let sbalpha = 0;
    let sbscroll = 0;
	let huehuehue = 0;
     
    LoadTexture(sbimg);
    ObjPrim_SetTexture(sbobj2,sbimg);
	 ObjSprite2D_SetSourceRect(sbobj2,0-200,0-200,600+200,600+200);
    ObjSprite2D_SetDestCenter(sbobj2);
    //ObjSprite2D_SetDestRect(sbobj2,-256,-256-100,256,256+100);
    Obj_SetRenderPriorityI(sbobj2,59);
    //ObjRender_SetPosition(sbobj2,cx,cy,0);
    ObjRender_SetScaleXYZ(sbobj2,1.4,1.4,1);
	
	while(!Obj_IsDeleted(Enemy)){
	if(sbalpha<255){sbalpha+=6;}
if(sbalpha>255){sbalpha=255;}

ObjRender_SetAlpha(sbobj2,sbalpha);
    ObjRender_SetPosition(sbobj2,ObjMove_GetX(Player),ObjMove_GetY(Player),0);
	yield;
	}
	Obj_Delete(sbobj2);
}


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 OndaBullet2(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 OndaBullet3(x,y,speed,angle,graphic,delay){
let ola = CreateShotA2(x,y,speed,angle,-0.1,0,graphic,delay);
let Count = 2;
while(!Obj_IsDeleted(ola)){
if(Obj_IsDeleted(Enemy)){break;}
if(ObjMove_GetSpeed(ola) == 0 && Count > 0){ 
  ObjMove_SetAcceleration(ola,-0.1);
  ObjMove_SetMaxSpeed(ola,-speed);
  wait(30);
  ObjMove_SetAcceleration(ola,0.1);
  ObjMove_SetMaxSpeed(ola,0);
  Count--;
  }
  
  if(ObjMove_GetSpeed(ola) == 0 && Count == 0){ 
  ObjMove_SetAcceleration(ola,0.1);
  ObjMove_SetMaxSpeed(ola,speed);
  wait(30);
  ObjMove_SetAcceleration(ola,-0.1);
  ObjMove_SetMaxSpeed(ola,0);
  }
  
 yield;
 }
}

task movement{
loop{
wait(180);
ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2+rand(100,-100), 110+rand(0,-60), 20,4);
}
}

task blackout(time){
if(!Obj_IsDeleted(Enemy)){
 let sbobj2 = ObjPrim_Create(OBJ_SPRITE_2D);
    let sbimg = imgBLACK;
     
    let sbalpha = 0;
    let sbscroll = 0;
	let huehuehue = 0;
     SetCommonData("Oscuridad",true);
    LoadTexture(sbimg);
    ObjPrim_SetTexture(sbobj2,sbimg);
	 ObjSprite2D_SetSourceRect(sbobj2,0,0,510,512);
    ObjSprite2D_SetDestCenter(sbobj2);
    //ObjSprite2D_SetDestRect(sbobj2,-256,-256-100,256,256+100);
    Obj_SetRenderPriorityI(sbobj2,111);
    ObjRender_SetPosition(sbobj2,cx,cy,0);
    ObjRender_SetScaleXYZ(sbobj2,2,2,2);
	
	wait(time);
	Obj_Delete(sbobj2);
	SetCommonData("Oscuridad",false);
}
}