/// <summary> /// Check if player is allowed to rest at this location. /// </summary> bool CanRest() { remainingHoursRented = -1; allocatedBed = Vector3.zero; PlayerEnterExit playerEnterExit = GameManager.Instance.PlayerEnterExit; PlayerGPS playerGPS = GameManager.Instance.PlayerGPS; bool inTown = playerGPS.IsPlayerInTown(true); if (inTown && !playerEnterExit.IsPlayerInside) { CloseWindow(); DaggerfallUI.MessageBox(cityCampingIllegal); // Register crime and start spawning guards playerEntity.CrimeCommitted = PlayerEntity.Crimes.Vagrancy; playerEntity.SpawnCityGuards(true); return(false); } else if ((inTown || !playerGPS.HasCurrentLocation) && playerEnterExit.IsPlayerInsideBuilding) { // Check for guild hall rest privileges if (GameManager.Instance.GuildManager.GetGuild(playerEnterExit.BuildingDiscoveryData.factionID).CanRest()) { playerEnterExit.Interior.FindMarker(out allocatedBed, DaggerfallInterior.InteriorMarkerTypes.Rest); return(true); } // Check owned locations string sceneName = DaggerfallInterior.GetSceneName(playerGPS.CurrentLocation.MapTableData.MapId, playerEnterExit.BuildingDiscoveryData.buildingKey); if (SaveLoadManager.StateManager.ContainsPermanentScene(sceneName)) { // Can rest if it's an player owned ship/house. int buildingKey = playerEnterExit.BuildingDiscoveryData.buildingKey; if (playerEnterExit.BuildingType == DFLocation.BuildingTypes.Ship || DaggerfallBankManager.IsHouseOwned(buildingKey)) { return(true); } // Find room rental record and get remaining time.. int mapId = playerGPS.CurrentLocation.MapTableData.MapId; RoomRental_v1 room = GameManager.Instance.PlayerEntity.GetRentedRoom(mapId, buildingKey); remainingHoursRented = PlayerEntity.GetRemainingHours(room); allocatedBed = room.allocatedBed; if (remainingHoursRented > 0) { return(true); } } CloseWindow(); DaggerfallUI.MessageBox(HardStrings.haveNotRentedRoom); return(false); } return(true); }
public static int GetRemainingHours(RoomRental_v1 room) { if (room == null) { return(-1); } double remainingSecs = (double)(room.expiryTime - DaggerfallUnity.Instance.WorldTime.Now.ToSeconds()); return((int)Math.Ceiling((remainingSecs / DaggerfallDateTime.SecondsPerHour))); }
static void DrunkBed() { int mapId = GameManager.Instance.PlayerGPS.CurrentLocation.MapTableData.MapId; int buildingKey = GameManager.Instance.PlayerEnterExit.BuildingDiscoveryData.buildingKey; RoomRental_v1 rentedRoom = GameManager.Instance.PlayerEntity.GetRentedRoom(mapId, buildingKey); PlayerGPS.DiscoveredBuilding buildingData = GameManager.Instance.PlayerEnterExit.BuildingDiscoveryData; string sceneName = DaggerfallInterior.GetSceneName(mapId, buildingData.buildingKey); Vector3[] restMarkers = playerEnterExit.Interior.FindMarkers(DaggerfallInterior.InteriorMarkerTypes.Rest); Vector3 allocatedBed; if (rentedRoom == null) { // Get rest markers and select a random marker index for allocated bed // We store marker by index as building positions are not stable, they can move from terrain mods or floating Y int markerIndex = Random.Range(0, restMarkers.Length); // Create room rental and add it to player rooms RoomRental_v1 room = new RoomRental_v1() { name = buildingData.displayName, mapID = mapId, buildingKey = buildingData.buildingKey, allocatedBedIndex = markerIndex, expiryTime = DaggerfallUnity.Instance.WorldTime.Now.ToSeconds() + (ulong)(DaggerfallDateTime.SecondsPerDay * 1) }; playerEntity.RentedRooms.Add(room); SaveLoadManager.StateManager.AddPermanentScene(sceneName); Debug.LogFormat("Rented room for {1} days. {0}", sceneName, 1); } rentedRoom = GameManager.Instance.PlayerEntity.GetRentedRoom(mapId, buildingKey); int bedIndex = (rentedRoom.allocatedBedIndex >= 0 && rentedRoom.allocatedBedIndex < restMarkers.Length) ? rentedRoom.allocatedBedIndex : 0; allocatedBed = restMarkers[bedIndex]; if (allocatedBed != Vector3.zero) { PlayerMotor playerMotor = GameManager.Instance.PlayerMotor; playerMotor.transform.position = allocatedBed; playerMotor.FixStanding(0.4f, 0.4f); } }
private void RoomButton_OnMouseClick(BaseScreenComponent sender, Vector2 position) { int mapId = GameManager.Instance.PlayerGPS.CurrentLocation.MapTableData.MapId; int buildingKey = GameManager.Instance.PlayerEnterExit.BuildingDiscoveryData.buildingKey; rentedRoom = GameManager.Instance.PlayerEntity.GetRentedRoom(mapId, buildingKey); DaggerfallInputMessageBox inputMessageBox = new DaggerfallInputMessageBox(uiManager, this); inputMessageBox.SetTextTokens((rentedRoom == null) ? howManyDaysId : howManyAdditionalDaysId, this); inputMessageBox.TextPanelDistanceY = 0; inputMessageBox.InputDistanceX = 24; //inputMessageBox.InputDistanceY = -4; inputMessageBox.TextBox.Numeric = true; inputMessageBox.TextBox.MaxCharacters = 3; inputMessageBox.TextBox.Text = "1"; inputMessageBox.OnGotUserInput += InputMessageBox_OnGotUserInput; inputMessageBox.Show(); }
/// <summary> /// Check if player is allowed to rest at this location. /// </summary> bool CanRest() { remainingHoursRented = -1; allocatedBed = Vector3.zero; PlayerEnterExit playerEnterExit = GameManager.Instance.PlayerEnterExit; PlayerGPS playerGPS = GameManager.Instance.PlayerGPS; bool inTown = playerGPS.IsPlayerInTown(true); if (inTown && !playerEnterExit.IsPlayerInside) { CloseWindow(); DaggerfallUI.MessageBox(cityCampingIllegal); return(false); } else if ((inTown || !playerGPS.HasCurrentLocation) && playerEnterExit.IsPlayerInsideBuilding) { string sceneName = DaggerfallInterior.GetSceneName(playerGPS.CurrentLocation.MapTableData.MapId, playerEnterExit.BuildingDiscoveryData.buildingKey); if (SaveLoadManager.StateManager.ContainsPermanentScene(sceneName)) { // Can rest if it's an player owned ship/house. int buildingKey = playerEnterExit.BuildingDiscoveryData.buildingKey; if (playerEnterExit.BuildingType == DFLocation.BuildingTypes.Ship || DaggerfallBankManager.IsHouseOwned(buildingKey)) { return(true); } // Find room rental record and get remaining time.. int mapId = playerGPS.CurrentLocation.MapTableData.MapId; RoomRental_v1 room = GameManager.Instance.PlayerEntity.GetRentedRoom(mapId, buildingKey); remainingHoursRented = PlayerEntity.GetRemainingHours(room); allocatedBed = room.allocatedBed; if (remainingHoursRented > 0) { return(true); } } CloseWindow(); DaggerfallUI.MessageBox(HardStrings.haveNotRentedRoom); return(false); } return(true); }
private void ConfirmRenting_OnButtonClick(DaggerfallMessageBox sender, DaggerfallMessageBox.MessageBoxButtons messageBoxButton) { CloseWindow(); if (messageBoxButton == DaggerfallMessageBox.MessageBoxButtons.Yes) { PlayerEntity playerEntity = GameManager.Instance.PlayerEntity; PlayerEnterExit playerEnterExit = GameManager.Instance.PlayerEnterExit; if (playerEntity.GetGoldAmount() >= tradePrice) { playerEntity.DeductGoldAmount(tradePrice); int mapId = GameManager.Instance.PlayerGPS.CurrentLocation.MapTableData.MapId; string sceneName = DaggerfallInterior.GetSceneName(mapId, buildingData.buildingKey); if (rentedRoom == null) { // Get rest marker Vector3 restMarker; playerEnterExit.Interior.FindMarker(out restMarker, DaggerfallInterior.InteriorMarkerTypes.Rest, true); // Create room rental and add it to player rooms RoomRental_v1 room = new RoomRental_v1() { name = buildingData.displayName, mapID = mapId, buildingKey = buildingData.buildingKey, allocatedBed = restMarker, expiryTime = DaggerfallUnity.Instance.WorldTime.Now.ToSeconds() + (ulong)(DaggerfallDateTime.SecondsPerDay * daysToRent) }; playerEntity.RentedRooms.Add(room); SaveLoadManager.StateManager.AddPermanentScene(sceneName); Debug.LogFormat("Rented room for {1} days. {0}", sceneName, daysToRent); } else { rentedRoom.expiryTime += (ulong)(DaggerfallDateTime.SecondsPerDay * daysToRent); Debug.LogFormat("Rented room for additional {1} days. {0}", sceneName, daysToRent); } } else { DaggerfallUI.MessageBox(notEnoughGoldId); } } }
/// <summary> /// Check if player is allowed to rest at this location. /// </summary> bool CanRest(bool alreadyWarned = false) { remainingHoursRented = -1; allocatedBed = Vector3.zero; PlayerEnterExit playerEnterExit = GameManager.Instance.PlayerEnterExit; PlayerGPS playerGPS = GameManager.Instance.PlayerGPS; if (playerGPS.IsPlayerInTown(true, true)) { if (!alreadyWarned) { CloseWindow(); DaggerfallUI.MessageBox(cityCampingIllegal); } // Register crime and start spawning guards playerEntity.CrimeCommitted = PlayerEntity.Crimes.Vagrancy; playerEntity.SpawnCityGuards(true); return(alreadyWarned); } else if (playerGPS.IsPlayerInTown() && playerEnterExit.IsPlayerInsideBuilding) { // Check owned locations string sceneName = DaggerfallInterior.GetSceneName(playerGPS.CurrentLocation.MapTableData.MapId, playerEnterExit.BuildingDiscoveryData.buildingKey); if (SaveLoadManager.StateManager.ContainsPermanentScene(sceneName)) { // Can rest if it's an player owned ship/house. int buildingKey = playerEnterExit.BuildingDiscoveryData.buildingKey; if (playerEnterExit.BuildingType == DFLocation.BuildingTypes.Ship || DaggerfallBankManager.IsHouseOwned(buildingKey)) { return(true); } // Find room rental record and get remaining time.. int mapId = playerGPS.CurrentLocation.MapTableData.MapId; RoomRental_v1 room = GameManager.Instance.PlayerEntity.GetRentedRoom(mapId, buildingKey); remainingHoursRented = PlayerEntity.GetRemainingHours(room); // Get allocated bed marker - default to 0 if out of range // We relink marker position by index as building positions are not stable, they can move from terrain mods or floating Y Vector3[] restMarkers = playerEnterExit.Interior.FindMarkers(DaggerfallInterior.InteriorMarkerTypes.Rest); int bedIndex = (room.allocatedBedIndex >= 0 && room.allocatedBedIndex < restMarkers.Length) ? room.allocatedBedIndex : 0; allocatedBed = restMarkers[bedIndex]; if (remainingHoursRented > 0) { return(true); } } // Check for guild hall rest privileges (exclude taverns since they are all marked as fighters guilds in data) if (playerEnterExit.BuildingDiscoveryData.buildingType != DFLocation.BuildingTypes.Tavern && GameManager.Instance.GuildManager.GetGuild(playerEnterExit.BuildingDiscoveryData.factionID).CanRest()) { playerEnterExit.Interior.FindMarker(out allocatedBed, DaggerfallInterior.InteriorMarkerTypes.Rest); return(true); } CloseWindow(); DaggerfallUI.MessageBox(TextManager.Instance.GetLocalizedText("haveNotRentedRoom")); return(false); } return(true); }