From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Sat, 4 Nov 2023 13:19:23 +0000 (-0400) Subject: Fix double counting bounties (#21399) X-Git-Url: https://git.smokeofanarchy.ru/gitweb.cgi?a=commitdiff_plain;h=4a730c59108550da1e14eef21dddb8b7fc9ae8fd;p=space-station-14.git Fix double counting bounties (#21399) --- diff --git a/Content.Server/Cargo/Components/StationCargoBountyDatabaseComponent.cs b/Content.Server/Cargo/Components/StationCargoBountyDatabaseComponent.cs index d94c2995e3..68517ea144 100644 --- a/Content.Server/Cargo/Components/StationCargoBountyDatabaseComponent.cs +++ b/Content.Server/Cargo/Components/StationCargoBountyDatabaseComponent.cs @@ -33,8 +33,15 @@ public sealed partial class StationCargoBountyDatabaseComponent : Component public float MinBountyTime = 600f; /// - /// The maxmium amount of time the bounty lasts before being removed. + /// The maximum amount of time the bounty lasts before being removed. /// [DataField("maxBountyTime"), ViewVariables(VVAccess.ReadWrite)] public float MaxBountyTime = 905f; + + /// + /// A list of bounty IDs that have been checked this tick. + /// Used to prevent multiplying bounty prices. + /// + [DataField] + public HashSet CheckedBounties = new(); } diff --git a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs index be8f54dfee..f502b7f92f 100644 --- a/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs +++ b/Content.Server/Cargo/Systems/CargoSystem.Bounty.cs @@ -89,18 +89,24 @@ public sealed partial class CargoSystem if (!_container.TryGetContainingContainer(uid, out var container) || container.ID != LabelSystem.ContainerName) return; - if (_station.GetOwningStation(uid) is not { } station) + if (_station.GetOwningStation(uid) is not { } station || !TryComp(station, out var database)) + return; + + if (database.CheckedBounties.Contains(component.Id)) return; - if (!TryGetBountyFromId(station, component.Id, out var bounty)) + if (!TryGetBountyFromId(station, component.Id, out var bounty, database)) return; - if (!_protoMan.TryIndex(bounty.Value.Bounty, out var bountyProtoype) ||!IsBountyComplete(container.Owner, bountyProtoype)) + if (!_protoMan.TryIndex(bounty.Value.Bounty, out var bountyPrototype) || + !IsBountyComplete(container.Owner, bountyPrototype)) return; + + database.CheckedBounties.Add(component.Id); args.Handled = true; component.Calculating = true; - args.Price = bountyProtoype.Reward - _pricing.GetPrice(container.Owner); + args.Price = bountyPrototype.Reward - _pricing.GetPrice(container.Owner); component.Calculating = false; } @@ -329,6 +335,7 @@ public sealed partial class CargoSystem var query = EntityQueryEnumerator(); while (query.MoveNext(out var uid, out var bountyDatabase)) { + bountyDatabase.CheckedBounties.Clear(); var bounties = new ValueList(bountyDatabase.Bounties); foreach (var bounty in bounties) {