Scriptname _00E_NQ_G_02_Functions extends Quest Conditional

Import Math
Import Utility

;=====================================================================================
;              							FUNCTIONS                  					 
;=====================================================================================
Function AddMapMarker()

	_00E_NQ_G_02_HafnerMapMarkerREF.AddToMap(false)

EndFunction

Function PrepareMenhirForQuest()
	
	_00E_NQ_G_02_Menhir.MoveTo(_00E_NQ_G_02_MenhirWaitLocation)
	_00E_NQ_G_02_Menhir.Disable()

EndFunction

Function DespawnGuardHafner()

	_00E_NQ_G_02_GuardREF.Disable()
	_00E_NQ_G_02_HelgeHafner.MoveTo(_00E_NQ_G_02_HafnerPrisonMarker)
	
EndFunction

Function DespawnGuardMendelus()

	_00E_NQ_G_02_GuardREF.Disable()
	_00E_SC_MendelusVollerbeutel.MoveToMyEditorLocation()

EndFunction

Function DespawnMendelus()

	_00E_SC_MendelusVollerbeutel.MoveToMyEditorLocation()

EndFunction

Function SetUpSC03()

	_00E_NQ_G_02_HelgeHafner.MoveTo(_00E_NQ_G_02_HafnerDialoguePos)
	_00E_SC_MendelusVollerbeutel.MoveTo(_00E_NQ_G_02_MendelusDialoguePos)
	_00E_NQ_G_02_GuardREF.Enable()
	_00E_NQ_G_02_GuardREF.MoveTo(_00E_NQ_G_02_GuardDialoguePos)
	PlayerREF.MoveTo(_00E_NQ_G_02_PlayerDialoguePos)
	
	NQ_G_02_SC03_DialogueMenhirDead.ForceStart()

EndFunction

Function SetUpSC04()
	
	_00E_NQ_G_02_Menhir.MoveTo(_00E_NQ_G_02_MenhirDialoguePos)
	_00E_NQ_G_02_HelgeHafner.MoveTo(_00E_NQ_G_02_HafnerDialoguePos)
	_00E_SC_MendelusVollerbeutel.MoveTo(_00E_NQ_G_02_MendelusDialoguePos)
	_00E_NQ_G_02_GuardREF.Enable()
	_00E_NQ_G_02_GuardREF.MoveTo(_00E_NQ_G_02_GuardDialoguePos)
	PlayerREF.MoveTo(_00E_NQ_G_02_PlayerDialoguePos)
	
	NQ_G_02_SC04_DialogueMenhirAlive.ForceStart()
	
EndFunction

Function FadeOut()

	int iButton = _00E_NQ_G_02_LeaveCaveBox.Show()
	
	If iButton == 0
		
		_00E_UILockpickingUnlockM.Play(BAGL2Exit)
		FadeToBlackIMOD.Apply()
		Wait(2)
		FadeToBlackHoldIMOD.ApplyCrossFade(1)
			
		If (GetCurrentStageID() == 35 || GetCurrentStageID() == 40)
			SetUpSC03()
		ElseIf (GetCurrentStageID() == 45)
			SetUpSC04()
		EndIf
		
		FadeToBlackBackIMOD.ApplyCrossFade(1)
			
		SetObjectiveCompleted(35)
		
		_00E_TeleportGlobal.SetValueInt(0)
		
	Else
		Return
	EndIf
	
EndFunction

Function KillMenhir()
	
	NQ_G_02_CollisionBox1.Disable()
	Wait(0.1)
	_00E_NQ_G_02_Menhir.SetGhost(False)
	_00E_NQ_G_02_Menhir.GetActorBase().SetEssential(False)
	_00E_NQ_G_02_Menhir.PlayIdle(_00E_IdleSuicide)
	Wait(1.5)
	_00E_NQ_G_02_Menhir.Kill(_00E_NQ_G_02_Menhir)
	Wait(1)
	NQ_G_02_CollisionBox1.Enable()
	; adding the key to Menhir just in case he doesn't die properly
	_00E_NQ_G_02_Menhir.Additem(_00E_BAltGaragathaL2ExitKey, 1)
	NQ_G_02_KeyREF.Enable()
	Game.EnablePlayerControls()
	Wait(8)
	_00E_NQ_G_02_Menhir.Disable()
	
EndFunction

Function RewardMoney(float Amount)

	PlayerREF.AddItem(Gold001, (__Config_RewardMoney*Amount) as int)

EndFunction

Function FinishQuest()

	If (GetCurrentStageID() == 80)
		_00E_EPHandler.GiveEP(__Config_RewardEXP - __Config_EXPMalus)
	Else
		_00E_EPHandler.GiveEP(__Config_RewardEXP)
	EndIf
			
	Self.CompleteQuest()

EndFunction

Function StartSC01()

	PrepareMenhirForQuest()

	NQ_G_02_SC01_HafnerFirstConversation.ForceStart()

EndFunction

Function StartSC02()
	
	; need to reset Menhir otherwise he might be stuck in some animation and wiggle around as well as being unresponsive in SC4
	; due to enabling him afterwards, he snaps back to the navmesh, fixes issue 1044 until proven wrong or causing other issues
	; added MoveTo again after Menhir got reset to Vyn 0,0 and never got placed in the dungeon
	_00E_NQ_G_02_Menhir.Reset(_00E_NQ_G_02_MenhirWaitLocation)
	_00E_NQ_G_02_Menhir.MoveTo(_00E_NQ_G_02_MenhirWaitLocation)
	_00E_NQ_G_02_Menhir.Enable()

	NQ_G_02_SC02_MenhirFirstConversation.ForceStart()
	
EndFunction

;=====================================================================================
;              							PROPERTIES                  					 
;=====================================================================================
bool Property bHafnerInPrison Auto Conditional
bool Property bMenhirReward Auto Conditional

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

Idle Property _00E_IdleSuicide Auto

;scenes
Scene Property NQ_G_02_SC01_HafnerFirstConversation Auto
Scene Property NQ_G_02_SC02_MenhirFirstConversation Auto
Scene Property NQ_G_02_SC03_DialogueMenhirDead Auto
Scene Property NQ_G_02_SC04_DialogueMenhirAlive Auto

ImagespaceModifier Property FadeToBlackIMOD Auto
ImagespaceModifier Property FadeToBlackHoldIMOD Auto
ImagespaceModifier Property FadeToBlackBackIMOD Auto

;actors
Actor Property _00E_NQ_G_02_Menhir Auto
Actor Property _00E_NQ_G_02_HelgeHafner Auto
Actor Property _00E_SC_MendelusVollerbeutel Auto
Actor Property _00E_NQ_G_02_GuardREF Auto
Actor Property PlayerREF Auto

Message Property _00E_NQ_G_02_LeaveCaveBox Auto

GlobalVariable Property _00E_TeleportGlobal Auto

;marker
ObjectReference Property _00E_NQ_G_02_MenhirWaitLocation Auto
ObjectReference Property _00E_NQ_G_02_MenhirDialoguePos Auto
ObjectReference Property _00E_NQ_G_02_HafnerDialoguePos Auto
ObjectReference Property _00E_NQ_G_02_MendelusDialoguePos Auto
ObjectReference Property _00E_NQ_G_02_GuardDialoguePos Auto
ObjectReference Property _00E_NQ_G_02_PlayerDialoguePos Auto
ObjectReference Property _00E_NQ_G_02_HafnerPrisonMarker Auto
ObjectReference Property _00E_NQ_G_02_HafnerMapMarkerREF Auto
ObjectReference Property NQ_G_02_CollisionBox1 Auto
ObjectReference Property NQ_G_02_KeyREF Auto
ObjectReference Property BAGL2Exit Auto

Sound Property _00E_UILockpickingUnlockM Auto

Key Property _00E_BAltGaragathaL2ExitKey Auto