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(); } }
public override void RestoreSaveData(object dataIn) { if (dataIn == null) { return; } SaveData_v1 data = (SaveData_v1)dataIn; anchorSet = data.anchorSet; anchorPosition = data.anchorPosition; forcedRoundsRemaining = data.forcedRoundsRemaining; }
public static int Get(PlayerPositionData_v1 playerPosition) { if (playerPosition.insideBuilding) { return(Building); } if (playerPosition.insideDungeon) { return(Dungeon); } return(Default); }
private void SaveLoadManager_OnStartLoad(SaveData_v1 saveData) { PlayerPositionData_v1 savePos = saveData.playerData.playerPosition; // save is crouched if (!savePos.isCrouching && playerMotor.IsCrouching) { heightAction = HeightChangeAction.DoStanding; } else if (savePos.isCrouching && !playerMotor.IsCrouching) { heightAction = HeightChangeAction.DoCrouching; } toggleRiding = playerMotor.IsRiding; toggleSink = OnWater; }
void SetAnchor() { // Validate references if (!serializablePlayer || !playerEnterExit) { return; } // Get position information anchorPosition = serializablePlayer.GetPlayerPositionData(); if (playerEnterExit.IsPlayerInsideBuilding) { anchorPosition.exteriorDoors = playerEnterExit.ExteriorDoors; anchorPosition.buildingDiscoveryData = playerEnterExit.BuildingDiscoveryData; } anchorSet = true; }
private void SaveLoadManager_OnStartLoad(SaveData_v1 saveData) { PlayerPositionData_v1 savePos = saveData.playerData.playerPosition; // save is crouched if (!savePos.isCrouching && playerMotor.IsCrouching) { heightAction = HeightChangeAction.DoStanding; } else if (savePos.isCrouching && !playerMotor.IsCrouching) { heightAction = HeightChangeAction.DoCrouching; } toggleRiding = playerMotor.IsRiding; toggleSink = GameManager.Instance.PlayerMotor.OnExteriorWater == PlayerMotor.OnExteriorWaterMethod.Swimming; forcedSwimCrouch = levitateMotor.IsSwimming; }
public override void RestoreSaveData(object dataIn) { if (dataIn == null) { return; } SaveData_v1 data = (SaveData_v1)dataIn; anchorPosition = data.anchorPosition; // On resume migrate legacy anchor position to player entity then end effect if (anchorPosition != null) { GameManager.Instance.PlayerEntity.AnchorPosition = anchorPosition; End(); } }
void SetAnchor() { // Validate references if (!serializablePlayer || !playerEnterExit) { return; } // Get position information PlayerPositionData_v1 newAnchorPosition = serializablePlayer.GetPlayerPositionData(); if (playerEnterExit.IsPlayerInsideBuilding) { newAnchorPosition.exteriorDoors = playerEnterExit.ExteriorDoors; newAnchorPosition.buildingDiscoveryData = playerEnterExit.BuildingDiscoveryData; } // Assign anchor to player entity then end effect GameManager.Instance.PlayerEntity.AnchorPosition = newAnchorPosition; End(); }
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 if they haven't been cached yet if (!CacheReferences()) { return; } // Get anchor position from player entity anchorPosition = GameManager.Instance.PlayerEntity.AnchorPosition; // Restore final position and unwire event serializablePlayer.RestorePosition(anchorPosition); PlayerEnterExit.OnRespawnerComplete -= PlayerEnterExit_OnRespawnerComplete; // Set "teleported into dungeon" flag when anchor is inside a dungeon GameManager.Instance.PlayerEnterExit.PlayerTeleportedIntoDungeon = anchorPosition.insideDungeon; // 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 } GameManager.Instance.PlayerEntity.AnchorPosition = null; End(); }
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; } }
public override void End() { anchorPosition = null; RoundsRemaining = 0; base.End(); }
public override void End() { anchorPosition = null; base.End(); }
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; } }