Scriptname _00E_TeleportControl extends Quest Hidden 

import Utility

Function TeleportPlayer(ObjectReference TeleportTarget)

	Game.DisablePlayerControls(abCamSwitch = true)
	Wait(3)
	If PlayerREF.IsWeaponDrawn()
		PlayerREF.SheatheWeapon()
	EndIf
	Wait(2)
	TeleportIn()
	PlayerREF.MoveTo(TeleportTarget)
	TeleportOut()

	_00E_Func_RefreshFace.RefreshFace()
	
EndFunction

Function TeleportIn()

	Game.ForceThirdPerson()

	if Player.GetSex() == 0
		PlayerREF.PlayIdle(IdleT02AscendMale)
	Else
		PlayerREF.PlayIdle(IdleT02AscendFemale)
	EndIf

	_00E_MagicProtectionSpellM.Play(PlayerREF)
	Wait(2.7)
	TimeFadeOut01FXS.Play(PlayerREF)
	Wait(1.3)
	_00E_TeleportImod.Apply()
	Wait(2)

EndFunction

Function TeleportOut()

	_00E_A2_Ghostwalk_TeleportDoneSound.Play(playerREF)
	PlayerREF.PlaceAtMe(_00E_NPCOorbayaTeleportExplosionBlue, 1)
	Debug.sendAnimationEvent(playerREF, "IdleWebEnterInstant")
	PlayerREF.setActorValue("Variable03", 5)
	TimeFadeOut01FXS.Stop(PlayerREF)
	TimeFadeIn01FXS.Play(PlayerREF)
	Wait(0.5)
	PlayerREF.playidle(WebIdleExit)
	TimeFadeIn01FXS.Stop(PlayerREF)
	PlayerREF.setActorValue("Variable03", 0)
	PlayerREF.DrawWeapon()
	Wait(3)
	Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState")
	PlayerREF.PlayIdle(IdleForceDefaultState)
	PlayerREF.setActorValue("Variable03", 0)
	Game.EnablePlayerControls()
	_FS_Phasmalist_ControlQuest.MoveApparitionToPlayer()
	RegisterForSingleUpdate(2)

EndFunction

Event OnUpdate()
	Game.EnablePlayerControls()
EndEvent

Function TeleportNPC(Actor NPCToTeleport, ObjectReference TeleportTarget)
{Teleport an NPC, with animations and FX}

	Weapon weap01 = NPCToTeleport.GetEquippedWeapon(0)
	Weapon weap02 = NPCToTeleport.GetEquippedWeapon(1)
	
	If weap01 != None
		NPCToTeleport.UnEquipItem(weap01)
	EndIf
	If weap02 != None
		NPCToTeleport.UnEquipItem(weap02)
	EndIf
	NPCToTeleport.PlayIdle(IdleMagic_01)
	_00E_TeleportCastSound.Play(NPCToTeleport)
	Wait(3)

	if NPCToTeleport.GetActorBase().GetSex() == 0
		NPCToTeleport.PlayIdle(IdleT02AscendMale)
	Else
		NPCToTeleport.PlayIdle(IdleT02AscendFemale)
	EndIf

	_00E_MagicProtectionSpellM.Play(NPCToTeleport)
	Wait(4)
	TimeFadeOut01FXS.Play(NPCToTeleport)
	Wait(2)
	_00E_A2_Ghostwalk_TeleportDoneSound.Play(NPCToTeleport)

	ObjectReference TeleportFXMarker = NPCToTeleport.PlaceAtMe(XMarkerHeading, 1)
	TeleportFXMarker.MoveTo(NPCToTeleport, 0.0, 0.0, 100.0)
	ObjectReference FXExplosion = TeleportFXMarker.PlaceAtMe(_00E_TeleportExplosion, 1)
	_00E_NPCTeleportExplosionIMOD.Apply()
	Game.ShakeCamera(afStrength = 0.2)
	NPCToTeleport.MoveTo(TeleportTarget)
	Debug.sendAnimationEvent(NPCToTeleport, "IdleWebEnterInstant")
	NPCToTeleport.setActorValue("Variable03", 5)
	TimeFadeOut01FXS.Stop(NPCToTeleport)
	If NPCToTeleport.Is3DLoaded()
		TimeFadeIn01FXS.Play(NPCToTeleport)
	EndIf
	Wait(0.5)
	NPCToTeleport.playidle(WebIdleExit)
	Wait(1)
	TimeFadeIn01FXS.Stop(NPCToTeleport)
	NPCToTeleport.setActorValue("Variable03", 0)
	If weap01 != None
		NPCToTeleport.EquipItem(weap01)
	EndIf
	If weap02 != None
		NPCToTeleport.EquipItem(weap02)
	EndIf

EndFunction

actor Property PlayerRef  Auto  

Idle Property IdleT02AscendMale  Auto  

Idle Property IdleT02AscendFemale  Auto  

Sound Property _00E_MagicProtectionSpellM  Auto  

EffectShader Property TimeFadeOut01FXS  Auto  

ImageSpaceModifier Property _00E_TeleportImod  Auto  

Sound Property _00E_A2_Ghostwalk_TeleportDoneSound  Auto  

Explosion Property _00E_NPCOorbayaTeleportExplosionBlue  Auto  

EffectShader Property TimeFadeIn01FXS  Auto  

Idle Property WebIdleExit  Auto  

Idle Property IdleForceDefaultState  Auto  

ActorBase Property Player  Auto  

Sound Property _00E_TeleportCastSound  Auto  

STATIC Property XMarkerHeading  Auto  

ImageSpaceModifier Property _00E_NPCTeleportExplosionIMOD  Auto  

Idle Property IdleMagic_01  Auto  

Explosion Property _00E_TeleportExplosion  Auto