Scriptname _00E_FS_NQ02_Functions2 extends Quest  

Import _00E_QuestFunctions
Import Utility
Import Game

;=====================================================================================
;              							FUNCTIONS                  					 
;=====================================================================================

Function StartTravelWithEsme()

	_00E_QuestFunctions.SetNPCAsCompanion(_00E_FS_NQ02_EsmeREF, True, 500, 200, 150)
	_00E_FS_NQ02_TravelState.SetValue(1.0)
	_00E_FS_NQ02_EsmeREF.EvaluatePackage()

EndFunction

Function StopTravelWithEsme()

	_00E_QuestFunctions.SetNPCAsCompanion(_00E_FS_NQ02_EsmeREF, FALSE)
	_00E_FS_NQ02_TravelState.SetValue(0.0)
	_00E_FS_NQ02_EsmeREF.EvaluatePackage()

EndFunction

Function TeleportEsmeToDuenenhaim()

	RegisterForUpdateGameTime(24)
	GameDay = GameDaysPassed.GetValue() as Int

	Levelsystem.TeleportNPC(_00E_FS_NQ02_EsmeREF, _00E_FS_NQ02_EsmeTeleportMarker)
	StopTravelWithEsme()
	wait(0.1)
	_00E_FS_NQ02_EsmeREF.Disable()

EndFunction

Function StartSC16()

	_00E_FS_NQ02_EsmeREF.Enable()
	_00E_FS_NQ02_EsmeREF.SetOutfit(_00E_FS_NQ02_EsmeOutfit)
	_00E_FS_NQ02_EsmeREF.AddItem(_02E_15_Scimitar, 1)
	_00E_FS_NQ02_EsmeREF.EquipItem(_02E_15_Scimitar)
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_EsmeTeleportMarker)
	_00E_FS_NQ02_SC16_Bandit1REF.MoveTo(_00E_FS_NQ02_SC16_Marker1)
	_00E_FS_NQ02_SC16_Bandit2REF.MoveTo(_00E_FS_NQ02_SC16_Marker2)
	_00E_FS_NQ02_SC16_Bandit3REF.MoveTo(_00E_FS_NQ02_SC16_Marker3)
	_00E_FS_NQ02_SC16_Bandit1REF.Enable()
	_00E_FS_NQ02_SC16_Bandit2REF.Enable()
	_00E_FS_NQ02_SC16_Bandit3REF.Enable()
	wait(0.1)
	FS_NQ02_SC16_Duenenhaim.ForceStart()

EndFunction

Function BanditDrawWeapon()

	_00E_FS_NQ02_SC16_Bandit1REF.DrawWeapon()
	Debug.SendAnimationEvent(_00E_FS_NQ02_EsmeREF, "IdleForceDefaultState")

EndFunction

Function BanditPrepareForFight(Actor akBandit)
	akBandit.SetGhost(False)
	akBandit.AddToFaction(BanditFaction)
EndFunction

Function BanditStartFight(Actor akBandit)
	akBandit.SetAV("Aggression", 2)
	akBandit.StartCombat(PlayerREF)
	akBandit.StartCombat(_00E_FS_NQ02_EsmeREF)
EndFunction

Function BanditFight()

	BanditPrepareForFight(_00E_FS_NQ02_SC16_Bandit1REF)
	BanditPrepareForFight(_00E_FS_NQ02_SC16_Bandit2REF)
	BanditPrepareForFight(_00E_FS_NQ02_SC16_Bandit3REF)

	BanditStartFight(_00E_FS_NQ02_SC16_Bandit1REF)
	BanditStartFight(_00E_FS_NQ02_SC16_Bandit2REF)
	BanditStartFight(_00E_FS_NQ02_SC16_Bandit3REF)

EndFunction

Function DisableBandits()

	_00E_FS_NQ02_SC16_Bandit1REF.Disable()
	_00E_FS_NQ02_SC16_Bandit2REF.Disable()
	_00E_FS_NQ02_SC16_Bandit3REF.Disable()

EndFunction

Function PlayerKillBandit1()

	Game.DisablePlayerControls()
	Game.SetPlayerAIDriven(True)
	PlayerREF.DrawWeapon()
	Utility.Wait(0.5)
	_00E_FS_NQ02_SC16_Bandit1REF.SetGhost(false)
	wait(0.1)
	PlayerREF.PlayIdleWithTarget(pa_1HMKillMoveShortB, _00E_FS_NQ02_SC16_Bandit1REF)
	Utility.Wait(3.0)
	Game.EnablePlayerControls()
	Game.SetPlayerAIDriven(False)

EndFunction

Function BanditFightWithoutBandit1()

	BanditPrepareForFight(_00E_FS_NQ02_SC16_Bandit2REF)
	BanditPrepareForFight(_00E_FS_NQ02_SC16_Bandit3REF)

	BanditStartFight(_00E_FS_NQ02_SC16_Bandit2REF)
	BanditStartFight(_00E_FS_NQ02_SC16_Bandit3REF)

EndFunction

Function EnableTravelToIshmartep()

	_00E_FS_NQ02_Travelbox15.Enable()
	_00E_FS_NQ02_Travelbox16.Enable()
	_00E_FS_NQ02_Travelbox17.Enable()
	_00E_FS_NQ02_Travelbox18.Enable()
	_00E_FS_NQ02_Travelbox19.Enable()
	_00E_FS_NQ02_SC17_Door1.SetOpen(true)
	_00E_FS_NQ02_SC17_Door2.SetOpen(false)
	_00E_FS_NQ02_SC17_Door2.lock(255)
	_00E_FS_NQ02_CreatureDisableMarker.Disable()
	_00E_FS_NQ02_RobeDisableMarker.Enable()
	_00E_FS_NQ02_SC17_Arp1.Enable()
	_00E_FS_NQ02_SC17_Arp2.Enable()
	FS_NQ02_SC17_Ishmartep.ForceStart()
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(1)
	StartTravelWithEsme()

EndFunction

Function TravelToIshmartepFailsave()

	If _00E_FS_NQ02_EsmeREF.GetDistance(PlayerREF) > 1000
	_00E_FS_NQ02_EsmeREF.Moveto(PlayerREF)
	Endif

EndFunction

Function OpenIshmartepDoor()

	_00E_FS_NQ02_SC17_Door2.lock(false)
	StartTravelWithEsme()

EndFunction

Function PrepareSC18()
	
	;DEBUG ONLY
	_00E_FS_NQ02_EsmeREF.Enable()
	_00E_FS_NQ02_EsmeREF.Moveto(PlayerREF)
	;DEBUG ONLY
	
	StartTravelWithEsme()
	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.0)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC12_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC14_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC15_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC14_ManREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC15_ManREF.SetAlpha(0.0)
	_00E_FS_NQ02_DalMercerREF.Enable()
	_00E_FS_NQ02_TaraREF.Enable()
	_00E_FS_NQ02_SC12_WomanREF.Enable()
	_00E_FS_NQ02_SC14_WomanREF.Enable()
	_00E_FS_NQ02_SC15_WomanREF.Enable()
	_00E_FS_NQ02_SC14_ManREF.Enable()
	_00E_FS_NQ02_SC15_ManREF.Enable()
	_00E_FS_NQ02_SC18_SchreinActREF.Enable()
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(0)

EndFunction

Function StartSC18()
	
	_00E_FS_NQ02_DalMercerREF.MoveTo(_00E_FS_NQ02_SC18_DalMercerMarker1)
	_00E_FS_NQ02_TaraREF.MoveTo(_00E_FS_NQ02_SC18_PrayMarker4)
	_00E_FS_NQ02_SC12_WomanREF.MoveTo(_00E_FS_NQ02_SC18_PrayMarker1)
	_00E_FS_NQ02_SC14_WomanREF.MoveTo(_00E_FS_NQ02_SC18_PrayMarker3)
	_00E_FS_NQ02_SC15_WomanREF.MoveTo(_00E_FS_NQ02_SC18_PrayMarker6)
	_00E_FS_NQ02_SC14_ManREF.MoveTo(_00E_FS_NQ02_SC18_PrayMarker2)
	_00E_FS_NQ02_SC15_ManREF.MoveTo(_00E_FS_NQ02_SC18_PrayMarker5)
	_00E_FS_NQ02_RobeDisableMarker.Disable()
	FS_NQ02_SC18_Vision.ForceStart()
	AudioCategoryAmb.SetVolume(0.5)
	Levelsystem.VisionEffectNoTimestop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC18_FreezeRefs, True)
	_00E_SilenceTransitionLowPriority.Add()
	_00E_FS_NQ02_SC14_ManREF.SetAlpha(0.5)
	_00E_FS_NQ02_SC14_WomanREF.SetAlpha(0.5)
	_00E_FS_NQ02_SC12_WomanREF.SetAlpha(0.5)
	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.5)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.5)
	_00E_FS_NQ02_SC15_WomanREF.SetAlpha(0.5)
	_00E_FS_NQ02_SC15_ManREF.SetAlpha(0.5)
	Utility.Wait(1.0)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC14_ManREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC14_WomanREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC12_WomanREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_DalMercerREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_TaraREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC15_WomanREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC15_ManREF)
	Utility.Wait(2.0)

EndFunction  

Function EnableVeiledWoman1()

	_00E_Music_Character_VeiledWomanLoop.Add()
	_00E_SilenceTransitionLowPriority.Add()
	_00E_FS_NQ02_TaraREF.SetGhost(False)
	_00E_FS_NQ02_TaraREF.KnockAreaEffect(1.0, 128)
	_00E_FS_NQ02_TaraREF.SetGhost(True)
	_00E_FS_NQ02_VeiledWoman1.Enable()
	_00E_FS_NQ02_VeiledWoman1.MoveTo(_00E_FS_NQ02_SC17_VW1Marker)
	_00E_FS_NQ02_VeiledWoman1.SetAlpha(0.0)
	Utility.Wait(0.5)
	_00E_FS_NQ02_VeiledWomanAppearFXS.Play(_00E_FS_NQ02_VeiledWoman1)
	_00E_FS_NQ02_VeiledWoman1.SetAlpha(0.5)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_VeiledWoman1)

EndFunction

Function EnableVeiledWoman2()

	_00E_FS_NQ02_VeiledWoman2.Enable()
	_00E_FS_NQ02_VeiledWoman2.MoveTo(_00E_FS_NQ02_SC17_VW2Marker)
	_00E_FS_NQ02_VeiledWoman2.SetAlpha(0.0)
	_00E_FS_NQ02_VeiledWomanAppearFXS.Play(_00E_FS_NQ02_VeiledWoman2)
	Utility.Wait(0.5)
	_00E_FS_NQ02_VeiledWomanAppearFXS.Play(_00E_FS_NQ02_VeiledWoman2)
	_00E_FS_NQ02_VeiledWoman2.SetAlpha(0.5)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_VeiledWoman2)
	
EndFunction

Function EnableVeiledWoman3()

	_00E_FS_NQ02_VeiledWoman3.Enable()
	_00E_FS_NQ02_VeiledWoman3.MoveTo(_00E_FS_NQ02_SC17_VW3Marker)
	_00E_FS_NQ02_VeiledWoman3.SetAlpha(0.0)
	_00E_FS_NQ02_VeiledWomanAppearFXS.Play(_00E_FS_NQ02_VeiledWoman3)
	Utility.Wait(0.5)
	_00E_FS_NQ02_VeiledWomanAppearFXS.Play(_00E_FS_NQ02_VeiledWoman3)
	_00E_FS_NQ02_VeiledWoman3.SetAlpha(0.5)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_VeiledWoman3)
	
EndFunction

Function DisableVeiledWoman2and3()

	_00E_FS_NQ02_VeiledWomanAppearFXS.Play(_00E_FS_NQ02_VeiledWoman3)
	_00E_FS_NQ02_VeiledWomanAppearFXS.Play(_00E_FS_NQ02_VeiledWoman2)
	Utility.Wait(0.3)
	_00E_FS_NQ02_VeiledWoman2.Disable()
	_00E_FS_NQ02_VeiledWoman3.Disable()

EndFunction

Function StopSC18()

	Levelsystem.SetAllowIdleChatter(True)
	_00E_SilenceTransitionLowPriority.Remove()
	_00E_Music_Character_VeiledWomanLoop.Remove()
	_00E_FS_NQ02_SC12_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.0)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC14_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC15_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC14_ManREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC15_ManREF.SetAlpha(0.0)
	_00E_FS_NQ02_VeiledWoman1.SetAlpha(0.0)
	wait(0.1)
	_00E_FS_NQ02_SC12_WomanREF.Disable()
	_00E_FS_NQ02_DalMercerREF.Disable()
	_00E_FS_NQ02_TaraREF.Disable()
	_00E_FS_NQ02_SC14_WomanREF.Disable()
	_00E_FS_NQ02_SC15_WomanREF.Disable()
	_00E_FS_NQ02_SC14_ManREF.Disable()
	_00E_FS_NQ02_SC15_ManREF.Disable()
	_00E_FS_NQ02_VeiledWoman1.Disable()
	_00E_FS_NQ02_RobeDisableMarker.Enable()
	Levelsystem.VisionEffectNoTimestopStop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC18_FreezeRefs)
	AudioCategoryAmb.SetVolume(1.0)
	FS_NQ02_SC19_AfterVision.ForceStart()
	; _00E_FS_NQ02_EsmeREF.SetAlpha(1.0)
	; _00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC19_EsmeMarker1)

EndFunction

Function SC19FadeOut()

	Levelsystem.FadeToBlack()
	Levelsystem.FadeToBlackBack()
	_00E_SilenceLongTransitionHighPriority.Add()

EndFunction

Function SC19DisableEsme()

	_00E_FS_NQ02_EsmeREF.Disable()
	StopTravelWithEsme()
	EnablePlayerControls()
	_00E_SilenceLongTransitionHighPriority.Remove()
	_00E_FS_NQ02_Music_Theme.Remove()
	if SympathyEsme.GetValue() >= 0
	SetStage(960)
	else
	SetStage(1060)
	Levelsystem.GiveEP(3000)
	endif

EndFunction

Function StartSC20()

	_00E_FS_NQ02_SC20_MessengerGuyREF.Enable()
	_00E_FS_NQ02_SC20_MessengerGuyREF.MoveTo(_00E_FS_NQ02_SC20_Marker1)
	wait(0.1)
	FS_NQ02_SC20_Messenger.ForceStart()

EndFunction

Function GivePlayerEpilogNote()

	PlayerREF.AddItem(_00E_FS_NQ02_EpilogNote, 1)
	_00E_FS_NQ02_CreatureDisableMarker.Enable()

EndFunction

Function StartSC21()

	_00E_FS_NQ02_EsmeREF.Enable()
	_00E_FS_NQ02_SC20_MessengerGuyREF.Disable()
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC21_Marker1)
	wait(0.1)
	FS_NQ02_SC21_Epilog.ForceStart()

EndFunction

Function MoveToEpilogPosition()

	If PlayerREF.IsSneaking()
    		PlayerREF.StartSneaking()
	EndIf
	Levelsystem.FadeToBlack()
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC21_EsmeMarker)
	PlayerREF.MoveTo(_00E_FS_NQ02_SC21_PlayerMarker)
	_00E_SilenceLongTransitionHighPriority.Add()
	Levelsystem.SkipTimeToHour(20)
	SkyrimClear_Aurora_Green.ForceActive(True)
	Game.ForceThirdPerson()
	Levelsystem.FadeToBlackBack()
	DisablePlayerControls()
	SetStage(1005)

EndFunction

Function EndEpilog()

	Levelsystem.FadeToBlack()
	PlayerREF.MoveTo(_00E_FS_NQ02_SC21_Marker2)
	EnablePlayerControls()
	_00E_SilenceLongTransitionHighPriority.Remove()
	_00E_FS_NQ02_Music_Theme.Remove()
	Levelsystem.FadeToBlackBack()
	Weather.ReleaseOverride()
	Levelsystem.GiveEP(3500)
	Setstage(1030)
	
	If _00E_AchievementsEnabled.GetValueInt() == 1
		Game.UnlockAchievement("END_ESME_01")
	EndIf

EndFunction

Function MoveEsmeToDuenenhaim()

	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ07_MaxusTavernMarker)

EndFunction

;=====================================================================================
;              							EVENTS                 					 
;=====================================================================================

Event OnUpdateGameTime() ; because of how we registered, this event occurs every 30 minutes of game time    
	if (GameDaysPassed.GetValue() + 1 >= GameDay)
		SetStage(GetStage()+5)
		UnregisterForUpdateGameTime()
	Endif
EndEvent

;=====================================================================================
;              							PROPERTIES                  					 
;=====================================================================================

int GameDay

_00E_QuestFunctions Property Levelsystem Auto

Quest Property FS_NQ02 Auto

Actor Property _00E_FS_NQ02_EsmeREF Auto
Actor Property PlayerREF Auto
Actor Property _00E_FS_NQ02_SC16_Bandit1REF Auto
Actor Property _00E_FS_NQ02_SC16_Bandit2REF Auto
Actor Property _00E_FS_NQ02_SC16_Bandit3REF Auto
Actor Property _00E_FS_NQ02_SC17_Arp1 Auto
Actor Property _00E_FS_NQ02_SC17_Arp2 Auto
Actor Property _00E_FS_NQ02_TaraREF Auto
Actor Property _00E_FS_NQ02_DalMercerREF Auto
Actor Property _00E_FS_NQ02_SC12_WomanREF Auto
Actor Property _00E_FS_NQ02_SC14_WomanREF Auto
Actor Property _00E_FS_NQ02_SC14_ManREF Auto
Actor Property _00E_FS_NQ02_SC15_WomanREF Auto
Actor Property _00E_FS_NQ02_SC15_ManREF Auto
Actor Property _00E_FS_NQ02_VeiledWoman1 Auto
Actor Property _00E_FS_NQ02_VeiledWoman2 Auto
Actor Property _00E_FS_NQ02_VeiledWoman3 Auto
Actor Property _00E_FS_NQ02_SC20_MessengerGuyREF Auto

SoundCategory Property AudioCategoryAmb Auto

EffectShader Property _00E_FS_NQ02_VeiledWomanAppearFXS Auto

Book Property _00E_FS_NQ02_EpilogNote Auto

Formlist Property _00E_FS_NQ02_VisionRefs Auto
Formlist Property _00E_FS_NQ02_SC16_FreezeRefs Auto
Formlist Property _00E_FS_NQ02_SC18_FreezeRefs Auto

GlobalVariable Property _00E_FS_NQ02_TravelState Auto
GlobalVariable Property GameDaysPassed Auto
GlobalVariable Property SympathyEsme Auto
GlobalVariable Property _00E_FS_NQ02_EsmeMiscTalkVar Auto
GlobalVariable Property _00E_AchievementsEnabled Auto

MusicType Property _00E_SilenceLongTransitionHighPriority Auto
MusicType Property _00E_FS_NQ02_Music_Theme Auto
MusicType Property _00E_Music_Character_VeiledWomanLoop Auto
MusicType Property _00E_SilenceTransitionLowPriority Auto

ObjectReference Property _00E_FS_NQ02_EsmeTeleportMarker Auto
ObjectReference Property _00E_FS_NQ02_SC16_Marker1 Auto
ObjectReference Property _00E_FS_NQ02_SC16_Marker2 Auto
ObjectReference Property _00E_FS_NQ02_SC16_Marker3 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox15 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox16 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox17 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox18 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox19 Auto
ObjectReference Property _00E_FS_NQ02_CreatureDisableMarker Auto
ObjectReference Property _00E_FS_NQ02_SC17_Door1 Auto
ObjectReference Property _00E_FS_NQ02_SC17_Door2 Auto
ObjectReference Property _00E_FS_NQ02_SC18_SchreinActREF Auto
ObjectReference Property _00E_FS_NQ02_SC19_EsmeMarker1 Auto
ObjectReference Property _00E_FS_NQ02_SC18_PrayMarker1 Auto
ObjectReference Property _00E_FS_NQ02_SC18_PrayMarker2 Auto
ObjectReference Property _00E_FS_NQ02_SC18_PrayMarker3 Auto
ObjectReference Property _00E_FS_NQ02_SC18_PrayMarker4 Auto
ObjectReference Property _00E_FS_NQ02_SC18_PrayMarker5 Auto
ObjectReference Property _00E_FS_NQ02_SC18_PrayMarker6 Auto
ObjectReference Property _00E_FS_NQ02_SC18_DalMercerMarker1 Auto
ObjectReference Property _00E_FS_NQ02_SC17_VW1Marker Auto
ObjectReference Property _00E_FS_NQ02_SC17_VW2Marker Auto
ObjectReference Property _00E_FS_NQ02_SC17_VW3Marker Auto
ObjectReference Property _00E_FS_NQ02_RobeDisableMarker Auto
ObjectReference Property _00E_FS_NQ02_SC20_Marker1 Auto
ObjectReference Property _00E_FS_NQ02_SC21_Marker1 Auto
ObjectReference Property _00E_FS_NQ02_SC21_Marker2 Auto
ObjectReference Property _00E_FS_NQ07_MaxusTavernMarker Auto
ObjectReference Property _00E_FS_NQ02_SC21_EsmeMarker Auto
ObjectReference Property _00E_FS_NQ02_SC21_PlayerMarker Auto

VisualEffect Property MS04MemoryFXBody01VFX Auto

Idle Property pa_1HMKillMoveShortB Auto

Outfit Property _00E_FS_NQ02_EsmeOutfit Auto

Scene Property FS_NQ02_SC16_Duenenhaim Auto
Scene Property FS_NQ02_SC17_Ishmartep Auto
Scene Property FS_NQ02_SC18_Vision Auto
Scene Property FS_NQ02_SC19_AfterVision Auto
Scene Property FS_NQ02_SC20_Messenger Auto
Scene Property FS_NQ02_SC21_Epilog Auto

Weather Property SkyrimClear Auto
Weather Property SkyrimClear_Aurora_Green Auto

Weapon Property _02E_15_Scimitar Auto
Weapon Property _01E_02_IronSword Auto

Faction Property BanditFaction Auto