private void CancelLease() { var data = BaseService.GetPlayerTempData(GetPC()); bool canCancelLease = BasePermissionService.HasBasePermission(GetPC(), data.PCBaseID, BasePermission.CanCancelLease); if (!canCancelLease) { GetPC().FloatingText("You don't have permission to cancel this base's lease."); return; } if (data.IsConfirming) { data.IsConfirming = false; PCBase pcBase = DataService.PCBase.GetByID(data.PCBaseID); BaseService.ClearPCBaseByID(data.PCBaseID); MessageHub.Instance.Publish(new OnBaseLeaseCancelled(pcBase)); GetPC().FloatingText("Your lease has been canceled. Any property left behind has been delivered to the planetary government. Speak with them to retrieve it."); BuildMainPage(); SetResponseText("CancelLeasePage", 1, "Confirm Cancel Lease"); EndConversation(); } else { data.IsConfirming = true; SetResponseText("CancelLeasePage", 1, "CONFIRM CANCEL LEASE"); } }
private void LoadManageStructureDetails() { ClearPageResponses("ManageStructureDetailsPage"); var data = BaseService.GetPlayerTempData(GetPC()); var structure = data.ManipulatingStructure.Structure; var pcBaseStructureID = data.ManipulatingStructure.Structure.Area.GetLocalString("PC_BASE_STRUCTURE_ID"); Guid?structureID = string.IsNullOrWhiteSpace(pcBaseStructureID) ? null : (Guid?)new Guid(pcBaseStructureID); bool canRetrieveStructures; bool canPlaceEditStructures; if (structureID != null) { canRetrieveStructures = BasePermissionService.HasStructurePermission(GetPC(), (Guid)structureID, StructurePermission.CanRetrieveStructures); canPlaceEditStructures = BasePermissionService.HasStructurePermission(GetPC(), (Guid)structureID, StructurePermission.CanPlaceEditStructures); } else { canRetrieveStructures = BasePermissionService.HasBasePermission(GetPC(), data.ManipulatingStructure.PCBaseID, BasePermission.CanRetrieveStructures); canPlaceEditStructures = BasePermissionService.HasBasePermission(GetPC(), data.ManipulatingStructure.PCBaseID, BasePermission.CanPlaceEditStructures); } string header = ColorTokenService.Green("Structure: ") + structure.Name + "\n\n"; header += "What would you like to do with this structure?"; SetPageHeader("ManageStructureDetailsPage", header); AddResponseToPage("ManageStructureDetailsPage", "Retrieve Structure", canRetrieveStructures); AddResponseToPage("ManageStructureDetailsPage", "Rotate", canPlaceEditStructures); }
private void LoadBaseDetailsPage() { var data = BaseService.GetPlayerTempData(GetPC()); PCBase pcBase = DataService.PCBase.GetByID(data.PCBaseID); Area dbArea = DataService.Area.GetByResref(pcBase.AreaResref); var owner = DataService.Player.GetByID(pcBase.PlayerID); bool canExtendLease = BasePermissionService.HasBasePermission(GetPC(), pcBase.ID, BasePermission.CanExtendLease); bool canCancelLease = BasePermissionService.HasBasePermission(GetPC(), pcBase.ID, BasePermission.CanCancelLease); int dailyUpkeep = dbArea.DailyUpkeep + (int)(dbArea.DailyUpkeep * (owner.LeaseRate * 0.01f)); string header = ColorTokenService.Green("Location: ") + dbArea.Name + " (" + pcBase.Sector + ")\n\n"; header += ColorTokenService.Green("Owned By: ") + owner.CharacterName + "\n"; header += ColorTokenService.Green("Purchased: ") + pcBase.DateInitialPurchase + "\n"; header += ColorTokenService.Green("Rent Due: ") + pcBase.DateRentDue + "\n"; header += ColorTokenService.Green("Daily Upkeep: ") + dailyUpkeep + " credits\n\n"; header += "Daily upkeep may be paid up to 30 days in advance.\n"; // Starships have slightly different setups. They only pay rent when in a public starport and // the cost is set by the starport. if (pcBase.PCBaseTypeID == (int)Enumeration.PCBaseType.Starship) { canCancelLease = false; if (SpaceService.IsLocationPublicStarport(pcBase.ShipLocation)) { var shipLocationGuid = new Guid(pcBase.ShipLocation); SpaceStarport starport = DataService.SpaceStarport.GetByID(shipLocationGuid); header = ColorTokenService.Green("Location: ") + starport.Name + " (" + starport.Planet + ")\n"; header += ColorTokenService.Green("Rent Due: ") + pcBase.DateRentDue + "\n"; header += ColorTokenService.Green("Daily Upkeep: ") + starport.Cost + " credits\n\n"; } else { header = "This ship has no lease currently. You only need to pay when in a starport."; canExtendLease = false; } } SetPageHeader("BaseDetailsPage", header); const int MaxAdvancePay = 30; DateTime newRentDate = pcBase.DateRentDue.AddDays(1); TimeSpan ts = newRentDate - DateTime.UtcNow; bool canPayRent = ts.TotalDays < MaxAdvancePay; SetResponseVisible("BaseDetailsPage", 1, canPayRent && canExtendLease); newRentDate = pcBase.DateRentDue.AddDays(7); ts = newRentDate - DateTime.UtcNow; canPayRent = ts.TotalDays < MaxAdvancePay; SetResponseVisible("BaseDetailsPage", 2, canPayRent && canExtendLease); SetResponseVisible("BaseDetailsPage", 3, canCancelLease); }
private void ExtendLease(int days, int responseID, string optionText) { var data = BaseService.GetPlayerTempData(GetPC()); PCBase pcBase = DataService.PCBase.GetByID(data.PCBaseID); Area dbArea = DataService.Area.GetByResref(pcBase.AreaResref); bool canExtendLease = BasePermissionService.HasBasePermission(GetPC(), pcBase.ID, BasePermission.CanExtendLease); var owner = DataService.Player.GetByID(pcBase.PlayerID); if (!canExtendLease) { GetPC().FloatingText("You don't have permission to extend leases on this base."); return; } int dailyUpkeep = dbArea.DailyUpkeep + (int)(dbArea.DailyUpkeep * (owner.LeaseRate * 0.01f)); // Starship override. if (pcBase.PCBaseTypeID == (int)Enumeration.PCBaseType.Starship) { Guid shipLocationGuid = new Guid(pcBase.ShipLocation); SpaceStarport starport = DataService.SpaceStarport.GetByID(shipLocationGuid); dailyUpkeep = starport.Cost + (int)(starport.Cost * (owner.LeaseRate * 0.01f)); } if (GetPC().Gold < dailyUpkeep * days) { GetPC().SendMessage("You don't have enough credits to extend your lease."); data.IsConfirming = false; SetResponseText("BaseDetailsPage", responseID, optionText); return; } if (data.IsConfirming) { _.TakeGoldFromCreature(dailyUpkeep * days, GetPC(), TRUE); data.IsConfirming = false; SetResponseText("BaseDetailsPage", responseID, optionText); pcBase.DateRentDue = pcBase.DateRentDue.AddDays(days); DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); LoadBaseDetailsPage(); } else { data.IsConfirming = true; SetResponseText("BaseDetailsPage", responseID, "CONFIRM " + optionText.ToUpper()); } }
private void BuildMainPageResponses() { var player = GetPC(); var data = BaseService.GetPlayerTempData(player); Player dbPlayer = DataService.Player.GetByID(player.GlobalID); Player primaryResident; bool isPrimaryResident; bool canEditPrimaryResidence; bool canRemovePrimaryResidence; if (data.BuildingType == BuildingType.Interior || data.BuildingType == BuildingType.Starship) { Guid structureID = data.StructureID; primaryResident = DataService.Player.GetByPrimaryResidencePCBaseStructureIDOrDefault(structureID); isPrimaryResident = dbPlayer.PrimaryResidencePCBaseStructureID != null && dbPlayer.PrimaryResidencePCBaseStructureID == structureID; canEditPrimaryResidence = BasePermissionService.HasStructurePermission(player, structureID, StructurePermission.CanEditPrimaryResidence); canRemovePrimaryResidence = BasePermissionService.HasStructurePermission(player, structureID, StructurePermission.CanRemovePrimaryResidence); } else if (data.BuildingType == BuildingType.Apartment) { Guid pcBaseID = data.PCBaseID; primaryResident = DataService.Player.GetByPrimaryResidencePCBaseIDOrDefault(pcBaseID); isPrimaryResident = dbPlayer.PrimaryResidencePCBaseID != null && dbPlayer.PrimaryResidencePCBaseID == pcBaseID; canEditPrimaryResidence = BasePermissionService.HasBasePermission(player, pcBaseID, BasePermission.CanEditPrimaryResidence); canRemovePrimaryResidence = BasePermissionService.HasBasePermission(player, pcBaseID, BasePermission.CanRemovePrimaryResidence); } else { throw new Exception("Invalid building type on EditPrimaryResidence conversation. Type = " + data.BuildingType); } // If another person is a resident and this player does not have the "remove" permission, don't allow them to make primary residence. if (!isPrimaryResident && primaryResident != null && !canRemovePrimaryResidence) { canEditPrimaryResidence = false; } SetResponseVisible("MainPage", 1, canEditPrimaryResidence); SetResponseVisible("MainPage", 2, canRemovePrimaryResidence || isPrimaryResident); }
public bool Run(params object[] args) { NWPlayer clicker = (_.GetPlaceableLastClickedBy()); NWPlaceable tower = (Object.OBJECT_SELF); clicker.ClearAllActions(); if (!clicker.IsPlayer) { return(false); } // Check the distance. if (_.GetDistanceBetween(clicker.Object, tower.Object) > 15.0f) { clicker.SendMessage("You are too far away to interact with that control tower."); return(false); } Guid structureID = new Guid(tower.GetLocalString("PC_BASE_STRUCTURE_ID")); PCBaseStructure structure = DataService.Single <PCBaseStructure>(x => x.ID == structureID); // Does the player have permission to access the fuel bays? if (BasePermissionService.HasBasePermission(clicker, structure.PCBaseID, BasePermission.CanManageBaseFuel)) { // Is the tower in reinforced mode? If so, fuel cannot be accessed. var pcBase = DataService.Single <PCBase>(x => x.ID == structure.PCBaseID); if (pcBase.IsInReinforcedMode) { clicker.SendMessage("This tower is currently in reinforced mode and cannot be accessed."); } else { DialogService.StartConversation(clicker, tower, "ControlTower"); } } else { clicker.SendMessage("You don't have permission to interact with this control tower."); } return(true); }
private void MainResponses(int responseID) { var data = BaseService.GetPlayerTempData(GetPC()); switch (responseID) { case 1: // Change Permissions if (!BasePermissionService.HasBasePermission(GetPC(), data.PCBaseID, BasePermission.CanAdjustPermissions)) { GetPC().FloatingText("You do not have permission to change other players' permissions."); return; } BuildPlayerListPage(); ChangePage("PlayerListPage"); break; case 2: // Change Public Permissions var pcBase = DataService.Get <PCBase>(data.PCBaseID); if (pcBase.Sector == "AP") { GetPC().FloatingText("Public permissions cannot be adjusted inside apartments."); return; } if (!BasePermissionService.HasBasePermission(GetPC(), data.PCBaseID, BasePermission.CanAdjustPublicPermissions)) { GetPC().FloatingText("You do not have permission to change this base's public permissions."); return; } BuildPublicPermissionsPage(); ChangePage("PublicPermissionsPage"); break; } }
public override PlayerDialog SetUp(NWPlayer player) { PlayerDialog dialog = new PlayerDialog("MainPage"); string structureID = _.GetLocalString(_.GetArea(player), "PC_BASE_STRUCTURE_ID"); if (string.IsNullOrWhiteSpace(structureID)) { player.SendMessage("Base structure ID not found on area. Please report this problem."); return(null); } Guid pcBaseStructureID = new Guid(structureID); PCBaseStructure structure = DataService.PCBaseStructure.GetByID(pcBaseStructureID); PCBase pcBase = DataService.PCBase.GetByID(structure.PCBaseID); bool bSpace = SpaceService.IsLocationSpace(pcBase.ShipLocation); List <string> options = new List <string>(); if (bSpace && BasePermissionService.HasStructurePermission(player, structure.ID, StructurePermission.CanFlyStarship)) { // See if we are near enough to the planet to land. if (SpaceService.CanLandOnPlanet(player.Area)) { options.Add("Land"); } options.Add("Pilot Ship"); options.Add("Hyperspace Jump"); } else if (BasePermissionService.HasStructurePermission(player, structure.ID, StructurePermission.CanFlyStarship)) { options.Add("Take Off"); } if (!bSpace && BasePermissionService.HasBasePermission(player, structure.PCBaseID, BasePermission.CanManageBaseFuel)) { options.Add("Access Fuel Bay"); options.Add("Access Stronidium Bay"); } if (BasePermissionService.HasBasePermission(player, structure.PCBaseID, BasePermission.CanAccessStructureInventory)) { if (!bSpace) { options.Add("Access Resource Bay"); } options.Add("Export Starcharts"); } DialogPage mainPage = new DialogPage("", options.ToArray()); dialog.AddPage("MainPage", mainPage); // Hyperspace destinations. string[] responses = SpaceService.GetHyperspaceDestinationList(pcBase); DialogPage destinationPage = new DialogPage("Please select a destination to fly to.", responses); dialog.AddPage("HyperDestPage", destinationPage); // Landing destinations. Hashtable landingspots = SpaceService.GetLandingDestinationList(player, pcBase); List <String> responseList = landingspots.Keys.Cast <String>().ToList(); DialogPage landingPage = new DialogPage("Where do you want to land?", responseList.ToArray()); dialog.AddPage("LandingDestPage", landingPage); // Save off the landing responses in CustomData. This ensures we can access the structure IDs later. foreach (var key in landingspots.Keys) { dialog.CustomData.Add("LAND_" + key, landingspots[key]); } return(dialog); }
private void DoSetAsResidence() { var player = GetPC(); var data = BaseService.GetPlayerTempData(player); var newResident = DataService.Player.GetByID(player.GlobalID); Player currentResident; bool isPrimaryResident; bool canEditPrimaryResidence; bool canRemovePrimaryResidence; if (data.BuildingType == BuildingType.Interior || data.BuildingType == BuildingType.Starship) { Guid structureID = data.StructureID; currentResident = DataService.Player.GetByPrimaryResidencePCBaseStructureIDOrDefault(structureID); isPrimaryResident = newResident.PrimaryResidencePCBaseStructureID != null && newResident.PrimaryResidencePCBaseStructureID == structureID; canEditPrimaryResidence = BasePermissionService.HasStructurePermission(player, structureID, StructurePermission.CanEditPrimaryResidence); canRemovePrimaryResidence = BasePermissionService.HasStructurePermission(player, structureID, StructurePermission.CanRemovePrimaryResidence); } else if (data.BuildingType == BuildingType.Apartment) { Guid pcBaseID = data.PCBaseID; currentResident = DataService.Player.GetByPrimaryResidencePCBaseIDOrDefault(pcBaseID); isPrimaryResident = newResident.PrimaryResidencePCBaseID != null && newResident.PrimaryResidencePCBaseID == pcBaseID; canEditPrimaryResidence = BasePermissionService.HasBasePermission(player, pcBaseID, BasePermission.CanEditPrimaryResidence); canRemovePrimaryResidence = BasePermissionService.HasBasePermission(player, pcBaseID, BasePermission.CanRemovePrimaryResidence); } else { throw new Exception("EditPrimaryResidence -> DoSetAsResidence: Can't handle building type ID " + data.BuildingType); } // If another person is a resident and this player does not have the "remove" permission, don't allow them to make primary residence. if (!isPrimaryResident && currentResident != null && !canRemovePrimaryResidence) { player.FloatingText("You do not have permission to revoke the current resident's residency."); return; } if (!canEditPrimaryResidence) { player.FloatingText("You do not have permission to select this as your primary residency."); return; } if (currentResident != null) { currentResident.PrimaryResidencePCBaseID = null; currentResident.PrimaryResidencePCBaseStructureID = null; NotifyPlayer(currentResident.ID); DataService.SubmitDataChange(currentResident, DatabaseActionType.Update); } if (data.BuildingType == BuildingType.Interior || data.BuildingType == BuildingType.Starship) { newResident.PrimaryResidencePCBaseStructureID = data.StructureID; newResident.PrimaryResidencePCBaseID = null; } else if (data.BuildingType == BuildingType.Apartment) { newResident.PrimaryResidencePCBaseStructureID = null; newResident.PrimaryResidencePCBaseID = data.PCBaseID; } DataService.SubmitDataChange(newResident, DatabaseActionType.Update); BuildMainPageHeader(); BuildMainPageResponses(); ClearNavigationStack(); ChangePage("MainPage", false); }
private void DoRotate(float degrees, bool isSet) { var data = BaseService.GetPlayerTempData(GetPC()); bool canPlaceEditStructures; var structure = data.ManipulatingStructure.Structure; if (data.BuildingType == Enumeration.BuildingType.Exterior || data.BuildingType == Enumeration.BuildingType.Apartment) { canPlaceEditStructures = BasePermissionService.HasBasePermission(GetPC(), data.ManipulatingStructure.PCBaseID, BasePermission.CanPlaceEditStructures); } else if (data.BuildingType == Enumeration.BuildingType.Interior) { var structureID = new Guid(data.ManipulatingStructure.Structure.Area.GetLocalString("PC_BASE_STRUCTURE_ID")); canPlaceEditStructures = BasePermissionService.HasStructurePermission(GetPC(), structureID, StructurePermission.CanPlaceEditStructures); } else { throw new Exception("BaseManagementTool -> DoRotate: Cannot handle building type " + data.BuildingType); } if (!canPlaceEditStructures) { GetPC().FloatingText("You don't have permission to edit structures."); return; } float facing = structure.Facing; if (isSet) { facing = degrees; } else { facing += degrees; } while (facing > 360) { facing -= 360; } structure.Facing = facing; LoadRotatePage(); var dbStructure = DataService.PCBaseStructure.GetByID(data.ManipulatingStructure.PCBaseStructureID); var baseStructure = DataService.BaseStructure.GetByID(dbStructure.BaseStructureID); dbStructure.LocationOrientation = facing; if (baseStructure.BaseStructureTypeID == (int)BaseStructureType.Building) { // The structure's facing isn't updated until after this code executes. // Build a new location object for use with spawning the door. var exteriorStyle = DataService.BuildingStyle.GetByID(Convert.ToInt32(dbStructure.ExteriorStyleID)); Location locationOverride = _.Location(data.TargetArea.Object, structure.Position, facing); data.ManipulatingStructure.ChildStructure.Destroy(); data.ManipulatingStructure.ChildStructure = BaseService.SpawnBuildingDoor(exteriorStyle.DoorRule, structure, locationOverride); // Update the cache List <AreaStructure> areaStructures = data.TargetArea.Data["BASE_SERVICE_STRUCTURES"]; var cacheStructure = areaStructures.Single(x => x.PCBaseStructureID == data.ManipulatingStructure.PCBaseStructureID && x.ChildStructure == null); int doorIndex = areaStructures.IndexOf(cacheStructure); areaStructures[doorIndex].Structure = data.ManipulatingStructure.ChildStructure; } DataService.SubmitDataChange(dbStructure, DatabaseActionType.Update); }
private void DoRetrieveStructure() { var data = BaseService.GetPlayerTempData(GetPC()); PCBaseStructure structure = DataService.PCBaseStructure.GetByID(data.ManipulatingStructure.PCBaseStructureID); BaseStructure baseStructure = DataService.BaseStructure.GetByID(structure.BaseStructureID); PCBase pcBase = DataService.PCBase.GetByID(structure.PCBaseID); BaseStructureType structureType = (BaseStructureType)baseStructure.BaseStructureTypeID; var tempStorage = _.GetObjectByTag("TEMP_ITEM_STORAGE"); var pcStructureID = structure.ID; int impoundedCount = 0; var controlTower = BaseService.GetBaseControlTower(pcBase.ID); int maxShields = BaseService.CalculateMaxShieldHP(controlTower); if (structureType == BaseStructureType.Starship) { GetPC().SendMessage("You cannot pick up starships once they are built. You can only fly them away."); return; } if (pcBase.PCBaseTypeID != (int)Enumeration.PCBaseType.Starship && pcBase.ShieldHP < maxShields && structureType != BaseStructureType.ControlTower) { GetPC().FloatingText("You cannot retrieve any structures because the control tower has less than 100% shields."); return; } bool canRetrieveStructures; if (data.BuildingType == Enumeration.BuildingType.Exterior || data.BuildingType == Enumeration.BuildingType.Apartment) { canRetrieveStructures = BasePermissionService.HasBasePermission(GetPC(), data.ManipulatingStructure.PCBaseID, BasePermission.CanRetrieveStructures); } else if (data.BuildingType == Enumeration.BuildingType.Interior || data.BuildingType == Enumeration.BuildingType.Starship) { var structureID = new Guid(data.ManipulatingStructure.Structure.Area.GetLocalString("PC_BASE_STRUCTURE_ID")); canRetrieveStructures = BasePermissionService.HasStructurePermission(GetPC(), structureID, StructurePermission.CanRetrieveStructures); } else { throw new Exception("BaseManagementTool -> DoRetrieveStructure: Cannot handle building type " + data.BuildingType); } if (!canRetrieveStructures) { GetPC().FloatingText("You don't have permission to retrieve structures."); return; } if (structureType == BaseStructureType.ControlTower) { var structureCount = DataService.PCBaseStructure.GetAllByPCBaseID(structure.PCBaseID).Count(); if (structureCount > 1) { GetPC().FloatingText("You must remove all structures in this sector before picking up the control tower."); return; } // Impound resources retrieved by drills. var items = DataService.PCBaseStructureItem.GetAllByPCBaseStructureID(structure.ID); foreach (var item in items) { ImpoundService.Impound(item); DataService.SubmitDataChange(item, DatabaseActionType.Delete); impoundedCount++; } } else if (structureType == BaseStructureType.Building) { var childStructures = DataService.PCBaseStructure.GetAllByParentPCBaseStructureID(structure.ID).ToList(); for (int x = childStructures.Count - 1; x >= 0; x--) { var furniture = childStructures.ElementAt(x); NWItem furnitureItem = BaseService.ConvertStructureToItem(furniture, tempStorage); ImpoundService.Impound(GetPC().GlobalID, furnitureItem); furnitureItem.Destroy(); DataService.SubmitDataChange(furniture, DatabaseActionType.Delete); impoundedCount++; } // Remove any primary owner permissions. var primaryOwner = DataService.Player.GetByPrimaryResidencePCBaseStructureIDOrDefault(structure.ID); if (primaryOwner != null) { primaryOwner.PrimaryResidencePCBaseStructureID = null; DataService.SubmitDataChange(primaryOwner, DatabaseActionType.Update); } // Remove any access permissions. foreach (var buildingPermission in DataService.PCBaseStructurePermission.GetAllByPCBaseStructureID(structure.ID)) { DataService.SubmitDataChange(buildingPermission, DatabaseActionType.Delete); } } else if (structureType == BaseStructureType.StarshipProduction && data.ManipulatingStructure.Structure.GetLocalInt("DOCKED_STARSHIP") == 1) { GetPC().SendMessage("You cannot move a dock that has a starship docked in it. Fly the ship away first."); return; } BaseService.ConvertStructureToItem(structure, GetPC()); DataService.SubmitDataChange(structure, DatabaseActionType.Delete); data.ManipulatingStructure.Structure.Destroy(); // Impound any fuel that's over the limit. if (structureType == BaseStructureType.StronidiumSilo || structureType == BaseStructureType.FuelSilo) { int maxFuel = BaseService.CalculateMaxFuel(pcBase.ID); int maxReinforcedFuel = BaseService.CalculateMaxReinforcedFuel(pcBase.ID); if (pcBase.Fuel > maxFuel) { int returnAmount = pcBase.Fuel - maxFuel; NWItem refund = _.CreateItemOnObject("fuel_cell", tempStorage, returnAmount); pcBase.Fuel = maxFuel; ImpoundService.Impound(pcBase.PlayerID, refund); GetPC().SendMessage("Excess fuel cells have been impounded by the planetary government. The owner of the base will need to retrieve it."); refund.Destroy(); } if (pcBase.ReinforcedFuel > maxReinforcedFuel) { int returnAmount = pcBase.ReinforcedFuel - maxReinforcedFuel; NWItem refund = _.CreateItemOnObject("stronidium", tempStorage, returnAmount); pcBase.ReinforcedFuel = maxReinforcedFuel; ImpoundService.Impound(pcBase.PlayerID, refund); GetPC().SendMessage("Excess stronidium units have been impounded by the planetary government. The owner of the base will need to retrieve it."); refund.Destroy(); } } else if (structureType == BaseStructureType.ResourceSilo) { int maxResources = BaseService.CalculateResourceCapacity(pcBase.ID); var items = DataService.PCBaseStructureItem.GetAllByPCBaseStructureID(controlTower.ID).ToList(); while (items.Count > maxResources) { var item = items.ElementAt(0); var impoundItem = new PCImpoundedItem { PlayerID = pcBase.PlayerID, ItemResref = item.ItemResref, ItemObject = item.ItemObject, DateImpounded = DateTime.UtcNow, ItemName = item.ItemName, ItemTag = item.ItemTag }; DataService.SubmitDataChange(impoundItem, DatabaseActionType.Insert); GetPC().SendMessage(item.ItemName + " has been impounded by the planetary government because your base ran out of space to store resources. The owner of the base will need to retrieve it."); DataService.SubmitDataChange(item, DatabaseActionType.Delete); } } // Update the cache List <AreaStructure> areaStructures = data.TargetArea.Data["BASE_SERVICE_STRUCTURES"]; var records = areaStructures.Where(x => x.PCBaseStructureID == pcStructureID).ToList(); for (int x = records.Count() - 1; x >= 0; x--) { var record = records[x]; record.ChildStructure?.Destroy(); areaStructures.Remove(record); } EndConversation(); if (impoundedCount > 0) { GetPC().FloatingText(impoundedCount + " item(s) were sent to the planetary impound."); } }
private void LoadMainPage() { ClearPageResponses("MainPage"); var data = BaseService.GetPlayerTempData(GetPC()); int cellX = (int)(_.GetPositionFromLocation(data.TargetLocation).m_X / 10.0f); int cellY = (int)(_.GetPositionFromLocation(data.TargetLocation).m_Y / 10.0f); string sector = BaseService.GetSectorOfLocation(data.TargetLocation); Area dbArea = DataService.Area.GetByResref(data.TargetArea.Resref); bool hasUnclaimed = false; Guid playerID = GetPC().GlobalID; int buildingTypeID = data.TargetArea.GetLocalInt("BUILDING_TYPE"); Enumeration.BuildingType buildingType = buildingTypeID <= 0 ? Enumeration.BuildingType.Exterior : (Enumeration.BuildingType)buildingTypeID; data.BuildingType = buildingType; bool canEditBasePermissions = false; bool canEditBuildingPermissions = false; bool canEditBuildingPublicPermissions = false; bool canEditStructures = false; bool canEditPrimaryResidence = false; bool canRemovePrimaryResidence = false; bool canRenameStructure = false; bool canChangeStructureMode = false; bool canEditPublicBasePermissions = false; string header = ColorTokenService.Green("Base Management Menu\n\n"); header += ColorTokenService.Green("Area: ") + data.TargetArea.Name + " (" + cellX + ", " + cellY + ")\n\n"; // Are we in a starship? if (buildingType == Enumeration.BuildingType.Starship) { Guid pcBaseStructureID = new Guid(data.TargetArea.GetLocalString("PC_BASE_STRUCTURE_ID")); var structure = DataService.PCBaseStructure.GetByID(pcBaseStructureID); var buildingStyle = DataService.BuildingStyle.GetByID(Convert.ToInt32(structure.InteriorStyleID)); int itemLimit = buildingStyle.FurnitureLimit + structure.StructureBonus; var childStructures = DataService.PCBaseStructure.GetAllByParentPCBaseStructureID(structure.ID); header += ColorTokenService.Green("Structure Limit: ") + childStructures.Count() + " / " + itemLimit + "\n"; // Get all child structures contained by this building which improve atmosphere. var structures = DataService.PCBaseStructure.GetAllByParentPCBaseStructureID(pcBaseStructureID).Where(x => { var childStructure = DataService.BaseStructure.GetByID(x.BaseStructureID); return(childStructure.HasAtmosphere); }); // Add up the total atmosphere rating, being careful not to go over the cap. int bonus = structures.Sum(x => 1 + x.StructureBonus) * 2; if (bonus > 150) { bonus = 150; } header += ColorTokenService.Green("Atmosphere Bonus: ") + bonus + "% / " + "150%"; header += "\n"; canEditPrimaryResidence = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanEditPrimaryResidence); canRemovePrimaryResidence = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanRemovePrimaryResidence); canRenameStructure = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanRenameStructures); canEditStructures = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanPlaceEditStructures); canEditBuildingPermissions = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanAdjustPermissions); canEditBuildingPublicPermissions = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanAdjustPublicPermissions); canChangeStructureMode = false; // Starships cannot be workshops. data.StructureID = pcBaseStructureID; } // Area is not buildable. else if (!dbArea.IsBuildable) { header += "Land in this area cannot be claimed. However, you can still manage any leases you own from the list below."; } // Building type is an interior of a building else if (buildingType == Enumeration.BuildingType.Interior) { Guid pcBaseStructureID = new Guid(data.TargetArea.GetLocalString("PC_BASE_STRUCTURE_ID")); var structure = DataService.PCBaseStructure.GetByID(pcBaseStructureID); var baseStructure = DataService.BaseStructure.GetByID(structure.BaseStructureID); int itemLimit = baseStructure.Storage + structure.StructureBonus; var childStructures = DataService.PCBaseStructure.GetAllByParentPCBaseStructureID(structure.ID); header += ColorTokenService.Green("Structure Limit: ") + childStructures.Count() + " / " + itemLimit + "\n"; // Get all child structures contained by this building which improve atmosphere. var structures = DataService.PCBaseStructure.GetAllByParentPCBaseStructureID(pcBaseStructureID).Where(x => { var childStructure = DataService.BaseStructure.GetByID(x.BaseStructureID); return(childStructure.HasAtmosphere); }); // Add up the total atmosphere rating, being careful not to go over the cap. int bonus = structures.Sum(x => 1 + x.StructureBonus) * 2; if (bonus > 150) { bonus = 150; } header += ColorTokenService.Green("Atmosphere Bonus: ") + bonus + "% / " + "150%"; header += "\n"; // The building must be set to the "Residence" mode in order for a primary resident to be selected. if (structure.StructureModeID == (int)StructureModeType.Residence) { canEditPrimaryResidence = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanEditPrimaryResidence); canRemovePrimaryResidence = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanRemovePrimaryResidence); } canRenameStructure = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanRenameStructures); canEditStructures = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanPlaceEditStructures); canEditBuildingPermissions = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanAdjustPermissions); canEditBuildingPublicPermissions = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanAdjustPublicPermissions); canChangeStructureMode = BasePermissionService.HasStructurePermission(GetPC(), pcBaseStructureID, StructurePermission.CanChangeStructureMode); data.StructureID = pcBaseStructureID; } // Building type is an apartment // Apartments may only ever be in the "Residence" mode. else if (buildingType == Enumeration.BuildingType.Apartment) { Guid pcBaseID = new Guid(data.TargetArea.GetLocalString("PC_BASE_ID")); var pcBase = DataService.PCBase.GetByID(pcBaseID); var buildingStyle = DataService.BuildingStyle.GetByID(Convert.ToInt32(pcBase.BuildingStyleID)); int itemLimit = buildingStyle.FurnitureLimit; var structures = DataService.PCBaseStructure.GetAllByPCBaseID(pcBase.ID); header += ColorTokenService.Green("Structure Limit: ") + structures.Count() + " / " + itemLimit + "\n"; // Add up the total atmosphere rating, being careful not to go over the cap. int bonus = structures.Sum(x => 1 + x.StructureBonus) * 2; if (bonus > 150) { bonus = 150; } header += ColorTokenService.Green("Atmosphere Bonus: ") + bonus + "% / " + "150%"; header += "\n"; canEditStructures = BasePermissionService.HasBasePermission(GetPC(), pcBaseID, BasePermission.CanPlaceEditStructures); canEditBasePermissions = BasePermissionService.HasBasePermission(GetPC(), pcBaseID, BasePermission.CanAdjustPermissions); canEditPrimaryResidence = BasePermissionService.HasBasePermission(GetPC(), pcBaseID, BasePermission.CanEditPrimaryResidence); canRemovePrimaryResidence = BasePermissionService.HasBasePermission(GetPC(), pcBaseID, BasePermission.CanRemovePrimaryResidence); canRenameStructure = BasePermissionService.HasBasePermission(GetPC(), pcBaseID, BasePermission.CanRenameStructures); data.PCBaseID = pcBaseID; } // Building type is an exterior building else if (buildingType == Enumeration.BuildingType.Exterior) { var pcBase = DataService.PCBase.GetByAreaResrefAndSectorOrDefault(data.TargetArea.Resref, sector); var northeastOwner = dbArea.NortheastOwner == null ? null : DataService.Player.GetByID((Guid)dbArea.NortheastOwner); var northwestOwner = dbArea.NorthwestOwner == null ? null : DataService.Player.GetByID((Guid)dbArea.NorthwestOwner); var southeastOwner = dbArea.SoutheastOwner == null ? null : DataService.Player.GetByID((Guid)dbArea.SoutheastOwner); var southwestOwner = dbArea.SouthwestOwner == null ? null : DataService.Player.GetByID((Guid)dbArea.SouthwestOwner); if (northeastOwner != null) { header += ColorTokenService.Green("Northeast Owner: ") + "Claimed"; if (dbArea.NortheastOwner == playerID) { header += " (" + northeastOwner.CharacterName + ")"; } header += "\n"; } else { header += ColorTokenService.Green("Northeast Owner: ") + "Unclaimed\n"; hasUnclaimed = true; } if (northwestOwner != null) { header += ColorTokenService.Green("Northwest Owner: ") + "Claimed"; if (dbArea.NorthwestOwner == playerID) { header += " (" + northwestOwner.CharacterName + ")"; } header += "\n"; } else { header += ColorTokenService.Green("Northwest Owner: ") + "Unclaimed\n"; hasUnclaimed = true; } if (southeastOwner != null) { header += ColorTokenService.Green("Southeast Owner: ") + "Claimed"; if (dbArea.SoutheastOwner == playerID) { header += " (" + southeastOwner.CharacterName + ")"; } header += "\n"; } else { header += ColorTokenService.Green("Southeast Owner: ") + "Unclaimed\n"; hasUnclaimed = true; } if (southwestOwner != null) { header += ColorTokenService.Green("Southwest Owner: ") + "Claimed"; if (dbArea.SouthwestOwner == playerID) { header += " (" + southwestOwner.CharacterName + ")"; } header += "\n"; } else { header += ColorTokenService.Green("Southwest Owner: ") + "Unclaimed\n"; hasUnclaimed = true; } canEditStructures = pcBase != null && BasePermissionService.HasBasePermission(GetPC(), pcBase.ID, BasePermission.CanPlaceEditStructures); canEditBasePermissions = pcBase != null && BasePermissionService.HasBasePermission(GetPC(), pcBase.ID, BasePermission.CanAdjustPermissions); canEditPublicBasePermissions = pcBase != null && BasePermissionService.HasBasePermission(GetPC(), pcBase.ID, BasePermission.CanAdjustPublicPermissions); if (pcBase != null) { data.PCBaseID = pcBase.ID; } } else { throw new Exception("BaseManagementTool -> Cannot locate building type with ID " + buildingTypeID); } SetPageHeader("MainPage", header); bool showManage = DataService.PCBasePermission.GetAllByPlayerID(GetPC().GlobalID).Count(x => x.CanExtendLease) > 0; AddResponseToPage("MainPage", "Manage My Leases", showManage); AddResponseToPage("MainPage", "Purchase Territory", hasUnclaimed && dbArea.IsBuildable); AddResponseToPage("MainPage", "Edit Nearby Structures", canEditStructures); AddResponseToPage("MainPage", "Edit Base Permissions", canEditBasePermissions || canEditPublicBasePermissions); AddResponseToPage("MainPage", "Edit Building Permissions", canEditBuildingPermissions || canEditBuildingPublicPermissions); AddResponseToPage("MainPage", "Edit Primary Residence", canEditPrimaryResidence || canRemovePrimaryResidence); AddResponseToPage("MainPage", "Rename Building", canRenameStructure); AddResponseToPage("MainPage", "Edit Building Mode", canChangeStructureMode); }
public override void Initialize() { Guid structureID = new Guid(GetDialogTarget().GetLocalString("PC_BASE_STRUCTURE_ID")); PCBaseStructure structure = DataService.PCBaseStructure.GetByID(structureID); Guid pcBaseID = structure.PCBaseID; PCBase pcBase = DataService.PCBase.GetByID(pcBaseID); double currentCPU = BaseService.GetCPUInUse(pcBaseID); double currentPower = BaseService.GetPowerInUse(pcBaseID); double maxCPU = BaseService.GetMaxBaseCPU(pcBaseID); double maxPower = BaseService.GetMaxBasePower(pcBaseID); int currentReinforcedFuel = pcBase.ReinforcedFuel; int currentFuel = pcBase.Fuel; int currentResources = DataService.PCBaseStructureItem.GetNumberOfItemsContainedBy(structure.ID); int maxReinforcedFuel = BaseService.CalculateMaxReinforcedFuel(pcBaseID); int maxFuel = BaseService.CalculateMaxFuel(pcBaseID); int maxResources = BaseService.CalculateResourceCapacity(pcBaseID); string time; if (pcBase.DateFuelEnds > DateTime.UtcNow) { TimeSpan deltaTime = pcBase.DateFuelEnds - DateTime.UtcNow; var tower = BaseService.GetBaseControlTower(pcBaseID); if (tower == null) { Console.WriteLine("Could not locate control tower in ControlTower -> Initialize. PCBaseID = " + pcBaseID); return; } var towerStructure = DataService.BaseStructure.GetByID(tower.BaseStructureID); int fuelRating = towerStructure.FuelRating; int minutes; switch (fuelRating) { case 1: // Small minutes = 45; break; case 2: // Medium minutes = 15; break; case 3: // Large minutes = 5; break; default: throw new Exception("Invalid fuel rating value: " + fuelRating); } TimeSpan timeSpan = TimeSpan.FromMinutes(minutes * currentFuel) + deltaTime; time = TimeService.GetTimeLongIntervals(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, false); time = "Fuel will expire in " + time; } else { time = ColorTokenService.Red("Fuel has expired."); } string header = ColorTokenService.Green("Power: ") + currentPower + " / " + maxPower + "\n"; header += ColorTokenService.Green("CPU: ") + currentCPU + " / " + maxCPU + "\n"; header += ColorTokenService.Green("Fuel: ") + currentFuel + " / " + maxFuel + "\n"; header += ColorTokenService.Green("Reinforced Fuel: ") + currentReinforcedFuel + " / " + maxReinforcedFuel + "\n"; header += ColorTokenService.Green("Resource Bay: ") + currentResources + " / " + maxResources + "\n"; header += time + "\n"; header += "What would you like to do with this control tower?"; SetPageHeader("MainPage", header); if (!BasePermissionService.HasBasePermission(GetPC(), structure.PCBaseID, BasePermission.CanManageBaseFuel)) { SetResponseVisible("MainPage", 1, false); SetResponseVisible("MainPage", 2, false); } if (!BasePermissionService.HasBasePermission(GetPC(), structure.PCBaseID, BasePermission.CanAccessStructureInventory)) { SetResponseVisible("MainPage", 3, false); } }