Scriptname _00E_NQ17Functions extends Quest  

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

function SetUpHouse()
	NQ17Door.lock(0)
	NQ17Door.Activate(None)
EndFunction

function UnlockDoor()
	NQ17DoorInterior.lock(0)
EndFunction

Function UnlockDoorFailsave()

    ; Failsave to ensure that Andrasta's ForceGreet in phase 2 of
    ; scene NQ17_SC1 is not prevented by pathfinding failure.
    if AndrastaRef.GetDistance(NQ17_SC1_AndrastaAppearMarker) > 120
        AndrastaRef.MoveTo(NQ17_SC1_AndrastaAppearMarker)
    endif
    
EndFunction

function SetUpAndrastaScene()

	NQ17_RysRef.Enable()
	NQ17_RysRef.SetGhost(True)
	NQ17_RysRef.BlockActivation(True)
	AndrastaRef.EnableNoWait()
	NQ17_SC1.ForceStart()
	
endfunction

function GivePainting()
	MovableCont.RemoveAllItems(Game.GetPlayer(), 0, 1)
	PaintingRef.Disable()
EndFunction

Function StartSC1()
	NQ17_SC2.ForceStart()
EndFunction

Function StartSC2()

	EnablePainting()

	NQ17_SC2.ForceStart()
	
EndFunction

Function StartSC3()
	NQ17_SC3.ForceStart()
EndFunction

Function ForceCombat()

	NQ17_RysRef.Enable()
	NQ17_RysRef.SetGhost(1)
	Game.RequestAutoSave()
	_00E_AndrastaTapfenblutes.SetEssential(0)
	AndrastaRef.SetGhost(0)
	AndrastaRef.StartCombat(PlayerREF)
	AndrastaRef.SetActorValue("Aggression", 3)
	NQ17_DefiedAndrasta.SetValueInt(1)
	
EndFunction

Function GiveLetter()

	PlayerREF.AddItem(Game.GetFormFromFile(0x0101CAC3, "Enderal - Forgotten Stories.esm") as Potion, 1)

	PlayerREF.AddItem(JewelryNecklaceGoldDiamond, 1)
	PlayerREF.AddItem(_00E_NQ17_CoinBag)
	
EndFunction

Function RemoveLetter()

	PlayerREF.RemoveItem(_00E_NQ17_CoinBag)

EndFunction

Function StartSC04()

	AndrastaRef.PlaceAtMe(_00E_NPCOorbayaUnleashHeavenExplosion02)
	AndrastaRef.PlaceAtMe(_00E_NPCOorbayaTeleportExplosionRed)
	_00E_MQ16_EchoScreamsM.Play(PlayerREF)
	NQ17_SC04_SecretDoorREF.SetOpen(True)
	Game.ShakeCamera(afStrength = 0.3)
	Ryz.ForceRefTo(NQ17_RysRef)
	NQ17_SC4.ForceStart()
	
EndFunction

Function EnableRys()

	NQ17_RysRef.GetActorBase().SetEssential(1)
	IllusionDarkMassiveImod.Apply()
	NQ17_SC02_RysPainting.PlaceAtMe(_00E_NPCOorbayaTeleportExplosionRed)
	NQ17_MagicLightREF.Disable()
	MAGIllusionCharm.Play(NQ17_SC02_RysPainting)
	NQ17_SC04_AnomalyRys.EvaluatePackage()
	
EndFunction

Function ReviveRys()

	NQ17_RysRef.PlaceAtMe(_00E_NPCOorbayaTeleportExplosionRed)
	MAGIllusionCharm.Play(NQ17_RysRef)
	_00E_HighOnesMaterializeFXS.Play(NQ17_RysRef)
	NQ17_SC04_AnomalyRys.Disable()
	IllusionDarkMassiveImod.Apply()
	NQ17_RysRef.SetGhost(False)
	NQ17_RysRef.BlockActivation(False)
	NQ17_FreedRyz.SetValueInt(1)
	
EndFunction

Function EnableRyz()

	NQ17Ryz.EnableNoWait()
	
EndFunction

Function GiveRewardAndrastaDead()

	If NQ17_ToldTruthToErika.GetValueInt() == 0
		PlayerREF.AddItem(Gold001, 200)
	EndIf

	Levelsystem.GiveEP(2500)
	
EndFunction

Function EnablePainting()

	PlayerREF.RemoveItem(PaintingItem.GetReference(), 1)

	If PlayerREF.GetItemCount(_00E_NQ17Bildnis) >= 1
		PlayerREF.RemoveItem(_00E_NQ17Bildnis, 1)
	EndIf

	If NQ17_SC02_RysPainting == NONE
		NQ17_SC02_RysPainting = Game.GetForm(0x00036753) as ObjectReference
	EndIf
	
	If NQ17_MagicLightREF == NONE
		NQ17_MagicLightREF = Game.GetForm(0x000036754) as ObjectReference
	EndIf
	
	NQ17_SC02_RysPainting.Enable()
	NQ17_MagicLightREF.Enable()
	MAGConjureFire.Play(NQ17_SC02_RysPainting)
	
EndFunction

Function AndrastaMagicIdle()

	AndrastaRef.PlayIdle(IdleMagic_01)
	
EndFunction

Function DisableLight()

	NQ17_MagicLightREF.Disable()

EndFunction

Function DissolveRysPainting()

	_00E_MQ07b_DissolvePlatformFXS.Play(NQ17_SC02_RysPainting)
	OBJEyeofMagnusVanishM.Play(NQ17_SC02_RysPainting)
	
EndFunction

Function AndrastaStopIdle()

	Debug.SendAnimationEvent(AndrastaRef, "IdleForceDefaultState")

EndFunction

Function RysResetShader()

	_00E_HighOnesMaterializeFXS.Stop(NQ17_RysRef)

EndFunction

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

_00E_QuestFunctions Property Levelsystem Auto

MiscObject Property _00E_NQ17_CoinBag Auto
MiscObject Property _00E_NQ17Bildnis Auto
MiscObject Property Gold001 Auto

Explosion Property _00E_NPCOorbayaTeleportExplosionRed Auto
Explosion Property _00E_NPCOorbayaUnleashHeavenExplosion02 Auto

EffectShader Property _00E_MQ07b_DissolvePlatformFXS Auto
EffectShader Property _00E_HighOnesMaterializeFXS Auto

ReferenceAlias Property Ryz Auto
ReferenceAlias Property PaintingItem Auto

ImageSpaceModifier Property IllusionDarkMassiveImod Auto

GlobalVariable Property NQ17_DefiedAndrasta Auto
GlobalVariable Property NQ17_FreedRyz Auto
GlobalVariable Property NQ17_ToldTruthToErika Auto

Actor Property PlayerREF Auto
Actor Property NQ17Ryz Auto
Actor Property NQ17_SC04_AnomalyRys Auto
Actor Property AndrastaRef Auto
Actor Property NQ17_RysRef Auto

Armor Property JewelryNecklaceGoldDiamond Auto

Scene Property NQ17_SC1 Auto
Scene Property NQ17_SC2 Auto
Scene Property NQ17_SC3 Auto
Scene Property NQ17_SC4 Auto

Sound Property MAGConjureFire Auto
Sound Property OBJEyeofMagnusVanishM Auto
Sound Property _00E_MQ16_EchoScreamsM Auto
Sound Property MAGIllusionCharm Auto

Idle Property IdleMagic_01 auto

ObjectReference Property NQ17Door Auto
ObjectReference Property MovableCont Auto
ObjectReference Property PaintingRef Auto
ObjectReference Property NQ17DoorInterior Auto
ObjectReference Property NQ17_SC02_RysPainting Auto
ObjectReference Property NQ17_MagicLightREF Auto
ObjectReference Property NQ17_SC04_SecretDoorREF Auto
ObjectReference Property NQ17_SC1_AndrastaAppearMarker Auto

ActorBase Property _00E_AndrastaTapfenblutes Auto