scriptName _00E_MQ01_Functions extends Quest Conditional

Import Utility
Import _00E_QuestFunctions

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

Function AdjustTimescale()

	Timescale.SetValue(15)

EndFunction

Function ResetTimescale()

	Timescale.SetValue(10)

EndFunction

Function ShowDialogueTutorial()

	Message.ResetHelpMessage("Empty")
	_00E_MQP03_Tutorial_Dialogues.ShowAsHelpMessage("Empty", 5 as Float, 1 as Float, 1)

EndFunction

Function GiveHealingPotion()

	PlayerREF.AddItem(_02E_Genesungstrank, 1)

EndFunction

Function BeginHeadache()
	
	PlayerREF.ModAV("LastFlattered", -15)
	_00E_BlitzheilungArkanistenfieber_sFeverIncreased.Show(15.0, -1*PlayerREF.GetAV("LastFlattered"))
	debug.SendAnimationEvent(PlayerREF as objectreference, "StaggerPlayer")
	MagVampireSunlight.Play(PlayerREF as objectreference)
	Message.ResetHelpMessage("Empty")
	_00E_MQ01_ThoughtsHeadache.ShowAsHelpMessage("Empty", 3 as Float, 1 as Float, 1)
	_00E_MQ01_HeadacheShort.apply(1.00000)
	Wait(1)
	SoundID01 = UIHealthHeartbeatALP.Play(PlayerREF as objectreference)
	_00E_MQ01_HeadacheLoop.ApplyCrossFade(0.5)
	
EndFunction

function EndHeadache()

	If PlayerREF.IsWeaponDrawn()
		PlayerREF.SheatheWeapon()
		Utility.Wait(3)
	EndIf

	PlayerREF.RestoreActorValue("Health", PlayerREF.GetAV("Health"))
	_00E_NPCUncorkPotionAndDrinkM.Play(PlayerREF)
	MAGRestorationFFFire.Play(PlayerREF)
	Sound.StopInstance(SoundID01)
	_00E_MQ01_HeadacheLoop.PopTo(_00E_MQ01_HeadacheEnd, 1.00000)
	bHeadacheCured = True
	
endFunction

Function StartSC01()
	
	if Torch01 == None
		Torch01 = Game.GetForm(0x0001D4EC) as Light
	EndIf
	
	if PlayerREF.IsEquipped(Torch01)
		PlayerREF.UnequipItem(Torch01)
	EndIf

	MQ01_SC1_FinnHealsPlayer.ForceStart()

EndFunction


Function StartPreVisionScene()

	MQ01_UnchartedLand_PreVisionScene.Start()
	;In case the save doesn't get triggered properly, hopefully fixes report ERB-754.
	Wait(1)
	If !MQ01_UnchartedLand_PreVisionScene.IsPlaying()
		MQ01_UnchartedLand_PreVisionScene.ForceStart()
	EndIf
	
EndFunction

Function StartHeadacheAndVisionScene()

	MQ01_SC4_Vision.ForceStart()
	FXSparks.EnableNoWait(False)
	SparksSounds.EnableNoWait(False)

endFunction
	
function BeginVision()
		
	_00E_MQ01_FinnREF.SetGhost(False)
	_00E_MQ01_CarbosREF.SetGhost(False)
	_00E_Ability_StaggerSelfSpell.Cast(_00E_MQ01_FinnREF, _00E_MQ01_FinnREF)
	_00E_Ability_StaggerSelfSpell.Cast(_00E_MQ01_CarbosREF, _00E_MQ01_CarbosREF)
	ExplodeDestillator()
	Levelsystem.VisionEffectTimestop(False, False, False)
	Wait(0.5)
	_00E_MQ01_FinnREF.EnableAI(False)
	_00E_MQ01_CarbosREF.EnableAI(False)
	Wait(11)
	SetStage(50)
	
endFunction

Function ExplodeDestillator()

	MQ01_SC4_ExplosionMarker.PlaceAtMe(_00E_MQ01_BottleFlameExplosion)
	MQ01_SC4_BurnerREF.PlaceAtMe(_00E_MQ01_BottleExplosion)
	MQ01_SC4_BurnerREF.DisableNoWait(false)
	MQ01_SC4_MetalPieceREF.Enable()
	FXSparks.DisableNoWait(false)
	SparksSounds.DisableNoWait(false)

EndFunction

function EndVision()
	
	_00E_MQ01_FinnREF.SetGhost(True)
	_00E_MQ01_CarbosREF.SetGhost(True)
	Game.DisablePlayerControls()
	Levelsystem.VisionEffectTimestopStop(true)
	VisionVoice.GetReference().Disable(false)
	_00E_MQ01_FinnREF.EnableAI(True)
	_00E_MQ01_CarbosREF.EnableAI(True)
	_00E_MQ01_HeadacheLoop.ApplyCrossFade(0.5)
	
endFunction

function StartSC05()

	_00E_MQ01_FinnREF.SetGhost(False)
	_00E_MQ01_CarbosREF.SetGhost(False)
	MQ01_SC5_BanditAttack.ForceStart()
	
endFunction

Function StartSC2CarbosStairs()

	Game.DisablePlayerControls()
	Carbos.GetReference().Enable()
	Wait(1)
	MQ01_SC2_CarbosStairs.ForceStart()
	
EndFunction
	
Function StartSC02()

	Game.DisablePlayerControls()
	Carbos.GetReference().Enable()
	Wait(1)
	MQ01_SC2_CarbosAppears.ForceStart()
		
EndFunction

Function StartNewHorizons()

	NQ02_NewHorizons.Start()
	
EndFunction

function FakeHeadtrackStart()

	PlayerREF.AddSpell(_00E_Vision_UpdateAb, false)
	Wait(0.500000)
	PlayerREF.RemoveSpell(_00E_Vision_UpdateAb)
	
endFunction


function FakeHeadtrackEnd()

	PlayerREF.AddSpell(_00E_Vision_UpdateAb, false)
	utility.Wait(0.500000)
	PlayerREF.RemoveSpell(_00E_Vision_UpdateAb)
	
endFunction

function KillCarbos()

	Carbos.GetActorReference().SetGhost(false)
	WPNBowFire.Play(Carbos.GetActorReference())
	_00E_MQ01_KillerArrow01.Cast(ShootMarker, Carbos.GetActorReference() as objectreference)
	
endFunction

function KillCarbosFinal()

	actorbase TargetBase = _00E_MQ01_CarbosREF.GetBaseObject() as actorbase
	TargetBase.SetEssential(false)
	_00E_MQ01_CarbosREF.DamageActorValue("health", 400.0)
	
endFunction

function CarbosHeadTrack()

	Carbos.GetActorReference().SetLookAt(Finn.GetReference(), true)
	
endFunction

function FinnHeadTrack()

	Finn.GetActorReference().SetLookAt(FinnPointMarker.GetReference(), true)
	
endFunction

function KillFinn()

	Finn.GetActorReference().SetGhost(false)
	WPNBowFire.Play(Carbos.GetActorReference())
	_00E_MQ01_KillerArrow02.Cast(ShootMarker, Finn.GetActorReference() as objectreference)
	
endFunction

Function CleanUp()

	FadeToBlackHoldImod.Apply()
	ResetTimescale()
	Timescale.SetValue(10.0)
	AudioCategoryFST.UnMute()
	PlayerREF.SetAlpha(1)
	_00E_MQ01_CarbosREF.SetOutfit(_00E_Rags)
	_00E_MQ01_FinnREF.SetOutfit(_00E_Rags)
	; SE: Fixes "cannot disable an object with an enable state parent"
	;_00E_MQ01_FinnREF.Disable()
	;MQ01_SC5_TableREF.Disable()
	MQ01_SC5_TableREF.Disable()
	MQ01_SC4_BurnerREF.Disable()
	MQ01_SC4_MetalPieceREF.Disable()
	MQ01_SC5_DamGate.Lock(False)
	MQ01_SC5_DamGate.SetOpen(True)
	MQ01_SC01DoorREF.SetLockLevel(0)
	MQ01_SC01DoorREF.Lock(False)
	Self.CompleteQuest()
	Wait(1)
	MQ02.Start()
	FadeToBlackHoldImod.Remove()
	MQ02.SetStage(10)
	
EndFunction

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

_00E_QuestFunctions Property Levelsystem Auto

bool Property bInVision Auto Conditional Hidden
bool Property bHeadacheCured Auto Conditional Hidden

Float SpeedBefore
Int SoundID01

Actor Property _00E_MQ01_FinnREF Auto
Actor Property _00E_MQ01_CarbosREF Auto
actor property PlayerREF auto

Scene Property MQ01_SC4_Vision Auto
Scene Property MQ01_SC5_BanditAttack Auto
Scene Property MQ01_SC1_FinnHealsPlayer Auto
scene property MQ01_UnchartedLand_PreVisionScene auto
scene property MQ01_SC2_CarbosAppears auto
scene property MQ01_SC2_CarbosStairs auto

Message Property _00E_MQP03_Tutorial_Dialogues Auto
Message Property _00E_BlitzheilungArkanistenfieber_sFeverIncreased Auto
message property _00E_MQ01_ThoughtsHeadache auto

objectreference property FXSparks auto
objectreference property SparksSounds auto
objectreference property ShootMarker auto
ObjectReference Property MQ01_SC4_BurnerREF Auto
ObjectReference Property MQ01_SC4_ExplosionMarker Auto
ObjectReference Property MQ01_SC5_TableREF Auto
ObjectReference Property MQ01_SC5_DamGate Auto
ObjectReference Property MQ01_SC4_MetalPieceREF Auto
ObjectReference Property MQ01_SC01DoorREF Auto

GlobalVariable Property Timescale Auto

sound property MagVampireSunlight auto
sound property WPNBowFire auto
sound property _00E_NPCUncorkPotionAndDrinkM auto
sound property MAGRestorationFFFire auto
sound property UIHealthHeartbeatALP auto

imagespacemodifier property _00E_MQ01_HeadacheEnd auto
imagespacemodifier property _00E_MQ01_HeadacheLoop auto
imagespacemodifier property _00E_MQ01_HeadacheShort auto
imagespacemodifier property FadeToBlackHoldImod auto

referencealias property Finn auto
referencealias property Carbos auto
referencealias property FinnPointMarker auto
referencealias property VisionVoice auto

light property Torch01 auto

spell property _00E_Vision_UpdateAb auto
spell property _00E_MQ01_KillerArrow02 auto
spell property _00E_Ability_StaggerSelfSpell auto
spell property _00E_MQ01_KillerArrow01 auto

explosion property _00E_MQ01_BottleExplosion auto
explosion property _00E_MQ01_BottleFlameExplosion auto

Quest Property MQ02 Auto
Quest property MQ01_UnchartedLand auto
Quest property NQ02_NewHorizons auto

Outfit Property _00E_Rags Auto

SoundCategory Property AudioCategoryFST Auto

Potion Property _02E_Genesungstrank Auto