#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["St1_S4"]
#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 \"Sakura Explosion\""];

@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);

SetDamageRateAtFrame(Enemy,35,20,240);
name("Kaori Mystique",0,10);
//LifeCircleBar_A(Enemy,1,0.0,false);
//LifeCircleBar_B(Enemy,0.2,0.0,false);
//LifeCircleBar_Marker(Enemy,0.8);
//LifeCircleBar_MarkerEx(Enemy,0.8,1200);
//LifeStock(0,2);
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]);
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
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 as = 0;
let taim = 120;
let count = [0,20,30,40,50];
let size = [0,40,50,60,70];
let sizeadd = [0,15,20,30,30];
let sep1 = [0,100,90,80,70];
let sep2 = [0,80,70,60,50];
let ang = 270;
Attack2;
loop{
if(Obj_IsDeleted(Enemy)){break;}
as = 0;
loop(10){
	if(Obj_IsDeleted(Enemy)){break;}
	ascent(i in 0..10){

		exploding(0+as,(0+i*sep1[GetDifficulty])+rand(50,-50));
		}
	as+= sep2[GetDifficulty];
	wait(5);
}
wait(200);

  }
}
function angleToPlayer{
let angle=atan2(GetPlayerY-EnemyY,GetPlayerX-EnemyX);
return angle;
}

task Attack2{
	let geg = 0;
	wait(240);
	loop{
		if(Obj_IsDeleted(Enemy)){break;}
		geg = rand(0,360);
		loop(5){
			PlaySFX(tan01);
			if(Obj_IsDeleted(Enemy)){break;}
		ascent(i in 0..15){
			MShot01(EnemyX,EnemyY,geg+i*360/15,3,5,SMALL_RED,SMALL_RED,0.3,0.3,3);
		}
		geg+= 7;
		wait(10);
	    }
		wait(180);
				geg = rand(0,360);
		loop(5){
			PlaySFX(tan01);
			if(Obj_IsDeleted(Enemy)){break;}
		ascent(i in 0..15){
			MShot01(EnemyX,EnemyY,geg+i*360/15,3,5,SMALL_BLUE,SMALL_BLUE,0.3,0.3,3);
		}
		geg-= 7;
		wait(10);
	    }
	    wait(180);
	}
}





task exploding(x,y){
	PlaySFX(tan00);
let obj = CreateShotA1(x,y,0,0,SMALL_PURPLE,60);
let objx= ObjMove_GetX(obj);
let objy = ObjMove_GetY(obj);

let angul= 0;
wait(60);
ObjShot_FadeDelete(obj);
wait(60);
PlaySFX(kira00);
loop(10){
AutoDeleteShot(objx,objy,angul);
angul+= 360/10;
}
}
task AutoDeleteShot(x,y,angle){
	if(Obj_IsDeleted(Enemy)){break;}
let a= CreateShotA2(x,y,2,angle,-0.1,0,OVAL_PURPLE,0);
//let b= CreateShotA2(x,y,2.5,angle,-0.08,0,DS_BALL_L_RED,0);
wait(120);
ObjShot_FadeDelete(a);
//ObjShot_FadeDelete(b);
}

task MShot01(x,y,angle,speed,count,graphic,graphic2,spdadd,respd,anv){
let a=CreateShotA1(x,y,speed,angle,graphic,0);
ObjMove_AddPatternA2(a,0,NO_CHANGE,NO_CHANGE,0,anv,0);
wait(90);
if(!Obj_IsDeleted(a)){
 //let spdadd = 2.5;
 let adD = [0,2,2.5,3,3.5];
let angleadd= 0;
let angleadd2= 0;
ascent(i in 0..count){
if(Obj_IsDeleted(Enemy)){break;}
PlaySFX(kira00);
 CreateShotA1(ObjMove_GetX(a),ObjMove_GetY(a),speed+i*spdadd,ObjMove_GetAngle(a),graphic2,0);

 }
 }
 Obj_Delete(a);
}