From 29a4e9c8b55922d2ab5d9e08d195b9577372a326 Mon Sep 17 00:00:00 2001 From: blue3212 Date: Tue, 26 Mar 2024 23:26:35 -0400 Subject: [PATCH 1/3] Ported over code for delta-v to fix bounties --- .../Components/CargoBountyLabelComponent.cs | 9 +++++++- .../Cargo/Systems/CargoSystem.Bounty.cs | 23 ++++++++++++------- .../Cargo/Systems/CargoSystem.Shuttle.cs | 16 ++++++------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/Content.Server/Cargo/Components/CargoBountyLabelComponent.cs b/Content.Server/Cargo/Components/CargoBountyLabelComponent.cs index 8eea00e0993983..f531e79012fd82 100644 --- a/Content.Server/Cargo/Components/CargoBountyLabelComponent.cs +++ b/Content.Server/Cargo/Components/CargoBountyLabelComponent.cs @@ -1,4 +1,6 @@ -namespace Content.Server.Cargo.Components; +using Content.Server.Station.Systems; + +namespace Content.Server.Cargo.Components; /// /// This is used for marking containers as @@ -17,4 +19,9 @@ public sealed partial class CargoBountyLabelComponent : Component /// Used to prevent recursion in calculating the price. /// public bool Calculating; + + /// + /// The Station System to check and remove bounties from + /// + public EntityUid? AssociatedStationId = null; } diff --git a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs index ce15542ec534ae..b93e0286e12fa6 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs @@ -4,6 +4,7 @@ using Content.Server.Labels; using Content.Server.NameIdentifier; using Content.Server.Paper; +using Content.Server.Station.Systems; using Content.Shared.Cargo; using Content.Shared.Cargo.Components; using Content.Shared.Cargo.Prototypes; @@ -15,6 +16,7 @@ using Robust.Shared.Containers; using Robust.Shared.Random; using Robust.Shared.Utility; +using Serilog; namespace Content.Server.Cargo.Systems; @@ -65,16 +67,17 @@ private void OnPrintLabelMessage(EntityUid uid, CargoBountyConsoleComponent comp var label = Spawn(component.BountyLabelId, Transform(uid).Coordinates); component.NextPrintTime = _timing.CurTime + component.PrintDelay; - SetupBountyLabel(label, bounty.Value); + SetupBountyLabel(label, station, bounty.Value); _audio.PlayPvs(component.PrintSound, uid); } - public void SetupBountyLabel(EntityUid uid, CargoBountyData bounty, PaperComponent? paper = null, CargoBountyLabelComponent? label = null) + public void SetupBountyLabel(EntityUid uid, EntityUid stationId, CargoBountyData bounty, PaperComponent? paper = null, CargoBountyLabelComponent? label = null) { if (!Resolve(uid, ref paper, ref label) || !_protoMan.TryIndex(bounty.Bounty, out var prototype)) return; label.Id = bounty.Id; + label.AssociatedStationId = stationId; var msg = new FormattedMessage(); msg.AddText(Loc.GetString("bounty-manifest-header", ("id", bounty.Id))); msg.PushNewline(); @@ -103,7 +106,7 @@ private void OnGetBountyPrice(EntityUid uid, CargoBountyLabelComponent component if (!_container.TryGetContainingContainer(uid, out var container) || container.ID != LabelSystem.ContainerName) return; - if (_station.GetOwningStation(uid) is not { } station || !TryComp(station, out var database)) + if (component.AssociatedStationId is not { } station || !TryComp(station, out var database)) return; if (database.CheckedBounties.Contains(component.Id)) @@ -131,14 +134,18 @@ private void OnSold(ref EntitySoldEvent args) if (!TryGetBountyLabel(sold, out _, out var component)) continue; - if (!TryGetBountyFromId(args.Station, component.Id, out var bounty)) + if (component.AssociatedStationId is not { } station || !TryGetBountyFromId(station, component.Id, out var bounty)) + { continue; + } if (!IsBountyComplete(sold, bounty.Value)) + { continue; + } - TryRemoveBounty(args.Station, bounty.Value); - FillBountyDatabase(args.Station); + TryRemoveBounty(station, bounty.Value); + FillBountyDatabase(station); _adminLogger.Add(LogType.Action, LogImpact.Low, $"Bounty \"{bounty.Value.Bounty}\" (id:{bounty.Value.Id}) was fulfilled"); } } @@ -204,7 +211,7 @@ public bool IsBountyComplete(EntityUid container, EntityUid? station, out HashSe return false; } - station ??= _station.GetOwningStation(container); + station ??= component.AssociatedStationId; if (station == null) { bountyEntities = new(); @@ -225,7 +232,7 @@ public bool IsBountyComplete(EntityUid container, CargoBountyData data) return IsBountyComplete(container, data, out _); } - public bool IsBountyComplete(EntityUid container, CargoBountyData data, out HashSet bountyEntities) + public bool IsBountyComplete(EntityUid container, CargoBountyData data, out HashSet bountyEntities) { if (!_protoMan.TryIndex(data.Bounty, out var proto)) { diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs index ab66e6ff3fcf74..44d9d3f904d494 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs @@ -230,9 +230,9 @@ private int GetCargoSpace(EntityUid gridUid) #region Station - private bool SellPallets(EntityUid gridUid, EntityUid? station, out double amount) + private bool SellPallets(EntityUid gridUid, out double amount) { - station ??= _station.GetOwningStation(gridUid); + //station ??= _station.GetOwningStation(gridUid); GetPalletGoods(gridUid, out var toSell, out amount); Log.Debug($"Cargo sold {toSell.Count} entities for {amount}"); @@ -240,11 +240,9 @@ private bool SellPallets(EntityUid gridUid, EntityUid? station, out double amoun if (toSell.Count == 0) return false; - if (station != null) - { - var ev = new EntitySoldEvent(station.Value, toSell); - RaiseLocalEvent(ref ev); - } + + var ev = new EntitySoldEvent(toSell); + RaiseLocalEvent(ref ev); foreach (var ent in toSell) { @@ -332,7 +330,7 @@ private void OnPalletSale(EntityUid uid, CargoPalletConsoleComponent component, return; } - if (!SellPallets(gridUid, null, out var price)) + if (!SellPallets(gridUid, out var price)) return; var stackPrototype = _protoMan.Index(component.CashType); @@ -354,4 +352,4 @@ private void OnRoundRestart(RoundRestartCleanupEvent ev) /// deleted but after the price has been calculated. /// [ByRefEvent] -public readonly record struct EntitySoldEvent(EntityUid Station, HashSet Sold); +public readonly record struct EntitySoldEvent(HashSet Sold); From ba4178b8f597de09a77639e25cf2e12fddcedf17 Mon Sep 17 00:00:00 2001 From: blue3212 Date: Wed, 27 Mar 2024 00:02:29 -0400 Subject: [PATCH 2/3] Added requested changes --- Content.Server/Cargo/Components/CargoBountyLabelComponent.cs | 3 ++- Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Content.Server/Cargo/Components/CargoBountyLabelComponent.cs b/Content.Server/Cargo/Components/CargoBountyLabelComponent.cs index f531e79012fd82..2b9898be0212ce 100644 --- a/Content.Server/Cargo/Components/CargoBountyLabelComponent.cs +++ b/Content.Server/Cargo/Components/CargoBountyLabelComponent.cs @@ -23,5 +23,6 @@ public sealed partial class CargoBountyLabelComponent : Component /// /// The Station System to check and remove bounties from /// - public EntityUid? AssociatedStationId = null; + [DataField] + public EntityUid? AssociatedStationId; } diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs index 44d9d3f904d494..1fd584491eb8a6 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs @@ -232,7 +232,6 @@ private int GetCargoSpace(EntityUid gridUid) private bool SellPallets(EntityUid gridUid, out double amount) { - //station ??= _station.GetOwningStation(gridUid); GetPalletGoods(gridUid, out var toSell, out amount); Log.Debug($"Cargo sold {toSell.Count} entities for {amount}"); From b77f4ca5db6eb3324a72415375f153e6093d9f6d Mon Sep 17 00:00:00 2001 From: blue3212 Date: Wed, 27 Mar 2024 17:07:10 -0400 Subject: [PATCH 3/3] Removed the station arg from "IsBountyComplete". It is unneeded and all calls just use a null value for it anyways --- Content.Server/Cargo/Systems/CargoSystem.Bounty.cs | 7 +++---- Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs | 2 +- Content.Server/Cargo/Systems/PriceGunSystem.cs | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs index b93e0286e12fa6..ee5ae631fd9d37 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs @@ -16,7 +16,6 @@ using Robust.Shared.Containers; using Robust.Shared.Random; using Robust.Shared.Utility; -using Serilog; namespace Content.Server.Cargo.Systems; @@ -203,7 +202,7 @@ public void RerollBountyDatabase(Entity en FillBountyDatabase(entity); } - public bool IsBountyComplete(EntityUid container, EntityUid? station, out HashSet bountyEntities) + public bool IsBountyComplete(EntityUid container, out HashSet bountyEntities) { if (!TryGetBountyLabel(container, out _, out var component)) { @@ -211,7 +210,7 @@ public bool IsBountyComplete(EntityUid container, EntityUid? station, out HashSe return false; } - station ??= component.AssociatedStationId; + var station = component.AssociatedStationId; if (station == null) { bountyEntities = new(); @@ -321,7 +320,7 @@ private HashSet GetBountyEntities(EntityUid uid) var children = GetBountyEntities(ent); foreach (var child in children) { - entities.Add(child); + entities.Add(child); } } } diff --git a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs index 1fd584491eb8a6..3bcd6d8d2067cf 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs @@ -296,7 +296,7 @@ private bool CanSell(EntityUid uid, TransformComponent xform) return false; } - var complete = IsBountyComplete(uid, (EntityUid?) null, out var bountyEntities); + var complete = IsBountyComplete(uid, out var bountyEntities); // Recursively check for mobs at any point. var children = xform.ChildEnumerator; diff --git a/Content.Server/Cargo/Systems/PriceGunSystem.cs b/Content.Server/Cargo/Systems/PriceGunSystem.cs index 7bd49b857ae17f..19fe07bd253a28 100644 --- a/Content.Server/Cargo/Systems/PriceGunSystem.cs +++ b/Content.Server/Cargo/Systems/PriceGunSystem.cs @@ -57,7 +57,7 @@ private void OnAfterInteract(EntityUid uid, PriceGunComponent component, AfterIn return; // Check if we're scanning a bounty crate - if (_bountySystem.IsBountyComplete(args.Target.Value, (EntityUid?) null, out _)) + if (_bountySystem.IsBountyComplete(args.Target.Value, out _)) { _popupSystem.PopupEntity(Loc.GetString("price-gun-bounty-complete"), args.User, args.User); }