Scriptname _00E_NQ10_Functions extends Quest  

ReferenceAlias Property Alias_Eshra Auto
ReferenceAlias Property Alias_Elfride Auto
ReferenceAlias Property Alias_CageDoor Auto

Sound Property _00E_ElfriedeMoohMarker Auto
Faction Property NoFeedingIdleFaction Auto

ObjectReference Property _00E_NQ10_ElfriedeCageRef Auto
ObjectReference Property EshraPortRef Auto

Event OnUpdateGameTime()
	FinishEndTravel()
EndEvent

Function SetupFinalScene()
	Actor akElfride = Alias_Elfride.GetActorReference()
	If akElfride.IsDisabled() ; For backward compatibility
		PutElfrideToCage()
		_00E_Func_WaitForRef.WaitForReferenceToLoad(akElfride)
	EndIf

	_00E_NQ10_ElfriedeCageRef.Lock(0)
	_00E_NQ10_ElfriedeCageRef.SetOpen(True)
	_00E_ElfriedeMoohMarker.Play(akElfride)

	Actor akEshra = Alias_Eshra.GetActorReference()
	akEshra.MoveTo(EshraPortRef)
	Debug.SendAnimationEvent(akEshra, "IdleForceDefaultState")
EndFunction

Function FinishQuest()
	; Start end travel for Eshra
	Actor akEshra = Alias_Eshra.GetActorReference()
    _00E_Func_SafeMove.DistanceFailsafeMoveTo(Alias_Elfride.GetActorReference(), akEshra, 256.0)
	akEshra.SetActorValue("Variable01", 1.0)
	RegisterForSingleUpdateGameTime(1.0)

	Alias_CageDoor.Clear()

	; Cleanup
	_00E_NQ10_ElfriedeCageRef = None
	EshraPortRef = None
EndFunction

Function PutElfrideToCage()
	Actor akElfride = Alias_Elfride.GetActorReference()
	akElfride.SetFactionRank(NoFeedingIdleFaction, 0)
	akElfride.MoveToMyEditorLocation() ; Just in case
	akElfride.Enable()

	If Alias_CageDoor.GetRef() == None ; For backward compatibility
		Alias_CageDoor.ForceRefTo(_00E_NQ10_ElfriedeCageRef)
	EndIf
EndFunction

Function FinishEndTravel()
	UnregisterForUpdateGameTime()

	Actor akEshra = Alias_Eshra.GetActorReference()
	akEshra.SetActorValue("Variable01", 0.0)
	akEshra.EvaluatePackage()

	Actor akElfride = Alias_Elfride.GetActorReference()
	akElfride.RemoveFromFaction(NoFeedingIdleFaction)
EndFunction