#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["St1_S7 (Last Spell)"]
#Text[""]
#System[".\system\Default_System.txt"]

#include"./lib/WormShot_Const.dnh"
#include"./lib/TheFunctions.txt"
#include"./BGTask.txt"
#include"./Animation_lib_Kaori.txt"
#include"./Animation_lib_subRoka.txt"
#include"./lib/Dialogue Prototype2.dnh"
#include"./nuclear.txt"

let Enemy = ID_INVALID;
let Roka = ID_INVALID;
let EnemyX = 0;
let EnemyY = 0;
let RokaX = 0;
let RokaY = 0;

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","\"Mystical Elementic Rise\""];

@Event{
	alternative(GetEventType)
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(10000000);}
	case(EV_REQUEST_LIFE){SetScriptResult(5500);}
	case(EV_REQUEST_TIMER){SetScriptResult(200);}

}

@Initialize{

	Enemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	Roka = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(Enemy);
	ObjEnemy_Regist(Roka);

SetShotAutoDeleteClip(50,50,50,50);
SetAutoDeleteObject(true);

SetDamageRateAtFrame(Enemy,35,0,240);
name("Kaori Mystique",0,10);
//name("Enzaki Roka",0,20);
SetCommonData("OnEvent",true);
//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;
EnemyMarker(Enemy,Enemy);
/*
PlaySFX(spell);

SpellBGoverlay;
st1SpellBG2;	
st3SpellBG1;
//st1SpellBG3;				
ObjCutin_SetSpellcardS4(Spellname[GetLanguage], cutinImg, NAZRIN, 240, 104, 240);
ObjCutin_LaunchS3(YABUSAME, cutinImg, Diff[GetDifficulty]);
ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
*/
BossImage;
BossImage_Roka;
//InitializeAction(Enemy,MichaelDot);
//DrawBoss_Task(Enemy);
//SetAction(Enemy,ACT_MOVE,70);
	ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 100, 20,4);
	ObjMove_SetDestAtWeight(Roka, GetStgFrameWidth/2, 240, 20,4);
	BossActions;

}

@MainLoop{

	yield;
}



task BossActions{

	ShootBullets;
//Texto;
	while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 0){
		EnemyX = ObjMove_GetX(Enemy);
		EnemyY = ObjMove_GetY(Enemy);
		RokaX = ObjMove_GetX(Roka);
		RokaY = ObjMove_GetY(Roka);
		if(GetCommonData("OnEvent",false) ==false){
		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 Charla ;
	let gusano = "";
	let lapros = "";
	let michael = MichaelNormal;
	SetCommonData("OnEvent",true);
	StartEvent;
	SetPlayerNumber(1);
	SetEnemyNumber(1);

	SetNewPlayerPort1(ReimuSurprised); 
	SetNewEnemyPort1(KaoriHappy); 
	SetNewEnemyPort2(RokaNormal); 
	SetEventSpeaker(ENEMY1_SPEAKS);
    
    NotifyEventAll(EV_USER+70,1 );
	Charla = ["","..."];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],180);

	Charla = ["","..."];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],180);
    
    NotifyEventAll(EV_USER+71,1 );

	Charla = ["","No..."];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],180);

	Charla = ["","I can't lose..."];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],180);

	Charla = ["","I CANNOT LOSE!"];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],180);

	SetEventSpeaker(ENEMY2_SPEAKS);

	Charla = ["","Don't cry, this isn't over."];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],180);

	SetEventSpeaker(ENEMY1_SPEAKS);

	Charla = ["","NO!"];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],180);

	Charla = ["","I WON'T LET THIS HAPPEN AGAIN!"];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],300);

	Charla = ["","EVEN IF I HAVE TO ABSORB [r]EVERYTHING, I WON'T LET MY DREAMS          GO AWAY."];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],300);

	Charla = ["","YOU ARE GOING TO DIE HERE."];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],300);

	Concentration001(Enemy,180,50,90,30,255,0,0);
    //Concentration001(Enemy,180,50,90,-30,255,0,0);
    SpellBGoverlay;

	SetEventSpeaker(ENEMY2_SPEAKS);

	Charla = ["","STOP!"];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],180);

	Charla = ["","DON'T DO IT."];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],120);

	Charla = ["","I AM NOT GOING TO DIE!"];  //Normal
	SetEventTextB(SAY_YELLOW,Charla[GetLanguage],120);

	BFX_ExplosionA2(RokaX,RokaY,600,ChargeEffNeito2,wave,30);



	EndEvent;
	SetCommonData("OnEvent",false);
	wait(20);
	ObjMove_SetPosition(Roka,-100 ,0 );
    wait(30);

    st1SpellBG2;	
    st3SpellBG1;

    ObjCutin_SetSpellcardS4(Spellname[GetLanguage], cutinImg, NAZRIN, 240, 104, 240);
    ObjCutin_LaunchS3(YABUSAME, "", Diff[GetDifficulty]);
    PlaySFX(spell);
    ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
    wait(150);
    PlaySFX(nuclear);
        NuclearShot(2,EnemyX,EnemyY,0,0,2,0,0,"PURPLE",99999999999,true);
        ObjMove_SetDestAtWeight(Enemy, GetStgFrameWidth/2, 50, 20,4);
        wait(120);
        DefenseActions;
        Shot1;

loop{

	wait(240);
}

}

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

task DefenseActions{
while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 3500){yield;}
Attack2;
while(ObjEnemy_GetInfo(Enemy, INFO_LIFE) > 1500){yield;}
Attack3;
}

task Shot1{
	let count = [0,2,3,4,5];
	loop{
		if(Obj_IsDeleted(Enemy)){break;}
		PlaySFX(tan05);
		ascent(i in 0..count[GetDifficulty]){
		    CreateShotA1(EnemyX,EnemyY ,4 ,rand(0,360) ,SMALL_PURPLE ,0 );
	        }
		wait(3);
	}
}

task Attack2{
	let ass = 0;
	let counter = [0,5,6,7,8];
   loop{
   	if(Obj_IsDeleted(Enemy)){break;}
   	PlaySFX(tan00);
   	ascent(i in 0..counter[GetDifficulty]){
   		CreateShotA1(EnemyX,EnemyY ,3 ,ass+i*(360/counter[GetDifficulty]) ,LARGE_RED ,0 );
   	}
   	ass+= 5;
   	wait(5);
   }
}

task Attack3{
	let countero = [0,15,20,25,30];
	loop{
		if(Obj_IsDeleted(Enemy)){break;}
		PlaySFX(tan04);
		ShootShapeB(EnemyX, EnemyY, 4, rand(0,360), 3, countero[GetDifficulty], OVAL_BLUE, 0);
		wait(60);
	}
}