public override void Initialize() { Guid structureID = new Guid(_.GetLocalString(_.GetArea(GetDialogTarget()), "PC_BASE_STRUCTURE_ID")); PCBaseStructure structure = DataService.PCBaseStructure.GetByID(structureID); PCBase pcBase = DataService.PCBase.GetByID(structure.PCBaseID); BaseStructure baseStructure = DataService.BaseStructure.GetByID(structure.BaseStructureID); NWPlaceable bay = SpaceService.GetCargoBay(GetPC().Area, null); int currentReinforcedFuel = pcBase.ReinforcedFuel; int currentFuel = pcBase.Fuel; int currentResources = DataService.PCBaseStructureItem.GetAllByPCBaseStructureID(structure.ID).Count(); int maxReinforcedFuel = BaseService.CalculateMaxReinforcedFuel(pcBase.ID) + 25 * SpaceService.GetCargoBonus(bay, ItemPropertyType.StarshipStronidiumBonus); int maxFuel = BaseService.CalculateMaxFuel(pcBase.ID) + 25 * SpaceService.GetCargoBonus(bay, ItemPropertyType.StarshipFuelBonus); int maxResources = BaseService.CalculateResourceCapacity(pcBase.ID); string locationDescription; if (SpaceService.IsLocationSpace(pcBase.ShipLocation)) { locationDescription = "Ship is in orbit around " + ColorTokenService.Cyan(SpaceService.GetPlanetFromLocation(pcBase.ShipLocation)) + ".\n"; } else if (SpaceService.IsLocationPublicStarport(pcBase.ShipLocation)) { locationDescription = "Ship is docked in the public starport on " + ColorTokenService.Cyan(SpaceService.GetPlanetFromLocation(pcBase.ShipLocation)) + ".\n"; } else { locationDescription = "Ship is docked on " + ColorTokenService.Cyan(SpaceService.GetPlanetFromLocation(pcBase.ShipLocation)) + ".\n"; } string header = locationDescription; header += ColorTokenService.Green("Fuel: ") + currentFuel + " / " + maxFuel + "\n"; header += ColorTokenService.Green("Reinforced Fuel: ") + currentReinforcedFuel + " / " + maxReinforcedFuel + "\n"; header += ColorTokenService.Green("Resource Bay: ") + currentResources + " / " + maxResources + "\n"; header += ColorTokenService.Green("Hull integrity: ") + structure.Durability + " / " + baseStructure.Durability + "\n"; header += "The computer awaits your orders."; SetPageHeader("MainPage", header); }
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."); } }
public bool Run(params object[] args) { NWPlayer player = (_.GetLastDisturbed()); NWPlaceable bay = (Object.OBJECT_SELF); int disturbType = _.GetInventoryDisturbType(); NWItem item = (_.GetInventoryDisturbItem()); bool stronidiumOnly = bay.GetLocalInt("CONTROL_TOWER_FUEL_TYPE") == TRUE; string allowedResref = stronidiumOnly ? "stronidium" : "fuel_cell"; string structureID = bay.GetLocalString("PC_BASE_STRUCTURE_ID"); // Check for either fuel cells or stronidium when adding an item to the container. if (disturbType == INVENTORY_DISTURB_TYPE_ADDED) { if (item.Resref != allowedResref) { ItemService.ReturnItem(player, item); player.SendMessage("Only " + (stronidiumOnly ? "Stronidium" : "Fuel Cells") + " may be placed inside this fuel bay."); return(false); } } // If the item removed wasn't fuel cells or stronidium, exit early. We don't need to do anything else. else if (disturbType == INVENTORY_DISTURB_TYPE_REMOVED) { if (item.Resref != allowedResref) { return(false); } } var structure = DataService.Single <PCBaseStructure>(x => x.ID == new Guid(structureID)); var pcBase = DataService.Get <PCBase>(structure.PCBaseID); // Calculate how much fuel exists in the bay's inventory. int fuelCount = 0; foreach (var fuel in bay.InventoryItems) { fuelCount += fuel.StackSize; } // If there are extra units of fuel, destroy them. We will set the stack size of the first fuel later on. NWItem firstFuel = (_.GetFirstItemInInventory(bay.Object)); NWItem nextFuel = (_.GetNextItemInInventory(bay.Object)); while (nextFuel.IsValid) { nextFuel.Destroy(); nextFuel = (_.GetNextItemInInventory(bay.Object)); } int maxFuel; // Handle Stronidium fuel process if (stronidiumOnly) { maxFuel = BaseService.CalculateMaxReinforcedFuel(pcBase.ID); // For starships only: Add the ship's cargo bonus to the max stronidium amount. if (bay.Area.GetLocalInt("BUILDING_TYPE") == (int)Enumeration.BuildingType.Starship) { maxFuel += 25 * SpaceService.GetCargoBonus(SpaceService.GetCargoBay(player.Area, null), (int)CustomItemPropertyType.StarshipStronidiumBonus); } // Did the player put too much fuel inside? Return the excess to their inventory. if (fuelCount > maxFuel) { int returnAmount = fuelCount - maxFuel; _.CreateItemOnObject("stronidium", player.Object, returnAmount); fuelCount = maxFuel; } firstFuel.StackSize = fuelCount; pcBase.ReinforcedFuel = fuelCount; if (bay.Area.GetLocalInt("BUILDING_TYPE") == (int)Enumeration.BuildingType.Starship) { // This is a starship. Update the creature object, if any, with the new fuel count. NWCreature ship = bay.Area.GetLocalObject("CREATURE"); if (ship.IsValid) { ship.SetLocalInt("STRONIDIUM", fuelCount); } } } // Handle Fuel Cell process else { maxFuel = BaseService.CalculateMaxFuel(pcBase.ID); // For starships only: Add the ship's cargo bonus to the max fuel amount. if (bay.Area.GetLocalInt("BUILDING_TYPE") == (int)Enumeration.BuildingType.Starship) { maxFuel += 25 * SpaceService.GetCargoBonus(SpaceService.GetCargoBay(player.Area, null), (int)CustomItemPropertyType.StarshipFuelBonus); } // Did the player put too much fuel inside? Return the excess to their inventory. if (fuelCount > maxFuel) { int returnAmount = fuelCount - maxFuel; _.CreateItemOnObject("fuel_cell", player.Object, returnAmount); fuelCount = maxFuel; } firstFuel.StackSize = fuelCount; pcBase.Fuel = fuelCount; } // Submit a DB data change for the fuel or stronidium amount adjustment. DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); var tower = BaseService.GetBaseControlTower(structure.PCBaseID); var towerStructure = DataService.Single <BaseStructure>(x => x.ID == tower.BaseStructureID); if (towerStructure.BaseStructureTypeID == (int)BaseStructureType.Starship) { // This is a spaceship, so don't give the feedback message. return(true); } int fuelRating = towerStructure.FuelRating; // Stronidium - Every unit lasts for 6 seconds during reinforcement mode. if (stronidiumOnly) { int seconds = 6 * fuelCount; TimeSpan timeSpan = TimeSpan.FromSeconds(seconds); player.SendMessage(ColorTokenService.Gray("Reinforcement mode will last for " + TimeService.GetTimeLongIntervals(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, false) + " (" + fuelCount + " / " + maxFuel + " units")); } // Regular fuel cells - Every unit lasts for 45, 15, or 5 minutes depending on the size of the tower. else { 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 * fuelCount); player.SendMessage(ColorTokenService.Gray("Fuel will last for " + TimeService.GetTimeLongIntervals(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, false) + " (" + fuelCount + " / " + maxFuel + " units)")); } return(true); }
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); } }
public void OnItemDisturbed() { NWPlaceable bay = OBJECT_SELF; // Filer to only events created by a fuel bay, and ignore this event if it was triggered by clearing // the inventory when the bay is being destroyed. if (bay.Resref != "fuel_bay" || bay.GetLocalBool("SETUP") == true) { return; } NWItem item = StringToObject(NWNXEvents.GetEventData("ITEM")); NWPlayer player = bay.GetLocalObject("BAY_ACCESSOR"); var disturbType = NWNXEvents.GetCurrentEvent(); bool stronidiumOnly = GetLocalBool(bay, "CONTROL_TOWER_FUEL_TYPE"); string allowedResref = stronidiumOnly ? "stronidium" : "fuel_cell"; string structureID = bay.GetLocalString("PC_BASE_STRUCTURE_ID"); // Check for either fuel cells or stronidium when adding an item to the container. if (disturbType == EventType.ItemInventoryAddItemAfter) { if (item.Resref != allowedResref) { ItemService.ReturnItem(player, item); player.SendMessage("Only " + (stronidiumOnly ? "Stronidium" : "Fuel Cells") + " may be placed inside this fuel bay."); return; } } // If the item removed wasn't fuel cells or stronidium, exit early. We don't need to do anything else. else if (disturbType == EventType.ItemInventoryRemoveItemAfter) { if (item.Resref != allowedResref) { return; } } var structure = DataService.PCBaseStructure.GetByID(new Guid(structureID)); var pcBase = DataService.PCBase.GetByID(structure.PCBaseID); // Calculate how much fuel exists in the bay's inventory. int fuelCount = 0; foreach (var fuel in bay.InventoryItems) { fuelCount += fuel.StackSize; } // If there are extra units of fuel, destroy them. We will set the stack size of the first fuel later on. NWItem firstFuel = GetFirstItemInInventory(bay.Object); NWItem nextFuel = GetNextItemInInventory(bay.Object); while (nextFuel.IsValid) { nextFuel.Destroy(); nextFuel = GetNextItemInInventory(bay.Object); } int maxFuel; // Handle Stronidium fuel process if (stronidiumOnly) { maxFuel = BaseService.CalculateMaxReinforcedFuel(pcBase.ID); // For starships only: Add the ship's cargo bonus to the max stronidium amount. if (bay.Area.GetLocalInt("BUILDING_TYPE") == (int)Enumeration.BuildingType.Starship) { maxFuel += 25 * SpaceService.GetCargoBonus(SpaceService.GetCargoBay(player.Area, player), ItemPropertyType.StarshipStronidiumBonus); } // Did the player put too much fuel inside? Return the excess to their inventory. if (fuelCount > maxFuel) { int returnAmount = fuelCount - maxFuel; CreateItemOnObject("stronidium", player.Object, returnAmount); fuelCount = maxFuel; } firstFuel.StackSize = fuelCount; pcBase.ReinforcedFuel = fuelCount; if (bay.Area.GetLocalInt("BUILDING_TYPE") == (int)Enumeration.BuildingType.Starship) { // This is a starship. Update the creature object, if any, with the new fuel count. NWCreature ship = bay.Area.GetLocalObject("CREATURE"); if (ship.IsValid) { ship.SetLocalInt("STRONIDIUM", fuelCount); } } } // Handle Fuel Cell process else { maxFuel = BaseService.CalculateMaxFuel(pcBase.ID); // For starships only: Add the ship's cargo bonus to the max fuel amount. if (bay.Area.GetLocalInt("BUILDING_TYPE") == (int)Enumeration.BuildingType.Starship) { maxFuel += 25 * SpaceService.GetCargoBonus(SpaceService.GetCargoBay(player.Area, player), ItemPropertyType.StarshipFuelBonus); } // Did the player put too much fuel inside? Return the excess to their inventory. if (fuelCount > maxFuel) { int returnAmount = fuelCount - maxFuel; CreateItemOnObject("fuel_cell", player.Object, returnAmount); fuelCount = maxFuel; } firstFuel.StackSize = fuelCount; pcBase.Fuel = fuelCount; } // Submit a DB data change for the fuel or stronidium amount adjustment. DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); var tower = BaseService.GetBaseControlTower(structure.PCBaseID); if (tower == null) { Console.WriteLine("Could not locate tower in Fuel Bay. PCBaseID = " + structure.PCBaseID); return; } var towerStructure = DataService.BaseStructure.GetByID(tower.BaseStructureID); if (towerStructure.BaseStructureTypeID == (int)BaseStructureType.Starship) { // This is a spaceship, so don't give the feedback message. return; } int fuelRating = towerStructure.FuelRating; // Stronidium - Every unit lasts for 6 seconds during reinforcement mode. if (stronidiumOnly) { int seconds = 6 * fuelCount; TimeSpan timeSpan = TimeSpan.FromSeconds(seconds); player.SendMessage(ColorTokenService.Gray("Reinforcement mode will last for " + TimeService.GetTimeLongIntervals(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, false) + " (" + fuelCount + " / " + maxFuel + " units")); } // Regular fuel cells - Every unit lasts for 45, 15, or 5 minutes depending on the size of the tower. else { 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 * fuelCount); player.SendMessage(ColorTokenService.Gray("Fuel will last for " + TimeService.GetTimeLongIntervals(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, false) + " (" + fuelCount + " / " + maxFuel + " units)")); } return; }