#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spellcard 4 E"]
#Text[""]
#System[".\system\Default_System.txt"]

#include"script/default_system/Default_ShotConst.txt"
#include"./Functions.txt"
#include"./BGTask.txt"
#include"./Animation_lib.txt"
let Enemy = ID_INVALID;
let EnemyX = 0;
let EnemyY = 0;
let yuyuX = 0;
let yuyuY = 0;
let yuyuko = 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;
@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){SetScriptResult(2500);}
	case(EV_REQUEST_TIMER){SetScriptResult(50);}
case(EV_REQUEST_SPELL_SCORE){SetScriptResult(90000);}
}

@Initialize{
	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
yuyuko = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(yuyuko);
SetShotAutoDeleteClip(50,50,50,50);
SetAutoDeleteObject(true);
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
ObjEnemy_SetDamageRate(Enemy,60,10);
name("Remilia Scarlet",0,30);
name("Yuyuko Saigyouki",0,40);
CutinSpell("Fate Sign\"Fate Pilars\"",0,12);
InitializeAction(Enemy,GetCurrentScriptDirectory ~"img/dot_remilia.png");
DrawBoss_Task(Enemy);
spawnYuyuko;
SpellBGoverlay;
SpellBG1;
SpellBG2;
	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;}
	CloseScript(GetOwnScriptID);
}
function wait(t){loop(t){yield;}}

task ShootBullets{
wait(80);
loop{
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}

wait(260);
  }
}

function angleToPlayer{
let angle=atan2(GetPlayerY-EnemyY,GetPlayerX-EnemyX);
return angle;
}
task spawnYuyuko{
let yuyuko = ObjEnemy_Create(OBJ_ENEMY);
ObjEnemy_Regist(yuyuko);
ObjEnemy_SetLife(yuyuko,2500);
ObjRender_SetPosition(yuyuko,GetCommonData("FX",0),GetCommonData("FY",0),0);
InitializeAction(yuyuko,GetCurrentScriptDirectory ~"img/dot_yuyuko.png");
DrawBoss_Task(yuyuko);
SetAction(yuyuko,YACT_STAND,999999999999999999999);
ObjMove_SetDestAtWeight(yuyuko, -40, 120, 20,4);
yuyukoShot;
while(!Obj_IsDeleted(Enemy) && ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 0 && ObjEnemy_GetInfo(yuyuko, INFO_LIFE) > 0){
yuyuX = ObjMove_GetX(yuyuko);
yuyuY = ObjMove_GetY(yuyuko);
ObjEnemy_SetIntersectionCircleToShot(Enemy, yuyuX, yuyuY, 40);
ObjEnemy_SetIntersectionCircleToPlayer(Enemy, yuyuX, yuyuY, 30);
                                  
		yield;
	}
SetCommonData("FX",ObjMove_GetX(yuyuko));
SetCommonData("FY",ObjMove_GetY(yuyuko));
Obj_Delete(yuyuko);
}
task yuyukoShot{
wait(60);
let angle1 = 90;
let angle2 = 90;
//Fan(yuyuX,yuyuY);
let a = 0;
loop{
a = rand(0,-20);
//ObjMove_SetDestAtWeight(yuyuko, -90, -20, 20,4);
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
pilar(20,a,90,90);
pilar(GetStgFrameWidth-20,a,90,90);
angle1+=10.534;
wait(360);
}
}



//made by me
task GusanoCircle(x,y,speed,angle,graphic,count,delay){
loop(count){
CreateShotA1(x,y,speed,angle,graphic,delay);
angle += 360/count;
}
}


task pilar(x,y,angle,angle2){
let gus = 0;
let timer = 0;
loop(60){
ascent(i in 0..4){
let obj =CreateShotFA1(x+cos(angle)*gus,y+sin(angle)*gus,0,angle2+i*90,DS_KNIFE_KOUMA_BLUE,10,true);
ObjMove_AddPatternA2(obj,300-timer,0,NO_CHANGE,0.08,0,3);
}
gus+=22 ;
timer+= 6;
wait(6);
}
}