Allow cargo bounties to be sold off-station (#26469)

* Ported over code for delta-v to fix bounties

* Added requested changes

* Removed the station arg from "IsBountyComplete". It is unneeded and all calls just use a null value for it anyways
This commit is contained in:
blueDev2
2024-03-28 00:06:00 -04:00
committed by GitHub
parent 8a6879bb1b
commit 4d9a79d96b
4 changed files with 33 additions and 22 deletions

View File

@@ -4,6 +4,7 @@ using Content.Server.Cargo.Components;
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;
@@ -65,16 +66,17 @@ public sealed partial class CargoSystem
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<CargoBountyPrototype>(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 +105,7 @@ public sealed partial class CargoSystem
if (!_container.TryGetContainingContainer(uid, out var container) || container.ID != LabelSystem.ContainerName)
return;
if (_station.GetOwningStation(uid) is not { } station || !TryComp<StationCargoBountyDatabaseComponent>(station, out var database))
if (component.AssociatedStationId is not { } station || !TryComp<StationCargoBountyDatabaseComponent>(station, out var database))
return;
if (database.CheckedBounties.Contains(component.Id))
@@ -131,14 +133,18 @@ public sealed partial class CargoSystem
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");
}
}
@@ -196,7 +202,7 @@ public sealed partial class CargoSystem
FillBountyDatabase(entity);
}
public bool IsBountyComplete(EntityUid container, EntityUid? station, out HashSet<EntityUid> bountyEntities)
public bool IsBountyComplete(EntityUid container, out HashSet<EntityUid> bountyEntities)
{
if (!TryGetBountyLabel(container, out _, out var component))
{
@@ -204,7 +210,7 @@ public sealed partial class CargoSystem
return false;
}
station ??= _station.GetOwningStation(container);
var station = component.AssociatedStationId;
if (station == null)
{
bountyEntities = new();
@@ -225,7 +231,7 @@ public sealed partial class CargoSystem
return IsBountyComplete(container, data, out _);
}
public bool IsBountyComplete(EntityUid container, CargoBountyData data, out HashSet<EntityUid> bountyEntities)
public bool IsBountyComplete(EntityUid container, CargoBountyData data, out HashSet<EntityUid> bountyEntities)
{
if (!_protoMan.TryIndex(data.Bounty, out var proto))
{
@@ -314,7 +320,7 @@ public sealed partial class CargoSystem
var children = GetBountyEntities(ent);
foreach (var child in children)
{
entities.Add(child);
entities.Add(child);
}
}
}