Scriptname _00E_FS_NQ03_Functions extends Quest  

Import _00E_QuestFunctions
Import Utility
Import Game

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

Function PrepareSC01()

	RegisterForUpdateGameTime(12)
	GameDay = GameDaysPassed.GetValue() as Int
	FS_NQ03_SC00_Bugfix.ForceStart() ;never delete this scene!
	_00E_FS_NQ03_LexilREF.Enable()
	
EndFunction

Function StartSC01()

	_00E_FS_NQ03_MessengerGirlREF.Enable()
	_00E_FS_NQ03_MessengerGirlREF.Moveto(_00E_FS_NQ03_MessengerGirlMarker)
	wait(0.1)
	FS_NQ03_SC01_Messenger.ForceStart()

EndFunction

Function EndSC01()

	_00E_FS_NQ03_MessengerGirlREF.Disable()

EndFunction

Function PrepareSC02()

	Game.DisablePlayerControls()
	_FS_TheriantrophistControlQuest.TransformBackIfTransformed()
	_00E_TeleportGlobal.SetValue(1)
	Levelsystem.FadeToBlack()
	PlayerREF.MoveTo(_00E_FS_NQ03_SC02_PlayerMarker)
	_00E_FS_NQ03_DisableRatsMarker.Disable() ; This enables Yuslan, Lexil and Lishari
	_00E_FS_NQ03_YuslanREF.MoveTo(_00E_FS_NQ03_SC02_YuslanMarker)
	_00E_FS_NQ03_LexilREF.MoveTo(_00E_FS_NQ03_SC02_LexilMarker)
	_00E_FS_NQ03_LishariCorpseREF.MoveTo(FS_NQ03_AltarREF)
	_00E_FS_NQ03_LishariCorpseREF.BlockActivation()
	_00E_FS_NQ03_SC02_StorageDoor.Lock(255)
	wait(0.1)
	FS_NQ03_SC02_PreVision.ForceStart()
	SetStage(70)

EndFunction

Function FadeBack()

	Levelsystem.FadeToBlackBack()
	Game.EnablePlayerControls()
	
EndFunction

Function StartMemory1()

	_00E_FS_NQ03_SpiritActorREF.Enable()
	If PlayerREF.IsWeaponDrawn()
		PlayerREF.SheatheWeapon()
	EndIf
	OBJEyeofMagnusVanishM.Play(PlayerREF)
	_00E_MQ07a_WordOfTheDeadTransformSpiritM.Play(PlayerREF)
	_00E_FS_NQ03_ShockApply.Apply()
	_00E_Ability_StaggerSelfSpell.Cast(PlayerREF, PlayerREF)
	Game.ShakeCamera(afStrength = 0.2)
	_00E_FS_NQ03_SpiritActorREF.MoveTo(FS_NQ03_HeadSpawnMarkerREF)
	_00E_FS_NQ03_SpiritActorREF.SetPlayerControls(False)
  	_00E_FS_NQ03_SpiritActorREF.EnableAI(False)
  	_00E_FS_NQ03_SpiritActorREF.EnableAI(True)
	_00E_FS_NQ03_SpiritActorREF.SetAllowFlying(True)
	_00E_FS_NQ03_SpiritActorREF.MoveTo(FS_NQ03_HeadSpawnMarkerREF)
	Game.ForceThirdPerson() 
	Game.SetCameraTarget(_00E_FS_NQ03_SpiritActorREF)
	Game.SetPlayerAIDriven(True)
	Game.DisablePlayerControls(true, true, true, True, true, true, true, true)
	Game.SetHUDCartMode(True)
	_00E_FS_NQ03_WordOfTheDeadFLoatIMOD.Apply()
	_00E_FS_NQ03_SpiritActorREF.SplineTranslateToRef(FS_NQ03_WordOfTheDeadSummonMarkerREF, 35.0, 35.0, 2000.0)

EndFunction

Function FlyTowardsLishari()

	FXExplosionCatapultNearM.Play(PlayerREF)	
	_00E_FS_NQ03_SpiritActorREF.SplineTranslateToRef(_00E_FS_NQ03_SC02_HeadMarker, 500.0, 1000.0, 0.0)	

EndFunction

Function PortPlayerIntoMemory()
	
	_00E_FS_NQ03_WordOfTheDeadFLoatIMOD.Remove()
	FadeToBlackHoldImod.Apply()
	PlayerREF.StopTranslation()
	Wait(1)
	Game.SetPlayerAIDriven(False)
	_00E_FS_NQ03_SpiritActorREF.EnableAI(False)
	Game.SetCameraTarget(PlayerREF)
	GhostFXShader.Play(PlayerREF)
	PlayerREF.SetAlpha(0.5)
	_00E_MQ07a_VisionStartM.Play(PlayerREF)
	_00E_MQ07a_VisionAwake.Apply()
	PlayerREF.MoveTo(_00E_FS_NQ03_VisionStartMarker)
	Wait(1)
	Game.EnablePlayerControls()
	Game.SetHUDCartMode(False)
	FadeToBlackHoldImod.Remove()
	_00E_MQ07a_VisionIMOD.ApplyCrossFade(2)
	Game.RequestAutoSave()
	SetStage(100)
	
EndFunction

Function PlayCommentStart()

	FS_NQ03_SC03_CommentStart.ForceStart()

EndFunction

Function PlayCommentTrap1()

	FS_NQ03_SC04_CommentTrap1.ForceStart()

EndFunction

Function PlayCommentTrap2()

	FS_NQ03_SC05_CommentTrap2.ForceStart()

EndFunction

Function PlayCommentRat()

	FS_NQ03_SC06_CommentRat.ForceStart()

EndFunction

Function PlayCommentLight()

	FS_NQ03_SC07_CommentLight.ForceStart()

EndFunction

Function PlayCommentShow()

	FS_NQ03_SC08_CommentShow.ForceStart()

EndFunction

Function PlayCommentBread()

	FS_NQ03_SC09_CommentBread.ForceStart()

EndFunction

Function PlayCommentSkeleton()

	FS_NQ03_SC10_CommentSkeleton.ForceStart()

EndFunction

Function PlayCommentTrack()

	FS_NQ03_SC11_CommentTrack.ForceStart()

EndFunction

Function PlayCommentTrap3()

	FS_NQ03_SC12_CommentTrap3.ForceStart()

EndFunction

Function PlayCommentHideout()

	FS_NQ03_SC13_CommentHideout.ForceStart()

EndFunction

Function PlayCommentStaff()

	FS_NQ03_SC14_CommentStaff.ForceStart()

EndFunction

Function PlayCommentWine()

	FS_NQ03_SC15_CommentWine.ForceStart()

EndFunction

Function PlayCommentRobe()

	FS_NQ03_SC16_CommentRobe.ForceStart()

EndFunction

Function FoundSecret()

	if _00E_FS_NQ03_SecretCounterVar.GetValue() < 2
	_00E_FS_NQ03_SecretCounterVar.SetValue(_00E_FS_NQ03_SecretCounterVar.GetValue()+1)
	UpdateCurrentInstanceGlobal(_00E_FS_NQ03_SecretCounterVar)
	wait(0.1)
	SetObjectiveDisplayed(60, true, true)
	elseif _00E_FS_NQ03_SecretCounterVar.GetValue() == 2
	_00E_FS_NQ03_SecretCounterVar.SetValue(_00E_FS_NQ03_SecretCounterVar.GetValue()+1)
	UpdateCurrentInstanceGlobal(_00E_FS_NQ03_SecretCounterVar)
	wait(0.1)
	SetObjectiveDisplayed(60, true, true)
	SetStage(180)
	_00E_FS_NQ03_HideoutLetterBlanko.Disable()
	_00E_FS_NQ03_HideoutLetter.Enable()
	else
	;donothing
	endif

EndFunction

Function PlayCommentLetter()

	PlayerRef.SheatheWeapon()
	wait(0.1)
	;_00E_FS_NQ03_ReadNoteMarker.Enable()
	SetObjectiveCompleted(60)
	Game.ForceThirdPerson() 
	Game.SetPlayerAIDriven(True)
	Game.DisablePlayerControls()
	PlayerREF.UnequipItem(PlayerREF.GetEquippedObject(0))
	wait(0.5)
	PlayerREF.PlayIdle(IdleNoteRead)
	FS_NQ03_SC17_CommentLetter.ForceStart()
	_00E_FS_NQ03_HideoutLetter.Disable()

EndFunction

Function UpdateObjectivesDancingNomad()

	if PlayerREF.GetActorBase().GetSex() == 1
		SetObjectiveDisplayed(75)
	else
		SetObjectiveDisplayed(70)
	endif

EndFunction

Function MovePlayerVoiceToHideout()

	_00E_FS_NQ03_PlayerVoiceREF.MoveTo(_00E_FS_NQ03_PlayerVoiceMarker1)

EndFunction

Function TeleportPlayerToVision2()

	Levelsystem.FadeToBlack()
	PlayerREF.PlayIdle(IdleStop_Loose)
	Game.SetPlayerAIDriven(False)
	_00E_MAGEldritchFireM.Play(PlayerREF)
	Utility.Wait(3)
	PlayerREF.MoveTo(_00E_FS_NQ03_Vision2Marker)
	_00E_FS_NQ03_PlayerVoiceREF.MoveTo(_00E_FS_NQ03_PlayerVoiceMarker2)
	wait(0.1)
	Game.EnablePlayerControls()
	Levelsystem.FadeToBlackBack()
	wait(0.1)
	FS_NQ03_SC18_TavernForcegreet.ForceStart()
	Game.RequestAutoSave()

EndFunction

Function GarrecAppears()

	_00E_FS_NQ03_GarrecREF.Enable()
	_00E_FS_NQ03_GarrecREF.MoveTo(_00E_FS_NQ03_GarrecSpawnMarker)
	Game.DisablePlayerControls()
	wait(0.1)
	FS_NQ03_SC19_GarrecAppears.ForceStart()

EndFunction

Function PlayerDrawWeapon()

	Game.ForceThirdPerson() 
	Game.SetPlayerAIDriven(True)

EndFunction

Function PlayerSheatheWeapon()

	if IsObjectiveDisplayed(75)
		SetObjectiveCompleted(75)
	else
		SetObjectiveCompleted(70)
	endif

	PlayerRef.SheatheWeapon()
	Game.EnablePlayerControls()
	Game.SetPlayerAIDriven(False)
	SetObjectiveDisplayed(95)

EndFunction

Function StartSC20()

	Game.SetPlayerAIDriven(True)
	Levelsystem.FadeToBlack()
	FS_NQ03_SC20_TavernTalk.ForceStart()
	PlayerREF.Moveto(_00E_FS_NQ03_SC20_PlayerChair)
	_00E_FS_NQ03_GarrecREF.Moveto(_00E_FS_NQ03_SC20_GarrecChair)
	_00E_FS_NQ03_SC20_DinnerMarker.Enable()
	_00E_FS_NQ03_SC20_Door.SetOpen(false)
	Game.DisablePlayerControls()
	wait(3)
	Levelsystem.FadeToBlackBack()

EndFunction

Function EndSC20()

	SetObjectiveCompleted(95)
	Game.EnablePlayerControls()
	Game.SetPlayerAIDriven(False)
	_00E_FS_NQ03_GarrecREF.Disable()
	_00E_FS_NQ03_SC21_Door.Lock(false)

	If (Game.GetPlayer().GetActorBase().GetSex() == 0)
	SetObjectiveDisplayed(80)
	else
	SetObjectiveDisplayed(90)
	Endif

EndFunction

Function StartSC21()

	Game.SetPlayerAIDriven(True)
	Game.ShowFirstPersonGeometry(False)
	Game.ForceFirstPerson()
	Game.DisablePlayerControls( true, true, true, false, true, true, true,  true)
	_00E_FS_NQ03_SC21_Door.SetOpen(false)
	FS_NQ03_SC21_LishariMurdered.ForceStart()

EndFunction

Function Poison()

	MAGVampireSunlight.Play(PlayerREF)
	SoundID01 = UIHealthHeartbeatALP.Play(PlayerREF as objectreference)
	_00E_FS_NQ03_FaintIMOD.Apply()

EndFunction

Function KnockOut()

	Levelsystem.FadeToBlack()
	_00E_FS_NQ03_FaintIMOD.Remove()
	PlayerREF.MoveTo(_00E_FS_NQ03_SC21_PlayerMarker)
	wait(0.1)
	PlayerREF.PlayIdle(TG05_Knockout)

EndFunction

Function SpawnGarrecAndTraitor()

	_00E_FS_NQ03_GarrecREF.Enable()
	_00E_FS_NQ03_GarrecREF.MoveTo(_00E_FS_NQ03_SC21_GarrecMarker1)
	_00E_FS_NQ03_TraitorREF.Enable()
	_00E_FS_NQ03_TraitorREF.MoveTo(	_00E_FS_NQ03_SC21_TraitorMarker1)

EndFunction

Function Wakeup()

	_00E_FS_NQ03_SC21_Door.SetOpen(false)
	Levelsystem.FadeToBlackBack()
	_00E_FS_NQ03_FaintIMOD.Apply()

EndFunction

Function FadeToBlack()

	Levelsystem.FadeToBlack()
	_00E_FS_NQ03_FaintIMOD.Remove()
	_00E_MQ07a_VisionIMOD.Remove()

EndFunction

Function KillLishari() 

	NPCKillSlashMarker.Play(PlayerREF)
	PlayerREF.PlayIdle(TG05_GetUp)
	if IsObjectiveDisplayed(80)
		SetObjectiveCompleted(80)
	else
		SetObjectiveCompleted(90)
	endif

EndFunction

Function TeleportBack()

	Game.SetPlayerAIDriven(False)
	Game.RequestAutoSave()
	PlayerREF.SetAlpha(1)
	GhostFXShader.Stop(PlayerREF)
	PlayerREF.MoveTo(_00E_FS_NQ03_SC22_PlayerMarker1)
	_00E_FS_NQ03_YuslanREF.MoveTo(_00E_FS_NQ03_SC02_YuslanMarker)
	_00E_FS_NQ03_LexilREF.MoveTo(_00E_FS_NQ03_SC02_LexilMarker)
	_00E_FS_NQ03_LishariCorpseREF.MoveTo(FS_NQ03_AltarREF)
	Sound.StopInstance(SoundID01)
	_00E_MQ07a_VisionStartM.Play(PlayerREF)
	FS_NQ03_SC22_Epilog.ForceStart()
	Game.ShowFirstPersonGeometry(true)

EndFunction

Function SetUpEpilogTalk()

	Levelsystem.FadeToBlack()
	Game.DisablePlayerControls()
	PlayerREF.MoveTo(_00E_FS_NQ03_SC22_PlayerMarker2)
	_00E_FS_NQ03_LexilREF.MoveTo(_00E_FS_NQ03_SC22_LexilChair)
	_00E_FS_NQ03_YuslanREF.MoveTo(_00E_FS_NQ03_SC22_YuslanLean)

	; Wait for Lex and Yuslan to sit down (or for timeout)
	Int nCountDown = 50
	While (nCountDown > 0) &&((_00E_FS_NQ03_LexilREF.GetSitState() != 3) || (_00E_FS_NQ03_YuslanREF.GetSitState() != 3))
		wait(0.1)
		nCountDown -= 1
	EndWhile

	_00E_FS_NQ03_SC02_StorageDoor.Lock(false)
	Game.EnablePlayerControls()
	SetStage(260)
	Levelsystem.FadeToBlackBack()

EndFunction

Function FinishQuest()

	Levelsystem.GiveEP(1000)
	_00E_FS_NQ03_FinishedVar.SetValue(1)
	_00E_TeleportGlobal.SetValue(0)

EndFunction

Function CleanUp()

	_00E_FS_NQ03_DisableRatsMarker.Enable()

EndFunction

Function AddDeathMusic()

	_00E_Music_Special_Character_Death.Add()

EndFunction

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

Event OnUpdateGameTime() ; because of how we registered, this event occurs every 30 minutes of game time    
	if (GameDaysPassed.GetValue() + 1 >= GameDay)
		SetStage(20)
		UnregisterForUpdateGameTime()
	Endif
EndEvent

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

Int GameDay
Int SoundID01

_00E_QuestFunctions Property Levelsystem Auto

Quest Property FS_NQ03 Auto

Actor Property _00E_FS_NQ03_MessengerGirlREF Auto
Actor Property _00E_FS_NQ03_YuslanREF Auto
Actor Property _00E_FS_NQ03_LexilREF Auto
Actor Property PlayerREF Auto
Actor Property _00E_FS_NQ03_SpiritActorREF Auto
Actor Property _00E_FS_NQ03_LishariCorpseREF Auto
Actor Property _00E_FS_NQ03_GarrecREF Auto
Actor Property _00E_FS_NQ03_TraitorREF Auto

EffectShader Property GhostFXShader Auto

GlobalVariable Property GameDaysPassed Auto
GlobalVariable Property _00E_FS_NQ03_SecretCounterVar Auto
GlobalVariable Property _00E_FS_NQ03_FinishedVar Auto
GlobalVariable Property _00E_TeleportGlobal Auto

Idle Property IdleNoteRead Auto
Idle Property IdleStop_Loose Auto
Idle Property TG05_Knockout Auto
Idle Property TG05_GetUp Auto

ImageSpaceModifier Property _00E_FS_NQ03_WordOfTheDeadFLoatIMOD Auto
ImageSpaceModifier Property FadeToBlackHoldIMOD Auto
ImageSpaceModifier Property FadeToBlackBackIMOD Auto
ImageSpaceModifier Property _00E_MQ07a_VisionAwake Auto
ImageSpaceModifier Property _00E_MQ07a_VisionIMOD Auto
ImageSpaceModifier property _00E_FS_NQ03_FaintIMOD auto
ImageSpaceModifier property _00E_FS_NQ03_ShockApply auto

ObjectReference Property _00E_FS_NQ03_MessengerGirlMarker Auto
ObjectReference Property _00E_FS_NQ03_DisableRatsMarker Auto
ObjectReference Property _00E_FS_NQ03_SC02_YuslanMarker Auto
ObjectReference Property _00E_FS_NQ03_SC02_LexilMarker Auto
ObjectReference Property _00E_FS_NQ03_SC02_PlayerMarker Auto
ObjectReference Property _00E_FS_NQ03_SC02_StorageDoor Auto
ObjectReference Property _00E_FS_NQ03_SC02_HeadMarker Auto
ObjectReference Property _00E_FS_NQ03_VisionStartMarker Auto
ObjectReference Property _00E_FS_NQ03_PlayerVoiceREF Auto
ObjectReference Property _00E_FS_NQ03_HideoutLetter Auto
ObjectReference Property _00E_FS_NQ03_HideoutLetterBlanko Auto
ObjectReference Property _00E_FS_NQ03_PlayerVoiceMarker1 Auto
ObjectReference Property _00E_FS_NQ03_Vision2Marker Auto
ObjectReference Property _00E_FS_NQ03_PlayerVoiceMarker2 Auto
ObjectReference Property _00E_FS_NQ03_GarrecSpawnMarker Auto
ObjectReference Property _00E_FS_NQ03_SC20_PlayerChair Auto
ObjectReference Property _00E_FS_NQ03_SC20_GarrecChair Auto
ObjectReference Property _00E_FS_NQ03_SC20_DinnerMarker Auto
ObjectReference Property _00E_FS_NQ03_SC20_Door Auto
ObjectReference Property _00E_FS_NQ03_SC21_Door Auto
ObjectReference Property _00E_FS_NQ03_SC21_GarrecMarker1 Auto
ObjectReference Property _00E_FS_NQ03_SC21_TraitorMarker1 Auto
ObjectReference Property _00E_FS_NQ03_SC21_PlayerMarker Auto
ObjectReference Property _00E_FS_NQ03_SC22_PlayerMarker1 Auto
ObjectReference Property _00E_FS_NQ03_SC22_PlayerMarker2 Auto
ObjectReference Property _00E_FS_NQ03_SC22_LexilChair Auto
ObjectReference Property _00E_FS_NQ03_SC22_YuslanLean Auto
ObjectReference Property FS_NQ03_WordOfTheDeadSummonMarkerREF Auto
ObjectReference Property FS_NQ03_HeadSpawnMarkerREF Auto
ObjectReference Property FS_NQ03_AltarREF Auto

MusicType Property _00E_Music_Special_Character_Death Auto

Scene Property FS_NQ03_SC00_Bugfix Auto
Scene Property FS_NQ03_SC01_Messenger Auto
Scene Property FS_NQ03_SC02_PreVision Auto
Scene Property FS_NQ03_SC03_CommentStart Auto
Scene Property FS_NQ03_SC04_CommentTrap1 Auto
Scene Property FS_NQ03_SC05_CommentTrap2 Auto
Scene Property FS_NQ03_SC06_CommentRat Auto
Scene Property FS_NQ03_SC07_CommentLight Auto
Scene Property FS_NQ03_SC08_CommentShow Auto
Scene Property FS_NQ03_SC09_CommentBread Auto
Scene Property FS_NQ03_SC10_CommentSkeleton Auto
Scene Property FS_NQ03_SC11_CommentTrack Auto
Scene Property FS_NQ03_SC12_CommentTrap3 Auto
Scene Property FS_NQ03_SC13_CommentHideout Auto
Scene Property FS_NQ03_SC14_CommentStaff Auto
Scene Property FS_NQ03_SC15_CommentWine Auto
Scene Property FS_NQ03_SC16_CommentRobe Auto
Scene Property FS_NQ03_SC17_CommentLetter Auto
Scene Property FS_NQ03_SC18_TavernForcegreet Auto
Scene Property FS_NQ03_SC19_GarrecAppears Auto
Scene Property FS_NQ03_SC20_TavernTalk Auto
Scene Property FS_NQ03_SC21_LishariMurdered Auto
Scene Property FS_NQ03_SC22_Epilog Auto

Spell Property _00E_Ability_StaggerSelfSpell Auto

Sound Property OBJEyeofMagnusVanishM Auto
Sound Property _00E_MQ07a_WordOfTheDeadTransformSpiritM Auto
Sound Property FXExplosionCatapultNearM Auto
Sound Property _00E_MQ07a_VisionStartM Auto
Sound Property MAGVampireSunlight Auto
Sound Property UIHealthHeartbeatALP Auto
Sound Property NPCKillSlashMarker Auto
Sound Property _00E_MAGEldritchFireM Auto