void TeleportPlayer() { // Validate references if (!serializablePlayer || !playerEnterExit) { return; } // Get anchor position from player entity anchorPosition = GameManager.Instance.PlayerEntity.AnchorPosition; // Is player in same interior as anchor? if (IsSameInterior()) { // Just need to move player serializablePlayer.RestorePosition(anchorPosition); } else { // When teleporting to interior anchor, restore world compensation height early before initworld // Ensures exterior world level is aligned with building height at time of anchor // Only works with floating origin v3 saves and above with both serialized world compensation and context if (anchorPosition.worldContext == WorldContext.Interior) { GameManager.Instance.StreamingWorld.RestoreWorldCompensationHeight(anchorPosition.worldCompensation.y); } else { GameManager.Instance.StreamingWorld.RestoreWorldCompensationHeight(0); } // Cache scene before departing if (!playerEnterExit.IsPlayerInside) { SaveLoadManager.CacheScene(GameManager.Instance.StreamingWorld.SceneName); // Player is outside } else if (playerEnterExit.IsPlayerInsideBuilding) { SaveLoadManager.CacheScene(playerEnterExit.Interior.name); // Player inside a building } else // Player inside a dungeon { playerEnterExit.TransitionDungeonExteriorImmediate(); } // Need to load some other part of the world again - player could be anywhere PlayerEnterExit.OnRespawnerComplete += PlayerEnterExit_OnRespawnerComplete; playerEnterExit.RestorePositionHelper(anchorPosition, false, true); // Restore building summary data if (anchorPosition.insideBuilding) { playerEnterExit.BuildingDiscoveryData = anchorPosition.buildingDiscoveryData; } // When moving anywhere other than same interior trigger a fade so transition appears smoother DaggerfallUI.Instance.FadeBehaviour.FadeHUDFromBlack(); } }
void TeleportPlayer() { // Validate references if (!serializablePlayer || !playerEnterExit) { return; } // Is player in same interior as anchor? if (IsSameInterior()) { // Just need to move player serializablePlayer.RestorePosition(anchorPosition); return; } else { // Cache scene before departing if (!playerEnterExit.IsPlayerInside) { SaveLoadManager.CacheScene(GameManager.Instance.StreamingWorld.SceneName); // Player is outside } else if (playerEnterExit.IsPlayerInsideBuilding) { SaveLoadManager.CacheScene(playerEnterExit.Interior.name); // Player inside a building } else // Player inside a dungeon { playerEnterExit.TransitionDungeonExteriorImmediate(); } // Need to load some other part of the world again - player could be anywhere PlayerEnterExit.OnRespawnerComplete += PlayerEnterExit_OnRespawnerComplete; playerEnterExit.RestorePositionHelper(anchorPosition, false, true); // Restore building summary data if (anchorPosition.insideBuilding) { playerEnterExit.BuildingDiscoveryData = anchorPosition.buildingDiscoveryData; } // When moving anywhere other than same interior trigger a fade so transition appears smoother DaggerfallUI.Instance.FadeBehaviour.FadeHUDFromBlack(); } // End and resign // Player will need to create a new teleport with a new anchor from here // This is same behaviour as classic forcedRoundsRemaining = 0; ResignAsIncumbent(); anchorSet = false; }
private void PlayerEnterExit_OnRespawnerComplete() { // Must have a caster and it must be the player if (caster == null || caster != GameManager.Instance.PlayerEntityBehaviour) { return; } // Get peered SerializablePlayer and PlayerEnterExit SerializablePlayer serializablePlayer = caster.GetComponent <SerializablePlayer>(); PlayerEnterExit playerEnterExit = caster.GetComponent <PlayerEnterExit>(); if (!serializablePlayer || !playerEnterExit) { Debug.LogError("Teleport effect OnRespawnerComplete() could not find both SerializablePlayer and PlayerEnterExit components."); return; } // Restore final position and unwire event serializablePlayer.RestorePosition(anchorPosition); PlayerEnterExit.OnRespawnerComplete -= PlayerEnterExit_OnRespawnerComplete; // Restore scene cache on arrival if (!playerEnterExit.IsPlayerInside) { SaveLoadManager.RestoreCachedScene(GameManager.Instance.StreamingWorld.SceneName); // Player is outside } else if (playerEnterExit.IsPlayerInsideBuilding) { SaveLoadManager.RestoreCachedScene(playerEnterExit.Interior.name); // Player inside a building } }
private void UpdateMode(TransportModes transportMode) { // Update the transport mode and stop any riding sounds playing. mode = transportMode; if (ridingAudioSource.isPlaying) { ridingAudioSource.Stop(); } if (mode == TransportModes.Horse || mode == TransportModes.Cart) { // Tell player motor we're riding. playerMotor.IsRiding = true; // Setup appropriate riding sounds. SoundClips sound = (mode == TransportModes.Horse) ? horseRidingSound2 : cartRidingSound; ridingAudioSource.clip = dfAudioSource.GetAudioClip((int)sound); // Setup appropriate riding textures. string textureName = (mode == TransportModes.Horse) ? horseTextureName : cartTextureName; for (int i = 0; i < 4; i++) { ridingTexures[i] = ImageReader.GetImageData(textureName, 0, i, true, true); } ridingTexture = ridingTexures[0]; // Initialise neighing timer. neighTime = Time.time + Random.Range(1, 5); } else { // Tell player motor we're not riding. playerMotor.IsRiding = false; } if (mode == TransportModes.Ship) { GameManager.Instance.PlayerMotor.CancelMovement = true; SerializablePlayer serializablePlayer = GetComponent <SerializablePlayer>(); DaggerfallUI.Instance.FadeBehaviour.SmashHUDToBlack(); StreamingWorld world = GameManager.Instance.StreamingWorld; DFPosition shipCoords = DaggerfallBankManager.GetShipCoords(); // Is there recorded position before boarding and is player on the ship? if (IsOnShip()) { // Check for terrain sampler changes. (so don't fall through floor) StreamingWorld.RepositionMethods reposition = StreamingWorld.RepositionMethods.None; if (boardShipPosition.terrainSamplerName != DaggerfallUnity.Instance.TerrainSampler.ToString() || boardShipPosition.terrainSamplerVersion != DaggerfallUnity.Instance.TerrainSampler.Version) { reposition = StreamingWorld.RepositionMethods.RandomStartMarker; if (DaggerfallUI.Instance.DaggerfallHUD != null) { DaggerfallUI.Instance.DaggerfallHUD.PopupText.AddText("Terrain sampler changed. Repositioning player."); } } // Restore player position from before boarding ship, caching ship scene first. SaveLoadManager.CacheScene(world.SceneName); // TODO: Should this should move into teleport to support other teleports? Issue only if inside. (e.g. recall) DFPosition mapPixel = MapsFile.WorldCoordToMapPixel(boardShipPosition.worldPosX, boardShipPosition.worldPosZ); world.TeleportToCoordinates(mapPixel.X, mapPixel.Y, reposition); serializablePlayer.RestorePosition(boardShipPosition); boardShipPosition = null; // Restore cached scene (ship is special case, cache will not be cleared) SaveLoadManager.RestoreCachedScene(world.SceneName); } else { // Record current player position before boarding ship, and cache scene. (ship is special case, cache will not be cleared) boardShipPosition = serializablePlayer.GetPlayerPositionData(); SaveLoadManager.CacheScene(world.SceneName); // Teleport to the players ship, restoring cached scene. world.TeleportToCoordinates(shipCoords.X, shipCoords.Y, StreamingWorld.RepositionMethods.RandomStartMarker); SaveLoadManager.RestoreCachedScene(world.SceneName); } DaggerfallUI.Instance.FadeBehaviour.FadeHUDFromBlack(); mode = TransportModes.Foot; } }
private void UpdateMode(TransportModes transportMode) { // Update the transport mode and stop any riding sounds playing. mode = transportMode; if (ridingAudioSource.isPlaying) { ridingAudioSource.Stop(); } if (mode == TransportModes.Horse || mode == TransportModes.Cart) { // Tell player motor we're riding. TODO: Change to event system so other classes can listen for transport changes. playerMotor.IsRiding = true; // Setup appropriate riding sounds. SoundClips sound = (mode == TransportModes.Horse) ? horseRidingSound2 : cartRidingSound; ridingAudioSource.clip = dfAudioSource.GetAudioClip((int)sound); // Setup appropriate riding textures. string textureName = (mode == TransportModes.Horse) ? horseTextureName : cartTextureName; for (int i = 0; i < 4; i++) { ridingTexures[i] = ImageReader.GetImageData(textureName, 0, i, true, true); } ridingTexure = ridingTexures[0]; // Initialise neighing timer. neighTime = Time.time + Random.Range(1, 5); } else { // Tell player motor we're not riding. playerMotor.IsRiding = false; } if (mode == TransportModes.Ship) { GameManager.Instance.PlayerMotor.CancelMovement = true; SerializablePlayer serializablePlayer = GetComponent <SerializablePlayer>(); DaggerfallUI.Instance.SmashHUDToBlack(); // Is player on board ship? if (boardShipPosition != null) { // Check for terrain sampler changes. (so don't fall through floor) StreamingWorld.RepositionMethods reposition = StreamingWorld.RepositionMethods.None; if (boardShipPosition.terrainSamplerName != DaggerfallUnity.Instance.TerrainSampler.ToString() || boardShipPosition.terrainSamplerVersion != DaggerfallUnity.Instance.TerrainSampler.Version) { reposition = StreamingWorld.RepositionMethods.RandomStartMarker; if (DaggerfallUI.Instance.DaggerfallHUD != null) { DaggerfallUI.Instance.DaggerfallHUD.PopupText.AddText("Terrain sampler changed. Repositioning player."); } } // Restore player position from before boarding ship. DFPosition mapPixel = MapsFile.WorldCoordToMapPixel(boardShipPosition.worldPosX, boardShipPosition.worldPosZ); GameManager.Instance.StreamingWorld.TeleportToCoordinates(mapPixel.X, mapPixel.Y, reposition); serializablePlayer.RestorePosition(boardShipPosition); boardShipPosition = null; } else { // Record current player position before boarding ship. boardShipPosition = serializablePlayer.GetPlayerPositionData(); // Teleport to ship GameManager.Instance.StreamingWorld.TeleportToCoordinates(2, 2, StreamingWorld.RepositionMethods.RandomStartMarker); } DaggerfallUI.Instance.FadeHUDFromBlack(); mode = TransportModes.Foot; } }