Scriptname _00E_MQP01_Functions extends Quest  

Import Utility

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

Function SetUpScene()

	;Game.RequestAutoSave()
	Game.FadeOutGame(false, true, 0.5, 0.5)
	;Self.SetObjectiveDisplayed(5, false)
	FadeToBlackHoldIMOD.Apply()
	PlayerREF.SetScale(0.85)
	TimeScale.SetValue(0.1)
	GameHour.SetValue(18.5)
	Game.ForceFirstPerson()
	Game.DisablePlayerControls(false, true, true, false, true, false, false)
	FadeToBlackBackImod.Apply()
	FadeToBlackHoldIMOD.Remove()
	MQP01_DreamDoorREF.BlockActivation(True)
	Wait(5.0)
	Game.EnablePlayerControls()
	Game.DisablePlayerControls(false, true, true, false, true, false, false)

	Bool bFS = (Game.GetModByName("Enderal - Forgotten Stories.esm") != 255)
	Bool bSkyUI = (Game.GetModByName("SkyUI_SE.esp") != 255)
	If bFS == False && bSkyUI == False
		Debug.MessageBox("Enderal - Forgotten Stories.esm and SkyUI_SE.esp are not loaded! The game will not run properly. Open Data Files and enable them.")
		Game.QuitToMainMenu()
		Return
	ElseIf bFS == False
		Debug.MessageBox("Enderal - Forgotten Stories.esm is not loaded! The game will not run properly. Open Data Files and enable it.")
		Game.QuitToMainMenu()
		Return
	ElseIf bSkyUI == False
		Debug.MessageBox("SkyUI_SE.esp is not loaded! The game will not run properly. Open Data Files and enable it.")
		Game.QuitToMainMenu()
		Return
	EndIf

	Wait(1.0)
	_00E_MQP01_Thoughts01.ShowAsHelpMessage("Empty", 5, 1, 1)

EndFunction

Function UnlockDoor()

	MQP01_DreamDoorREF.Lock(False)
	MQP01_DreamDoorREF.BlockActivation(False)
	
EndFunction

Function UnblockDoor()

	MQP01_DreamDoorREF.BlockActivation(False)

EndFunction

Function ArriveInHouse()

	_00E_MQP01_InfantLaughing.Play(PlayerREF)
	TimeScale.SetValue(450)
	RegisterForSingleUpdate(1)

EndFunction

Function SC01_FatherFailsave()

	Game.DisablePlayerControls()

	if MQP01_FatherREF.GetDistance(MQP01_SC1_FatherArriveMarker) >= 75 
		MQP01_FatherREF.MoveTo(MQP01_SC1_FatherArriveMarker)
	EndIf

EndFunction

Function StartFatherWhistleScene()

	Game.DisablePlayerControls()
	MQP01_FatherREF.MoveTo(MQP01_SC1_FatherStartWalkingMarker)
	MQP01_SC1_FatherArrivesInKitchen.ForceStart()
	
EndFunction

Function StopMusic()

	_00E_SilenceTransitionHighPriority.Add()

EndFunction

Function  StartFatherAccuseScene()
	
	if PlayerREF.GetDistance(MQP01_SC01_PlayerWalkMarker) >= 55
		PlayerREF.TranslateToRef(MQP01_SC01_PlayerWalkMarker, 50, 50)
	EndIf
	
	AudioCategoryAMBr.SetVolume(__Config_MuteAmbienceVolume)
	AudioCategoryAMB.SetVolume(__Config_MuteAmbienceVolume)
	AudioCategorySFX.SetVolume(__Config_MuteAmbienceVolume)
	AudioCategoryMUS.SetVolume(3.25)
	AudioCategoryVOCGeneral.SetVolume(7.5)
	_00E_Music_Special_Dreams.Remove()
	_00E_SilenceTransitionHighPriority.Remove()
	_00E_Music_Special_MQP01_BuildUp.Add()
	FireSound = FXFireEmbers02LP.Play(PlayerREF)
	MQP01_SC2_EmbersEffect01.Enable()
	MQP01_SC2_FatherAccusesThePlayer.ForceStart()
	
EndFunction

Function StartFire()

	Game.ShakeCamera()
	ExplosionToDisable00 = MQP01_SC2_ExplosionSpawnMarker.PlaceAtMe(_00E_HarmlessFireExplosion, 1)
	ExplosionToDisable01 = MQP01_FatherREF.PlaceAtMe(_00E_MQP01_IntenseFire, 1)
	MAGFireBallExpImod.Apply()
	MQP01_SC2_FireREF03.EnableNoWait()
	MQP01_SC2_FireREF04.EnableNoWait()
	MAGDestructionFireStormExplosionM.Play(PlayerREF)
	Wait(0.5)
	Game.ShakeCamera(afStrength = 0.7)
	MQP01_SC2_FireREF05.EnableNoWait()
	MQP01_SC2_FireREF06.EnableNoWait()
	MAGDestructionFireballExplosionM.Play(PlayerREF)
	FireFXShader.Play(MQP01_FatherRef)
	FireFXShader.Play(MQP01_SC02_Elk)
	Wait(0.5)
	BFXFireImod.Apply()
	MAGFirebolt03Fire.Play(PlayerREF)
	Game.ShakeCamera(afStrength = 0.1)
	MQP01_SC2_FireREF01.EnableNoWait()
	MQP01_SC2_FireREF02.EnableNoWait()
	_00E_MAGFXFireOilIgniteLow.Play(PlayerREF)
	MQP01_SC2_SmokeREF01.EnableNoWait()
	MQP01_SC2_EmbersEffect02.EnableNoWait()

EndFunction

Function FatherStartFeeding()

	_00E_MQP01_DevourElkM.Play(PlayerREF)
	MQP01_FatherREF.SetAnimationVariableBool("bAnimationDriven", true)
	Debug.SendAnimationEvent(MQP01_FatherREF, "IdleCannibalFeedCrouching")
	
EndFunction

Function CrashDownEverything()

	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(0.5)
	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(0.5)
	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(0.5)
	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(0.5)
	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(0.5)
	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(0.5)
	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(0.5)
	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(0.5)
	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(0.5)
	MQP01_SC02_Elk.PlayImpactEffect(BloodSprayImpactSetRed )
	Wait(5.9)
	PlayerREF.TranslateToRef(MQP01_SC2_PlayerCameraTran, 1000.0, 1000.0)

EndFunction



Function PlayIntroAndMovePlayerToShip()

	AudioCategoryAMB.Mute()
	AudioCategoryMAG.Mute()
	AudioCategorySFX.Mute()
	MQP01_SC2_FatherAccusesThePlayer.Stop()
	_00E_SilenceAbruptHighPriority.Remove()
	PlayerREF.SetScale(1)
	Sound.StopInstance(FireSound)
	BFXFireImod.Remove()
	Wait(7.8)
	If _00E_AchievementsEnabled.GetValueInt() == 1	
		Game.UnlockAchievement("END_COMPLETE_MQP01_01")
	EndIf
	If _00E_VideoSkip.GetValueInt() == 0
		Game.PlayBink("EnderalIntro.bik", true, true, true, true)
	EndIf
	wait(0.2)
	AudioCategoryVOCGeneral.SetVolume(1)
	AudioCategoryMUS.SetVolume(0.7)
	AudioCategoryAMBr.SetVolume(1)
	AudioCategoryAMB.SetVolume(1)
	AudioCategorySFX.SetVolume(1)
	MQP02.SetStage(5)
	AudioCategoryAMB.UnMute()
	AudioCategoryMAG.UnMute()
	AudioCategorySFX.UnMute()
	_00E_SilenceAbruptHighPriority.Remove()
	_00E_Music_Special_Dreams.Remove()
	ExplosionToDisable00.delete()
	ExplosionToDisable01.delete()

EndFunction

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

Event OnUpdate()

	If (GameHour.GetValue() <= 22)
		RegisterForSingleUpdate(0.5)
	Else
		Timescale.SetValue(0.1)
	EndIf

EndEvent

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

int iVOCGeneralValue
int FireSound
ObjectReference ExplosionToDisable00
ObjectReference ExplosionToDisable01

float Property __Config_MuteAmbienceVolume = 0.75 Auto
{At which level should the ambience sound be played? (0.5 -> 50% of normal loudness)}

_00E_QuestFunctions Property Levelsystem Auto

MusicType Property _00E_Music_Special_Dreams Auto
MusicType Property _00E_SilenceAbruptHighPriority Auto
MusicType Property _00E_Music_Special_MQP01_BuildUp Auto
MusicType Property _00E_SilenceTransitionHighPriority Auto

Explosion Property _00E_HarmlessFireExplosion Auto

SoundCategory Property AudioCategoryVOCGeneral Auto
SoundCategory Property AudioCategoryAMB Auto
SoundCategory Property AudioCategoryMAG Auto
SoundCategory Property AudioCategorySFX Auto
SoundCategory Property AudioCategoryMUS Auto
SoundCategory Property AudioCategoryAMBr Auto

Actor Property PlayerREF Auto
Actor Property MQP01_FatherRef Auto

Scene Property MQP01_SC1_FatherArrivesInKitchen Auto
Scene Property MQP01_SC2_FatherAccusesThePlayer Auto

Message Property _00E_MQP01_Thoughts01 Auto

Sound Property _00E_MAGFXFireOilIgniteLow Auto
Sound Property _00E_MQP01_InfantLaughing Auto
Sound Property FXFireEmbers02LP Auto
Sound Property MAGDestructionFireStormExplosionM Auto
Sound Property MAGDestructionFireballExplosionM Auto
Sound Property MAGFirebolt03Fire Auto
Sound Property _00E_MQP01_DevourElkM Auto

ImpactDataSet Property BloodSprayImpactSetRed Auto

EffectShader Property FireFXShader Auto

Light Property _00E_MQP01_IntenseFire Auto

ObjectReference Property MQP01_SC1_FatherStartWalkingMarker Auto
ObjectReference Property MQP01_SC2_EmbersEffect01 Auto
ObjectReference Property MQP01_SC2_EmbersEffect02 Auto
ObjectReference Property MQP01_SC2_SmokeREF01 Auto
ObjectReference Property MQP01_SC2_FireREF01 Auto
ObjectReference Property MQP01_SC2_FireREF02 Auto
ObjectReference Property MQP01_SC2_FireREF03 Auto
ObjectReference Property MQP01_SC2_FireREF04 Auto
ObjectReference Property MQP01_SC2_FireREF05 Auto
ObjectReference Property MQP01_SC2_FireREF06 Auto
ObjectReference Property MQP01_SC2_ExplosionSpawnMarker Auto
ObjectReference Property MQP01_SC2_PlayerCameraTran Auto
ObjectReference Property MQP01_DreamDoorREF Auto
ObjectReference Property MQP01_SC02_Elk Auto
ObjectReference Property MQP01_SC1_FatherArriveMarker Auto
ObjectReference Property MQP01_SC01_PlayerWalkMarker Auto

Quest Property MQP02 Auto

GlobalVariable Property Timescale Auto
GlobalVariable Property GameHour Auto
GlobalVariable Property _00E_VideoSkip Auto
GlobalVariable Property _00E_AchievementsEnabled Auto

ImageSpaceModifier Property FadeToBlackHoldIMOD Auto
ImageSpaceModifier Property FadeToBlackBackImod Auto
ImageSpaceModifier Property MAGFireBallExpImod Auto
ImageSpaceModifier Property BFXFireImod Auto