Scriptname _00E_FS_NQ01_Functions extends Quest Conditional

Import _00E_QuestFunctions

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

Event OnUpdateGameTime()

	If GetStage() == 75
	
		SetStage(80)
		
	Elseif GetStage() == 150
		
		SetStage(155)
	
	EndIf

EndEvent

Event OnUpdate()

	if GetStage() < 115

		SetStage(115)
		
	EndIf

EndEvent

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

Function StartSC00()

	FS_NQ01_SC00_Start.ForceStart()

EndFunction

Function MoveYuslanToLaboratory()

	if _00E_MC_YuslanREF.IsDisabled()
		_00E_MC_YuslanREF.Enable()
	endif

	_00E_MC_YuslanREF.MoveTo(FS_NQ01_YuslanLookAtDrawing)

EndFunction

Function SetUpSC01()

	FS_NQ01_SC01_ExpositionInBath.ForceStart()
	FadeToBlackIMOD.Apply()
	Utility.Wait(2.7)
	FadeToBlackHoldIMOD.ApplyCrossFade(afFadeDuration = 0.3)
	FS_NQ01_YuslanREF.Enable()
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC01_YuslanRailMarker)
	PlayerREF.MoveTo(FS_NQ01_SC01_PlayerMarkerREF)
	
EndFunction

Function FadeBack()

	Game.EnablePlayerControls()
	FadeToBlackBackIMOD.ApplyCrossFade()

EndFunction

Function BenchFailsave()

	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC01_YuslanBenchREF)

EndFunction

Function MoveYuslan()

	If FS_NQ01_YuslanREF.IsDisabled()
		FS_NQ01_YuslanREF.Enable()
	EndIf
	
	FS_NQ01_SC02_Cloister_01.ForceStart()
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_YuslanLeanMarker)	
	FS_NQ01_SunbornParentREF.Enable()

EndFunction

Function RefreshCombatState()

	Levelsystem.RemoveCombatSoundtracks()
	FS_NQ01_YuslanREF.StopCombat()
	FS_NQ01_YuslanREF.StopCombatAlarm()

EndFunction

Function EnableEtherCrystal()

	FS_NQ01_YuslanREF.EvaluatePackage()
	FS_NQ01_SC03_EtherCrystal.Enable()
	_00E_FS_NQ01_ThalgardLever.Enable()

EndFunction

Function StartSC03()

	Levelsystem.RemoveCombatSoundtracks()
	_00E_TeleportGlobal.SetValueInt(1)
	FS_NQ01_SC03_MercenaryREF.Enable()
	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	MAGIllusionReleaseSound.Play(PlayerREF)
	FS_NQ01_SC03_MercenaryREF.SetAlpha(0.0)
	FS_NQ01_SC03_MercenaryREF.SetGhost(True)
	FS_NQ01_SC03_MercenaryREF.BlockActivation(True)
	FS_NQ01_YuslanREF.BlockActivation(True)
	FS_NQ01_SC03_Cloister_02.ForceStart()
	FS_NQ01_SC03_MercenaryREF.SetHeadTracking(False)
	FS_NQ01_YuslanREF.SetHeadTracking(False)
	FS_NQ01_SC03_MercenaryREF.MoveTo(FS_NQ01_SC03_MercenaryKneelingMarkerREF)
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC03_YuslanMarkerREF)
	FS_NQ01_YuslanREF.AddToFaction(IgnoreInCombatFaction)
	
	if !FS_NQ01_SC03_PortcullisREF.GetOpenState() == 1 || 2
		FS_NQ01_SC03_PortcullisREF.SetOpen(True)
	EndIf
	
EndFunction

Function SetAlphaMercenary()

	FS_NQ01_SC03_MercenaryREF.Enable()
	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	MAGIllusionReleaseSound.Play(PlayerREF)
	FS_NQ01_SC03_MercenaryREF.SetAlpha(1.0)

EndFunction

Function YuslanKillMercenary()

	_00E_FS_NQ01_Barrier1.Moveto(_00E_FS_NQ01_Barrier1Pos)
	_00E_FS_NQ01_Barrier1Msg.Enable()
	klosterback.lock()
	klosterback.setlocklevel(255)

	FS_NQ01_YuslanREF.PlayIdle(_00E_IdleStomp)
	_00E_FXEldritchShader03.Play(FS_NQ01_YuslanREF)
	Utility.Wait(0.25)
	FS_NQ01_SC03_LightREF.EnableNoWait()
	FS_NQ01_SC03_MercenaryREF.PlaceAtMe(_00E_A2_EldritchBloodExplosion)
	goreExplosion = FS_NQ01_SC03_MercenaryREF.PlaceAtMe(_00E_FS_MAGGoreExplosion)
	Game.TriggerScreenBlood(10)
	FS_NQ01_SC03_MercenaryREF.SetAlpha(0.0)
	_00E_MQ05_MerchantDeathM.Play(PlayerREF)
	Utility.Wait(3)
	MAGIllusionReleaseSound.Play(PlayerREF)
	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	FS_NQ01_SC03_LightREF.Disable()
	_00E_FXEldritchShader03.Stop(FS_NQ01_YuslanREF)
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_YuslanLeanMarker)
	FS_NQ01_YuslanREF.BlockActivation(False)
	FS_NQ01_YuslanREF.RemoveFromFaction(IgnoreInCombatFaction)
	FS_NQ01_YuslanREF.Disable()
	goreExplosion.Disable()
	FS_NQ01_SC03_MercenaryREF.Disable()
	
EndFunction

Function CleanUpSC03()

	SetStage(50)

EndFunction

Function StartSC04()

	Armor Body = PlayerREF.GetWornForm(0x00000004) as Armor
	Armor Head = PlayerREF.GetWornForm(0x00000001) as Armor
	Armor Hands = PlayerREF.GetWornForm(0x00000008) as Armor
	Armor Forearms = PlayerREF.GetWornForm(0x00000010) as Armor
	Armor Feet = PlayerREF.GetWornForm(0x00000080) as Armor
	Armor Calves = PlayerREF.GetWornForm(0x00000100) as Armor
	Armor Shield = PlayerREF.GetWornForm(0x00000200) as Armor
	Armor Circlet = PlayerREF.GetWornForm(0x00001000) as Armor
	Armor Chest = PlayerREF.GetWornForm(0x00010000) as Armor
	Armor Back = PlayerREF.GetWornForm(0x00020000) as Armor

	Weapon Left = PlayerREF.GetEquippedWeapon(true) as Weapon
	Weapon Right = PlayerREF.GetEquippedWeapon(false) as Weapon
	
	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	MAGIllusionReleaseSound.Play(PlayerREF)

	;failsafe
	Player.SetInvulnerable(false)

	SC04_PlayerCopy = FS_NQ01_SC04_PlayerCopySpawnMarkerREF.PlaceActorAtMe(Player)
	SC04_PlayerCopy.SetGhost(True)
	SC04_PlayerCopy.BlockActivation(True)
	SC04_FakePlayer.ForceRefTo(SC04_PlayerCopy)
	
	If Body != None
		SC04_PlayerCopy.AddItem(Body, 1)
		SC04_PlayerCopy.EquipItem(Body)
	EndIf
	If Head != None
		SC04_PlayerCopy.AddItem(Head, 1)
		SC04_PlayerCopy.EquipItem(Head)
	EndIf
	If Hands != None
		SC04_PlayerCopy.AddItem(Hands, 1)
		SC04_PlayerCopy.EquipItem(Hands)
	EndIf
	If Forearms != None
		SC04_PlayerCopy.AddItem(Forearms, 1)
		SC04_PlayerCopy.EquipItem(Forearms)
	EndIf
	If Feet != None
		SC04_PlayerCopy.AddItem(Feet, 1)
		SC04_PlayerCopy.EquipItem(Feet)
	EndIf
	If Calves != None
		SC04_PlayerCopy.AddItem(Calves, 1)
		SC04_PlayerCopy.EquipItem(Calves)
	EndIf
	If Shield != None
		SC04_PlayerCopy.AddItem(Shield, 1)
		SC04_PlayerCopy.EquipItem(Shield)
	EndIf
	If Circlet != None
		SC04_PlayerCopy.AddItem(Circlet, 1)
		SC04_PlayerCopy.EquipItem(Circlet)
	EndIf
	If Chest != None
		SC04_PlayerCopy.AddItem(Chest, 1)
		SC04_PlayerCopy.EquipItem(Chest)
	EndIf
	If Back != None
		SC04_PlayerCopy.AddItem(Back, 1)
		SC04_PlayerCopy.EquipItem(Back)
	EndIf
	If Left != None
		SC04_PlayerCopy.AddItem(Left, 1)
		SC04_PlayerCopy.EquipItem(Left)
	EndIf
	If Right != None
		SC04_PlayerCopy.AddItem(Right, 1)
		SC04_PlayerCopy.EquipItem(Right)
	EndIf
	FS_NQ01_SC04_Cloister_03.ForceStart()
    
EndFunction

Function SpawnArcherAndKillPlayer()

	FS_NQ01_SC04_ArcherREF.EnableNoWait()
	FS_NQ01_SC04_ArcherREF.MoveTo(FS_NQ01_SC04_ArcherMarkerREF)
	WPNBowDraw.Play(FS_NQ01_SC04_ArcherREF)
	FS_NQ01_SC04_ArcherREF.BlockActivation(True)
	Utility.Wait(1)
	SC04_PlayerCopy.SetGhost(False)
	_00E_FakeArrowSP.Cast(FS_NQ01_SC04_ArcherMarkerREF, SC04_PlayerCopy)
	Utility.Wait(0.1)
	
	if Player.GetSex() == 0
		_00E_Male_PlayerHitM.Play(SC04_PlayerCopy)

	Else
		_00E_Female_PlayerHitM.Play(SC04_PlayerCopy)
	EndIf
	
	Game.TriggerScreenBlood(10)
	_00E_FakeArrowSP.Cast(FS_NQ01_SC04_ArcherMarkerREF, SC04_PlayerCopy)
	Utility.Wait(0.5)
	SC04_PlayerCopy.KillEssential(SC04_PlayerCopy)

EndFunction

Function StopSC04()

	SC04_FakePlayer.Clear()
	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	MAGIllusionReleaseSound.Play(PlayerREF)
	SC04_PlayerCopy.Delete()
	FS_NQ01_SC04_ArcherREF.Delete()
	SetStage(60)
	
EndFunction

Function StartSC05()
	
	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	MAGIllusionReleaseSound.Play(PlayerREF)
	FS_NQ01_SC05_Lishari_REF.Enable()
	FS_NQ01_SC05_Lishari_REF.MoveTo(FS_NQ01_SC05_LishariMarkerREF)
	FS_NQ01_SC05_Lishari_REF.SetGhost(True)
	FS_NQ01_SC05_Lishari_REF.BlockActivation(True)
	FS_NQ01_SC05_Lishari_REF.AddToFaction(IgnoreInCombatFaction)
	FS_NQ01_YuslanREF.AddToFaction(IgnoreInCombatFaction)
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC05_YuslanExamineMarkerREF)
	FS_NQ01_YuslanREF.SetGhost(True)
	FS_NQ01_YuslanREF.BlockActivation(True)
	FS_NQ01_YuslanREF.Enable()
	FS_NQ01_SC05_Lishari_REF.SetHeadTracking(False)
	FS_NQ01_YuslanREF.SetHeadTracking(False)
	FS_NQ01_SC05_Cloister_04.ForceStart()
	
EndFunction

Function StopSC05()

	Debug.SendAnimationEvent(FS_NQ01_YuslanREF, "IdleForceDefaultState")
	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	MAGIllusionReleaseSound.Play(PlayerREF)
	FS_NQ01_SC05_Cloister_04.Stop()
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC06_YuslanBeamMarkerREF)
	FS_NQ01_YuslanREF.EvaluatePackage()
	FS_NQ01_YuslanREF.BlockActivation(False)
	FS_NQ01_YuslanREF.RemoveFromFaction(IgnoreInCombatFaction)
	FS_NQ01_YuslanREF.SetHeadTracking(True)
	FS_NQ01_SC05_Lishari_REF.Disable()
	SetStage(70)

EndFunction

Function PortBackYuslanClearFirstAct()

	_00E_TeleportGlobal.SetValueInt(0)
	FS_NQ01_YuslanREF.RemoveFromFaction(IgnoreInCombatFaction)
	Levelsystem.TeleportNPC(FS_NQ01_YuslanREF, _00E_NPCDumpMarker)
	RegisterForSingleUpdateGameTime(48.0)
	_00E_FS_NQ01_Barrier1.Disable()
	_00E_FS_NQ01_Barrier1Msg.Disable()
	klosterback.lock(false)

EndFunction

Function SetUpSC06()

	If FS_NQ01_YuslanREF.IsDisabled()
		FS_NQ01_YuslanREF.Enable()
	EndIf

	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC06_YuslanMarkerREF)
	FS_NQ01_SC06_DustPit.ForceStart()
	
EndFunction

Function EnableWorldshifter()

	FS_NQ01_SC05_WorldwalkerREF.Enable()
	_00E_FS_NQ01_Anja.Disable()
	UndercityBarracks2ZorkbansCellar.SetActorOwner(None)
	FS_NQ01_YuslanREF.AddItem(_00E_UC2_ZorkbansKey)
	FS_NQ01_SC07_ZorkbanDoorREF.Lock(False)

EndFunction

Function EnableWorldshifterFailsave()

	if FS_NQ01_SC05_WorldwalkerREF.IsDisabled()
		FS_NQ01_SC05_WorldwalkerREF.Enable()
	EndIf

EndFunction

Function PortYuslanToPlayer()

	FS_NQ01_YuslanREF.MoveTo(PlayerREF)

EndFunction

Function PortYuslanFailsave()

	If FS_NQ01_YuslanREF.GetParentCell() != UndercityBarracks2ZorkbansCellar
	
		FS_NQ01_YuslanREF.MoveTo(PlayerREF)
	
	EndIf

EndFunction

Function StartSC07()

	; DEBUG! Delete
 	FS_NQ01_YuslanREF.Enable()
	FS_NQ01_YuslanREF.MoveTo(PlayerREF)
	EnableWorldshifterFailsave() 
	; DEBUG DELETE

	_FS_TheriantrophistControlQuest.TransformBackIfTransformed()
	_00E_FS_NQ01_CellarDoor.Lock(255)
	_00E_TeleportGlobal.SetValueInt(1)
	FS_NQ01_SC07_Worldwalker_Activation.ForceStart()

EndFunction

Function AddMusic()

	; _00E_FS_Special_SeaOfEventualitiesLoop.Add()

EndFunction

Function InitiateRitual()
	
	int iIndex = FS_NQ01_SC12_PusBugs.GetSize()
	
	while iIndex > 0
	
		iIndex -= 1
		
		Actor akActorToDisable = FS_NQ01_SC12_PusBugs.GetAt(iIndex) as Actor
		
		if akActorToDisable.IsEnabled()
			akActorToDisable.Disable()
		EndIf
		
	endwhile

	MAGIllusionCharm.Play(PlayerREF)
	_00E_FireBlueFXS.Play(PlayerREF)
	_00E_FireBlueFXS.Play(FS_NQ01_YuslanREF)
	_00E_FireBlueFXS.Play(FS_NQ01_SC05_WorldwalkerREF)
	FXCameraAttachFalmerDustEffect.Play(PlayerREF)
	iActivationSoundLP = MAGDestructionBlizzard2DLP.Play(PlayerREF)
	FS_NQ01_YuslanREF.SetLookAt(FS_NQ01_SC05_WorldwalkerREF)
	_00E_MQ11a_SC19_BlackStoneChannelBeam.Cast(FS_NQ01_SC07_PlayerFireMarkerREF, FS_NQ01_SC05_WorldwalkerREF)
	_00E_MQ11a_SC19_BlackStoneChannelBeam.Cast(FS_NQ01_SC07_YuslanFireMarkerREF, FS_NQ01_SC05_WorldwalkerREF)
	MAGDragonPowerAbsorbEffect.Play(FS_NQ01_SC05_WorldwalkerREF, -1, FS_NQ01_YuslanREF)
	MAGDragonPowerAbsorbManEffect.Play(PlayerREF, -1, FS_NQ01_YuslanREF)
	FS_NQ01_BeamLightREF.Enable()
	FS_NQ01_SC07_WorldwalkerExpMarkerREF.PlaceAtMe(_00E_FS_NQ01_SC07_WorldwalkerExp)
	Utility.Wait(3)
	_00E_A2_ChaosruneImplosionSoundM.Play(PlayerREF)
	
EndFunction

Function EndRitual()

	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	FS_NQ01_SC07_PlayerFireMarkerREF.InterruptCast()
	FS_NQ01_SC07_YuslanFireMarkerREF.InterruptCast()
	Sound.StopInstance(iActivationSoundLP)
	FXCameraAttachFalmerDustEffect.Stop(PlayerREF)
	QSTAlduinDeathExplosionA.Play(PlayerREF)
	_00E_FireBlueFXS.Stop(PlayerREF)
	_00E_FireBlueFXS.Stop(FS_NQ01_YuslanREF)
	_00E_FireBlueFXS.Stop(FS_NQ01_SC05_WorldwalkerREF)
	FS_NQ01_SC05_WorldwalkerREF.PlaceAtMe(_00E_FS_NQ01_SC07_ActivationExplosion)
	MAGIllusionReleaseSound.Play(PlayerREF)
	FS_NQ01_YuslanREF.KnockAreaEffect(1, 1024)
	MAGIllusionReleaseSound.Play(PlayerREF)
	IncreaseArcaneFever(30, 70)

EndFunction

Function OpenWorldwalker()

	Game.SetPlayerAIDriven(False)
	Game.EnablePlayerControls()
	FS_NQ01_SC07_DustREF.Activate(PlayerREF)
	FS_NQ01_SC05_WorldwalkerREF.PlayAnimation("trigger01") 
	FS_NQ01_SC08_PortalMarkerREF.Enable()
	FS_NQ01_PortalREF.Enable()
	
EndFunction

Function CreateFloatingBody()

	; objBody01 = FS_NQ01_YuslanSpawnBodyMarkerREF.PlaceAtMe(_00E_FS_NQ01_YuslanDissolvingBody)
	; objBody02 = FS_NQ01_YuslanSpawnBodyMarkerREF.PlaceAtMe(_00E_FS_NQ01_YuslanDissolvingBody)
	; objBody03 = FS_NQ01_YuslanSpawnBodyMarkerREF.PlaceAtMe(_00E_FS_NQ01_YuslanDissolvingBody)

EndFunction

Function PortYuslanWithEffects()

	_00E_FS_Tharael_DematerializeFXS.Play(FS_NQ01_YuslanREF)
	MAGIllusionReleaseSound.Play(FS_NQ01_YuslanREF)
	Utility.Wait(0.40)
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC08_YuslanMarker)
	_00E_FS_Tharael_DematerializeFXS.Stop(FS_NQ01_YuslanREF)
	FS_NQ01_PortalREF.EnableNoWait()
	
	Utility.Wait(1.5)
	
	objBody01.Disable()
	objBody02.Disable()
	objBody03.Disable()
	
EndFunction

Function StartSC08()

	FS_NQ01_SC08_Qyra_01.ForceStart()

EndFunction

Function AdjustGameHourQyra()

	if (PlayerREF.GetItemCount(_00E_FS_CraftingPlan_MQ18c_DreamflowerElixir) >= 1 || _00E_FS_BlueprintContainerActorREF.GetItemCount(_00E_FS_CraftingPlan_MQ18c_DreamflowerElixir) >= 1) || (_00E_FS_SpectralChestActorREF.GetItemCount(_00E_FS_CraftingPlan_MQ18c_DreamflowerElixir) >= 1 || _00E_SecureChest_HostChestREF.GetItemCount(_00E_FS_CraftingPlan_MQ18c_DreamflowerElixir) >= 1)
		FS_MQ18c_DreamflowerREF.Enable()
	EndIf

	_00E_TeleportGlobal.SetValueInt(1)
	Timescale.SetValue(0.01)
	Levelsystem.SkipTimeToHour(21)

EndFunction

Function ResetGameHourQyra()
	
	_00E_TeleportGlobal.SetValueInt(0)
	Timescale.SetValue(10)

EndFunction

Function FadeBackQyra()

	;DEBUG ONLY!
	; PlayerREF.MoveTo(FS_NQ01_SC08_DebugPlayerMoveMarker)
	; FS_NQ01_YuslanREF.Enable()
	;DEBUG ONLY

	FS_NQ01_SC10_DoorREF.Disable()
	SetObjectiveCompleted(45)
	FadeToBlackHoldIMOD.Remove()
	FadeToBlackBackIMOD.Apply()
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC08_YuslanMarker)


EndFunction

Function UpdateObjectives()

	_00E_FS_Special_SeaOfEventualitiesLoop.Add()
	RegisterForSingleUpdate(300)
	
EndFunction

Function DisableYuslan()

	FS_NQ01_YuslanREF.Disable()

EndFunction

Function UpdateObjectives02()

	If GetStage() < 120

		_00E_FS_NQ01_EventualityShiftIMOD.Apply()
		MAGIllusionReleaseSound.Play(PlayerREF)
		
		IncreaseArcaneFever(10, 90)
		
		_00E_FS_NQ01_RespectedYuslansWish.SetValueInt(1)
		_00E_FS_NQ01_YuslanThought.ShowAsHelpMessage("Jump", 5, 1, 1)
		SetObjectiveCompleted(50)
		SetObjectiveDisplayed(55, False)
		SetObjectiveDisplayed(60)
		
	Else
	
		_00E_FS_NQ01_RespectedYuslansWish.SetValueInt(0)
		SetObjectiveCompleted(55)
		SetObjectiveDisplayed(60)
		
	EndIf

EndFunction

Function IncreaseArcaneFever(int iStrength, int iMax)

	If (-1*PlayerREF.GetAV("LastFlattered") < iMax)
		PlayerREF.ModAV("LastFlattered", -iStrength)
		_00E_BlitzheilungArkanistenfieber_sFeverIncreased.Show(iStrength, -1*PlayerREF.GetAV("LastFlattered"))
	EndIf

EndFunction

Function StartSC09()


	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	MAGIllusionReleaseSound.Play(PlayerREF)
		
	IncreaseArcaneFever(10, 90)
		
	FS_NQ01_YuslanREF.Enable()
	SC09_LeanMarker.ForceRefTo(FS_NQ01_SC09_YuslanLeanMarker_02)
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC09_YuslanLeanMarker_02)

	FS_NQ01_SC09_Qyra_02.ForceStart()
	
	If _00E_AchievementsEnabled.GetValueInt() == 1
		Game.UnlockAchievement("END_NAEA_01")
	EndIf

EndFunction

Function SetSecretEnding()

	_00E_FS_NQ01_YuslanSecretEnding.SetValueInt(1)
	Levelsystem.GiveEP(300)

EndFunction

Function StartSC10Or11()

	SetObjectiveCompleted(60)
	Game.RequestAutosave()
	FS_NQ01_SC10_DoorREF.Disable()
	
	If _00E_FS_NQ01_YuslanSecretEnding.GetValueInt() == 1
		SetObjectiveDisplayed(70)
		FS_NQ01_SC10_Qyra_SecretEnding.ForceStart()
	Else
		FS_NQ01_YuslanREF.SetActorValue("Aggression", 3)
		FS_NQ01_YuslanREF.StartCombat(PlayerREF)
		FS_NQ01_YuslanREF.BlockActivation(True)
		FS_NQ01_YuslanREF.SetGhost(False)
		SetObjectiveDisplayed(75)
		FS_NQ01_SC11_Qyra_03.ForceStart()
	EndIf

EndFunction

Function UpdateObjectives04()

	FS_NQ01_YuslanREF.GetActorBase().SetEssential(False)
	FS_NQ01_YuslanREF.Kill(FS_NQ01_YuslanREF)
	SetObjectiveCompleted(75)
	SetObjectiveDisplayed(80)

EndFunction

Function ShowCarryMessage()

	int iButton = _00E_FS_NQ01_SC10_YuslanMessage.Show()
	
	if iButton == 0
	
		FadeToBlackIMOD.Apply()
		Utility.Wait(2.7)
		FadeToBlackHoldIMOD.ApplyCrossFade(afFadeDuration = 0.3)
		SetStage(140)
		
	Else
	
		Return
		
	EndIf

EndFunction

Function YuslanStopAnimation()

	Debug.SendAnimationEvent(FS_NQ01_YuslanREF, "IdleForceDefaultState")

EndFunction

Function TriggerCorrectionPain()

	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	MAGIllusionReleaseSound.Play(PlayerREF)
	
	IncreaseArcaneFever(10, 90)

EndFunction

Function YuslanFallDown()

	FS_NQ01_YuslanREF.PlayIdle(_00E_IdleSuicide)
	Utility.Wait(1.5)
	_00E_FS_NQ01_EventualityShiftIMOD.Apply()
	MAGIllusionReleaseSound.Play(PlayerREF)
	FS_NQ01_YuslanREF.Disable()
	FS_NQ01_SC08_PortalMarkerREF.Disable()
	FS_NQ01_SC05_WorldwalkerREF.Disable()
	FS_NQ01_SC05_WorldwalkerClosedREF.Enable()
	Game.EnablePlayerControls()
	
EndFunction

Function EnableDoor()

	FS_NQ01_SC10_DoorREF.Enable()

EndFunction

Function SetUpSC12()

	FadeToBlackIMOD.Apply()
	Utility.Wait(2.7)
	Game.DisablePlayerControls()
	FadeToBlackHoldIMOD.ApplyCrossFade(afFadeDuration = 0.3)
	FS_NQ01_SC08_PortalMarkerREF.Disable()
	FS_NQ01_SC05_WorldwalkerREF.Disable()
	FS_NQ01_SC05_WorldwalkerClosedREF.Enable()
	FS_NQ01_PortalREF.Disable()
	Timescale.SetValue(10)
	_00E_FS_NQ01_CellarDoor.lock(false)
	FS_NQ01_YuslanREF.SetGhost(True)
	FS_NQ01_YuslanREF.SetActorValue("Aggression", 0)
	FS_NQ01_YuslanREF.StopCombat()
	FS_NQ01_YuslanREF.StopCombatAlarm()
	
	if FS_NQ01_YuslanREF.IsDisabled()
		FS_NQ01_YuslanREF.Enable()
	EndIf
	
	if FS_NQ01_YuslanREF.IsDead()
		FS_NQ01_YuslanREF.Resurrect()
		FS_NQ01_YuslanREF.ResetHealthAndLimbs()
	EndIf
	
	FS_NQ01_YuslanREF.MoveTo(FS_NQ01_SC12_YuslanMarker02REF)
	PlayerREF.MoveTo(FS_NQ01_SC12_PlayerPortREF)
	Utility.wait(0.1)
	FS_NQ01_SC12_Aftermath.ForceStart()

EndFunction

Function GivePlayerSpecialReward()

	PlayerREF.AddItem(_00E_BankKey1211, 1)

EndFunction

Function GivePlayerRewardNormal()

	PlayerREF.AddItem(Gold001, 500)
	PlayerREF.AddItem(_05E_Genesungstrank, 3)
	PlayerREF.AddItem(_05E_Manatrank, 3)
	PlayerREF.AddItem(_04E_Unsichtbarkeitstrank, 2)

EndFunction

Function PlayerRemoveDreamflower()

	PlayerREF.RemoveItem(_00E_FS_MQ18c_Dreamflower, PlayerREF.GetItemCount(_00E_FS_MQ18c_Dreamflower))
	
EndFunction

Function FinishUp()

	CompleteAllObjectives()
	_00E_TeleportGlobal.SetValueInt(0)
	FS_NQ01_YuslanREF.RemoveFromFaction(IgnoreInCombatFaction)
	FS_NQ01_YuslanREF.GetActorBase().SetEssential(True)
	UndercityBarracks2ZorkbansCellar.SetActorOwner(FS_NQ01_ZorkbanREF.GetActorBase())
	Timescale.SetValue(10)
	Levelsystem.RemoveSilence()
	Levelsystem.RemoveCombatSoundtracks()
	CompleteQuest()
	TeleportYuslan()
		
EndFunction

Function TeleportYuslan()

	Levelsystem.TeleportNPC(FS_NQ01_YuslanREF, _00E_NPCDumpMarker)
	FS_NQ01_YuslanREF.Disable()
	FS_NQ01_YuslanREF.DeleteWhenAble()

EndFunction

Function GiveClearedPotion()

	PlayerREF.AddItem(_00E_FS_MQ18c_DreamflowerPotionCleared, 1)

EndFunction

Function FinishUpDreamflower()

	RegisterForSingleUpdateGameTime(48)
	_00E_TeleportGlobal.SetValueInt(0)
	FS_NQ01_YuslanREF.RemoveFromFaction(IgnoreInCombatFaction)
	FS_NQ01_YuslanREF.GetActorBase().SetEssential(True)
	UndercityBarracks2ZorkbansCellar.SetActorOwner(FS_NQ01_ZorkbanREF.GetActorBase())
	Timescale.SetValue(10)
	Levelsystem.RemoveSilence()
	Levelsystem.RemoveCombatSoundtracks()
	TeleportYuslan()

EndFunction

Function GivePlayerBook()
	
	PlayerREF.RemoveItem(_00E_FS_NQ01_MG06Crystal, 1)
	PlayerREF.AddItem(_00E_FS_A3_Rogue_Frostbomb_Book_02, 1)

EndFunction

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

int iRewardEXP = 1000
int iActivationSoundLP

int iGoldReward = 500

_00E_QuestFunctions Property Levelsystem Auto

Actor SC04_PlayerCopy

ObjectReference goreExplosion

Actor Property PlayerREF Auto
Actor Property _00E_MC_YuslanREF Auto
Actor Property FS_NQ01_YuslanREF Auto
Actor Property FS_NQ01_SC03_MercenaryREF Auto
Actor Property FS_NQ01_SC04_ArcherREF Auto
Actor Property FS_NQ01_SC05_Lishari_REF Auto
Actor Property FS_NQ01_ZorkbanREF Auto
Actor Property _00E_FS_NQ01_Anja Auto
Actor Property _00E_FS_SpectralChestActorREF Auto
Actor Property _00E_FS_BlueprintContainerActorREF Auto

ActorBase Property Player Auto

Activator Property _00E_FS_NQ01_YuslanDissolvingBody Auto

Explosion Property _00E_A2_EldritchBloodExplosion Auto
Explosion Property _00E_FS_MAGGoreExplosion Auto
Explosion Property _00E_FS_NQ01_SC07_WorldwalkerExp Auto
Explosion Property _00E_A2_RiftExplosion Auto
Explosion Property _00E_FS_NQ01_SC07_ActivationExplosion Auto

Key Property _00E_UC2_ZorkbansKey Auto
Key Property _00E_BankKey1211 Auto

Potion Property _05E_Genesungstrank Auto
Potion Property _05E_Manatrank Auto
Potion Property _04E_Unsichtbarkeitstrank Auto
Potion Property _00E_FS_MQ18c_DreamflowerPotionCleared Auto
Potion Property _00E_FS_A3_Rogue_Frostbomb_Book_02 Auto

Cell Property UndercityBarracks2ZorkbansCellar Auto

ObjectReference objBody01
ObjectReference objBody02
ObjectReference objBody03

ObjectReference Property FS_NQ01_YuslanLookAtDrawing Auto
ObjectReference Property FS_NQ01_SC01_YuslanRailMarker Auto
ObjectReference Property FS_NQ01_SC01_PlayerMarkerREF Auto
ObjectReference Property FS_NQ01_SC01_YuslanBenchREF Auto
ObjectReference Property FS_NQ01_SC02_YuslanCloisterMarkerREF Auto
ObjectReference Property FS_NQ01_YuslanLeanMarker Auto
ObjectReference Property FS_NQ01_SunbornParentREF Auto
ObjectReference Property FS_NQ01_SC03_EtherCrystal Auto
ObjectReference Property FS_NQ01_SC03_MercenaryMarkerREF Auto
ObjectReference Property FS_NQ01_SC03_MercenaryKneelingMarkerREF Auto
ObjectReference Property FS_NQ01_SC03_YuslanMarkerREF Auto
ObjectReference Property FS_NQ01_SC03_PortcullisREF Auto
ObjectReference Property FS_NQ01_SC03_LightREF Auto
ObjectReference Property FS_NQ01_SC04_PlayerCopySpawnMarkerREF Auto
ObjectReference Property FS_NQ01_SC04_PlayerKillRockREF Auto
ObjectReference Property FS_NQ01_SC04_ArcherMarkerREF Auto
ObjectReference Property FS_NQ01_SC05_LishariMarkerREF Auto
ObjectReference Property FS_NQ01_SC05_YuslanExamineMarkerREF Auto
ObjectReference Property FS_NQ01_SC06_YuslanBeamMarkerREF Auto
ObjectReference Property FS_NQ01_SC06_YuslanMarkerREF Auto
ObjectReference Property FS_NQ01_SC05_WorldwalkerREF Auto
ObjectReference Property FS_NQ01_SC07_WorldwalkerExpMarkerREF Auto
ObjectReference Property FS_NQ01_SC07_YuslanRitualMarker Auto
ObjectReference Property FS_NQ01_SC07_ZorkbanDoorREF Auto
ObjectReference Property FS_NQ01_SC07_DustREF Auto
ObjectReference Property FS_NQ01_SC07_YuslanFireMarkerREF Auto
ObjectReference Property FS_NQ01_SC07_PlayerFireMarkerREF Auto
ObjectReference Property FS_NQ01_SC08_YuslanMarker Auto
ObjectReference Property FS_NQ01_SC08_ObjectLeanWallREF Auto
ObjectReference Property FS_NQ01_SC08_DebugPlayerMoveMarker Auto
ObjectReference Property FS_NQ01_SC09_FenceGate Auto
ObjectReference Property FS_NQ01_SC09_YuslanLeanMarker_01 Auto
ObjectReference Property FS_NQ01_SC09_YuslanLeanMarker_02 Auto
ObjectReference Property FS_NQ01_SC09_YuslanLeanMarker_03 Auto
ObjectReference Property FS_NQ01_SC09_YuslanLeanMarker_04 Auto
ObjectReference Property FS_NQ01_SC09_YuslanKneelMarkerREF Auto
ObjectReference Property FS_NQ01_SC10_DoorREF Auto
ObjectReference Property FS_NQ01_SC08_PortalMarkerREF Auto
ObjectReference Property FS_NQ01_SC12_YuslanMarkerREF Auto
ObjectReference Property FS_NQ01_SC12_PlayerChairMarkerREF Auto
ObjectReference Property FS_NQ01_SC05_WorldwalkerClosedREF Auto
ObjectReference Property FS_NQ01_SC12_YuslanMarker02REF Auto
ObjectReference Property FS_MQ18c_DreamflowerREF Auto
ObjectReference Property FS_NQ01_SC12_PlayerPortREF Auto
ObjectReference Property _00E_NPCDumpMarker Auto
ObjectReference Property _00E_FS_NQ01_ThalgardLever Auto
ObjectReference Property _00E_FS_NQ01_Barrier1 Auto
ObjectReference Property _00E_FS_NQ01_Barrier1Msg Auto
ObjectReference Property _00E_FS_NQ01_Barrier1Pos Auto
ObjectReference Property klosterback auto
ObjectReference Property FS_NQ01_BeamLightREF auto
ObjectReference Property FS_NQ01_PortalREF auto
ObjectReference Property FS_NQ01_LightSpawnerREF auto
ObjectReference Property FS_NQ01_YuslanSpawnBodyMarkerREF auto
ObjectReference Property _00E_SecureChest_HostChestREF auto
ObjectReference Property _00E_FS_NQ01_CellarDoor Auto

MiscObject Property Gold001 Auto
MiscObject Property _00E_FS_MQ18c_Dreamflower Auto
MiscObject Property _00E_FS_CraftingPlan_MQ18c_DreamflowerElixir Auto
MiscObject Property _00E_FS_NQ01_MG06Crystal Auto

ReferenceAlias Property SC04_FakePlayer Auto
ReferenceAlias Property SC09_LeanMarker Auto

VisualEffect Property MAGDragonPowerAbsorbManEffect Auto
VisualEffect Property MAGDragonPowerAbsorbEffect Auto
VisualEffect Property FXCameraAttachFalmerDustEffect Auto

Sound Property _00E_MQ05_MerchantDeathM Auto
Sound Property _00E_Male_PlayerHitM Auto
Sound Property _00E_Female_PlayerHitM Auto
Sound Property WPNBowDraw Auto
Sound Property MAGConjurePortal Auto
Sound Property OBJDwemerRepositoryRotateM Auto
Sound Property OBJDwemerRepositoryDoorM Auto
Sound Property MAGIllusionCharm Auto
Sound Property _00E_A2_ChaosruneImplosionSoundM Auto
Sound Property MAGDestructionBlizzard2DLP Auto
Sound Property QSTAlduinDeathExplosionA Auto
Sound Property MAGIllusionReleaseSound Auto

Spell Property _00E_FakeArrowSP Auto
Spell Property _00E_MQ11a_SC19_BlackStoneChannelBeam Auto

Message Property _00E_FS_NQ01_YuslanThought Auto
Message Property _00E_BlitzheilungArkanistenfieber_sFeverIncreased Auto
Message Property _00E_FS_NQ01_SC10_YuslanMessage Auto

Formlist Property FS_NQ01_SC12_PusBugs Auto

Faction Property IgnoreInCombatFaction Auto

Idle Property IdleMagic_01 Auto
Idle Property _00E_IdleStomp Auto
Idle Property IdleRitualStart Auto
Idle Property _00E_IdleSuicide Auto

MusicType Property _00E_FS_Special_SeaOfEventualitiesLoop Auto

Scene Property FS_NQ01_SC00_Start Auto
Scene Property FS_NQ01_SC01_ExpositionInBath Auto
Scene Property FS_NQ01_SC02_Cloister_01 Auto
Scene Property FS_NQ01_SC03_Cloister_02 Auto
Scene Property FS_NQ01_SC04_Cloister_03 Auto
Scene Property FS_NQ01_SC05_Cloister_04 Auto
Scene Property FS_NQ01_SC06_DustPit Auto
Scene Property FS_NQ01_SC07_Worldwalker_Activation Auto
Scene Property FS_NQ01_SC08_Qyra_01 Auto
Scene Property FS_NQ01_SC09_Qyra_02 Auto
Scene Property FS_NQ01_SC11_Qyra_03 Auto
Scene Property FS_NQ01_SC10_Qyra_SecretEnding Auto
Scene Property FS_NQ01_SC12_Aftermath Auto

EffectShader Property _00E_A2_GhostwalkReappear Auto
EffectShader Property _00E_FXEldritchShader03 Auto
EffectShader Property _00E_FireBlueFXS Auto
EffectShader Property EnchBlueFXShader Auto
EffectShader Property _00E_FS_Tharael_DematerializeFXS Auto

GlobalVariable Property _00E_TeleportGlobal Auto
GlobalVariable Property Timescale Auto
GlobalVariable Property _00E_FS_NQ01_RespectedYuslansWish Auto
GlobalVariable Property _00E_FS_NQ01_YuslanSecretEnding Auto
GlobalVariable Property _00E_AchievementsEnabled Auto

ImageSpaceModifier Property FadeToBlackHoldIMOD Auto
ImageSpaceModifier Property FadeToBlackIMOD Auto
ImageSpaceModifier Property FadeToBlackBackIMOD Auto
ImageSpaceModifier Property _00E_FS_NQ01_EventualityShiftIMOD Auto
ImageSpaceModifier Property IllusionBlueMassiveImod Auto