public string IsValidTarget(NWCreature user, NWItem item, NWObject target, Location targetLocation) { NWArea area = user.Area; if (area.GetLocalInt("BUILDING_TYPE") != (int)Enumeration.BuildingType.Starship) { return("This repair kit may only be used inside a starship"); } string structureID = area.GetLocalString("PC_BASE_STRUCTURE_ID"); Guid structureGuid = new Guid(structureID); PCBaseStructure pcbs = DataService.PCBaseStructure.GetByID(structureGuid); BaseStructure structure = DataService.BaseStructure.GetByID(pcbs.BaseStructureID); if (structure.Durability == pcbs.Durability) { return("This starship is already fully repaired."); } bool canRepair = (PerkService.GetCreaturePerkLevel(new NWPlayer(user), PerkType.CombatRepair) >= 1); PCBase pcBase = DataService.PCBase.GetByID(pcbs.PCBaseID); if (!canRepair && SpaceService.IsLocationSpace(pcBase.ShipLocation)) { return("You need the Combat Repair perk to repair ships in space."); } return(""); }
public int CalculateResourceCapacity(Guid pcBaseID) { const int siloType = (int)BaseStructureType.ResourceSilo; PCBaseStructure tower = GetBaseControlTower(pcBaseID); var towerBaseStructure = _data.Get <BaseStructure>(tower.BaseStructureID); float siloBonus = _data.Where <PCBaseStructure> (x => { var baseStructure = _data.Get <BaseStructure>(x.BaseStructureID); return(x.PCBaseID == pcBaseID && baseStructure.BaseStructureTypeID == siloType); }) .DefaultIfEmpty() .Sum(x => { if (x == null) { return(0); } var baseStructure = _data.Get <BaseStructure>(x.BaseStructureID); return(baseStructure.Storage + x.StructureBonus); }) * 0.01f; var resourceMax = towerBaseStructure.ResourceStorage; return((int)(resourceMax + resourceMax * siloBonus)); }
public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData) { NWPlayer player = (user.Object); int starcharts = item.GetLocalInt("Starcharts"); if (starcharts == 0) { player.SendMessage("This disk is empty."); return; } // Get the base. string starshipID = _.GetLocalString(_.GetArea(target), "PC_BASE_STRUCTURE_ID"); Guid starshipGuid = new Guid(starshipID); PCBaseStructure starship = DataService.PCBaseStructure.GetByID(starshipGuid); PCBase starkillerBase = DataService.PCBase.GetByID(starship.PCBaseID); starkillerBase.Starcharts |= starcharts; DataService.SubmitDataChange(starkillerBase, DatabaseActionType.Update); _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectVisualEffect(VFX_IMP_CONFUSION_S), target); _.FloatingTextStringOnCreature("Starcharts loaded!", player); item.Destroy(); }
public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData) { NWArea area = user.Area; NWPlayer player = new NWPlayer(user); string structureID = area.GetLocalString("PC_BASE_STRUCTURE_ID"); Guid structureGuid = new Guid(structureID); PCBaseStructure pcbs = DataService.PCBaseStructure.GetByID(structureGuid); BaseStructure structure = DataService.BaseStructure.GetByID(pcbs.BaseStructureID); int repair = SkillService.GetPCSkillRank(player, SkillType.Piloting); int maxRepair = (int)structure.Durability - (int)pcbs.Durability; if (maxRepair < repair) { repair = maxRepair; } // TODO - add perks to make repairing faster/better/shinier/etc. // Maybe a perk to allow repairing in space, with ground repairs only otherwise? NWCreature ship = area.GetLocalObject("CREATURE"); if (ship.IsValid) { ship.SetLocalInt("HP", ship.GetLocalInt("HP") + repair); ship.FloatingText("Hull repaired: " + ship.GetLocalInt("HP") + "/" + ship.MaxHP); } pcbs.Durability += repair; DataService.SubmitDataChange(pcbs, DatabaseActionType.Update); player.SendMessage("Ship repaired for " + repair + " points. (Hull points: " + pcbs.Durability + "/" + structure.Durability + ")"); }
public NWPlaceable SpawnStructure(NWArea area, Guid pcBaseStructureID) { PCBaseStructure pcStructure = _data.Get <PCBaseStructure>(pcBaseStructureID); PCBase pcBase = _data.Get <PCBase>(pcStructure.PCBaseID); BaseStructure baseStructure = _data.Get <BaseStructure>(pcStructure.BaseStructureID); var exteriorStyle = _data.Get <BuildingStyle>(pcStructure.ExteriorStyleID); NWLocation location = _.Location(area.Object, _.Vector((float)pcStructure.LocationX, (float)pcStructure.LocationY, (float)pcStructure.LocationZ), (float)pcStructure.LocationOrientation); BaseStructureType structureType = (BaseStructureType)baseStructure.BaseStructureTypeID; string resref = baseStructure.PlaceableResref; List <AreaStructure> areaStructures = area.Data["BASE_SERVICE_STRUCTURES"]; if (string.IsNullOrWhiteSpace(resref) && structureType == BaseStructureType.Building) { resref = exteriorStyle.Resref; } NWPlaceable plc = (_.CreateObject(OBJECT_TYPE_PLACEABLE, resref, location)); plc.SetLocalString("PC_BASE_STRUCTURE_ID", pcStructure.ID.ToString()); plc.SetLocalInt("REQUIRES_BASE_POWER", baseStructure.RequiresBasePower ? 1 : 0); plc.SetLocalString("ORIGINAL_SCRIPT_CLOSED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_CLOSED)); plc.SetLocalString("ORIGINAL_SCRIPT_DAMAGED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_DAMAGED)); plc.SetLocalString("ORIGINAL_SCRIPT_DEATH", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_DEATH)); plc.SetLocalString("ORIGINAL_SCRIPT_HEARTBEAT", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_HEARTBEAT)); plc.SetLocalString("ORIGINAL_SCRIPT_INVENTORYDISTURBED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_INVENTORYDISTURBED)); plc.SetLocalString("ORIGINAL_SCRIPT_LOCK", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_LOCK)); plc.SetLocalString("ORIGINAL_SCRIPT_MELEEATTACKED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_MELEEATTACKED)); plc.SetLocalString("ORIGINAL_SCRIPT_OPEN", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_OPEN)); plc.SetLocalString("ORIGINAL_SCRIPT_SPELLCASTAT", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_SPELLCASTAT)); plc.SetLocalString("ORIGINAL_SCRIPT_UNLOCK", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_UNLOCK)); plc.SetLocalString("ORIGINAL_SCRIPT_USED", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_USED)); plc.SetLocalString("ORIGINAL_SCRIPT_USER_DEFINED_EVENT", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_USER_DEFINED_EVENT)); plc.SetLocalString("ORIGINAL_SCRIPT_LEFT_CLICK", _.GetEventScript(plc.Object, EVENT_SCRIPT_PLACEABLE_ON_LEFT_CLICK)); plc.SetLocalString("ORIGINAL_JAVA_SCRIPT_1", _.GetLocalString(plc.Object, "JAVA_SCRIPT_1")); NWPlaceable door = null; if (structureType == BaseStructureType.Building) { door = SpawnBuildingDoor(exteriorStyle.DoorRule, plc); areaStructures.Add(new AreaStructure(pcStructure.PCBaseID, pcStructure.ID, door, false, null)); } areaStructures.Add(new AreaStructure(pcStructure.PCBaseID, pcStructure.ID, plc, true, door)); if (area.IsInstance && area.GetLocalInt("PC_BASE_STRUCTURE_ID") > 0) { if (DateTime.UtcNow > pcBase.DateFuelEnds && pcBase.Fuel <= 0) { ToggleInstanceObjectPower(area, false); } } return(plc); }
public int CalculateMaxReinforcedFuel(PCBase pcBase) { const int siloType = (int)BaseStructureType.StronidiumSilo; PCBaseStructure tower = GetBaseControlTower(pcBase.ID); var towerBaseStructure = _data.Get <BaseStructure>(tower.BaseStructureID); float siloBonus = _data.Where <PCBaseStructure> (x => { var baseStructure = _data.Get <BaseStructure>(x.BaseStructureID); return(x.PCBaseID == pcBase.ID && baseStructure.BaseStructureTypeID == siloType); }) .DefaultIfEmpty() .Sum(x => { if (x == null) { return(0); } var baseStructure = _data.Get <BaseStructure>(x.BaseStructureID); return(baseStructure.Storage + x.StructureBonus); }) * 0.01f; var fuelMax = towerBaseStructure.ReinforcedStorage; return((int)(fuelMax + fuelMax * siloBonus)); }
public bool Run(params object[] args) { NWPlayer clicker = (_.GetPlaceableLastClickedBy()); NWPlaceable tower = (Object.OBJECT_SELF); clicker.ClearAllActions(); if (!clicker.IsPlayer) { return(false); } if (_.GetDistanceBetween(clicker.Object, tower.Object) > 5.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 = _data.Single <PCBaseStructure>(x => x.ID == structureID); if (_perm.HasBasePermission(clicker, structure.PCBaseID, BasePermission.CanManageBaseFuel)) { _dialog.StartConversation(clicker, tower, "ControlTower"); } else { clicker.SendMessage("You don't have permission to interact with this control tower."); } return(true); }
public void GetAllByPCBaseID_ThreeItems_AreSame() { // Arrange var pcBaseID = Guid.NewGuid(); var entity1 = new PCBaseStructure { ID = Guid.NewGuid(), PCBaseID = pcBaseID }; var entity2 = new PCBaseStructure { ID = Guid.NewGuid(), PCBaseID = pcBaseID }; var entity3 = new PCBaseStructure { ID = Guid.NewGuid(), PCBaseID = pcBaseID }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCBaseStructure>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <PCBaseStructure>(entity2)); MessageHub.Instance.Publish(new OnCacheObjectSet <PCBaseStructure>(entity3)); var results = _cache.GetAllByPCBaseID(pcBaseID).ToList(); // Assert Assert.AreNotSame(entity1, results[0]); Assert.AreNotSame(entity2, results[1]); Assert.AreNotSame(entity3, results[2]); }
public bool Run(params object[] args) { NWCreature attacker = (_.GetLastDamager(Object.OBJECT_SELF)); NWPlaceable tower = (Object.OBJECT_SELF); NWItem weapon = (_.GetLastWeaponUsed(attacker.Object)); int damage = _.GetTotalDamageDealt(); var structureID = tower.GetLocalString("PC_BASE_STRUCTURE_ID"); PCBaseStructure structure = _data.Single <PCBaseStructure>(x => x.ID == new Guid(structureID)); int maxShieldHP = _base.CalculateMaxShieldHP(structure); PCBase pcBase = _data.Get <PCBase>(structure.PCBaseID); pcBase.ShieldHP -= damage; if (pcBase.ShieldHP <= 0) { pcBase.ShieldHP = 0; } float hpPercentage = (float)pcBase.ShieldHP / (float)maxShieldHP * 100.0f; if (hpPercentage <= 25.0f && pcBase.ReinforcedFuel > 0) { pcBase.IsInReinforcedMode = true; pcBase.ShieldHP = (int)(maxShieldHP * 0.25f); } attacker.SendMessage("Tower Shields: " + hpPercentage.ToString("0.00") + "%"); if (pcBase.IsInReinforcedMode) { attacker.SendMessage("Control tower is in reinforced mode and cannot be damaged. Reinforced mode will be disabled when the tower runs out of fuel."); } _.ApplyEffectToObject(DURATION_TYPE_INSTANT, _.EffectHeal(9999), tower.Object); var durability = _durability.GetDurability(weapon) - _random.RandomFloat(0.01f, 0.03f); _durability.SetDurability(weapon, durability); if (pcBase.ShieldHP <= 0) { pcBase.ShieldHP = 0; structure.Durability -= _random.RandomFloat(0.5f, 2.0f); if (structure.Durability < 0.0f) { structure.Durability = 0.0f; } attacker.SendMessage("Structure Durability: " + structure.Durability.ToString("0.00")); if (structure.Durability <= 0.0f) { structure.Durability = 0.0f; BlowUpBase(pcBase); return(true); } } _data.SubmitDataChange(pcBase, DatabaseActionType.Update); _data.SubmitDataChange(structure, DatabaseActionType.Update); return(true); }
public override void Initialize() { Guid structureID = new Guid(GetDialogTarget().GetLocalString("PC_BASE_STRUCTURE_ID")); PCBaseStructure structure = _data.Single <PCBaseStructure>(x => x.ID == structureID); Guid pcBaseID = structure.PCBaseID; PCBase pcBase = _data.Get <PCBase>(pcBaseID); double currentCPU = _base.GetCPUInUse(pcBaseID); double currentPower = _base.GetPowerInUse(pcBaseID); double maxCPU = _base.GetMaxBaseCPU(pcBaseID); double maxPower = _base.GetMaxBasePower(pcBaseID); int currentReinforcedFuel = pcBase.ReinforcedFuel; int currentFuel = pcBase.Fuel; int currentResources = _data.Where <PCBaseStructureItem>(x => x.PCBaseStructureID == structure.ID).Count(); int maxReinforcedFuel = _base.CalculateMaxReinforcedFuel(pcBaseID); int maxFuel = _base.CalculateMaxFuel(pcBaseID); int maxResources = _base.CalculateResourceCapacity(pcBaseID); string time; if (pcBase.DateFuelEnds > DateTime.UtcNow) { TimeSpan deltaTime = pcBase.DateFuelEnds - DateTime.UtcNow; TimeSpan timeSpan = TimeSpan.FromMinutes(30.0f * currentFuel) + deltaTime; time = _time.GetTimeLongIntervals(timeSpan.Days, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds, false); time = "Fuel will expire in " + time; } else { time = _color.Red("Fuel has expired."); } string header = _color.Green("Power: ") + currentPower + " / " + maxPower + "\n"; header += _color.Green("CPU: ") + currentCPU + " / " + maxCPU + "\n"; header += _color.Green("Fuel: ") + currentFuel + " / " + maxFuel + "\n"; header += _color.Green("Reinforced Fuel: ") + currentReinforcedFuel + " / " + maxReinforcedFuel + "\n"; header += _color.Green("Resource Bay: ") + currentResources + " / " + maxResources + "\n"; header += time + "\n"; header += "What would you like to do with this control tower?"; SetPageHeader("MainPage", header); if (!_perm.HasBasePermission(GetPC(), structure.PCBaseID, BasePermission.CanManageBaseFuel)) { SetResponseVisible("MainPage", 1, false); SetResponseVisible("MainPage", 2, false); } if (!_perm.HasBasePermission(GetPC(), structure.PCBaseID, BasePermission.CanAccessStructureInventory)) { SetResponseVisible("MainPage", 3, false); } }
public int CalculateMaxShieldHP(PCBaseStructure controlTower) { if (controlTower == null) { return(0); } return((int)(controlTower.Durability * 300)); }
public void GetByID_OneItem_ReturnsPCBaseStructure() { // Arrange var id = Guid.NewGuid(); PCBaseStructure entity = new PCBaseStructure { ID = id }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCBaseStructure>(entity)); // Assert Assert.AreNotSame(entity, _cache.GetByID(id)); }
private void DoPlaceStructure() { var data = BaseService.GetPlayerTempData(GetPC()); string canPlaceStructure = BaseService.CanPlaceStructure(GetPC(), data.StructureItem, data.TargetLocation, data.BaseStructureID); var baseStructure = DataService.BaseStructure.GetByID(data.BaseStructureID); if (!string.IsNullOrWhiteSpace(canPlaceStructure)) { GetPC().SendMessage(canPlaceStructure); return; } var position = _.GetPositionFromLocation(data.TargetLocation); int?interiorStyleID = data.StructureItem.GetLocalInt("STRUCTURE_BUILDING_INTERIOR_ID"); int?exteriorStyleID = data.StructureItem.GetLocalInt("STRUCTURE_BUILDING_EXTERIOR_ID"); interiorStyleID = interiorStyleID <= 0 ? null : interiorStyleID; exteriorStyleID = exteriorStyleID <= 0 ? null : exteriorStyleID; var structure = new PCBaseStructure { BaseStructureID = data.BaseStructureID, Durability = DurabilityService.GetDurability(data.StructureItem), LocationOrientation = _.GetFacingFromLocation(data.TargetLocation), LocationX = position.m_X, LocationY = position.m_Y, LocationZ = position.m_Z, PCBaseID = data.PCBaseID, InteriorStyleID = interiorStyleID, ExteriorStyleID = exteriorStyleID, CustomName = string.Empty, ParentPCBaseStructureID = data.ParentStructureID, StructureBonus = data.StructureItem.StructureBonus, StructureModeID = baseStructure.DefaultStructureModeID }; DataService.SubmitDataChange(structure, DatabaseActionType.Insert); // Placing a control tower. Set base shields to 100% if (baseStructure.BaseStructureTypeID == (int)BaseStructureType.ControlTower) { var pcBase = DataService.PCBase.GetByID(data.PCBaseID); pcBase.ShieldHP = BaseService.CalculateMaxShieldHP(structure); DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); } BaseService.SpawnStructure(data.TargetArea, structure.ID); data.StructureItem.Destroy(); EndConversation(); }
public override void Initialize() { Guid structureID = new Guid(GetDialogTarget().GetLocalString("PC_BASE_STRUCTURE_ID")); PCBaseStructure structure = _data.Single <PCBaseStructure>(x => x.ID == structureID); if (!_perm.HasBasePermission(GetPC(), structure.PCBaseID, BasePermission.CanManageBaseFuel)) { SetResponseVisible("MainPage", 1, false); SetResponseVisible("MainPage", 2, false); } if (!_perm.HasBasePermission(GetPC(), structure.PCBaseID, BasePermission.CanAccessStructureInventory)) { SetResponseVisible("MainPage", 3, false); } }
private void SetHeader() { NWPlaceable door = GetDialogTarget().Object; var structureID = new Guid(door.GetLocalString("PC_BASE_STRUCTURE_ID")); PCBaseStructure structure = DataService.PCBaseStructure.GetByID(structureID); PCBase pcBase = DataService.PCBase.GetByID(structure.PCBaseID); Player owner = PlayerService.GetPlayerEntity(pcBase.PlayerID); string buildingName = owner.CharacterName + "'s Building"; if (!string.IsNullOrWhiteSpace(structure.CustomName)) { buildingName = structure.CustomName; } string header = buildingName + "\n\nPlease select an option."; SetPageHeader("MainPage", header); }
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); }
public void GetByID_TwoItems_ReturnsCorrectObject() { // Arrange var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); PCBaseStructure entity1 = new PCBaseStructure { ID = id1 }; PCBaseStructure entity2 = new PCBaseStructure { ID = id2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCBaseStructure>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <PCBaseStructure>(entity2)); // Assert Assert.AreNotSame(entity1, _cache.GetByID(id1)); Assert.AreNotSame(entity2, _cache.GetByID(id2)); }
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); }
public void GetByID_RemovedItem_ReturnsCorrectObject() { // Arrange var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); PCBaseStructure entity1 = new PCBaseStructure { ID = id1 }; PCBaseStructure entity2 = new PCBaseStructure { ID = id2 }; // Act MessageHub.Instance.Publish(new OnCacheObjectSet <PCBaseStructure>(entity1)); MessageHub.Instance.Publish(new OnCacheObjectSet <PCBaseStructure>(entity2)); MessageHub.Instance.Publish(new OnCacheObjectDeleted <PCBaseStructure>(entity1)); // Assert Assert.Throws <KeyNotFoundException>(() => { _cache.GetByID(id1); }); Assert.AreNotSame(entity2, _cache.GetByID(id2)); }
public NWItem ConvertStructureToItem(PCBaseStructure pcBaseStructure, NWObject target) { var baseStructure = _data.Get <BaseStructure>(pcBaseStructure.BaseStructureID); NWItem item = (_.CreateItemOnObject(baseStructure.ItemResref, target.Object)); item.SetLocalInt("BASE_STRUCTURE_ID", pcBaseStructure.BaseStructureID); item.Name = baseStructure.Name; _durability.SetMaxDurability(item, (float)pcBaseStructure.Durability); _durability.SetDurability(item, (float)pcBaseStructure.Durability); item.StructureBonus = pcBaseStructure.StructureBonus; if (pcBaseStructure.InteriorStyleID != null && pcBaseStructure.ExteriorStyleID != null) { item.SetLocalInt("STRUCTURE_BUILDING_INTERIOR_ID", (int)pcBaseStructure.InteriorStyleID); item.SetLocalInt("STRUCTURE_BUILDING_EXTERIOR_ID", (int)pcBaseStructure.ExteriorStyleID); item.SetLocalInt("STRUCTURE_BUILDING_INITIALIZED", TRUE); } return(item); }
public void ApplyEffects(NWCreature user, NWItem item, NWObject target, Location targetLocation, CustomData customData) { NWArea area = user.Area; NWPlayer player = new NWPlayer(user); string structureID = area.GetLocalString("PC_BASE_STRUCTURE_ID"); PCBaseStructure pcbs = DataService.Single <PCBaseStructure>(x => x.ID.ToString() == structureID); BaseStructure structure = DataService.Get <BaseStructure>(pcbs.BaseStructureID); var dbItem = new PCBaseStructureItem { PCBaseStructureID = pcbs.ID, ItemGlobalID = item.GlobalID.ToString(), ItemName = item.Name, ItemResref = item.Resref, ItemTag = item.Tag, ItemObject = SerializationService.Serialize(item) }; DataService.SubmitDataChange(dbItem, DatabaseActionType.Insert); player.SendMessage(item.Name + " was successfully added to your ship. Access the cargo bay via the ship's computer to remove it."); item.Destroy(); }
private static void OnRemoveStructureItem(NWPlayer player, PCBaseStructureItem entity) { PCBaseStructure pcBaseStructure = DataService.PCBaseStructure.GetByID(entity.PCBaseStructureID); var @event = new ModuleEvent { ModuleEventTypeID = 8, PlayerID = player.GlobalID, CDKey = GetPCPublicCDKey(player), AccountName = GetPCPlayerName(player), ItemID = new Guid(entity.ItemGlobalID), ItemName = entity.ItemName, ItemTag = entity.ItemTag, ItemResref = entity.ItemResref, PCBaseID = pcBaseStructure.PCBaseID, PCBaseStructureID = entity.PCBaseStructureID, BaseStructureID = pcBaseStructure.BaseStructureID, CustomName = pcBaseStructure.CustomName }; // Bypass the caching logic DataService.DataQueue.Enqueue(new DatabaseAction(@event, DatabaseActionType.Insert)); }
public string IsValidTarget(NWCreature user, NWItem item, NWObject target, Location targetLocation) { NWArea area = user.Area; if (area.GetLocalInt("BUILDING_TYPE") != (int)Enumeration.BuildingType.Starship) { return("This enhancement may only be deployed inside a starship"); } string structureID = area.GetLocalString("PC_BASE_STRUCTURE_ID"); PCBaseStructure pcbs = DataService.Single <PCBaseStructure>(x => x.ID.ToString() == structureID); BaseStructure structure = DataService.Get <BaseStructure>(pcbs.BaseStructureID); int count = DataService.Where <PCBaseStructureItem>(x => x.PCBaseStructureID == pcbs.ID).Count() + 1; if (count > (structure.ResourceStorage + pcbs.StructureBonus)) { return("Your cargo bay is full! You cannot add any enhancements."); } return(""); }
public string IsValidTarget(NWCreature user, NWItem item, NWObject target, Location targetLocation) { NWArea area = user.Area; if (area.GetLocalInt("BUILDING_TYPE") != (int)Enumeration.BuildingType.Starship) { return("This enhancement may only be deployed inside a starship"); } string structureID = area.GetLocalString("PC_BASE_STRUCTURE_ID"); Guid structureGuid = new Guid(structureID); PCBaseStructure pcbs = DataService.PCBaseStructure.GetByID(structureGuid); BaseStructure structure = DataService.BaseStructure.GetByID(pcbs.BaseStructureID); int count = DataService.PCBaseStructureItem.GetNumberOfItemsContainedBy(pcbs.ID) + 1; if (count > (structure.ResourceStorage + pcbs.StructureBonus)) { return("Your cargo bay is full! You cannot add any enhancements."); } return(""); }
private void LoadMainPage() { NWPlaceable door = NWGameObject.OBJECT_SELF; string starportID = door.GetLocalString("STARPORT_ID"); if (string.IsNullOrWhiteSpace(starportID)) { _.SpeakString("STARPORT_ID is not set. Please inform an admin."); return; } ClearPageResponses("MainPage"); var player = GetPC(); // Get starships owned by player and docked at this starport. var ships = DataService.PCBase.GetAll().Where(x => x.PlayerID == player.GlobalID && x.ShipLocation == starportID.ToLower() && x.DateRentDue > DateTime.UtcNow) .OrderBy(o => o.DateInitialPurchase) .ToList(); // Get starships owned by other players and the current player currently has access to. var permissions = DataService.PCBaseStructurePermission.GetAllByPlayerID(player.GlobalID); var permissionedShips = DataService.PCBase.GetAll().Where(x => { if (x.ShipLocation != starportID.ToLower() || x.DateRentDue <= DateTime.UtcNow || x.PlayerID == player.GlobalID) { return(false); } PCBaseStructure ship = DataService.PCBaseStructure.GetStarshipExteriorByPCBaseID(x.ID); var permission = permissions.SingleOrDefault(p => p.PCBaseStructureID == ship.ID); return(permission != null && permission.CanEnterBuilding); }) .ToList(); int count = 1; foreach (var ship in ships) { string name = "Starship #" + count; if (!string.IsNullOrWhiteSpace(ship.CustomName)) { // Custom names are probably set at the base structure level, so this likely needs reworking. name = ship.CustomName; } AddResponseToPage("MainPage", name, true, ship.ID); count++; } foreach (var ship in permissionedShips) { var owner = DataService.Player.GetByID(ship.PlayerID); string name = owner.CharacterName + "'s Starship [" + owner.CharacterName + "]"; if (!string.IsNullOrWhiteSpace(ship.CustomName)) { name = ship.CustomName + " [" + owner.CharacterName + "]"; } AddResponseToPage("MainPage", name, true, ship.ID); } }
public void Main() { NWPlaceable tower = _.OBJECT_SELF; Guid structureID = new Guid(tower.GetLocalString("PC_BASE_STRUCTURE_ID")); PCBaseStructure structure = DataService.PCBaseStructure.GetByID(structureID); int maxShieldHP = BaseService.CalculateMaxShieldHP(structure); var pcBase = DataService.PCBase.GetByID(structure.PCBaseID); // Regular fuel usage if (DateTime.UtcNow >= pcBase.DateFuelEnds && pcBase.Fuel > 0) { pcBase.Fuel--; BaseStructure towerStructure = DataService.BaseStructure.GetByID(structure.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); } pcBase.DateFuelEnds = DateTime.UtcNow.AddMinutes(minutes); // If a player is manipulating fuel, look for a fuel item and reduce its stack size or destroy it NWPlaceable bay = tower.GetLocalObject("CONTROL_TOWER_FUEL_BAY"); if (bay.IsValid) { bool isStronidium = bay.GetLocalBool("CONTROL_TOWER_FUEL_TYPE") == true; if (!isStronidium) { NWItem fuel = _.GetFirstItemInInventory(bay.Object); if (fuel.IsValid) { fuel.ReduceItemStack(); } } } } // If completely out of power, show tower in red. if (pcBase.Fuel <= 0 && DateTime.UtcNow > pcBase.DateFuelEnds) { bool outOfPowerHasBeenApplied = false; foreach (var effect in tower.Effects) { if (_.GetEffectTag(effect) == "CONTROL_TOWER_OUT_OF_POWER") { outOfPowerHasBeenApplied = true; break; } } if (!outOfPowerHasBeenApplied) { Effect outOfPowerEffect = _.EffectVisualEffect(VisualEffect.Vfx_Dur_Aura_Red); outOfPowerEffect = _.TagEffect(outOfPowerEffect, "CONTROL_TOWER_OUT_OF_POWER"); _.ApplyEffectToObject(DurationType.Permanent, outOfPowerEffect, tower.Object); var instances = NWModule.Get().Areas.Where(x => x.GetLocalString("PC_BASE_STRUCTURE_ID") == structureID.ToString()); foreach (var instance in instances) { BaseService.ToggleInstanceObjectPower(instance, false); } } } else { bool outOfPowerWasRemoved = false; foreach (var effect in tower.Effects) { if (_.GetEffectTag(effect) == "CONTROL_TOWER_OUT_OF_POWER") { _.RemoveEffect(tower.Object, effect); outOfPowerWasRemoved = true; break; } } if (outOfPowerWasRemoved) { var instances = NWModule.Get().Areas.Where(x => x.GetLocalString("PC_BASE_STRUCTURE_ID") == structureID.ToString()); foreach (var instance in instances) { BaseService.ToggleInstanceObjectPower(instance, true); } } } // Reinforced mode fuel usage if (pcBase.IsInReinforcedMode) { pcBase.ReinforcedFuel--; if (pcBase.ReinforcedFuel <= 0) { pcBase.ReinforcedFuel = 0; pcBase.IsInReinforcedMode = false; } } // Tower regeneration only happens if fueled. else if (pcBase.DateFuelEnds > DateTime.UtcNow) { pcBase.ShieldHP += 12 + 4 * structure.StructureBonus; } if (pcBase.ShieldHP > maxShieldHP) { pcBase.ShieldHP = maxShieldHP; } DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); }
public void Main() { NWPlaceable drill = _.OBJECT_SELF; string structureID = drill.GetLocalString("PC_BASE_STRUCTURE_ID"); if (string.IsNullOrWhiteSpace(structureID)) { string areaName = drill.Area.Name; Console.WriteLine("There was an error retrieving the PC_BASE_STRUCTURE_ID variable on drill in area: " + areaName); return; } Guid structureGUID = new Guid(structureID); PCBaseStructure pcStructure = DataService.PCBaseStructure.GetByID(structureGUID); PCBase pcBase = DataService.PCBase.GetByID(pcStructure.PCBaseID); PCBaseStructure tower = BaseService.GetBaseControlTower(pcBase.ID); if (tower == null) { Console.WriteLine("Could not locate valid tower in Drill OnHeartbeat. PCBaseID = " + pcBase.ID); return; } // Check whether there's space in this tower. int capacity = BaseService.CalculateResourceCapacity(pcBase.ID); int count = DataService.PCBaseStructureItem.GetNumberOfItemsContainedBy(tower.ID) + 1; if (count > capacity) { return; } BaseStructure baseStructure = DataService.BaseStructure.GetByID(pcStructure.BaseStructureID); DateTime now = DateTime.UtcNow; var outOfPowerEffect = drill.Effects.SingleOrDefault(x => _.GetEffectTag(x) == "CONTROL_TOWER_OUT_OF_POWER"); if (now >= pcBase.DateFuelEnds) { if (outOfPowerEffect == null) { outOfPowerEffect = _.EffectVisualEffect(VisualEffect.Vfx_Dur_Aura_Red); outOfPowerEffect = _.TagEffect(outOfPowerEffect, "CONTROL_TOWER_OUT_OF_POWER"); _.ApplyEffectToObject(DurationType.Permanent, outOfPowerEffect, drill); } return; } else if (now < pcBase.DateFuelEnds && outOfPowerEffect != null) { _.RemoveEffect(drill, outOfPowerEffect); } int minuteReduce = 2 * pcStructure.StructureBonus; int increaseMinutes = 60 - minuteReduce; int retrievalRating = baseStructure.RetrievalRating; if (increaseMinutes <= 20) { increaseMinutes = 20; } if (pcStructure.DateNextActivity == null) { pcStructure.DateNextActivity = now.AddMinutes(increaseMinutes); DataService.SubmitDataChange(pcStructure, DatabaseActionType.Update); } if (!(now >= pcStructure.DateNextActivity)) { return; } // Time to spawn a new item and reset the timer. var dbArea = DataService.Area.GetByResref(pcBase.AreaResref); string sector = pcBase.Sector; int lootTableID = 0; switch (sector) { case "NE": lootTableID = dbArea.NortheastLootTableID ?? 0; break; case "NW": lootTableID = dbArea.NorthwestLootTableID ?? 0; break; case "SE": lootTableID = dbArea.SoutheastLootTableID ?? 0; break; case "SW": lootTableID = dbArea.SouthwestLootTableID ?? 0; break; } if (lootTableID <= 0) { Console.WriteLine("WARNING: Loot table ID not defined for area " + dbArea.Name + ". Drills cannot retrieve items."); return; } pcStructure.DateNextActivity = now.AddMinutes(increaseMinutes); var controlTower = BaseService.GetBaseControlTower(pcStructure.PCBaseID); if (controlTower == null) { Console.WriteLine("Could not locate control tower in drill heartbeat. PCBaseID = " + pcStructure.PCBaseID); return; } var itemDetails = LootService.PickRandomItemFromLootTable(lootTableID); var tempStorage = _.GetObjectByTag("TEMP_ITEM_STORAGE"); NWItem item = _.CreateItemOnObject(itemDetails.Resref, tempStorage, itemDetails.Quantity); // Guard against invalid resrefs and missing items. if (!item.IsValid) { Console.WriteLine("ERROR: Could not create base drill item with resref '" + itemDetails.Resref + "'. Is this item valid?"); return; } if (!string.IsNullOrWhiteSpace(itemDetails.SpawnRule)) { var rule = SpawnService.GetSpawnRule(itemDetails.SpawnRule); rule.Run(item, retrievalRating); } var dbItem = new PCBaseStructureItem { PCBaseStructureID = controlTower.ID, ItemGlobalID = item.GlobalID.ToString(), ItemName = item.Name, ItemResref = item.Resref, ItemTag = item.Tag, ItemObject = SerializationService.Serialize(item) }; DataService.SubmitDataChange(pcStructure, DatabaseActionType.Update); DataService.SubmitDataChange(dbItem, DatabaseActionType.Insert); item.Destroy(); }
private void DoRetrieveStructure() { var data = _base.GetPlayerTempData(GetPC()); PCBaseStructure structure = _data.Get <PCBaseStructure>(data.ManipulatingStructure.PCBaseStructureID); BaseStructure baseStructure = _data.Get <BaseStructure>(structure.BaseStructureID); PCBase pcBase = _data.Get <PCBase>(structure.PCBaseID); BaseStructureType structureType = (BaseStructureType)baseStructure.BaseStructureTypeID; var tempStorage = _.GetObjectByTag("TEMP_ITEM_STORAGE"); var pcStructureID = structure.ID; int impoundedCount = 0; var controlTower = _base.GetBaseControlTower(pcBase.ID); int maxShields = _base.CalculateMaxShieldHP(controlTower); if (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 = _perm.HasBasePermission(GetPC(), data.ManipulatingStructure.PCBaseID, BasePermission.CanRetrieveStructures); } else if (data.BuildingType == Enumeration.BuildingType.Interior) { var structureID = new Guid(data.ManipulatingStructure.Structure.Area.GetLocalString("PC_BASE_STRUCTURE_ID")); canRetrieveStructures = _perm.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 = _data.GetAll <PCBaseStructure>().Count(x => x.PCBaseID == structure.PCBaseID); if (structureCount > 1) { GetPC().FloatingText("You must remove all structures in this sector before picking up the control tower."); return; } } else if (structureType == BaseStructureType.Building) { var childStructures = _data.Where <PCBaseStructure>(x => x.ParentPCBaseStructureID == structure.ID).ToList(); for (int x = childStructures.Count - 1; x >= 0; x--) { var furniture = childStructures.ElementAt(x); NWItem furnitureItem = _base.ConvertStructureToItem(furniture, tempStorage); _impound.Impound(GetPC().GlobalID, furnitureItem); furnitureItem.Destroy(); _data.SubmitDataChange(furniture, DatabaseActionType.Delete); impoundedCount++; } } _base.ConvertStructureToItem(structure, GetPC()); _data.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 = _base.CalculateMaxFuel(pcBase.ID); int maxReinforcedFuel = _base.CalculateMaxReinforcedFuel(pcBase.ID); if (pcBase.Fuel > maxFuel) { int returnAmount = pcBase.Fuel - maxFuel; NWItem refund = _.CreateItemOnObject("fuel_cell", tempStorage, returnAmount); pcBase.Fuel = maxFuel; _impound.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; _impound.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 = _base.CalculateResourceCapacity(pcBase.ID); var items = _data.Where <PCBaseStructureItem>(x => x.PCBaseStructureID == 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 }; _data.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."); _data.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 override void DoAction(NWPlayer player, string pageName, int responseID) { PlayerDialog dialog = DialogService.LoadPlayerDialog(GetPC().GlobalID); Guid structureID = new Guid(_.GetLocalString(player.Area, "PC_BASE_STRUCTURE_ID")); PCBaseStructure structure = DataService.PCBaseStructure.GetByID(structureID); PCBase pcBase = DataService.PCBase.GetByID(structure.PCBaseID); DialogPage page = dialog.GetPageByName(pageName); DialogResponse response = page.Responses[responseID - 1]; bool carefulPilot = PerkService.GetCreaturePerkLevel(player, PerkType.CarefulPilot) > 0; if (pageName == "MainPage") { // The number of dialog options available can vary. So query based on the actual text of the response. if (response.Text == "Land") { ChangePage("LandingDestPage"); } else if (response.Text == "Pilot Ship") { SpaceService.CreateShipInSpace(player.Area); // In case we logged in here. SpaceService.DoFlyShip(GetPC(), GetPC().Area); EndConversation(); } else if (response.Text == "Hyperspace Jump") { // Build the list of destinations. ChangePage("HyperDestPage"); } else if (response.Text == "Take Off") { // Check fuel if (pcBase.Fuel < 1) { GetPC().SendMessage("You don't have enough fuel! You need 1 fuel to take off."); dialog.ResetPage(); } else { // Fuel is good - we have liftoff. if (!SpaceService.DoPilotingSkillCheck(GetPC(), 2, carefulPilot)) { // Failed our skill check. Deduct fuel but don't do anything else. GetPC().FloatingText("The ship shudders a bit, but your awkwardness on the throttle shows, and it doesn't make it off the dock. Try again."); pcBase.Fuel -= 1; DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); return; } EndConversation(); // Save details of the current dock for later. Guid shipPCBaseID = new Guid(pcBase.ShipLocation); PCBaseStructure dock = DataService.PCBaseStructure.GetByIDOrDefault(shipPCBaseID); pcBase.Fuel -= 1; pcBase.DateRentDue = DateTime.UtcNow.AddDays(99); pcBase.ShipLocation = SpaceService.GetPlanetFromLocation(pcBase.ShipLocation) + " - Orbit"; DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); SpaceService.CreateShipInSpace(player.Area); // Give the impression of movement foreach (var creature in player.Area.Objects) { if (creature.IsPC || creature.IsDM) { _.FloatingTextStringOnCreature("The ship is taking off", creature); } } _.ApplyEffectToObject(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), player); // Clean up the base structure, if we were in a PC dock not public starport. // Get a reference to our placeable (and door), and delete them with some VFX. if (dock != null) { PCBase dockBase = DataService.PCBase.GetByID(dock.PCBaseID); IEnumerable <NWArea> areas = NWModule.Get().Areas; NWArea landingArea = new NWArea(_.GetFirstArea()); foreach (var area in areas) { if (_.GetResRef(area) == dockBase.AreaResref) { landingArea = area; } } List <AreaStructure> areaStructures = landingArea.Data["BASE_SERVICE_STRUCTURES"]; foreach (var plc in areaStructures) { if (plc.PCBaseStructureID == dock.ID) { // Found our dock. Clear its variable and play some VFX. plc.Structure.SetLocalInt("DOCKED_STARSHIP", 0); DoDustClouds(plc.Structure.Location); _.ApplyEffectToObject(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), plc.Structure); } else if (plc.PCBaseStructureID == structure.ID) { // found either our ship or our entrance (both are saved with our structure ID). Delete them. // Dp NOT remove the PC base structure object from the database. We still need that. plc.Structure.Destroy(); } } } } } else if (response.Text == "Access Fuel Bay") { OpenFuelBay(false); EndConversation(); } else if (response.Text == "Access Stronidium Bay") { OpenFuelBay(true); EndConversation(); } else if (response.Text == "Access Resource Bay") { NWPlaceable bay = SpaceService.GetCargoBay(player.Area, GetPC()); if (bay != null) { GetPC().AssignCommand(() => _.ActionInteractObject(bay.Object)); } EndConversation(); } else if (response.Text == "Export Starcharts") { NWItem item = _.CreateItemOnObject("starcharts", player, 1, _.Random(10000).ToString()); // Initialise the list, in case it hasn't been populated yet. SpaceService.GetHyperspaceDestinationList(pcBase); item.SetLocalInt("Starcharts", (int)pcBase.Starcharts); } } else if (pageName == "HyperDestPage") { // Check fuel if (pcBase.Fuel < 50) { GetPC().SendMessage("You don't have enough fuel! You need 50 fuel to make a hyperspace jump."); dialog.ResetPage(); } else { // Fuel is good - make the jump if (!SpaceService.DoPilotingSkillCheck(GetPC(), 13, carefulPilot)) { // Failed our skill check. Deduct fuel but don't do anything else. GetPC().FloatingText("Jump failed! You forgot to whatsit the thingummyjig."); pcBase.Fuel -= 50; DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); EndConversation(); return; } // Move the ship out of the old orbit. SpaceService.RemoveShipInSpace(player.Area); // Fade to black for hyperspace. EndConversation(); pcBase.Fuel -= 50; pcBase.ShipLocation = response.Text + " - Orbit"; DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); // Put the ship in its new orbit. SpaceService.CreateShipInSpace(player.Area); // Give the impression of movement - would be great to have the actual hyperspace jump graphics here. foreach (var creature in player.Area.Objects) { if (creature.IsPC || creature.IsDM) { _.FloatingTextStringOnCreature("Making a hyperspace jump!", creature); _.FadeToBlack(creature, 0.5f); _.DelayCommand(1.0f, () => { _.FadeFromBlack(creature, 0.5f); }); } } } } else if (pageName == "LandingDestPage") { // Skill check. if (!SpaceService.DoPilotingSkillCheck(GetPC(), 5, carefulPilot)) { // Failed our skill check. Land anyway but burn more fuel. if (pcBase.Fuel > 0) { GetPC().FloatingText("You overshoot the landing spot, burning extra fuel getting your ship into position."); pcBase.Fuel -= 1; DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); } } // Get the response, then find the structure ID. Guid dockStructureID = dialog.CustomData["LAND_" + response.Text]; // This could be a public startport ID or a private dock base structure ID. Starport starport = DataService.Starport.GetByStarportIDOrDefault(dockStructureID); if (starport != null) { // We have a public starport. if (player.Gold < starport.Cost) { player.SendMessage("You do not have enough credits to land here."); return; } else { _.TakeGoldFromCreature(starport.Cost, player, true); // Land. pcBase.ShipLocation = starport.StarportID.ToString(); pcBase.DateRentDue = DateTime.UtcNow.AddDays(1); DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); // Notify PC. player.SendMessage("You have paid your first day's berthing fees. Use the Base Management System to extend your lease if you plan to stay longer, or your ship will be impounded."); EndConversation(); } } else { LoggingService.Trace(TraceComponent.Space, "Landing in PC base dock, ID: " + dockStructureID.ToString()); PCBaseStructure dock = DataService.PCBaseStructure.GetByIDOrDefault(dockStructureID); if (dock == null) { player.SendMessage("ERROR: Could not find landing dock by ID. Please report this."); LoggingService.Trace(TraceComponent.Space, "Could not find landing dock ID " + dockStructureID.ToString()); return; } NWPlaceable plc = BaseService.FindPlaceableFromStructureID(dock.ID.ToString()); if (plc == null) { LoggingService.Trace(TraceComponent.Space, "Failed to find dock placeable."); player.SendMessage("ERROR: Could not find landing dock placeable. Please report this."); return; } LoggingService.Trace(TraceComponent.Space, "Found dock, landing ship."); // We've found our dock. Update our record of where the ship's exterior should spawn. NWLocation loc = plc.Location; structure.LocationX = loc.X; structure.LocationY = loc.Y; structure.LocationZ = loc.Z; structure.LocationOrientation = _.GetFacingFromLocation(loc); DataService.SubmitDataChange(structure, DatabaseActionType.Update); // And update the base to mark the parent dock as the location. pcBase.ShipLocation = dock.ID.ToString(); DataService.SubmitDataChange(pcBase, DatabaseActionType.Update); // Now use the Base Service to spawn the ship exterior. BaseService.SpawnStructure(plc.Area, structure.ID); // Mark the dock as occupied. plc.SetLocalInt("DOCKED_STARSHIP", 1); // Notify PCs in the landing area. foreach (var creature in plc.Area.Objects) { if (creature.IsPC || creature.IsDM) { _.FloatingTextStringOnCreature("A ship has just landed!", creature); } } // And shake the screen, because stuff. _.ApplyEffectAtLocation(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), loc); DoDustClouds(loc); } // We're landing. Make sure any pilot or gunner get out of flight mode. SpaceService.LandCrew(player.Area); // If we are still here, we landed successfully. Shake the screen about and notify PCs on the ship. // Give the impression of movement foreach (var creature in player.Area.Objects) { if (creature.IsPC || creature.IsDM) { _.FloatingTextStringOnCreature("The ship is landing.", creature); } } _.ApplyEffectToObject(DurationType.Instant, _.EffectVisualEffect(VisualEffect.Vfx_Fnf_Screen_Shake), player); SpaceService.RemoveShipInSpace(player.Area); EndConversation(); } }
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); }