Scriptname _00E_FS_NQ02_Functions extends Quest  

Import _00E_QuestFunctions
Import Utility
Import Game

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

Function StartSC01()

	FS_NQ02_SC01_Tavern.ForceStart()
	_00E_FS_NQ02_EsmeLeorREF.Enable()

EndFunction

Function EnableGamblingTable()

	_00E_FS_NQ02_SC01_DisableMarker.Disable()
	PrepareCardgame()

EndFunction

Function DisableGamblingTable()

	_00E_FS_NQ02_SC01_DisableMarker.Enable()

EndFunction

Function StartSC02()

	FS_NQ02_SC02_Travel.ForceStart()
	_00E_MAGFXFireOilIgniteLow.Play(PlayerREF)
	_00E_FS_NQ02_SC02_FeuerActivatorREF.Enable()

EndFunction

Function GivePlayerGewuerzwein()

	Levelsystem.FadeToBlack()
	Levelsystem.FadeToBlackBack()
	PlayerREF.AddItem(FoodSolitudeSpicedWine, 1)
	SetStage(90)

EndFunction

Function InventarCheckForBook()

	_00E_SilenceLongTransitionHighPriority.Remove()
	_00E_FS_NQ02_Music_Theme.Remove()
	DisableGamblingTable()
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(1)
	If PlayerREF.GetItemCount(_00E_FS_NQ02_Passagierbuch) >= 1 ;if the player already owns the book
		PlayerREF.RemoveItem(_00E_FS_NQ02_Passagierbuch, 1, true)
		_00E_FS_NQ02_Passagierbuch_EntryREF.Enable()
		PlayerREF.AddItem(_00E_FS_NQ02_Passagierbuch_EntryREF, 1, true)
		SetStage(110)
	Else
		_00E_FS_NQ02_PassagierbuchREF.Disable()
		_00E_FS_NQ02_Passagierbuch_EntryREF.Enable()
		SetObjectiveDisplayed(30)
	EndIf

EndFunction

Function GiveEsmePassagierbuch()

	PlayerREF.RemoveItem(_00E_FS_NQ02_Passagierbuch_EntryREF, 1, false, _00E_FS_NQ02_EsmeREF)
	;PlayerREF.RemoveItem(_00E_FS_NQ02_Passagierbuch, 1, false, _00E_FS_NQ02_EsmeREF)
	;_00E_FS_NQ02_EsmeREF.AddItem(_00E_FS_NQ02_Passagierbuch, 1)

EndFunction

; called from _00E_PlayerSetUpScript on patch 1.6.0.0
Function UpdatePassengerBook()

	If GetStage() >= 5
		Passagierbuch_Entry.ForceRefTo(_00E_FS_NQ02_Passagierbuch_EntryREF as ObjectReference)
	EndIf
		
	If GetStage() >= 90 && GetStage() <= 130
		If PlayerREF.GetItemCount(_00E_FS_NQ02_Passagierbuch) >= 1
			PlayerREF.RemoveItem(_00E_FS_NQ02_Passagierbuch, 1, true)
			_00E_FS_NQ02_Passagierbuch_EntryREF.Enable()
			PlayerREF.AddItem(_00E_FS_NQ02_Passagierbuch_EntryREF, 1, true)
		Else
			_00E_FS_NQ02_Passagierbuch_EntryREF.Enable()
			_00E_FS_NQ02_PassagierbuchREF.Disable()
		EndIf
	EndIf
	
EndFunction

Function ErsteBelohnung()

	PlayerRef.AddItem(Gold001, 250)

EndFunction

Function EnableEsmeNotiz1()

	_00E_FS_NQ02_EsmeLetterREF1.Enable()

EndFunction

Function EnableEsmeNotiz2()

	_00E_FS_NQ02_EsmeLetterREF2.Enable()

EndFunction

Function MoveEsmeToBadehaus()

	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_EsmeBadehausMarker)
	_00E_FS_NQ02_EsmeLeorREF.Disable()
	_00E_FS_NQ02_EsmeREF.SetOutfit(_00E_FS_NQ02_EsmeOutfit)
	_00E_FS_NQ02_EsmeREF.Additem(_01E_07_SteelDagger, 1)
	_00E_FS_NQ02_DunkanREF.Enable()
	FS_NQ02_SC03_Badehaus.ForceStart()
	_00E_FS_NQ02_Travelbox1.Enable()
	_00E_FS_NQ02_CaravanCampfireOff.Enable()
	 ; Failsafe because they blocked Esmes way
	_00E_HundBelloFleeREF.Disable()
	_00E_CapitalCityMaraGaboffREF.Disable()
	_00E_CapitalCity_MerrelFunkenfrstREF.Disable()

EndFunction

Function DunkanExamineDisabler()

	Debug.SendAnimationEvent(_00E_FS_NQ02_DunkanREF, "IdleForceDefaultState")

EndFunction

Function StartTravelWithEsme()

	SetNPCAsCompanion(_00E_FS_NQ02_EsmeREF, True, 500, 200, 150)
	_00E_FS_NQ02_TravelState.SetValue(1.0)
	_00E_FS_NQ02_EsmeREF.EvaluatePackage()

EndFunction

Function StopTravelWithEsme()

	SetNPCAsCompanion(_00E_FS_NQ02_EsmeREF, FALSE)
	_00E_FS_NQ02_TravelState.SetValue(0.0)
	_00E_FS_NQ02_EsmeREF.EvaluatePackage()

EndFunction

Function SC03Failsafe()

	If (_00E_FS_NQ02_EsmeREF.GetDistance(_00E_FS_NQ02_SC03_EsmeMarker) > 100)
		_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC03_EsmeMarker)
	EndIf

EndFunction

Function PrepareDoorVision()

	_00E_FS_NQ02_SC03_DoorActivatorREF.Enable()
	StartTravelWithEsme()

EndFunction

Function StartDoorVision()
	
	Levelsystem.VisionEffectNoTimestop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC04_FreezeRefs)
	FS_NQ02_SC04_Vision.ForceStart()
	_00E_FS_NQ02_TaraREF.Enable()
	
	If _00E_FS_NQ02_EsmeREF.GetDistance(FS_NQ02_SC03_EsmePortMarkerREF) >= 50
		_00E_FS_NQ02_EsmeREF.MoveTo(FS_NQ02_SC03_EsmePortMarkerREF)
	EndIf
	
	If _00E_FS_NQ02_DunkanREF.GetDistance(_00E_FS_NQ02_SC03_DunkanMarker) >= 50
		_00E_FS_NQ02_DunkanREF.MoveTo(_00E_FS_NQ02_SC03_DunkanMarker)
	EndIf
	
	; _00E_FS_NQ02_EsmeREF.SetAlpha(0.0)
	; _00E_FS_NQ02_DunkanREF.SetAlpha(0.0)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.5)
	Wait(1.0)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_TaraREF)

EndFunction

Function EnableDalMercer()

	_00E_FS_NQ02_DalMercerREF.Enable()
	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.5)
	Wait(0.5)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_DalMercerREF)
	
EndFunction

Function StopDoorVision()

	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.0)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.0)
	wait(0.1)
	_00E_FS_NQ02_DalMercerREF.Disable()
	_00E_FS_NQ02_TaraREF.Disable()
	Levelsystem.VisionEffectNoTimestopStop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC04_FreezeRefs)
	FS_NQ02_SC05_AfterVision.ForceStart()
	_00E_FS_NQ02_EsmeREF.SetAlpha(1.0)
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC03_EsmeMarker)
	_00E_FS_NQ02_DunkanREF.SetAlpha(1.0)
	_00E_FS_NQ02_DunkanREF.MoveTo(_00E_FS_NQ02_SC03_DunkanMarker)

EndFunction

Function StartSC06mitDunkan()

	_00E_FS_NQ02_DalMercerDoor.Lock(false)
	FS_NQ02_SC06_mitDunkan.ForceStart()
	_00E_FS_NQ02_DunkanVar.SetValue(1)
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(0)
	StartTravelWithEsme()

EndFunction

Function StartSC06ohneDunkan()

	_00E_FS_NQ02_DalMercerDoor.Lock(false)
	FS_NQ02_SC06_ohneDunkan.ForceStart()
	_00E_FS_NQ02_DunkanVar.SetValue(0)
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(0)
	StartTravelWithEsme()

EndFunction

Function StartSC07()

	FS_NQ02_SC07_Keller.ForceStart()
	StartTravelWithEsme()

EndFunction

Function OpenKeller()

	_00E_FS_NQ02_SC07_Door.Lock(false)
	_00E_FS_NQ02_SC07_Door.SetOpen()
	StartTravelWithEsme()

EndFunction

Function SpawnElementar()

	_00E_FS_NQ02_PhasmalistREF.Enable()
	_00E_MQ11a_MagicAnomalyScreamAM.Play(PlayerREF)
	_00E_FS_NQ02_DunkanREF.Disable()
	_00E_FS_NQ02_PhasmalistREF.MoveTo(_00E_FS_NQ02_SC07_Marker3)
	_00E_FS_NQ02_EsmeREF.AddToFaction(PlayerAlliesFaction)
	_00E_FS_NQ02_EsmeREF.SetGhost(false)
	_00E_FS_NQ02_PhasmalistREF.PlaceAtMe(_00E_FS_NQ02_Phasmalist_EnterWorldExp)
	_00E_FS_NQ02_PhasmalistREF.SetAlpha(0.5)
	_00E_Phasmalist_ApparitionShaderFXS.Play(_00E_FS_NQ02_PhasmalistREF)
	wait(1.0)
	_00E_FS_NQ02_PhasmalistREF.StartCombat(PlayerREF)
	_00E_FS_NQ02_PhasmalistREF.StartCombat(_00E_FS_NQ02_EsmeREF)
	_00E_FS_NQ02_EsmeREF.StartCombat(_00E_FS_NQ02_PhasmalistREF)

EndFunction

Function EnableSchreinActivator()

	_00E_FS_NQ02_SC07_SchreinActivatorREF.Enable()
	StartTravelWithEsme()

EndFunction

Function StartSchreinVision()
	
	Levelsystem.VisionEffectNoTimestop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC08_FreezeRefs)
	FS_NQ02_SC08_Vision.ForceStart()
	_00E_FS_NQ02_DalMercerREF.MoveTo(_00E_FS_NQ02_SC08_Marker1)
	_00E_FS_NQ02_TaraREF.MoveTo(_00E_FS_NQ02_SC08_Marker2)
	_00E_FS_NQ02_TaraREF.SetOutfit(_00E_FS_NQ02_CultOutfit)
	_00E_FS_NQ02_TaraREF.Enable()
	_00E_FS_NQ02_TaraREF.SetAlpha(0.5)
	_00E_FS_NQ02_DalMercerREF.Enable()
	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.5)
	Wait(1.0)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_TaraREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_DalMercerREF)

EndFunction

Function StopSchreinVision()

	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.0)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.0)
	wait(0.1)
	_00E_FS_NQ02_DalMercerREF.Disable()
	_00E_FS_NQ02_TaraREF.Disable()
	Levelsystem.VisionEffectNoTimestopStop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC08_FreezeRefs)
	FS_NQ02_SC09_AfterVision.ForceStart()
	_00E_FS_NQ02_EsmeREF.SetAlpha(1.0)
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC07_Marker2)
	SetObjectiveDisplayed(110)
	_00E_FS_NQ02_DunkanREF.Enable()
 	_00E_FS_NQ02_DunkanREF.MoveTo(_00E_FS_NQ02_SC09_Marker1)

EndFunction

Function EnableGeheimraum()

	_00E_FS_NQ02_SC09_Hebel.Enable()

EndFunction

Function SC09Failsafe()

	_00E_FS_NQ02_DunkanREF.DrawWeapon()

	If (_00E_FS_NQ02_EsmeREF.GetDistance(_00E_FS_NQ02_SC09_Marker2) > 100)
		_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC09_Marker2)
	EndIf

EndFunction

Function DunkanFight()

	_00E_FS_NQ02_DunkanREF.setAv("Aggression", 2)
	_00E_FS_NQ02_DunkanREF.SetGhost(false)
	_00E_FS_NQ02_DunkanREF.StartCombat(PlayerREF)
	_00E_FS_NQ02_DunkanREF.StartCombat(_00E_FS_NQ02_EsmeREF)

EndFunction

Function EnableStatuette()

	_00E_FS_NQ02_StatuetteMisc.Enable()
	_00E_FS_NQ02_StatuetteMisc.SetPosition(-1115.0, -843.0, 5912.0)

EndFunction

Function RemoveStatuette()

	PlayerREF.RemoveItem(_00E_FS_NQ02_StatuetteMisc, 1)
	_00E_FS_NQ02_Travelbox1.Disable()

EndFunction

Function Timer()

	RegisterForUpdateGameTime(24)
	GameDay = GameDaysPassed.GetValue() as Int

EndFunction

Function StartSC10()

	FS_NQ02_SC10_Museum.ForceStart()
	_00E_FS_NQ02_DunkanREF.Disable()
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC10_Marker1)
	_00E_FS_NQ02_Travelbox3.Enable()
	_00E_HundBelloFleeREF.Enable()
	_00E_CapitalCityMaraGaboffREF.Enable()
	_00E_CapitalCity_MerrelFunkenfrstREF.Enable()

EndFunction

Function SC10Failsafe()

	If (_00E_FS_NQ02_EsmeREF.GetDistance(_00E_FS_NQ02_SC10_Marker3) > 1000)
		_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC10_FailsafeMarker)
	EndIf

EndFunction

Function SteintafelFound()

	Levelsystem.SetAllowIdleChatter(false)
	_00E_FS_NQ02_Travelbox3.Disable()
	Levelsystem.FadeToBlack()
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC10_Marker5)
	_00E_FS_NQ02_WaerterREF.MoveTo(_00E_FS_NQ02_SC10_Marker3)
	PlayerREF.MoveTo(_00E_FS_NQ02_SC10_Marker4)
	StopTravelWithEsme()
	Levelsystem.FadeToBlackBack()

EndFunction

Function StartSC11()

	Levelsystem.SetAllowIdleChatter(true)
	FS_NQ02_SC11_Fahlstern.ForceStart()
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC11_Marker1)
	_00E_FS_NQ02_EsmeREF.SetOutfit(_00E_FS_NQ02_EsmeArmorOutfit)
	_00E_FS_NQ02_EsmeREF.Additem(_02E_11_RuneSword, 1)

EndFunction

Function EnableSC11Travelbox()

	_00E_FS_NQ02_Travelbox5.Enable()
	_00E_FS_NQ02_Travelbox6.Enable()
	_00E_FS_NQ02_Travelbox7.Enable()
	_00E_FS_NQ02_Travelbox8.Enable()
	_00E_FS_NQ02_Travelbox9.Enable()
	_00E_FS_NQ02_Travelbox10.Enable()
	_00E_FS_NQ02_Travelbox11.Enable()
	_00E_FS_NQ02_Travelbox12.Enable()
	_00E_FS_NQ02_Travelbox13.Enable()
	_00E_FS_NQ02_Travelbox14.Enable()
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(1)
	StartTravelWithEsme()

EndFunction

Function SC11Failsafe()

	If (_00E_FS_NQ02_EsmeREF.GetDistance(_00E_FS_NQ02_FahlsternDoor) > 500)
		_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC11_Marker3)
	EndIf

EndFunction

Function SC11Failsafe2()
	
	If (_00E_FS_NQ02_EsmeREF.GetDistance(PlayerREF) > 500)
		_00E_FS_NQ02_EsmeREF.MoveTo(PlayerREF)
	EndIf
	_00E_FS_NQ02_Travelbox14.Disable()

EndFunction

Function SpawnElementar2()

	_00E_FS_NQ02_SC11_Barrier.PlaceAtMe(ExplosionRuneShock02)
	_00E_FS_NQ02_FahlsternDoor.KnockAreaEffect(1, 300)
	SpawnApparition(_00E_FS_NQ02_Phasmalist2REF)

EndFunction

Function DisableFahlsternBarrier()

	_00E_FS_NQ02_SC11_Barrier.PlaceAtMe(ExplosionRuneShock02)
	_00E_FS_NQ02_SC11_Barrier.Disable()
	_00E_FS_NQ02_Travelbox5.Disable()
	_00E_FS_NQ02_Travelbox6.Disable()
	_00E_FS_NQ02_Travelbox7.Disable()
	_00E_FS_NQ02_Travelbox8.Disable()
	_00E_FS_NQ02_Travelbox9.Disable()
	_00E_FS_NQ02_Travelbox10.Disable()
	_00E_FS_NQ02_Travelbox11.Disable()
	_00E_FS_NQ02_Travelbox12.Disable()
	_00E_FS_NQ02_Travelbox13.Disable()

EndFunction

Function OpenFahlsternDoor()

	_00E_FS_NQ02_FahlsternDoor.lock(false)
	StartTravelWithEsme()

EndFunction

Function GiveEsmeTorch()

	_00E_FS_NQ02_EsmeREF.AddItem(_00E_FS_NQ02_EsmeTorch, 1)

EndFunction

Function StartFahlsternVision1()
	
	Levelsystem.VisionEffectNoTimestop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC12_FreezeRefs, true)
	FS_NQ02_SC12_Vision.ForceStart()
	_00E_FS_NQ02_TaraREF.Enable()
	_00E_FS_NQ02_TaraREF.MoveTo(_00E_FS_NQ02_SC12_TMarker1)
	_00E_FS_NQ02_DalMercerREF.Enable()
	_00E_FS_NQ02_DalMercerREF.MoveTo(_00E_FS_NQ02_SC12_DMarker1)
	_00E_FS_NQ02_SC12_WomanREF.Enable()
	_00E_FS_NQ02_SC12_WomanREF.MoveTo(_00E_FS_NQ02_SC12_WMarker1)
	_00E_FS_NQ02_SC12_WomanREF.SetAlpha(0.5)
	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.5)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.5)
	Wait(1.0)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_TaraREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_DalMercerREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC12_WomanREF)

	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(0)
	
EndFunction

Function StopFahlsternVision1()

	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.0)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC12_WomanREF.SetAlpha(0.0)
	wait(0.1)
	_00E_FS_NQ02_DalMercerREF.Disable()
	_00E_FS_NQ02_TaraREF.Disable()
	_00E_FS_NQ02_SC12_WomanREF.Disable()
	Levelsystem.VisionEffectNoTimestopStop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC12_FreezeRefs)
	FS_NQ02_SC13_AfterVision.ForceStart()
	_00E_FS_NQ02_EsmeREF.SetAlpha(1.0)
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC13_Marker1)
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(1)

EndFunction

Function SpawnElementar3()

	_00E_FS_NQ02_Phasmalist3REF.MoveTo(_00E_FS_NQ02_SC13_Marker2)
	SpawnApparition(_00E_FS_NQ02_Phasmalist3REF)

EndFunction

Function SpawnElementar4()

	_00E_FS_NQ02_Phasmalist4REF.MoveTo(_00E_FS_NQ02_SC13_Marker4)
	SpawnApparition(_00E_FS_NQ02_Phasmalist4REF)

EndFunction

Function PrepareFahlsternVision2()

	FS_NQ02_SC14_Well.ForceStart()

EndFunction

Function StartFahlsternVision2()
	
	Levelsystem.VisionEffectNoTimestop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC14_FreezeRefs)
	_00E_FS_NQ02_SC14_WomanREF.Enable()
	_00E_FS_NQ02_SC14_WomanREF.MoveTo(_00E_FS_NQ02_SC14_WMarker)
	_00E_FS_NQ02_SC14_ManREF.Enable()
	_00E_FS_NQ02_SC14_ManREF.MoveTo(_00E_FS_NQ02_SC14_MMarker)
	_00E_FS_NQ02_SC14_ManREF.SetAlpha(0.5)
	_00E_FS_NQ02_SC14_WomanREF.SetAlpha(0.5)
	Wait(1.0)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC14_ManREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC14_WomanREF)
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(0)

EndFunction

Function StopFahlsternVision2()

	_00E_FS_NQ02_SC14_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC14_ManREF.SetAlpha(0.0)
	Wait(0.1)
	_00E_FS_NQ02_SC14_WomanREF.Disable()
	_00E_FS_NQ02_SC14_ManREF.Disable()
	Levelsystem.VisionEffectNoTimestopStop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC14_FreezeRefs)
	_00E_FS_NQ02_EsmeREF.SetAlpha(1.0)
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC14_EMarker)
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(1)

EndFunction

Function EnableSC15()

	_00E_FS_NQ02_SC15_Barrier.Disable()
	StartTravelWithEsme()

EndFunction

Function SpawnApparition(Actor akApparition)

	akApparition.Enable()
	_00E_MQ11a_MagicAnomalyScreamAM.Play(PlayerREF)
	akApparition.PlaceAtMe(_00E_FS_NQ02_Phasmalist_EnterWorldExp)
	akApparition.SetAlpha(0.5)
	_00E_Phasmalist_ApparitionShaderFXS.Play(akApparition)
	wait(1.0)
	akApparition.StartCombat(PlayerREF)
	akApparition.StartCombat(_00E_FS_NQ02_EsmeREF)
	_00E_FS_NQ02_EsmeREF.StartCombat(akApparition)

EndFunction

Function SpawnElementar5()

	_00E_FS_NQ02_Phasmalist5REF.MoveTo(_00E_FS_NQ02_SC13_Marker5)
	SpawnApparition(_00E_FS_NQ02_Phasmalist5REF)

EndFunction

Function PrepareFahlsternVision3()

	FS_NQ02_SC15_Granary.ForceStart()
	_00E_FS_NQ02_SC12_WomanREF.Enable()
	_00E_FS_NQ02_SC12_WomanREF.MoveTo(_00E_FS_NQ02_SC15_Marker1)
	_00E_FS_NQ02_SC12_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_DalMercerREF.Enable()
	_00E_FS_NQ02_DalMercerREF.MoveTo(_00E_FS_NQ02_SC15_Marker2)
	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.0)
	_00E_FS_NQ02_TaraREF.Enable()
	_00E_FS_NQ02_TaraREF.MoveTo(_00E_FS_NQ02_SC15_Marker3)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC14_WomanREF.Enable()
	_00E_FS_NQ02_SC14_WomanREF.MoveTo(_00E_FS_NQ02_SC15_Marker4)
	_00E_FS_NQ02_SC14_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC15_WomanREF.Enable()
	_00E_FS_NQ02_SC15_WomanREF.MoveTo(_00E_FS_NQ02_SC15_Marker5)
	_00E_FS_NQ02_SC15_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC14_ManREF.Enable()
	_00E_FS_NQ02_SC14_ManREF.MoveTo(_00E_FS_NQ02_SC15_Marker6)
	_00E_FS_NQ02_SC14_ManREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC15_ManREF.Enable()
	_00E_FS_NQ02_SC15_ManREF.MoveTo(_00E_FS_NQ02_SC15_Marker7)
	_00E_FS_NQ02_SC15_ManREF.SetAlpha(0.0)

EndFunction

Function StartFahlsternVision3()
	
	Levelsystem.VisionEffectNoTimestop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC15_FreezeRefs)
	_00E_FS_NQ02_CandleMarker.Enable()
	_00E_FS_NQ02_SC12_WomanREF.SetAlpha(1.0)
	_00E_FS_NQ02_DalMercerREF.SetAlpha(1.0)
	_00E_FS_NQ02_TaraREF.SetAlpha(1.0)
	_00E_FS_NQ02_SC14_WomanREF.SetAlpha(1.0)
	_00E_FS_NQ02_SC15_WomanREF.SetAlpha(1.0)
	_00E_FS_NQ02_SC14_ManREF.SetAlpha(1.0)
	_00E_FS_NQ02_SC15_ManREF.SetAlpha(1.0)
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(0)
	_00E_FS_NQ02_SC14_ManREF.SetAlpha(0.5)
	_00E_FS_NQ02_SC14_WomanREF.SetAlpha(0.5)
	_00E_FS_NQ02_SC12_WomanREF.SetAlpha(0.5)
	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.5)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.5)
	_00E_FS_NQ02_SC15_WomanREF.SetAlpha(0.5)
	_00E_FS_NQ02_SC15_ManREF.SetAlpha(0.5)
	Wait(1.0)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC14_ManREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC14_WomanREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC12_WomanREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_DalMercerREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_TaraREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC15_WomanREF)
	MS04MemoryFXBody01VFX.Play(_00E_FS_NQ02_SC15_ManREF)

EndFunction

Function SC15Failsafe()

	If _00E_FS_NQ02_SC15_WomanREF.GetDistance(_00E_FS_NQ02_SC15_Marker7) > 30
		_00E_FS_NQ02_SC15_WomanREF.MoveTo(_00E_FS_NQ02_SC15_Marker7)
	EndIf

	If _00E_FS_NQ02_SC15_ManREF.GetDistance(_00E_FS_NQ02_SC15_Marker5) > 30
		_00E_FS_NQ02_SC15_ManREF.MoveTo(_00E_FS_NQ02_SC15_Marker5)
	EndIf

EndFunction

Function StopFahlsternVision3()

	_00E_FS_NQ02_SC12_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_DalMercerREF.SetAlpha(0.0)
	_00E_FS_NQ02_TaraREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC14_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC15_WomanREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC14_ManREF.SetAlpha(0.0)
	_00E_FS_NQ02_SC15_ManREF.SetAlpha(0.0)
	_00E_FS_NQ02_EsmeREF.MoveTo(_00E_FS_NQ02_SC15_EsmeMarker)
	wait(0.1)
	_00E_FS_NQ02_SC12_WomanREF.Disable()
	_00E_FS_NQ02_DalMercerREF.Disable()
	_00E_FS_NQ02_TaraREF.Disable()
	_00E_FS_NQ02_SC14_WomanREF.Disable()
	_00E_FS_NQ02_SC15_WomanREF.Disable()
	_00E_FS_NQ02_SC14_ManREF.Disable()
	_00E_FS_NQ02_SC15_ManREF.Disable()
	_00E_FS_NQ02_CandleMarker.Disable()
	Levelsystem.VisionEffectNoTimestopStop(_00E_FS_NQ02_VisionRefs, _00E_FS_NQ02_SC15_FreezeRefs)
	_00E_FS_NQ02_EsmeREF.SetAlpha(1.0)
	_00E_FS_NQ02_EsmeMiscTalkVar.SetValue(1)

EndFunction

Function SC15FadeOutIn()

	Levelsystem.FadeToBlack()
	Levelsystem.FadeToBlackBack()

EndFunction

Function DisableFahlsternWall()

	Levelsystem.SetAllowIdleChatter(true)
	_00E_FS_NQ02_SC15_Wall.Disable()
	StartTravelWithEsme()	

EndFunction

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

Event OnUpdateGameTime() ; because of how we registered, this event occurs every 30 minutes of game time    

	If (GameDaysPassed.GetValue() + 1 >= GameDay)
		SetStage(GetStage()+10)
		UnregisterForUpdateGameTime()
	EndIf

EndEvent

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

int GameDay

_00E_QuestFunctions Property Levelsystem Auto

Quest Property FS_NQ02 Auto

Actor Property _00E_FS_NQ02_EsmeREF Auto
Actor Property _00E_FS_NQ02_EsmeLeorREF Auto
Actor Property _00E_FS_NQ02_DunkanREF Auto
Actor Property PlayerREF Auto
Actor Property _00E_FS_NQ02_TaraREF Auto
Actor Property _00E_FS_NQ02_DalMercerREF Auto
Actor Property _00E_FS_NQ02_PhasmalistREF Auto
Actor Property _00E_FS_NQ02_Phasmalist2REF Auto
Actor Property _00E_FS_NQ02_Phasmalist3REF Auto
Actor Property _00E_FS_NQ02_Phasmalist4REF Auto
Actor Property _00E_FS_NQ02_Phasmalist5REF Auto
Actor Property _00E_FS_NQ02_WaerterREF Auto
Actor Property _00E_FS_NQ02_SC12_WomanREF Auto
Actor Property _00E_FS_NQ02_SC14_WomanREF Auto
Actor Property _00E_FS_NQ02_SC14_ManREF Auto
Actor Property _00E_FS_NQ02_SC15_WomanREF Auto
Actor Property _00E_FS_NQ02_SC15_ManREF Auto
Actor Property _00E_HundBelloFleeREF Auto
Actor Property _00E_CapitalCityMaraGaboffREF Auto
Actor Property _00E_CapitalCity_MerrelFunkenfrstREF Auto

Armor Property _00E_TravellingMageArmor_Scarf Auto

Book Property _00E_FS_NQ02_Passagierbuch Auto
Book Property _00E_FS_NQ02_Passagierbuch_Entry Auto

Explosion Property _00E_FS_NQ02_Phasmalist_AppearExp Auto
Explosion Property _00E_FS_NQ02_Phasmalist_EnterWorldExp Auto
Explosion Property ExplosionRuneShock02 Auto

Faction Property PlayerAlliesFaction Auto

Formlist Property _00E_FS_NQ02_VisionRefs Auto
Formlist Property _00E_FS_NQ02_SC04_FreezeRefs Auto
Formlist Property _00E_FS_NQ02_SC08_FreezeRefs Auto
Formlist Property _00E_FS_NQ02_SC12_FreezeRefs Auto
Formlist Property _00E_FS_NQ02_SC14_FreezeRefs Auto
Formlist Property _00E_FS_NQ02_SC15_FreezeRefs Auto

GlobalVariable Property _00E_FS_NQ02_DunkanVar Auto
GlobalVariable Property GameDaysPassed Auto
GlobalVariable Property _00E_FS_NQ02_TravelState Auto
GlobalVariable Property _00E_FS_NQ02_EsmeMiscTalkVar Auto

Light Property _00E_FS_NQ02_EsmeTorch Auto

MusicType Property _00E_SilenceLongTransitionHighPriority Auto
MusicType Property _00E_FS_NQ02_Music_Theme Auto

ObjectReference Property _00E_FS_NQ02_SC01_DisableMarker Auto
ObjectReference Property _00E_FS_NQ02_EsmeChairREF Auto
ObjectReference Property _00E_FS_NQ02_PlayerChairREF Auto
ObjectReference Property _00E_FS_NQ02_SC02_FeuerActivatorREF Auto
ObjectReference Property _00E_FS_NQ02_EsmeLetterREF1 Auto
ObjectReference Property _00E_FS_NQ02_EsmeLetterREF2 Auto
ObjectReference Property _00E_FS_NQ02_EsmeBadehausMarker Auto
ObjectReference Property _00E_FS_NQ02_SC1_SoeldnerTavernMarker Auto
ObjectReference Property _00E_FS_NQ02_SC03_DoorActivatorREF Auto
ObjectReference Property _00E_FS_NQ02_SC03_EsmeMarker Auto
ObjectReference Property _00E_FS_NQ02_SC03_DunkanMarker Auto
ObjectReference Property _00E_FS_NQ02_DalMercerDoor Auto
ObjectReference Property _00E_FS_NQ02_SC07_Door Auto
ObjectReference Property _00E_FS_NQ02_SC07_Marker2 Auto
ObjectReference Property _00E_FS_NQ02_SC07_Marker3 Auto
ObjectReference Property _00E_FS_NQ02_SC07_SchreinActivatorREF Auto
ObjectReference Property _00E_FS_NQ02_SC08_Marker1 Auto
ObjectReference Property _00E_FS_NQ02_SC08_Marker2 Auto
ObjectReference Property _00E_FS_NQ02_SC09_Marker1 Auto
ObjectReference Property _00E_FS_NQ02_SC09_Marker2 Auto
ObjectReference Property _00E_FS_NQ02_SC09_Hebel Auto
ObjectReference Property _00E_FS_NQ02_StatuetteMisc Auto
ObjectReference Property _00E_FS_NQ02_SC10_Marker1 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox1 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox3 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox5 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox6 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox7 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox8 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox9 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox10 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox11 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox12 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox13 Auto
ObjectReference Property _00E_FS_NQ02_Travelbox14 Auto
ObjectReference Property _00E_FS_NQ02_SC10_Marker3 Auto
ObjectReference Property _00E_FS_NQ02_SC10_FailsafeMarker Auto
ObjectReference Property _00E_FS_NQ02_SC10_Marker4 Auto
ObjectReference Property _00E_FS_NQ02_SC10_Marker5 Auto
ObjectReference Property _00E_FS_NQ02_SC11_Marker1 Auto
ObjectReference Property _00E_FS_NQ02_SC11_Marker2 Auto
ObjectReference Property _00E_FS_NQ02_SC11_Barrier Auto
ObjectReference Property _00E_FS_NQ02_FahlsternDoor Auto
ObjectReference Property _00E_FS_NQ02_SC11_Marker3 Auto
ObjectReference Property _00E_FS_NQ02_SC12_TMarker1 Auto
ObjectReference Property _00E_FS_NQ02_SC12_DMarker1 Auto
ObjectReference Property _00E_FS_NQ02_SC12_WMarker1 Auto
ObjectReference Property _00E_FS_NQ02_SC13_Marker1 Auto
ObjectReference Property _00E_FS_NQ02_SC13_Marker2 Auto
ObjectReference Property _00E_FS_NQ02_SC13_Marker4 Auto
ObjectReference Property _00E_FS_NQ02_SC13_Marker5 Auto
ObjectReference Property _00E_FS_NQ02_SC14_WMarker Auto
ObjectReference Property _00E_FS_NQ02_SC14_MMarker Auto
ObjectReference Property _00E_FS_NQ02_SC14_EMarker Auto
ObjectReference Property _00E_FS_NQ02_SC15_Barrier Auto
ObjectReference Property _00E_FS_NQ02_SC15_Marker1 Auto
ObjectReference Property _00E_FS_NQ02_SC15_Marker2 Auto
ObjectReference Property _00E_FS_NQ02_SC15_Marker3 Auto
ObjectReference Property _00E_FS_NQ02_SC15_Marker4 Auto
ObjectReference Property _00E_FS_NQ02_SC15_Marker5 Auto
ObjectReference Property _00E_FS_NQ02_SC15_Marker6 Auto
ObjectReference Property _00E_FS_NQ02_SC15_Marker7 Auto
ObjectReference Property _00E_FS_NQ02_SC15_EsmeMarker Auto
ObjectReference Property _00E_FS_NQ02_SC15_Wall Auto
ObjectReference Property _00E_FS_NQ02_CaravanCampfireOff Auto
ObjectReference Property _00E_FS_NQ02_CandleMarker Auto
ObjectReference Property FS_NQ02_SC03_EsmePortMarkerREF Auto
ObjectReference Property _00E_FS_NQ02_Passagierbuch_EntryREF Auto
ObjectReference Property _00E_FS_NQ02_PassagierbuchREF Auto

Outfit Property _00E_FS_NQ02_EsmeArmorOutfit Auto
Outfit Property _00E_FS_NQ02_EsmeOutfit Auto
Outfit Property _00E_FS_NQ02_CultOutfit Auto

Potion Property FoodSolitudeSpicedWine Auto

ReferenceAlias Property Passagierbuch_Entry Auto

Scene Property FS_NQ02_SC01_Tavern Auto
Scene Property FS_NQ02_SC02_Travel Auto
Scene Property FS_NQ02_SC03_Badehaus Auto
Scene Property FS_NQ02_SC04_Vision Auto
Scene Property FS_NQ02_SC05_AfterVision Auto
Scene Property FS_NQ02_SC06_mitDunkan Auto
Scene Property FS_NQ02_SC06_ohneDunkan Auto
Scene Property FS_NQ02_SC07_Keller Auto
Scene Property FS_NQ02_SC08_Vision Auto
Scene Property FS_NQ02_SC09_AfterVision Auto
Scene Property FS_NQ02_SC10_Museum Auto
Scene Property FS_NQ02_SC11_Fahlstern Auto
Scene Property FS_NQ02_SC12_Vision Auto
Scene Property FS_NQ02_SC13_AfterVision Auto
Scene Property FS_NQ02_SC14_Well Auto
Scene Property FS_NQ02_SC15_Granary Auto

Weapon Property _02E_11_RuneSword Auto
Weapon Property _01E_07_SteelDagger Auto


;=====================================================================================
;                                       CARDGAME - FUNCTIONS                                        
;=====================================================================================

Function PrepareCardgame()

	If PlayerRef.GetItemCount(Gold001)<20; Failsafe, falls Player kein Gold hat
		PlayerRef.AddItem(Gold001, 20, true)
	EndIf
	
	If _00E_FS_NQ02_EsmeREF.GetItemCount(Gold001)<20 ; Failsafe, falls Esme kein Gold hat
		_00E_FS_NQ02_EsmeREF.AddItem(Gold001, 20, true)
	EndIf
	OpenCardInterface()
	;CardgameVar1 = 1 -> Spiel 1 gewonnen
	;CardgameVar1 = 2 -> Spiel 1 verloren
	;CardgameVar1 = 3 -> Spiel 1 unentschieden

	;CardgameVar2 = 1 -> Beide Spiele gewonnen
	;CardgameVar2 = 2 -> Ein Spiel verloren, ein Spiel gewonnen oder beide Spiele unentschieden
	;CardgameVar2 = 3 -> Ein Spiel unentschieden, ein Spiel gewonnen
	;CardgameVar2 = 4 -> Ein Spiel unentschieden, ein Spiel verloren
	;CardgameVar2 = 5 -> Beide Spiele verloren

EndFunction

Function OpenCardInterface()

	s_chargeninitialtext = GetGameSettingString("sCharGenControlsDisabled")
	SetGameSettingString("sCharGenControlsDisabled","")
	DisablePlayerControls(abMovement = true, abFighting = true, abCamSwitch =true, abLooking = true, abSneaking = true, abMenu = false, abActivate = true, abJournalTabs = false, aiDisablePOVType =  0)
	ForceFirstPerson()
	Commentator.GetActorBase().SetVoiceType(_00E_FS_NQ02_EsmeREF.GetVoiceType())
	Commentator.SetName(_00E_FS_NQ02_EsmeREF.GetDisplayName())
	Commentator.SetDisplayName(_00E_FS_NQ02_EsmeREF.GetDisplayName(), true)
	SetInChargen(abDisableSaving = true, abDisableWaiting = true, abShowControlsDisabledMessage = true)
	Wait(0.3)
	PlayerRef.MoveTo(Cameraman)

	Wait(1)
	PlayCards()
    
EndFunction

Function PlayCards()
	Step01()
EndFunction

int Function Step01() ; place your bet
	; need to calculate the max bet first
	If _00E_FS_NQ02_EsmeREF.GetItemCount(Gold001) > PlayerRef.GetItemCount(Gold001)
		MaxBet = (PlayerRef.GetItemCount(Gold001))/2
	ElseIf _00E_FS_NQ02_EsmeREF.GetItemCount(Gold001) < PlayerRef.GetItemCount(Gold001)
		MaxBet = (_00E_FS_NQ02_EsmeREF.GetItemCount(Gold001))/2
	Else
		MaxBet = (PlayerRef.GetItemCount(Gold001))/2
	EndIf
	PlayerBet = (((self as QUEST) as FORM) as UILIB_1).ShowTextInput(PlaceYourBet .GetName()+MaxBet, MaxBet) as int
	If PlayerBet > MaxBet || PlayerBet == 0
		Step01()
		RETURN 0
	EndIf
	PlayerPurse.EnableNoWait(true)
	OpponentBet = RandomInt(PlayerBet +(-3) , PlayerBet +5)
	If OpponentBet <= 0
		OpponentBet = PlayerBet
	EndIf
	GlobalBet = OpponentBet + PlayerBet
	_00E_FS_NQ02_PC_BetMessage.Show(PlayerBet, OpponentBet, GlobalBet)
	EnemyPurse.EnableNoWait(true)
	RegisterForKey(14)
	RegisterForKey(271) 
	Step02()
	Return PlayerBet
EndFunction

Function Step02() ; take player's cards
	PCardLeft = RandomInt(0, 9)
	PCardMiddle = RandomInt(0, 9)
	PCardRight = RandomInt(0, 9)
	totalplayer = 3 + PCardLeft + PCardMiddle + PCardRight
	int BoostPrice = (PlayerBet*45)/100
	Wait(2.0)
	CardFlip.Play(PlayerRef)
	PlayersLeft[PCardLeft].EnableNoWait(true)
	Wait(2)
	CardFlip.Play(PlayerRef)
	PlayersRight[PCardRight].EnableNoWait(true)
	Wait(2)
	CardFlip.Play(PlayerRef)
	PlayersMiddle[PCardMiddle].EnableNoWait(true)
	Wait(2)
	totalplayer = 3 + PCardLeft + PCardMiddle + PCardRight ;update+utility.wait in case the player cheated or was caught cheating
	PlayerScore.Show(totalplayer)
	int choicedices = _00E_FS_NQ02_PC_ThrowDices.Show(BoostPrice)
	If ChoiceDices == 0
		_00E_TavernGames_DiceRollM.Play(PlayerRef)
		Wait(0.75)
		int Dices = RandomInt(2, 12)
		PlayerDice01 = RandomInt(1,6)
		PlayerDice02 = RandomInt(1,6)
		Dices = PlayerDice01 +PlayerDice02
		PlayerDiceGroup01[PlayerDice01+(-1)].Enable(true)
		PlayerDiceGroup02[PlayerDice02+(-1)].Enable(true)
		totalplayer = totalplayer + Dices
		PlayerRef.RemoveItem(Gold001, BoostPrice, false, _00E_FS_NQ02_EsmeREF)
		_00E_FS_NQ02_PC_DicesResult.Show(Dices, totalplayer)
	EndIf
	Step03()
EndFunction

Function Step03() ; take opponent's cards
	Wait(1.5)
	ECardLeft = RandomInt(0, 9)
	ECardRight = RandomInt(0, 9)
	ECardMiddle = RandomInt(0, 9)
	totalEnemy = 3 + ECardLeft + EcardRight + EcardMiddle
	int EBoostPrice = (OpponentBet*45)/100
	int EnemyDices = RandomInt(2, 12)
	OpponentDice01 = RandomInt(1,6)
	OpponentDice02 = RandomInt(1,6)
	EnemyDices = OpponentDice01 + OpponentDice02
	CardFlip.Play(PlayerRef)
	EnemyMiddle[ECardMiddle].EnableNoWait(true)
	Wait(2)
	CardFlip.Play(PlayerRef)
	EnemyRight[ECardRight].EnableNoWait(true)
	Wait(2)
	CardFlip.Play(PlayerRef)
	EnemyLeft[ECardLeft].EnableNoWait(true)
	Wait(2.0)
	If totalEnemy > totalplayer
		_00E_FS_NQ02_PC_EnemyResult.Show(totalEnemy)
	ElseIf totalEnemy + 11 >= totalplayer
        _00E_TavernGames_DiceRollM.Play(PlayerRef)
        Wait(0.75)
        OpponentDiceGroup01[OpponentDice01+(-1)].Enable(true)
        OpponentDiceGroup02[OpponentDice02+(-1)].Enable(true)
        _00E_FS_NQ02_PC_EnemyDicesResult.Show(totalEnemy, EnemyDices, EBoostPrice)
        _00E_FS_NQ02_EsmeREF.RemoveItem(Gold001, EBoostPrice, false, PlayerRef)
		totalEnemy = totalEnemy + EnemyDices
	Else
		_00E_FS_NQ02_PC_EnemyResult.Show(totalEnemy)
	EndIf
	Step04()
EndFunction

Function Step04() ; check who won

	If totalEnemy > totalPlayer
		_00E_FS_NQ02_PC_EnemyWon.Show(totalplayer, totalEnemy, GlobalBet)
		PlayerRef.RemoveItem(Gold001, PlayerBet, false, _00E_FS_NQ02_EsmeREF)
		LostGames.Value += 1
		LostBets.Value += GlobalBet
		If _00E_FS_NQ02_CardgameVar1.GetValue() == 0
			_00E_FS_NQ02_CardgameVar1.SetValue(2)
		ElseIf _00E_FS_NQ02_CardgameVar1.GetValue() == 1
			_00E_FS_NQ02_CardgameVar2.SetValue(2)
		ElseIf _00E_FS_NQ02_CardgameVar1.GetValue() == 2
			_00E_FS_NQ02_CardgameVar2.SetValue(5)
		ElseIf _00E_FS_NQ02_CardgameVar1.GetValue() == 3
			_00E_FS_NQ02_CardgameVar2.SetValue(4)
		EndIf
		Wait(4)
	ElseIf totalEnemy < totalPlayer
		_SAG_PC_Victory_MT.Add()
		_00E_FS_NQ02_PC_PlayerWon.Show(totalplayer, totalEnemy, GlobalBet)
		_00E_FS_NQ02_EsmeREF.RemoveItem(Gold001, OpponentBet, false, PlayerRef)
		WonGames.Value += 1
		WonBets.Value += GlobalBet
		If _00E_FS_NQ02_CardgameVar1.GetValue() == 0
			_00E_FS_NQ02_CardgameVar1.SetValue(1)
		ElseIf _00E_FS_NQ02_CardgameVar1.GetValue() == 1
			_00E_FS_NQ02_CardgameVar2.SetValue(1)
		ElseIf _00E_FS_NQ02_CardgameVar1.GetValue() == 2
			_00E_FS_NQ02_CardgameVar2.SetValue(2)	
		ElseIf _00E_FS_NQ02_CardgameVar1.GetValue() == 3
			_00E_FS_NQ02_CardgameVar2.SetValue(3)	
		EndIf
		Wait(4)
	ElseIf totalEnemy == totalPlayer
		_00E_FS_NQ02_PC_NoOneWon.Show(totalplayer, totalEnemy)  
		ExAequo.Value += 1
		If _00E_FS_NQ02_CardgameVar1.GetValue() == 0
			_00E_FS_NQ02_CardgameVar1.SetValue(3)
		ElseIf _00E_FS_NQ02_CardgameVar1.GetValue() == 1
			_00E_FS_NQ02_CardgameVar2.SetValue(3)
		ElseIf _00E_FS_NQ02_CardgameVar1.GetValue() == 2
			_00E_FS_NQ02_CardgameVar2.SetValue(4)	
		ElseIf _00E_FS_NQ02_CardgameVar1.GetValue() == 3
			_00E_FS_NQ02_CardgameVar2.SetValue(2)	
		EndIf
		Wait(4)
	EndIf
	FinishGameAndClearUp()

EndFunction

Function FinishGameAndClearUp()

	PlayerDiceGroup01[PlayerDice01+(-1)].Disable(false)
	PlayerDiceGroup02[PlayerDice02+(-1)].Disable(false)
	OpponentDiceGroup01[OpponentDice01+(-1)].Disable(false)
	OpponentDiceGroup02[OpponentDice02+(-1)].Disable(false)
	PlayersLeft[PCardLeft].Disable(FALSE)
	PlayersRight[PCardRight].Disable(false)
	PlayersMiddle[PCardMiddle].Disable(false)
	EnemyLeft[ECardLeft].Disable(false)
	EnemyRight[ECardRight].Disable(false)
	EnemyMiddle[ECardMiddle].Disable(false)
	EnemyPurse.Disable(false)
	PlayerPurse.Disable(false)
	_SAG_PC_Victory_MT.Remove()
	playerbet = 0
	opponentbet = 0
	globalbet = 0
	totalplayer = 0
	totalenemy = 0
    
	SetStage(GetStage()+5)
	PlayerREF.MoveTo(_00E_FS_NQ02_PlayerChairREF)

	EnablePlayerControls()
	SetGameSettingString("sCharGenControlsDisabled", s_chargeninitialtext)
	SetInChargen(abDisableSaving = false, abDisableWaiting = true, abShowControlsDisabledMessage = false)
    
EndFunction

;=====================================================================================
;                                       CARDGAME - PROPERTIES                                       
;=====================================================================================

String s_chargeninitialtext

Int TotalEnemy = 0
Int OpponentBet = 0
Int MaxBet = 0
Int Property TotalPlayer = 0 Auto
Int GlobalBet = 0
Int Property PlayerBet = 0 Auto

Int PlayerDice01
Int PlayerDice02

Int ReplacedCard

Int ECardMiddle
Int ECardLeft
Int ECardRight
Int PCardMiddle
Int PCardLeft
Int PCardRight

Int PCardLeftBeforeCheat
Int PCardMiddleBeforeCheat
Int PCardRightBeforeCheat

Int OpponentDice01
Int OpponentDice02

Spell Property dunReanimateSelf Auto

Actor Property Commentator Auto

Message Property PlaceYourBet  Auto

GlobalVariable Property ExAequo Auto
GlobalVariable Property WonGames  Auto
GlobalVariable Property LostGames Auto
GlobalVariable Property LostBets Auto
GlobalVariable Property WonBets Auto
GlobalVariable Property _00E_FS_NQ02_CardgameVar1 Auto
GlobalVariable Property _00E_FS_NQ02_CardgameVar2 Auto

VisualEffect Property MS04MemoryFXBody01VFX Auto

Message Property PlayerScore Auto
Message Property _00E_FS_NQ02_PC_DicesResult Auto
Message Property _00E_FS_NQ02_PC_ThrowDices Auto
Message Property _00E_FS_NQ02_PC_BetMessage Auto
Message Property _00E_FS_NQ02_PC_EnemyDicesResult Auto
Message Property _00E_FS_NQ02_PC_EnemyResult Auto
Message Property _00E_FS_NQ02_PC_PlayerWon Auto
Message Property _00E_FS_NQ02_PC_EnemyWon Auto
Message Property _00E_FS_NQ02_PC_NoOneWon Auto

ObjectReference Property EnemyPurse Auto
ObjectReference Property PlayerPurse Auto
ObjectReference Property Cameraman Auto
ObjectReference Property PlayCards_ThiefShouter Auto
ObjectReference Property CommentatorMoveToREF Auto

;PLAYER CARDS
ObjectReference[] Property PlayersLeft Auto
ObjectReference[] Property PlayersMiddle Auto
ObjectReference[] Property PlayersRight Auto

; OPPONENT CARDS
ObjectReference[] Property EnemyLeft Auto
ObjectReference[] Property EnemyMiddle Auto
ObjectReference[] Property EnemyRight Auto

ObjectReference[] Property PlayerDiceGroup01 Auto
ObjectReference[] Property PlayerDiceGroup02 Auto

ObjectReference[] Property OpponentDiceGroup01 Auto
ObjectReference[] Property OpponentDiceGroup02 Auto

MusicType Property _SAG_PC_Victory_MT Auto

EffectShader Property _00E_Phasmalist_ApparitionShaderFXS Auto

Sound Property CardFlip Auto
Sound Property _00E_MQ11a_MagicAnomalyScreamAM Auto
Sound Property _00E_TavernGames_ThiefShoutM Auto
Sound Property _00E_TavernGames_DiceRollM Auto
Sound Property _00E_MAGFXFireOilIgniteLow Auto
Sound Property _00E_FS_Phasmalist_EnterWorld_Male Auto

MiscObject Property Gold001 Auto