#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Dross S1"]
#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;
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 6 -Land of the Illuminati (Confirmed)-","Shape Magic -Strange Figures-"];

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}
	case(EV_REQUEST_LIFE){SetScriptResult(1100);}
	case(EV_REQUEST_TIMER){SetScriptResult(47);}

}

@Initialize{

	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
SetShotAutoDeleteClip(50,50,50,50);
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(2,1);
 TWaveCircle_Shadertask(Enemy,0);
 TAura(Enemy,0);
 LoadSounds;
PlaySFX(spell);
EnemyMarker(Enemy,Enemy);
SpellBGoverlay;
st3SpellBG2;	
st3SpellBG1;
//st1SpellBG3;			
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, 180, 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);
PlaySFX(D6);
let Count1 = [0,12,15,18];
let Count2 = [0,3,3.2,3.6,4];
Attack2;
let as = 0;
while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 500){
angul = rand(0,360);
if(Obj_IsDeleted(Enemy)){break;}
PlaySFX(tan00);
ascent(i in 0..Count1[GetDifficulty]){
let sd90 = CreateShotA1(EnemyX,EnemyY,2,angul+i*360/Count1[GetDifficulty],0,0);
ObjShot_SetSpellResist(sd90,true);
Squarething(0,sd90,20,0);
}

wait(40);
as =0;
  }
  DeleteShotAll(TYPE_ALL, TYPE_ITEM);
  SetDamageRateAtFrame(Enemy,10,10,0);
  loop{
angul = rand(0,360);
if(Obj_IsDeleted(Enemy)){break;}
PlaySFX(tan00);
ascent(i in 0..Count1[GetDifficulty]){
let sd90 = CreateShotA2(EnemyX,EnemyY,2,angul+i*360/Count1[GetDifficulty],0.03,4,0,0);
ObjShot_SetSpellResist(sd90,true);
Squarething(0,sd90,10,0);
}

wait(40);
as =0;
  }
  
}
function angleToPlayer{
let angle=atan2(GetPlayerY-EnemyY,GetPlayerX-EnemyX);
return angle;
}

task Attack2{

while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 500){
 if(Obj_IsDeleted(Enemy)){break;}
 PlaySFX(tan01);
 IlluminatiLeader(EnemyX,EnemyY,0,-1);
 IlluminatiLeader(EnemyX,EnemyY,180,1);
 wait(120);
 }
 
 loop{
 if(Obj_IsDeleted(Enemy)){break;}
 PlaySFX(tan01);
 IlluminatiLeader2(EnemyX,EnemyY,0,-1);
 IlluminatiLeader2(EnemyX,EnemyY,180,1);
 IlluminatiLeader2(EnemyX,EnemyY,0,1);
 IlluminatiLeader2(EnemyX,EnemyY,180,-1);
 wait(120);
 }
}

task IlluminatiLeader(x,y,angle,anv){
let illu = CreateShotA2(x,y,5,angle,-0.1,0,LARGE_GREEN,0);
ObjShot_SetSpellResist(illu,true);
ObjMove_SetAngularVelocity(illu,anv);
let C1 = [0,5,6,7];
let C2 = [0,20,25,30];
wait(60);
if(!Obj_IsDeleted(illu)){
ShootShapeB(ObjMove_GetX(illu),ObjMove_GetY(illu),3,getAtanAngle(illu,Player),3,C1[GetDifficulty],SMALL_GREEN,0);
PlaySFX(tan04);
ascent(i in 0..C2[GetDifficulty]){
  CreateShotA1(ObjMove_GetX(illu),ObjMove_GetY(illu),3,getAtanAngle(illu,Player)+i*360/C2[GetDifficulty],SMALL_GREEN,0);
 }
Obj_Delete(illu);
}
}

task IlluminatiLeader2(x,y,angle,anv){
let illu = CreateShotA2(x,y,5,angle,-0.1,0,LARGE_GREEN,0);
ObjShot_SetSpellResist(illu,true);
ObjMove_SetAngularVelocity(illu,anv);
wait(60);
let C1 = [0,5,6,7];
if(!Obj_IsDeleted(illu)){
PlaySFX(tan04);
ShootShapeB(ObjMove_GetX(illu),ObjMove_GetY(illu),3,getAtanAngle(illu,Player),3,C1[GetDifficulty],SMALL_GREEN,0);
ascent(i in 0..30){
  //sCreateShotA1(ObjMove_GetX(illu),ObjMove_GetY(illu),3,getAtanAngle(illu,Player)+i*360/30,SMALL_GREEN,0);
 }
Obj_Delete(illu);
}
}

task Squarething(time,obj,radius,sizeadd){
wait(time);
let L1;
let L2;
let L3;
let L4;
let L1a = 0+45;
let L2a = 90;
let L3a = 180;
let L4a = 270;
let angol = 0;
let angol2 = 0;
let ses = 3;
L1 = CreateStraightLaserA1(ObjMove_GetX(obj)+radius*cos(angol),ObjMove_GetY(obj)+radius*sin(angol),L1a,GetDistance(ObjMove_GetX(obj)+radius*cos(angol),ObjMove_GetY(obj)+radius*sin(angol),ObjMove_GetX(obj)+radius*cos(angol+90),ObjMove_GetY(obj)+radius*sin(angol+90)),10,999900,ST_LASER_RED,0);
L2 = CreateStraightLaserA1(ObjMove_GetX(obj)+radius*cos(angol+90),ObjMove_GetY(obj)+radius*sin(angol+90),L2a,GetDistance(ObjMove_GetX(obj)+radius*cos(angol+90),ObjMove_GetY(obj)+radius*sin(angol+90),ObjMove_GetX(obj)+radius*cos(angol+180),ObjMove_GetY(obj)+radius*sin(angol+180)),10,999900,ST_LASER_RED,0);
L3 = CreateStraightLaserA1(ObjMove_GetX(obj)+radius*cos(angol+180),ObjMove_GetY(obj)+radius*sin(angol+180),L3a,GetDistance(ObjMove_GetX(obj)+radius*cos(angol+180),ObjMove_GetY(obj)+radius*sin(angol+180),ObjMove_GetX(obj)+radius*cos(angol+270),ObjMove_GetY(obj)+radius*sin(angol+270)),10,999900,ST_LASER_RED,0);
//L4 = CreateStraightLaserA1(ObjMove_GetX(obj)+radius*cos(angol+270),ObjMove_GetY(obj)+radius*sin(angol+270),L4a,GetDistance(ObjMove_GetX(obj)+radius*cos(angol+270),ObjMove_GetY(obj)+radius*sin(angol+270),ObjMove_GetX(obj)+radius*cos(angol+360),ObjMove_GetY(obj)+radius*sin(angol+360)),10,999900,ST_LASER_RED,0);
ObjStLaser_SetSource(L1,false);
ObjStLaser_SetSource(L2,false);
ObjStLaser_SetSource(L3,false);
//ObjStLaser_SetSource(L4,false);
//ObjShot_SetAutoDelete(L1,false);
//ObjShot_SetAutoDelete(L2,false);
//ObjShot_SetAutoDelete(L3,false);
//ObjShot_SetAutoDelete(L4,false);
ObjShot_SetSpellResist(L1,true);
ObjShot_SetSpellResist(L2,true);
ObjShot_SetSpellResist(L3,true);
//ObjShot_SetSpellResist(L4,true);
while(!Obj_IsDeleted(obj)){

ObjMove_SetPosition(L1,ObjMove_GetX(obj)+radius*cos(angol),ObjMove_GetY(obj)+radius*sin(angol));
ObjMove_SetPosition(L2,ObjMove_GetX(obj)+radius*cos(angol+120),ObjMove_GetY(obj)+radius*sin(angol+120));
ObjMove_SetPosition(L3,ObjMove_GetX(obj)+radius*cos(angol+240),ObjMove_GetY(obj)+radius*sin(angol+240));
//ObjMove_SetPosition(L4,ObjMove_GetX(obj)+radius*cos(angol+270),ObjMove_GetY(obj)+radius*sin(angol+270));
ObjStLaser_SetAngle(L1,getAtanAngle(L1,L2));
ObjStLaser_SetAngle(L2,getAtanAngle(L2,L3));
ObjStLaser_SetAngle(L3,getAtanAngle(L3,L1));
//ObjStLaser_SetAngle(L4,getAtanAngle(L4,L1));
ObjLaser_SetLength(L1,GetDistance(ObjMove_GetX(obj)+radius*cos(angol),ObjMove_GetY(obj)+radius*sin(angol),ObjMove_GetX(obj)+radius*cos(angol+120),ObjMove_GetY(obj)+radius*sin(angol+120)));
ObjLaser_SetLength(L2,GetDistance(ObjMove_GetX(obj)+radius*cos(angol+120),ObjMove_GetY(obj)+radius*sin(angol+120),ObjMove_GetX(obj)+radius*cos(angol+240),ObjMove_GetY(obj)+radius*sin(angol+240)));
ObjLaser_SetLength(L3,GetDistance(ObjMove_GetX(obj)+radius*cos(angol+240),ObjMove_GetY(obj)+radius*sin(angol+240),ObjMove_GetX(obj)+radius*cos(angol+360),ObjMove_GetY(obj)+radius*sin(angol+360)));
//ObjLaser_SetLength(L4,GetDistance(ObjMove_GetX(obj)+radius*cos(angol+270),ObjMove_GetY(obj)+radius*sin(angol+270),ObjMove_GetX(obj)+radius*cos(angol+360),ObjMove_GetY(obj)+radius*sin(angol+360)));

angol+= 5;
 yield;
 }
 Obj_Delete(L1);
  Obj_Delete(L2);
   Obj_Delete(L3);
    //Obj_Delete(L4);
}