#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["St1_S3"]
#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","Plant Sign \"The Tree Filled with Energy\""];

@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 time = [0,8,7,6,5];
let ang = 270;
ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 300, 20,4);
wait(90);
FanIsh;
ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 100, 20,4);
wait(90);
Attack2;
loop{
if(Obj_IsDeleted(Enemy)){break;}
PlaySFX(tan05);
CreateShotA1(EnemyX+rand(180,-180),EnemyY+rand(-180,0),rand(1,3),90,PELLET_RED,10);
CreateShotA1(EnemyX+rand(180,-180),EnemyY+rand(-180,0),rand(1,3),90,PELLET_RED,10);
wait(time[GetDifficulty]);

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


task FanIsh{
	let anglel = 45;
	PlaySFX(tan04);
	loop{
		if(Obj_IsDeleted(Enemy)){break;}
		ascent(i in 0..15){
			CreateShotA1(EnemyX,EnemyY ,6 ,(45-i*(360-90)/14)+rand(15,-15) ,PELLET_PURPLE ,0 );
		}
		wait(2);
	}
}

task LaserFuck(x,y,angle,count,leng,width,anv,graphic){
	ascent (i in 0..count){
		let kaori = CreateCurveLaserA1(x,y ,5 ,angle+i*8 ,leng ,width ,graphic ,0 );
		let kaori2 = CreateCurveLaserA1(x,y ,5 ,angle-i*8 ,leng ,width ,graphic ,0 );
		ObjCrLaser_SetTipDecrement(kaori,0 );
		ObjCrLaser_SetTipDecrement(kaori2,0 );
		ObjMove_SetAngularVelocity(kaori,anv );
		ObjMove_SetAngularVelocity(kaori2,anv );
		ObjMove_SetAcceleration(kaori,-0.1 );
		ObjMove_SetAcceleration(kaori2,-0.1 );
		ObjMove_SetMaxSpeed(kaori,1 );
		ObjMove_SetMaxSpeed(kaori2,1 );
		ObjMove_AddPatternA2(kaori,120 ,5 ,NO_CHANGE ,0 ,0 ,0 );
		ObjMove_AddPatternA2(kaori2,120 ,5 ,NO_CHANGE ,0 ,0 ,0 );
	}
}

task Attack2{
	let angle1 = 0;
	let posit = [0,10,14,17,20];
	loop{
		if(Obj_IsDeleted(Enemy)){break;}
		PlaySFX(tan00);
		ascent(a in -3..4){
CreateShotA2(EnemyX,EnemyY,5,angle1+a*posit[GetDifficulty],-0.1,3,LARGE_BLUE,10);
}
ascent(a in -3..4){
CreateShotA2(EnemyX,EnemyY,5,-angle1+a*posit[GetDifficulty],-0.1,3,LARGE_BLUE,10);
}
angle1+=10.534;
wait(5);
	}
}