Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow cargo bounties to be sold off-station #26469

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Content.Server/Cargo/Components/CargoBountyLabelComponent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Content.Server.Cargo.Components;
using Content.Server.Station.Systems;

namespace Content.Server.Cargo.Components;

/// <summary>
/// This is used for marking containers as
Expand All @@ -17,4 +19,10 @@ public sealed partial class CargoBountyLabelComponent : Component
/// Used to prevent recursion in calculating the price.
/// </summary>
public bool Calculating;

/// <summary>
/// The Station System to check and remove bounties from
/// </summary>
[DataField]
public EntityUid? AssociatedStationId;
}
23 changes: 15 additions & 8 deletions Content.Server/Cargo/Systems/CargoSystem.Bounty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,7 @@
using Robust.Shared.Containers;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using Serilog;
blueDev2 marked this conversation as resolved.
Show resolved Hide resolved

namespace Content.Server.Cargo.Systems;

Expand Down Expand Up @@ -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<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();
Expand Down Expand Up @@ -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<StationCargoBountyDatabaseComponent>(station, out var database))
if (component.AssociatedStationId is not { } station || !TryComp<StationCargoBountyDatabaseComponent>(station, out var database))
return;

if (database.CheckedBounties.Contains(component.Id))
Expand Down Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -204,7 +211,7 @@ public bool IsBountyComplete(EntityUid container, EntityUid? station, out HashSe
return false;
}

station ??= _station.GetOwningStation(container);
station ??= component.AssociatedStationId;
blueDev2 marked this conversation as resolved.
Show resolved Hide resolved
if (station == null)
{
bountyEntities = new();
Expand All @@ -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<EntityUid> bountyEntities)
public bool IsBountyComplete(EntityUid container, CargoBountyData data, out HashSet<EntityUid> bountyEntities)
{
if (!_protoMan.TryIndex(data.Bounty, out var proto))
{
Expand Down
15 changes: 6 additions & 9 deletions Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,18 @@ 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);
GetPalletGoods(gridUid, out var toSell, out amount);

Log.Debug($"Cargo sold {toSell.Count} entities for {amount}");

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)
{
Expand Down Expand Up @@ -332,7 +329,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<StackPrototype>(component.CashType);
Expand All @@ -354,4 +351,4 @@ private void OnRoundRestart(RoundRestartCleanupEvent ev)
/// deleted but after the price has been calculated.
/// </summary>
[ByRefEvent]
public readonly record struct EntitySoldEvent(EntityUid Station, HashSet<EntityUid> Sold);
public readonly record struct EntitySoldEvent(HashSet<EntityUid> Sold);
Loading