Scriptname _00E_FS_NQR03_Functions extends Quest  

Import _00E_QuestFunctions
Import Utility

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

Event OnUpdateGameTime()

	SetStage(10)

EndEvent

Event OnUpdate()
	Game.EnablePlayerControls()
EndEvent

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

Function SetUp()

	SetObjectiveDisplayed(5)
	RegisterForSingleUpdateGameTime(24)

EndFunction

Function UnlockDoorEnableTharael()
	
	FS_NQR03_BardREF.Enable()
	FS_NQR03_BardREF.BlockActivation()
	FS_NQR03_SC99_BardSC.ForceStart()
	FS_NQR03_TharaelREF.Enable()
	FS_NQR03_TharaelREF.MoveTo(FS_NQR03_SC01_TharaelMarkerREF)
	FS_NQR03_TharaelREF.SetOutfit(_00E_FS_TharaelOutfit)
	FS_NQR03_TharaelREF.RemoveItem(_00E_FS_NQR05_Tharael_Dagger, 2)
	FS_NQR03_LethoREF.Enable()
	SetObjectiveDisplayed(5, False)
	SetObjectiveDisplayed(10)
	FS_NQR03_DoorREF.Lock(False)
	FS_NQR03_SC01_TharaelShedDiscussion.ForceStart()
	FS_NQR03_SC03_SecretDoorREF.BlockActivation(True)
	
EndFunction

Function TharaelFailsave()

	if FS_NQR03_TharaelREF.IsDisabled()
		FS_NQR03_TharaelREF.Enable()
		FS_NQR03_TharaelREF.MoveTo(FS_NQR03_SC01_TharaelMarkerREF)
	EndIf
	
	if !FS_NQR03_SC01_TharaelShedDiscussion.IsPlaying()
		FS_NQR03_SC01_TharaelShedDiscussion.ForceStart()
	endif

EndFunction

Function DisableBard()

	FS_NQR03_BardREF.Disable()
	FS_NQR03_SC99_BardSC.Stop()

EndFunction

Function OpenDoor()

	FS_NQR03_SC03_SecretDoorREF.SetOpen(True)

EndFunction

Function PlayerEquipRobes()

	PlayerREF.AddItem(_00E_FS_RhalataRobes_NoviceWithHood, 1)
	PlayerREF.EquipItem(_00E_FS_RhalataRobes_NoviceWithHood)

EndFunction

Function SetUpBrotherSorrow()

	SetObjectiveCompleted(10)
	SetObjectiveDisplayed(15)
	
	if !FS_NQR03_SC01_TharaelShedDiscussion.IsPlaying()
		FS_NQR03_SC01_TharaelShedDiscussion.ForceStart()
	EndIf

	FS_NQR03_RhalataTempleDoorREF.Lock(False)
	FS_NQR03_TharaelREF.AddItem(_00E_FS_NQR05_Tharael_Dagger, 2)

EndFunction

Function TeleportBrotherGalang()

	Levelsystem.TeleportNPC(FS_NQR03_LethoREF, FS_NQR03_BrotherGriefMarkerREF)
	SetStage(20)
	SetObjectiveCompleted(10)
	SetObjectiveDisplayed(15)
	
EndFunction

Function StartSC02()

	FS_NQR03_SC02_TempleScene_01.ForceStart()

EndFunction

Function RemovePages()

	FS_NQR_SQ_01.SetStage(5)

	if PlayerREF.GetItemCount(_00E_FS_NQR02_MissingPages) >= 1
		PlayerREF.RemoveItem(_00E_FS_NQR02_MissingPages, 1)
	EndIf
	
	FS_NQR03_RhalataTemple.SetName(_00E_sRhalataTempleName.GetName())

EndFunction

Function ModDistrust(int iAmount)

	_00E_FS_NQR_RhalataMistrust.Mod(iAmount)

EndFunction

Function AddNote()

	PlayerREF.AddItem(_00E_FS_NQR03_SeerMoneyNote, 1)

EndFunction

Function StartSC04()

	SetObjectiveDisplayed(55)
	FS_NQR03_SC04_TempleScene_02.ForceStart()

EndFunction

Function AddRewardMoney()

	PlayerREF.RemoveItem(_00E_FS_NQR03_SeerMoneyNote, 1)
	PlayerREF.AddItem(Gold001, 300)
	SetObjectiveCompleted(55)

EndFunction

Function UpdateObjectives_01()

	SetObjectiveCompleted(15)
	SetObjectiveDisplayed(20)

EndFunction

Function TeleportPlayer()
	
	Levelsystem.TeleportNPC(FS_NQR03_BrotherGreedREF, FS_NQR03_BrotherGreedMarkerREF)
	FS_NQR03_BrotherGreedREF.EvaluatePackage()
	Levelsystem.TeleportPlayer(FS_NQR03_DarkValleyMarkerREF)
	
	SetStage(75)
	RegisterForSingleUpdate(2)
	
EndFunction

Function GivePlayerNote()

	PlayerREF.AddItem(_00E_FS_NQR03_BrotherGreedNote, 1)
	SetObjectiveCompleted(20)
	SetObjectiveDisplayed(25)
	Utility.Wait(2)
	
EndFunction

Function UpdateObjectives_02()

	SetObjectiveCompleted(25)
	SetObjectiveDisplayed(30)

EndFunction

Function UpdateObjectives_03()

	SetObjectiveCompleted(30)
	FS_NQR03_SisterPrideREF.SetGhost(False)

	if GetStage() == 90
	
		SetObjectiveDisplayed(40)
		
	Elseif GetStage() == 95
	
		SetObjectiveDisplayed(40)
		SetObjectiveDisplayed(45)
		
		if PlayerREF.GetItemCount(HumanHeart) < 1
			SetObjectiveDisplayed(60)	
		endif
		
	EndIf
	
EndFunction

Function ClearPlayerAlias()

	FS_NQR03_BrotherGreedREF.SetOutfit(_00E_FS_TharaelOutfit)
	SetObjectiveCompleted(60)
	
EndFunction

Function TakeHeartReal()

	PlayerREF.AddItem(_00E_FS_NQR03_BrotherGreedNote_02, 1)
	ModDistrust(-10)
	UpdateStageAndObjectivesGivenHeart()

EndFunction

Function TakeHeartFake()

	PlayerREF.AddItem(_00E_FS_NQR03_BrotherGreedNote_02, 1)
	ModDistrust(10)
	FS_NQR03_GivenFakeHeart.SetValueInt(1)

	UpdateStageAndObjectivesGivenHeart()
EndFunction

Function UpdateStageAndObjectivesGivenHeart()
	
	SetStage(100)
	
	if IsObjectiveDisplayed(45) && !IsObjectiveDisplayed(40)
		SetObjectiveCompleted(45)
	Elseif IsObjectiveDisplayed(40) && !IsObjectiveDisplayed(45)
		SetObjectiveCompleted(40)
	Else
		SetObjectiveCompleted(40)
		SetObjectiveCompleted(45)
	EndIf
	
	SetObjectiveDisplayed(50)
EndFunction

Function TeleportBrotherGreed()

	Levelsystem.TeleportNPC(FS_NQR03_BrotherGreedREF, FS_NQR03_TeleportBackMarkerBrotherGreed)

EndFunction

Function TeleportPlayerAndBrotherGreed()
	
	Levelsystem.TeleportNPC(FS_NQR03_BrotherGreedREF, FS_NQR03_TeleportBackMarkerBrotherGreed)
	FS_NQR03_BrotherGreedREF.EvaluatePackage()
	Levelsystem.TeleportPlayer(FS_NQR03_TeleportBackMarkerPlayer)
	
	RegisterForSingleUpdate(2)
	SetObjectiveCompleted(50)
	SetObjectiveDisplayed(51)

EndFunction

Function RemoveHeart()

	If FS_NQR03_GivenFakeHeart.GetValueInt() == 1
		PlayerREF.RemoveItem(HumanHeart, 1)
	Else
		PlayerREF.RemoveItem(_00E_FS_NQR03_NessahsHeart, 1)
	EndIf

EndFunction

Function FinishUp()
	
	PlayerREF.AddItem(_01E_FS_TeleportrolleRhalataTemple, 3)
	FS_NQR03_DoorREF.Lock(True)
	SetObjectiveCompleted(50) ; in case the player didn't teleport back with the brother greed
	SetObjectiveCompleted(51)
	Levelsystem.RemoveSilence()
	Levelsystem.RemoveCombatSoundtracks()
	Levelsystem.SetAllowIdleChatter(True)
	FS_NQR03_SC03_SecretDoorREF.SetOpen(False)
	FS_NQR03_SC03_SecretDoorREF.BlockActivation(True)
	FS_NQR03_TharaelREF.Disable()
	FS_NQR03_SphereREF.Enable()
	Levelsystem.GiveEP(iRewardEXP)
	FS_NQR04.SetStage(5)

EndFunction

Function ClearAliasesEnvironmentScene02()

	FS_NQR03_SC02_Flavour_NoviceFemale.Clear()
	FS_NQR03_SC02_Flavour_VoiceMale.Clear()

EndFunction

Function ClearAliasesEnvironmentScene03()

	FS_NQR03_Flavour_03_Akolythe_Male.Clear()
	FS_NQR03_Flavour_03_Akolythe_Female.Clear()

EndFunction

Function ClearAliasesEnvironmentScene01()

	FS_NQR03_SC01_Scion.Clear()

EndFunction

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

ReferenceAlias Property FS_NQR03_SC02_Flavour_VoiceMale Auto
ReferenceAlias Property FS_NQR03_SC02_Flavour_NoviceFemale Auto
ReferenceAlias Property FS_NQR03_Flavour_03_Akolythe_Male Auto
ReferenceAlias Property FS_NQR03_Flavour_03_Akolythe_Female Auto
ReferenceAlias Property FS_NQR03_SC01_Scion Auto

int Property iRewardEXP = 1000 Auto Hidden
int Property iPagesRewardEXP = 250 Auto Hidden

_00E_QuestFunctions Property Levelsystem Auto

Actor Property FS_NQR03_TharaelREF Auto
Actor Property FS_NQR03_BrotherGreedREF Auto
Actor Property FS_NQR03_LethoREF Auto
Actor Property FS_NQR03_SisterPrideREF Auto
Actor Property PlayerREF Auto
Actor Property FS_NQR03_BardREF Auto

Armor Property _00E_FS_RhalataRobes_NoviceWithHood Auto

Book Property _00E_FS_NQR03_SeerMoneyNote Auto
Book Property _00E_FS_NQR03_BrotherGreedNote Auto
Book Property _00E_FS_NQR03_BrotherGreedNote_02 Auto

Quest Property FS_NQR04 Auto
Quest Property FS_NQR_SQ_01 Auto

ObjectReference Property FS_NQR03_DoorREF Auto
ObjectReference Property FS_NQR03_SC03_SecretDoorREF Auto
ObjectReference Property FS_NQR03_BrotherGriefMarkerREF Auto
ObjectReference Property FS_NQR03_DarkValleyMarkerREF Auto
ObjectReference Property FS_NQR03_BrotherGreedMarkerREF Auto
ObjectReference Property FS_NQR03_TeleportBackMarkerBrotherGreed Auto
ObjectReference Property FS_NQR03_TeleportBackMarkerPlayer Auto
ObjectReference Property FS_NQR03_RhalataTempleDoorREF Auto
ObjectReference Property FS_NQR03_SC01_TharaelMarkerREF Auto
ObjectReference Property FS_NQR03_SphereREF Auto

Outfit Property _00E_FS_TharaelOutfit Auto

Ingredient Property _00E_FS_NQR03_NessahsHeart Auto
Ingredient Property HumanHeart Auto

Scroll Property _01E_FS_TeleportrolleRhalataTemple Auto

GlobalVariable Property _00E_FS_NQR_RhalataMistrust Auto
GlobalVariable Property FS_NQR03_GivenFakeHeart Auto

MiscObject Property _00E_FS_NQR02_MissingPages Auto
MiscObject Property Gold001 Auto

Scene Property FS_NQR03_SC01_TharaelShedDiscussion Auto
Scene Property FS_NQR03_SC02_TempleScene_01 Auto
Scene Property FS_NQR03_SC04_TempleScene_02 Auto
Scene Property FS_NQR03_SC99_BardSC Auto

Weapon Property _00E_FS_NQR05_Tharael_Dagger Auto

Message Property _00E_sRhalataTempleName Auto
Cell Property FS_NQR03_RhalataTemple Auto