Fix double counting bounties (#21399)
This commit is contained in:
@@ -33,8 +33,15 @@ public sealed partial class StationCargoBountyDatabaseComponent : Component
|
|||||||
public float MinBountyTime = 600f;
|
public float MinBountyTime = 600f;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The maxmium amount of time the bounty lasts before being removed.
|
/// The maximum amount of time the bounty lasts before being removed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField("maxBountyTime"), ViewVariables(VVAccess.ReadWrite)]
|
[DataField("maxBountyTime"), ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float MaxBountyTime = 905f;
|
public float MaxBountyTime = 905f;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A list of bounty IDs that have been checked this tick.
|
||||||
|
/// Used to prevent multiplying bounty prices.
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public HashSet<int> CheckedBounties = new();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,18 +89,24 @@ public sealed partial class CargoSystem
|
|||||||
if (!_container.TryGetContainingContainer(uid, out var container) || container.ID != LabelSystem.ContainerName)
|
if (!_container.TryGetContainingContainer(uid, out var container) || container.ID != LabelSystem.ContainerName)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_station.GetOwningStation(uid) is not { } station)
|
if (_station.GetOwningStation(uid) is not { } station || !TryComp<StationCargoBountyDatabaseComponent>(station, out var database))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!TryGetBountyFromId(station, component.Id, out var bounty))
|
if (database.CheckedBounties.Contains(component.Id))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!_protoMan.TryIndex<CargoBountyPrototype>(bounty.Value.Bounty, out var bountyProtoype) ||!IsBountyComplete(container.Owner, bountyProtoype))
|
if (!TryGetBountyFromId(station, component.Id, out var bounty, database))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!_protoMan.TryIndex<CargoBountyPrototype>(bounty.Value.Bounty, out var bountyPrototype) ||
|
||||||
|
!IsBountyComplete(container.Owner, bountyPrototype))
|
||||||
|
return;
|
||||||
|
|
||||||
|
database.CheckedBounties.Add(component.Id);
|
||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
|
|
||||||
component.Calculating = true;
|
component.Calculating = true;
|
||||||
args.Price = bountyProtoype.Reward - _pricing.GetPrice(container.Owner);
|
args.Price = bountyPrototype.Reward - _pricing.GetPrice(container.Owner);
|
||||||
component.Calculating = false;
|
component.Calculating = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,6 +335,7 @@ public sealed partial class CargoSystem
|
|||||||
var query = EntityQueryEnumerator<StationCargoBountyDatabaseComponent>();
|
var query = EntityQueryEnumerator<StationCargoBountyDatabaseComponent>();
|
||||||
while (query.MoveNext(out var uid, out var bountyDatabase))
|
while (query.MoveNext(out var uid, out var bountyDatabase))
|
||||||
{
|
{
|
||||||
|
bountyDatabase.CheckedBounties.Clear();
|
||||||
var bounties = new ValueList<CargoBountyData>(bountyDatabase.Bounties);
|
var bounties = new ValueList<CargoBountyData>(bountyDatabase.Bounties);
|
||||||
foreach (var bounty in bounties)
|
foreach (var bounty in bounties)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user