#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["St1_S2"]
#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;
//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;
let cutinImg = KaoriCutin;
let Diff = ["none","Easy","Normal","Hard","Abnormal"];
let Spellname = ["no","Flower Sign \"Imperfect Blossom\""];

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}
	case(EV_REQUEST_LIFE){SetScriptResult(1500);}
	case(EV_REQUEST_TIMER){SetScriptResult(67);}

}

@Initialize{

	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(Enemy);
SetShotAutoDeleteClip(50,50,50,50);
SetAutoDeleteObject(true);
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
SetDamageRateAtFrame(Enemy,35,20,160);
name("Kaori Mystique",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(1,1);
TWaveCircle_Shadertask(Enemy,6);
TAura(Enemy,6);
LoadSounds;
PlaySFX(spell);
EnemyMarker(Enemy,Enemy);
SpellBGoverlay;
st1SpellBG2;	
st3SpellBG1;
//st1SpellBG3;			
ObjCutin_SetSpellcardS4(Spellname[GetLanguage], cutinImg, NAZRIN, 240, 104, 240);
ObjCutin_LaunchS3(YABUSAME, cutinImg, Diff[GetDifficulty]);
BossImage;
//InitializeAction(Enemy,MichaelDot);
//DrawBoss_Task(Enemy);
//SetAction(Enemy,ACT_MOVE,70);
	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;}
		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);
let Count1 = [0,18,24,30,36];
let Count2 = [0,6,5,4,3];
let as = 0;
let taim = 120;
Attack2;
loop{
if(Obj_IsDeleted(Enemy)){break;}
PlaySFX(tan01);
FlowerShot(rand(0,GetStgFrameWidth),rand(0,90),90+rand(20,-20),3,SMALL_PURPLE,PELLET_PURPLE,10);

wait(Count2[GetDifficulty]);
  }
}
function angleToPlayer{
let angle=atan2(GetPlayerY-EnemyY,GetPlayerX-EnemyX);
return angle;
}

task FlowerShot(x,y,angle,speed,graphic,graphic2,radius){
let f1 = CreateShotA2(x,y,0,angle,0.05,speed,graphic,10);
ObjShot_SetDeleteFrame(f1,rand(80,100) );
let sub1= CreateShotA1(x+radius*cos(angle),y+radius*sin(angle),speed,angle,graphic2,10);
let sub2= CreateShotA1(x+radius*cos(angle+72),y+radius*sin(angle+72),speed,angle,graphic2,10);
let sub3= CreateShotA1(x+radius*cos(angle+144),y+radius*sin(angle+144),speed,angle,graphic2,10);
let sub4= CreateShotA1(x+radius*cos(angle+216),y+radius*sin(angle+216),speed,angle,graphic2,10);
let sub5= CreateShotA1(x+radius*cos(angle+288),y+radius*sin(angle+288),speed,angle,graphic2,10);
while(!Obj_IsDeleted(f1)){
ObjMove_SetPosition(sub1,ObjMove_GetX(f1)+radius*cos(angle),ObjMove_GetY(f1)+radius*sin(angle));
ObjMove_SetPosition(sub2,ObjMove_GetX(f1)+radius*cos(angle+72),ObjMove_GetY(f1)+radius*sin(angle+72));
ObjMove_SetPosition(sub3,ObjMove_GetX(f1)+radius*cos(angle+144),ObjMove_GetY(f1)+radius*sin(angle+144));
ObjMove_SetPosition(sub4,ObjMove_GetX(f1)+radius*cos(angle+216),ObjMove_GetY(f1)+radius*sin(angle+216));
ObjMove_SetPosition(sub5,ObjMove_GetX(f1)+radius*cos(angle+288),ObjMove_GetY(f1)+radius*sin(angle+288));

ObjMove_SetAngle(sub1,angle );
ObjMove_SetAngle(sub2,angle+72 );
ObjMove_SetAngle(sub3,angle+144 );
ObjMove_SetAngle(sub4,angle+216 );
ObjMove_SetAngle(sub5,angle+288 );

angle+=3;
yield;
}
}

task Attack2{
	wait(180);
	let algo = rand(0,360);
	loop{
		algo = rand(0,360);
		if(Obj_IsDeleted(Enemy)){break;}
		PlaySFX(tan04);
		ascent (i in 0..20){
			ascent(o in 0..6){
				CreateShotA1(EnemyX,EnemyY ,1+o*0.5 ,algo+i*360/20 ,LARGE_RED ,10 );
			}
		}
		wait(100);
		ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2+rand(100,-100), 100, 20,4);
		wait(100);
	}
}