#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non Spellcard 3"]
#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(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);
ObjEnemy_SetDamageRate(Enemy,50,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;
	ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 70, 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(300);
loop{
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
//SE(CSD ~ "sfx/tan00.wav");
wait(20.231949);
}
}


task spawnYuyuko{
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, GetStgFrameWidth/2, 150, 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 radius= 80;
let angul = 0;
let angul2 = 0;
ObjMove_SetDestAtWeight(Enemy, -90, -50, 20,4);
ObjMove_SetDestAtWeight(yuyuko, GetStgFrameWidth/2, 80, 20,4);
wait(60);
Fan(yuyuX,yuyuY);
loop{
if(ObjEnemy_GetInfo(Enemy, INFO_LIFE) == 0){break;}
SE(CSD ~ "sfx/tan05.wav");
loop(15){
CreateShotFA2(yuyuX+radius*cos(angul),yuyuY+50*sin(angul),0,angul2,0.02,5,DS_SCALE_PURPLE,10,true);
angul2+= 360/15;
}
angul+= 5.123;
angul2+= 5.123;
wait(9);
}
}

