protected virtual void RentRoom() { PlayerEntity playerEntity = GameManager.Instance.PlayerEntity; PlayerEnterExit playerEnterExit = GameManager.Instance.PlayerEnterExit; int mapId = GameManager.Instance.PlayerGPS.CurrentLocation.MapTableData.MapId; string sceneName = DaggerfallInterior.GetSceneName(mapId, buildingData.buildingKey); 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 Vector3[] restMarkers = playerEnterExit.Interior.FindMarkers(DaggerfallInterior.InteriorMarkerTypes.Rest); 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 * 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); } }
private void RentRoom() { PlayerEntity playerEntity = GameManager.Instance.PlayerEntity; PlayerEnterExit playerEnterExit = GameManager.Instance.PlayerEnterExit; 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); } }
/// <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; if (playerGPS.IsPlayerInTown(true, true)) { CloseWindow(); DaggerfallUI.MessageBox(cityCampingIllegal); // Register crime and start spawning guards playerEntity.CrimeCommitted = PlayerEntity.Crimes.Vagrancy; playerEntity.SpawnCityGuards(true); return(false); } 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(HardStrings.haveNotRentedRoom); return(false); } return(true); }
/// <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); }
void CheckInterior() { if (CurrentBuildingKey == 0) { Debug.LogWarning("CurrentBuildingKey == 0"); return; } else { if (!DaggerfallBankManager.IsHouseOwned(CurrentBuildingKey)) { if (playerHomeObjects.ContainsKey(CurrentBuildingKey)) { playerHomeObjects.Remove(CurrentBuildingKey); } if (DaggerfallInterior.GetSceneName(playerGPS.CurrentMapID, BuildingDirectory.buildingKey0) == Ship1Interior || DaggerfallInterior.GetSceneName(playerGPS.CurrentMapID, BuildingDirectory.buildingKey0) == Ship2Interior) { CreatePlacedObjects(playerShipObjects, PlayerShip); inPlayerHome = false; inPlayerShip = true; inPlayerShipExterior = false; } else { inPlayerHome = false; inPlayerShip = false; inPlayerShipExterior = false; } } else { PlacedObjectData_v2[] value = null; if (playerHomeObjects.ContainsKey(CurrentBuildingKey)) { playerHomeObjects.TryGetValue(CurrentBuildingKey, out value); CreatePlacedObjects(value, PlayerHome); } else { playerHomeObjects.Add(CurrentBuildingKey, value); } inPlayerHome = true; inPlayerShip = false; inPlayerShipExterior = false; } lastBuildingKey = CurrentBuildingKey; } }
public void RemoveExpiredRentedRooms() { rentedRooms.RemoveAll(r => { if (GetRemainingHours(r) < 1) { SaveLoadManager.StateManager.RemovePermanentScene(DaggerfallInterior.GetSceneName(r.mapID, r.buildingKey)); return(true); } else { return(false); } }); }
public static void AllocateHouseToPlayer(BuildingSummary house, int regionIndex) { // Set player owned house for this region DFLocation location = GameManager.Instance.PlayerGPS.CurrentLocation; int mapID = location.MapTableData.MapId; houses[regionIndex].location = location.Name; houses[regionIndex].mapID = mapID; houses[regionIndex].buildingKey = house.buildingKey; // Ensure building is discovered GameManager.Instance.PlayerGPS.DiscoverBuilding(house.buildingKey); // Add interior scene to permanent list SaveLoadManager.StateManager.AddPermanentScene(DaggerfallInterior.GetSceneName(mapID, house.buildingKey)); }
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); } }
public static TransactionResult SellHouse(int regionIndex) { BuildingSummary house; BuildingDirectory buildingDirectory = GameManager.Instance.StreamingWorld.GetCurrentBuildingDirectory(); if (buildingDirectory) { if (buildingDirectory.GetBuildingSummary(DaggerfallBankManager.OwnedHouseKey, out house)) { BankAccounts[regionIndex].accountGold += GetHouseSellPrice(house); SaveLoadManager.StateManager.RemovePermanentScene(DaggerfallInterior.GetSceneName(houses[regionIndex].mapID, house.buildingKey)); houses[regionIndex] = new HouseData_v1() { regionIndex = regionIndex }; } } return(TransactionResult.NONE); }
/// <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); } } }
public static void AllocateHouseToPlayer(BuildingSummary house, int regionIndex) { // Set player owned house for this region DFLocation location = GameManager.Instance.PlayerGPS.CurrentLocation; int mapID = location.MapTableData.MapId; houses[regionIndex].location = location.Name; houses[regionIndex].mapID = mapID; houses[regionIndex].buildingKey = house.buildingKey; // Ensure building is discovered GameManager.Instance.PlayerGPS.DiscoverBuilding(house.buildingKey); // Add interior scene to permanent list SaveLoadManager.StateManager.AddPermanentScene(DaggerfallInterior.GetSceneName(mapID, house.buildingKey)); // Add note to journal GameManager.Instance.PlayerEntity.Notebook.AddNote( TextManager.Instance.GetText("DaggerfallUI", "houseDeed").Replace("%town", location.Name).Replace("%region", MapsFile.RegionNames[regionIndex])); }
public static TransactionResult PurchaseHouse(BuildingSummary house, int regionIndex) { if (house.buildingKey < 1) { return(TransactionResult.NONE); } int amount = GetHousePrice(house); PlayerEntity playerEntity = GameManager.Instance.PlayerEntity; var playerGold = playerEntity.GetGoldAmount(); var accountGold = BankAccounts[regionIndex].accountGold; if (amount > playerGold + accountGold) { return(TransactionResult.NOT_ENOUGH_GOLD); } amount = playerEntity.DeductGoldAmount(amount); bankAccounts[regionIndex].accountGold -= amount; // Set player owned house for this region DFLocation location = GameManager.Instance.PlayerGPS.CurrentLocation; int mapID = location.MapTableData.MapId; houses[regionIndex].location = location.Name; houses[regionIndex].mapID = mapID; houses[regionIndex].buildingKey = house.buildingKey; // Ensure building is discovered GameManager.Instance.PlayerGPS.DiscoverBuilding(house.buildingKey); // Add interior scene to permanent list SaveLoadManager.StateManager.AddPermanentScene(DaggerfallInterior.GetSceneName(mapID, house.buildingKey)); return(TransactionResult.PURCHASED_HOUSE); }
/// <summary> /// Transition player through an exterior door into building interior. /// </summary> /// <param name="doorOwner">Parent transform owning door array..</param> /// <param name="door">Exterior door player clicked on.</param> public void TransitionInterior(Transform doorOwner, StaticDoor door, bool doFade = false, bool start = true) { // Ensure we have component references if (!ReferenceComponents()) { return; } // Copy owner position to door // This ensures the door itself is all we need to reposition interior // Useful when loading a save and doorOwner is null (as outside world does not exist) if (doorOwner) { door.ownerPosition = doorOwner.position; door.ownerRotation = doorOwner.rotation; } if (!start) { // Update scene cache from serializable state for exterior->interior transition SaveLoadManager.CacheScene(world.SceneName); // Explicitly deregister all stateful objects since exterior isn't destroyed SaveLoadManager.DeregisterAllSerializableGameObjects(true); // Clear all stateful objects from world loose object tracking world.ClearStatefulLooseObjects(); } // Raise event RaiseOnPreTransitionEvent(TransitionType.ToBuildingInterior, door); // Ensure expired rooms are removed GameManager.Instance.PlayerEntity.RemoveExpiredRentedRooms(); // Get climate ClimateBases climateBase = ClimateBases.Temperate; if (OverrideLocation) { climateBase = OverrideLocation.Summary.Climate; } else if (playerGPS) { climateBase = ClimateSwaps.FromAPIClimateBase(playerGPS.ClimateSettings.ClimateType); } // Layout interior // This needs to be done first so we know where the enter markers are GameObject newInterior = new GameObject(DaggerfallInterior.GetSceneName(playerGPS.CurrentLocation, door)); newInterior.hideFlags = defaultHideFlags; interior = newInterior.AddComponent <DaggerfallInterior>(); // Try to layout interior // If we fail for any reason, use that old chestnut "this house has nothing of value" try { interior.DoLayout(doorOwner, door, climateBase, buildingDiscoveryData); } catch { DaggerfallUI.AddHUDText(HardStrings.thisHouseHasNothingOfValue); Destroy(newInterior); return; } // Position interior directly inside of exterior // This helps with finding closest enter/exit point relative to player position interior.transform.position = door.ownerPosition + (Vector3)door.buildingMatrix.GetColumn(3); interior.transform.rotation = GameObjectHelper.QuaternionFromMatrix(door.buildingMatrix); // Position player above closest enter marker Vector3 marker; if (!interior.FindClosestEnterMarker(transform.position, out marker)) { // Could not find an enter marker, probably not a valid interior Destroy(newInterior); return; } // Enumerate all exterior doors belonging to this building DaggerfallStaticDoors exteriorStaticDoors = interior.ExteriorDoors; if (exteriorStaticDoors && doorOwner) { List <StaticDoor> buildingDoors = new List <StaticDoor>(); for (int i = 0; i < exteriorStaticDoors.Doors.Length; i++) { if (exteriorStaticDoors.Doors[i].recordIndex == door.recordIndex) { StaticDoor newDoor = exteriorStaticDoors.Doors[i]; newDoor.ownerPosition = doorOwner.position; newDoor.ownerRotation = doorOwner.rotation; buildingDoors.Add(newDoor); } } SetExteriorDoors(buildingDoors.ToArray()); } // Assign new interior to parent if (InteriorParent != null) { newInterior.transform.parent = InteriorParent.transform; } // Cache some information about this interior buildingType = interior.BuildingData.BuildingType; factionID = interior.BuildingData.FactionId; // Set player to marker position // TODO: Find closest door for player facing transform.position = marker + Vector3.up * (controller.height * 0.6f); SetStanding(); EnableInteriorParent(); // Add quest resources GameObjectHelper.AddQuestResourceObjects(SiteTypes.Building, interior.transform, interior.EntryDoor.buildingKey); // Update serializable state from scene cache for exterior->interior transition (unless new/load game) if (!start) { SaveLoadManager.RestoreCachedScene(interior.name); } // Raise event RaiseOnTransitionInteriorEvent(door, interior); // Fade in from black if (doFade) { DaggerfallUI.Instance.FadeHUDFromBlack(); } }