//TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non Spellcard 1"]
#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;

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){SetScriptResult(3000);}
	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);
ObjEnemy_SetDamageRate(Enemy,60,10);
SetAutoDeleteObject(true);
	InitializeAction(Enemy,GetCurrentScriptDirectory ~"img/dot_remilia.png");
DrawBoss_Task(Enemy);
SunflowerField(12);
name("Remilia Scarlet",0,30);
name("Yuyuko Saigyouki",0,40);
spawnYuyuko;
ObjRender_SetPosition(Enemy,GetStgFrameWidth/2, 100,0);
	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(60);

}
task spawnYuyuko{
ObjEnemy_SetLife(yuyuko,2500);
InitializeAction(yuyuko,GetCurrentScriptDirectory ~"img/dot_yuyuko.png");
ObjRender_SetPosition(yuyuko,GetCommonData("FX",0),GetCommonData("FY",0),0);
DrawBoss_Task(yuyuko);
SetAction(yuyuko,YACT_STAND,999999999999999999999);
ObjMove_SetDestAtFrame(yuyuko, GetStgFrameWidth/2, 50, 60);
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 = 0;
loop{
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
loop(30){
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
SE(CSD ~"sfx/tan03.wav");
ascent(a in -4..5){
CreateShotFA2(EnemyX,EnemyY,5,angle1+a*20,-0.1,3,DS_BALL_M_RED,10,true);
}
ascent(b in -2..3){
CreateShotFA2(EnemyX,EnemyY,5,angle2+b*60,-0.1,2.7,DS_BALL_L_RED,10,true);
}
angle1 += 25.534;
angle2 += 25.534;
wait(9);
}
wait(60);
ObjMove_SetDestAtWeight(yuyuko, GetStgFrameWidth/2, 100, 20,4);
ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 50, 20,4);
wait(60);
let angle3 = 0;
loop(30){
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
SE(CSD ~"sfx/kira00.wav");
loop(10){
RotatingButterfly(yuyuX,yuyuY,angle3,DS_BUTTERFLY_BLUE);
angle3 += 360/10;
}
angle3 += 8.2414;
wait(10);
}
wait(60);
ObjMove_SetDestAtWeight(yuyuko, GetStgFrameWidth/2+50, 100, 20,4);
ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2-50, 100, 20,4);
wait(60);
let angle4 = 0;
FateKnifes;
loop(120){
SE(CSD ~"sfx/tan05.wav");
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
CreateShotFA1(EnemyX,EnemyY,5,getAtanAngle(Enemy,GetPlayerObjectID)+50+sin(angle4)*40,DS_BALL_S_RED,10,true);
CreateShotFA1(EnemyX,EnemyY,5,getAtanAngle(Enemy,GetPlayerObjectID)-50-sin(angle4)*40,DS_BALL_S_RED,10,true);
CreateShotFA1(yuyuX,yuyuY,5,getAtanAngle(yuyuko,GetPlayerObjectID)+50+sin(angle4)*40,DS_BALL_S_RED,10,true);
CreateShotFA1(yuyuX,yuyuY,5,getAtanAngle(yuyuko,GetPlayerObjectID)-50-sin(angle4)*40,DS_BALL_S_RED,10,true);
angle4 += 8;
wait(2);
}
wait(60);
ObjMove_SetDestAtFrame(yuyuko, GetStgFrameWidth/2, 50, 60);
ObjMove_SetDestAtFrame(Enemy, GetStgFrameWidth/2, 100, 60);
wait(60);
}
}
task RotatingButterfly(x,y,angle,graphic){
let s1 = CreateShotFA1(x,y,3,angle,graphic,10,true);
ObjMove_AddPatternA3(s1,10,NO_CHANGE,NO_CHANGE,0,6,0,NO_CHANGE);
ObjMove_AddPatternA3(s1,100,NO_CHANGE,NO_CHANGE,0,0,0,NO_CHANGE);
wait(120);
let speed = 3.5;
loop(2){
CreateShotOA1(s1,speed,ObjMove_GetAngle(s1),graphic,0);
speed += 0.5;
}
}
task FateKnifes{ //no they are kunais!
let speedA = 1;
let angle = 0;
loop(40){
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
loop(5){
CreateShotA1(EnemyX+50,EnemyY,speedA,angle,DS_KUNAI_BLUE,10);
angle += 360/5;
   }
speedA += 0.1;
angle += 5.345;
wait(5);   
  }
wait(60);
 }
