//TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Dross S3 Survival"]
#Text[""]
#System[".\system\Default_System.txt"]

#include"./lib/AllStarShot_Const.dnh"
#include"./lib/TheFunctions.txt"
#include"./BGTask.txt"
#include"./Animation_lib_satori.txt"
#include"./nuclear.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 2 -Radioactive.avi-","Mystic Square -A Certain Magical Square-"];

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(66666666);}
	case(EV_REQUEST_LIFE){SetScriptResult(1000);}
	case(EV_REQUEST_TIMER){SetScriptResult(60);}
	case(EV_REQUEST_IS_DURABLE_SPELL){SetScriptResult(true)}

}

@Initialize{

	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
SetShotAutoDeleteClip(50,50,50,50);
SetAutoDeleteObject(true);

SetDamageRateAtFrame(Enemy,0,0,120);
name("Dross Rotzank",0,10);
//LifeCircleBar_A(Enemy,1,0.0,false);
//LifeCircleBar_B(Enemy,0.2,0.0,false);
//LifeCircleBar_Marker(Enemy,0.8);
//LifeCircleBar_MarkerEx(Enemy,0.8,1200);
//LifeStock(0,2);
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(YABUSAME, cutinImg, Diff[GetDifficulty]);
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
InitializeAction(Enemy,DrossDot);
DrawBoss_Task(Enemy);
SetAction(Enemy,ACT_MOVE,70);
	ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 100, 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 = 0;
let angul2 = 0;
wait(150);

let as = 0;
let taim = 120;
let count = [0,20,30,40,50];
let size = [0,40,50,60,70];
let sizeadd = [0,15,20,30,30];
let ang = 270;
let topkek = 0;
SetCommonData("Darkness Enable",true);
ObjMove_SetDestAtWeight(Enemy,-300, -100, 20,7);
//Dankness;
loop(150){
topkek = rand(50,-50);
ascent(i in -10..11){
descicion(GetStgFrameWidth/2+topkek +i*120,0,4,90,SMALL_RED,0);
}
wait(5);
}
wait(120);
loop(150){
topkek = rand(50,-50);
ascent(i in -10..11){
descicion(0,GetStgFrameHeight/2+topkek +i*120,4,0,SMALL_RED,0);
}
wait(5);
}
wait(120);

loop(80){
topkek = rand(200,-200);
as = rand(0,80);
ang = rand(0,360);
ascent(i in 0..30){
descicion(0,0,3,ang+i*360/30,SMALL_RED,10);
descicion(GetStgFrameWidth,0,3,ang+i*360/30,SMALL_RED,10);
}
wait(12);
}
wait(120);
NuclearShot(1,GetStgFrameWidth/2,GetStgFrameHeight/2,0,0,0.6,0,0,"BLUE",900,true);

loop{
if(Obj_IsDeleted(Enemy)){break;}
ang = rand(0,360);
ascent(i in 0..20){
 CreateShotA1(GetStgFrameWidth/2,GetStgFrameHeight/2,3,ang+i*360/20,SMALL_RED,0);
 }
wait(9);

  }
}
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) && GetCommonData("Darkness Enable",false) == true){
	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 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;
     
    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);
}
}

task BulletExplosion(x,y,speed,angle,graphic,delay){
let be = CreateShotA1(x,y,speed,angle,graphic,delay);
ObjShot_SetSpellResist(be,true);
while(GetDistance(ObjMove_GetX(be),ObjMove_GetY(be),ObjMove_GetX(Player),ObjMove_GetY(Player)) > 180 ){

yield;
}
LoadSound(CSD ~"sfx/nuclear.wav");
PlaySE(CSD ~"sfx/nuclear.wav");
NuclearShot(3,ObjMove_GetX(be),ObjMove_GetY(be),angle,speed,0.3,0,0.1,"BLUE",300,true);
Obj_Delete(be);
}

task BulletExplosion2(x,y,speed,angle,graphic,delay){
let be = CreateShotA1(x,y,speed,angle,graphic,delay);
ObjShot_SetSpellResist(be,true);
while(GetDistance(ObjMove_GetX(be),ObjMove_GetY(be),ObjMove_GetX(Player),ObjMove_GetY(Player)) > 170 ){

yield;
}
LoadSound(CSD ~"sfx/nuclear.wav");
PlaySE(CSD ~"sfx/nuclear.wav");
NuclearShot(3,ObjMove_GetX(be),ObjMove_GetY(be),angle,speed,0.4,0,0.1,"BLUE",300,true);
Obj_Delete(be);
}

task BulletExplosion3(x,y,speed,angle,graphic,delay){
let be = CreateShotA1(x,y,speed,angle,graphic,delay);
ObjShot_SetSpellResist(be,true);
while(GetDistance(ObjMove_GetX(be),ObjMove_GetY(be),ObjMove_GetX(Player),ObjMove_GetY(Player)) > 170 ){

yield;
}
LoadSound(CSD ~"sfx/nuclear.wav");
PlaySE(CSD ~"sfx/nuclear.wav");
NuclearShot(1,ObjMove_GetX(be),ObjMove_GetY(be),angle,speed,0.3,0,0.1,"BLUE",300,true);
Obj_Delete(be);
}

task descicion(x,y,speed,angle,graphic,delay){
let range = [0,0,0,0,0,0,0,0,1];
let seleccion = range[round(rand(0,8))];
if(seleccion == 0){CreateShotA1(x,y,speed,angle,graphic,delay);}
else{BulletExplosion(x,y,speed,angle,SMALL_BLUE,delay);}
}
task descicion2(x,y,speed,angle,graphic,delay){
let range = [0,0,0,0,0,0,1,1,1];
let seleccion = range[round(rand(0,8))];
if(seleccion == 0){CreateShotA1(x,y,speed,angle,graphic,delay);}
else{BulletExplosion2(x,y,speed,angle,SMALL_BLUE,delay);}
}

task descicion3(x,y,speed,angle,graphic,delay){
let range = [0,0,0,0,0,0,0,1,1,1];
let seleccion = range[round(rand(0,9))];
if(seleccion == 0){CreateShotA1(x,y,speed,angle,graphic,delay);}
else{BulletExplosion3(x,y,speed,angle,SMALL_BLUE,delay);}
}