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

#include"./lib/WormShot_Const.dnh"
#include"./lib/TheFunctions.txt"
#include"./BGTask.txt"
#include"./Animation_lib_Kaori.txt"
let Enemy = ID_INVALID;
let EnemyX = 0;
let EnemyY = 0;

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_LIFE){SetScriptResult(2300);}
	case(EV_REQUEST_TIMER){SetScriptResult(50);}
//case(EV_REQUEST_SPELL_SCORE){SetScriptResult(90000);}
}

@Initialize{
	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
SetDamageRateAtFrame(Enemy,80,30,160);
SetAutoDeleteObject(true);
//InitializeAction(Enemy,MichaelDot );
//DrawBoss_Task(Enemy);
BossImage;
name("Kaori Mystique",0,10);
//LifeCircleBar_A(Enemy,0.8,0.2,false);
//LifeCircleBar_B(Enemy,0.2,0.0,false);
//LifeCircleBar_Marker(Enemy,0.8);
//LifeStock(1,2);
EnemyMarker(Enemy,Enemy);
TWaveCircle_Shadertask(Enemy,6);
TAura(Enemy,6);
LoadSounds;
//ObjRender_SetPosition(Enemy,GetStgFrameWidth/2, 200,0);
//SetAction(Enemy,ACT_MOVE,70);
	ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 100, 10,5);
	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);
		if(ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_PLAYER_SHOOTDOWN_COUNT) == 0 && ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID(), INFO_PLAYER_SPELL_COUNT) == 0 ){
	SetCommonData("Perfects_Bombs",GetCommonData("Perfects_Bombs",perfectsB)+1);
	}
	if(GetCommonData("Perfects_Bombs",perfectsB) == 5){SetPlayerSpell(GetPlayerSpell+1); SetCommonData("Perfects_Bombs",0);NotifyEventAll(EV_USER+998,0)}
	loop(60){yield;}
	CloseScript(GetOwnScriptID);
}
function wait(t){loop(t){yield;}}

task ShootBullets{
wait(60);
//nTestCharge(EnemyX,EnemyY,90,0,0,255);
Concentration001(Enemy,70,90,90,90,255,0,255);
Concentration001(Enemy,70,90,90,-90,255,0,255);
PlaySFX(charge00);
wait(90);
let rad = 80;
let angul = 0;
let angul2 = 0;
let b_count = [0,5,6,7,8];
let bullets = [0,30,35,40,45];
loop{
if(Obj_IsDeleted(Enemy)){break;}
PlaySFX(tan00);
angul = rand(0,360);
ascent(i in 0..bullets[GetDifficulty]){
	Flower(EnemyX,EnemyY,5,angul+i*360/bullets[GetDifficulty],LARGE_GREEN,PELLET_BLUE,7,10);
	Flower(EnemyX,EnemyY,4,angul+i*360/bullets[GetDifficulty],LARGE_BLUE,PELLET_GREEN,7,10);
}	

wait(200);
}
}

task Flower(x,y,speed,angle,graphic1,graphic2,count,delay){
	let kao = CreateShotA2(x,y ,speed ,angle ,-0.1 , 0,graphic1 ,delay );
	wait(90);
	if(!Obj_IsDeleted(kao)){
		PlaySFX(kira00);
	ascent(i in 0..count){
    CreateShotA1(ObjMove_GetX(kao),ObjMove_GetY(kao) ,2 ,(angle+i*360/count)+10 ,graphic2 ,10 );
    
	}
	Obj_Delete(kao);
    }
}