Scriptname _00E_NQ_G_04_Functions extends Quest Conditional
  
Import _00E_QuestFunctions

;=====================================================================================
;              							FUNCTIONS                  					 
;=====================================================================================
Function GiveContract()

	PlayerREF.AddItem(_00E_NQ_G_04_GoldenSickleContract)

EndFunction

Function DuulToggleGhost()

	_00E_NQ_G_04_Duul.SetGhost(true)

EndFunction

Function RemoveContract()

	PlayerREF.RemoveItem(_00E_NQ_G_04_GoldenSickleContract)
	If _00E_AchievementsEnabled.GetValueInt() == 1
		Game.UnlockAchievement("END_PROTECTOR_01")
	EndIf
EndFunction

Function GiveLetter()

	PlayerREF.AddItem(_00E_NQ_G_04_LetterForDijaam)

EndFunction

Function RemoveLetter()
	
	;fixes EFSB-400: there was a condition mid dialogue which requested the player to have the letter at hand
	;if the player wouldn't have the letter in their inventory, they would get stuck in unskippable dialogue
	;we'll add the letter if it isn't present in the inventory at the time of dialogue
	If PlayerREF.GetItemCount(_00E_NQ_G_04_LetterForDijaam) == 0
		PlayerREF.AddItem(_00E_NQ_G_04_LetterForDijaam, 1, true)
	EndIf
	
	PlayerREF.RemoveItem(_00E_NQ_G_04_LetterForDijaam)

EndFunction

Function GiveKey()

	PlayerREF.AddItem(CapitalCityHaendlergilde)

EndFunction

Function EnableDuul()

	_00E_NQ_G_04_Duul.Enable()

EndFunction

Function DisableDuul()

	_00E_NQ_G_04_Duul.Disable()

EndFunction

Function EnableDijaam()

	_00E_SC_DijaamOnelys.Enable()

EndFunction

Function MoveDijaamToMarker()

	_00E_SC_DijaamOnelys.MoveTo(_00E_NQ_G_04_DijaamTeleportForSceneMarker)

EndFunction

Function MoveDijaamToTavern()

	_00E_SC_DijaamOnelys.SetOutfit(_00E_SC_DijaamOutfit)
	_00E_SC_DijaamOnelys.MoveTo(_00E_NQ_G_04_DijaamTeleportToTavernMarker)

EndFunction

Function PrepareDijaamForDialogue()

	EnableDijaam()
	MoveDijaamToMarker()

EndFunction

Function StripPlayer()

	PlayerREF.UnEquipAll()

EndFunction

Function BribeDuul()

	PlayerRef.RemoveItem(Gold001, 50)
	bBribed = true

EndFunction

Function StartSC02()

	_00E_NQ_G_04_Duul.RemoveFromAllFactions()
	NQ_G_04_SC02_DuulFight.ForceStart()
	_00E_NQ_G_04_Duul.EvaluatePackage()

EndFunction

Function DuulAttack()

	_00E_NQ_G_04_Duul.SetGhost(false)
	Levelsystem.Brawl(_00E_NQ_G_04_Duul)

EndFunction

Function StartSC03()

	Levelsystem.SetAllowIdleChatter(True)
	NQ_G_04_SC03_DijaamEncounter.ForceStart()

EndFunction

Function MaelStopWriting()

	_00E_SC_Mael.PlayIdle(IdleStop)

EndFunction

Function RewardMoney()

		PlayerREF.AddItem(Gold001, __Config_RewardMoney)

EndFunction

Function FinishQuest()

	Levelsystem.GiveEP(__Config_RewardEXP)
	Levelsystem.RemoveSilence()
	Levelsystem.SetAllowIdleChatter(True)
	Self.CompleteQuest()

EndFunction
;=====================================================================================
;              							PROPERTIES                  					 
;=====================================================================================
;conditionals
bool Property bContractRead Auto Conditional
bool Property bPlayerWon Auto Conditional
bool Property bDuulWon Auto Conditional
bool Property bBribed Auto Conditional

;items
Book Property _00E_NQ_G_04_GoldenSickleContract Auto
Book Property _00E_NQ_G_04_LetterForDijaam Auto
Key Property CapitalCityHaendlergilde Auto
Outfit Property _00E_SC_DijaamOutfit Auto

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

_00E_QuestFunctions Property Levelsystem Auto

Idle Property IdleStop Auto

;actors
Actor Property PlayerRef Auto
Actor Property _00E_NQ_G_04_Duul Auto
Actor Property _00E_SC_DijaamOnelys Auto
Actor Property _00E_SC_Mael Auto

;scenes
Scene Property NQ_G_04_SC02_DuulFight Auto
Scene Property NQ_G_04_SC03_DijaamEncounter Auto

;marker
ObjectReference Property _00E_NQ_G_04_DijaamTeleportForSceneMarker Auto
ObjectReference Property _00E_NQ_G_04_DijaamTeleportToTavernMarker Auto

;for guild rank, called by TIF__00139D66
Faction Property ArkHaendlergilde Auto

GlobalVariable Property _00E_AchievementsEnabled Auto