Scriptname _00E_NQ_G_03_Functions extends Quest Conditional

Import _00E_QuestFunctions
Import Utility

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

Event OnUpdate()
	Levelsystem.RemoveCombatSoundtracks()
EndEvent

;=====================================================================================
;              							FUNCTIONS                  					 
;=====================================================================================
Function GiveLetter()

	PlayerREF.AddItem(_00E_NQ_G_03_LetterForCaravan)

EndFunction

Function RemoveLetter()

	PlayerREF.RemoveItem(_00E_NQ_G_03_LetterForCaravan)

EndFunction

Function GivePaycheck()

	PlayerREF.AddItem(_00E_NQ_G_03_Paycheck)

EndFunction

Function RemovePaycheck()

	PlayerREF.RemoveItem(_00E_NQ_G_03_Paycheck)

EndFunction

Function RemoveBrooch()

	PlayerREF.RemoveItem(_00E_NQ_G_03_GoldenSickleBrooch)
	_00E_NQ_G_03_BroochHandedIn.SetValue(1)

EndFunction

Function RewardMoney()

		PlayerREF.AddItem(Gold001, __Config_RewardMoney)

EndFunction

Function EnableCaravan()

	_00E_NQ_G_03_CaravanEnableMarker001.Enable()
	_00E_NQ_G_03_AlyxREF001.SetGhost(true)
	_00E_NQ_G_03_DevraREF001.SetGhost(true)
	
EndFunction

Function DisableCaravan()

	_00E_NQ_G_03_CaravanEnableMarker001.Disable()
	
EndFunction

Function ShowInnerVoice()

	if !Done
		if !(__Config_MessageBox)
			Message.ResetHelpMessage(InputEventName)
			TutorialMessage.ShowAsHelpMessage(InputEventName, Duration, IntervalTime, HowManyTimesDisplayed)
			Done = True
		Else
			TutorialMessage.Show()
			Done = True
		EndIf
	EndIf

EndFunction

Function StartSC01()

	NQ_G_03_SC01_CaravanFight.ForceStart()

EndFunction

Function StartSC02()

	Levelsystem.RemoveSilence()
	Levelsystem.RemoveCombatSoundtracks()
	
	NQ_G_03_SC02_PetrifiedExamineCaravan.ForceStart()

EndFunction

Function StartFight()

	;rest is done in _00E_NG_G_03_PetrifiedCombatSC
	_00E_NQ_G_03_DevraREF001.StartCombat(PlayerREF)
	_00E_NQ_G_03_AlyxREF001.StartCombat(PlayerREF)
	
EndFunction

Function TryToChangeCombatSoundtrack()

	If (_00E_NQ_G_03_DevraREF001.IsInCombat() || _00E_NQ_G_03_AlyxREF001.IsInCombat()) && !bSoundtrackPlaying
		_00E_Music_Combat_Dark.Add()
		bSoundtrackPlaying = true
	ElseIf !_00E_NQ_G_03_DevraREF001.IsInCombat() && !_00E_NQ_G_03_AlyxREF001.IsInCombat()
		_00E_Music_Combat_Dark.Remove()
		bSoundtrackPlaying = false
	EndIf

EndFunction

Function StopFight()

	SetStage(20)
	_00E_NQ_G_03_DevraREF001.SetActorValue("Aggression", 0)
	_00E_NQ_G_03_AlyxREF001.SetActorValue("Aggression", 0)
	_00E_NQ_G_03_DevraREF001.StopCombat()
	_00E_NQ_G_03_AlyxREF001.StopCombat()
	_00E_NQ_G_03_DevraREF001.SetGhost(True)
	_00E_NQ_G_03_AlyxREF001.SetGhost(True)
	_00E_NQ_G_03_AlyxREF001.RestoreActorValue("Health", 300.0)
	_00E_NQ_G_03_DevraREF001.RestoreActorValue("Health", 300.0)
	; The birds need some time to get 3D-loaded for the animations to play (at least half a second)
	_00E_NQ_G_03_AlyxBirdsREF001.EnableNoWait()
	_00E_NQ_G_03_DevraBirdsREF001.EnableNoWait()
	Wait(2)
	Debug.SendAnimationEvent(_00E_NQ_G_03_AlyxREF001, "returnToDefault")
	_00E_NQ_G_03_AlyxREF001.PlayIdle(IdleRitualStart)
	ObjectReference refRavenMarkerAlyx = _00E_NQ_G_03_AlyxREF001.PlaceAtMe(XMarker, 1)
	refRavenMarkerAlyx.MoveTo(_00E_NQ_G_03_AlyxREF001, 0.0, 0.0, -250, false)
	_00E_NQ_G_03_AlyxBirdsREF001.MoveTo(refRavenMarkerAlyx, 0.0, 0.0, 0.0, false)
	_00E_NQ_G_03_AlyxBirdsREF001.SetAngle(0.0, 0.0, 0.0)
	_00E_NQ_G_03_AlyxBirdsREF001.PlayAnimation("Playanim01")
	_00E_NQ_G_03_AlyxBirdsREF001.PlayGamebryoAnimation("AnimPlay")
	ObjectReference refRavenMarkerDevra = _00E_NQ_G_03_DevraREF001.PlaceAtMe(XMarker, 1)
	refRavenMarkerDevra.MoveTo(_00E_NQ_G_03_DevraREF001, 0.0, 0.0, -250, false)
	_00E_NQ_G_03_DevraBirdsREF001.MoveTo(refRavenMarkerDevra, 0.0, 0.0, 0.0, false)
	_00E_NQ_G_03_DevraBirdsREF001.SetAngle(0.0, 0.0, 0.0)
	_00E_NQ_G_03_DevraBirdsREF001.PlayAnimation("Playanim01")
	_00E_NQ_G_03_DevraBirdsREF001.PlayGamebryoAnimation("AnimPlay")
	Wait(3)
	AtronachUnsummonDeathFXS.Play(_00E_NQ_G_03_AlyxREF001)
	_00E_A2_GhostwalkTeleportVFX.Play(_00E_NQ_G_03_AlyxREF001)
	AtronachUnsummonDeathFXS.Play(_00E_NQ_G_03_DevraREF001)
	_00E_A2_GhostwalkTeleportVFX.Play(_00E_NQ_G_03_DevraREF001)
	Wait(1.5)
	
	_00E_NQ_G_03_DevraREF001.PlaceAtMe(ExplosionShockMassNoEffects, 1)
	_00E_NQ_G_03_AlyxREF001.PlaceAtMe(ExplosionShockMassNoEffects, 1)
	_00E_NQ_G_03_DevraREF001.MoveTo(_00E_NPCDumpMarker)
	_00E_NQ_G_03_AlyxREF001.MoveTo(_00E_NPCDumpMarker)
	_00E_NQ_G_03_DevraREF001.KillEssential()
	_00E_NQ_G_03_AlyxREF001.KillEssential()
	_00E_Music_Combat_Dark.Remove()
	SetObjectiveDisplayed(20)
	_00E_NQ_G_03_AlyxBirdsREF001.DisableNoWait()
	_00E_NQ_G_03_DevraBirdsREF001.DisableNoWait()
	refRavenMarkerAlyx.DisableNoWait()
	refRavenMarkerDevra.DisableNoWait()
	refRavenMarkerAlyx.Delete()
	refRavenMarkerDevra.Delete()
	NQ_G_03_SC01_CaravanFight.Stop()
	RegisterForSingleUpdate(5)
EndFunction

Function FadeOutIn()

	FadeToBlackIMOD.Apply()
	Wait(2)
	FadeToBlackHoldIMOD.ApplyCrossFade(1)
	
	FadeToBlackBackIMOD.ApplyCrossFade(1)

EndFunction

Function FinishQuest()

	Levelsystem.GiveEP(__Config_RewardEXP)
	Self.CompleteQuest()

EndFunction
;=====================================================================================
;              							PROPERTIES                  					 
;=====================================================================================
bool Done
bool bSoundtrackPlaying

bool Property bLetterOpened Auto Conditional
bool Property bAmuletPickedUp Auto Conditional

;rewards
int Property __Config_RewardEXP Auto
int Property __Config_RewardMoney Auto
MiscObject Property Gold001 Auto

_00E_QuestFunctions Property Levelsystem Auto

;actors
Actor Property PlayerRef Auto
Actor Property _00E_NQ_G_03_AlyxREF001 Auto
Actor Property _00E_NQ_G_03_DevraREF001 Auto
ObjectReference Property _00E_NQ_G_03_CaravanEnableMarker001 Auto

;items
Book Property _00E_NQ_G_03_LetterForCaravan Auto
Book Property _00E_NQ_G_03_Paycheck Auto
Armor Property _00E_NQ_G_03_GoldenSickleBrooch Auto

;inner voice
bool Property __Config_MessageBox Auto ;If true, the message will be displayed in a messagebox rather than a floating tutorial message

int Property Duration Auto ;How long should the message be displayed
int Property IntervalTime Auto ;How much time should elapse between showings of the message
int Property HowManyTimesDisplayed Auto ;How often should the message be displayed in total

Message Property TutorialMessage Auto
String Property InputEventName Auto ; If available, specify and input event, such as "Jump" or "Attack". The message will disappear after sucessful execution of this event.

;marker
Objectreference Property _00E_NPCDumpMarker Auto

;effects for scene
VisualEffect Property _00E_A2_GhostwalkTeleportVFX Auto
Idle Property IdleRitualStart Auto
Static Property XMarker Auto ;for placing the ravens
ObjectReference Property _00E_NQ_G_03_AlyxBirdsREF001 Auto
ObjectReference Property _00E_NQ_G_03_DevraBirdsREF001 Auto
Explosion Property ExplosionShockMassNoEffects Auto
EffectShader Property AtronachUnsummonDeathFXS Auto

MusicType Property _00E_Music_Combat_Dark Auto

;scenes
Scene Property NQ_G_03_SC01_CaravanFight Auto
Scene Property NQ_G_03_SC02_PetrifiedExamineCaravan Auto

;fadeout
ImagespaceModifier Property FadeToBlackIMOD Auto
ImagespaceModifier Property FadeToBlackHoldIMOD Auto
ImagespaceModifier Property FadeToBlackBackIMOD Auto

;for  use in later quests
Globalvariable Property _00E_NQ_G_03_BroochHandedIn Auto