Skip to content

Commit

Permalink
Bounties work, but aren't removed and replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
blueDev2 committed Mar 26, 2024
1 parent 82d700f commit 54e3f4e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
9 changes: 8 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,9 @@ 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>
public EntityUid? AssociatedStationId = null;
}
31 changes: 22 additions & 9 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;

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 All @@ -126,19 +129,29 @@ private void OnGetBountyPrice(EntityUid uid, CargoBountyLabelComponent component

private void OnSold(ref EntitySoldEvent args)
{
_adminLogger.Add(LogType.Action, LogImpact.Low, $"OnSold has been called");
foreach (var sold in args.Sold)
{
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))
{
_adminLogger.Add(LogType.Action, LogImpact.Low, $"Failed to find the bounty");
continue;
}

if (!IsBountyComplete(sold, bounty.Value))
{
_adminLogger.Add(LogType.Action, LogImpact.Low, $"Failed to complete the bounty");
continue;
}

TryRemoveBounty(args.Station, bounty.Value);
FillBountyDatabase(args.Station);
if (TryRemoveBounty(station, bounty.Value))
{
_adminLogger.Add(LogType.Action, LogImpact.Low, $"Failed to remove the bounty");
}
FillBountyDatabase(station);
_adminLogger.Add(LogType.Action, LogImpact.Low, $"Bounty \"{bounty.Value.Bounty}\" (id:{bounty.Value.Id}) was fulfilled");
}
}
Expand Down Expand Up @@ -204,7 +217,7 @@ public bool IsBountyComplete(EntityUid container, EntityUid? station, out HashSe
return false;
}

station ??= _station.GetOwningStation(container);
station ??= component.AssociatedStationId;
if (station == null)
{
bountyEntities = new();
Expand All @@ -225,7 +238,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 Expand Up @@ -314,7 +327,7 @@ private HashSet<EntityUid> GetBountyEntities(EntityUid uid)
var children = GetBountyEntities(ent);
foreach (var child in children)
{
entities.Add(child);
entities.Add(child);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private int GetCargoSpace(EntityUid gridUid)

private bool SellPallets(EntityUid gridUid, EntityUid? station, 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}");
Expand All @@ -266,7 +266,7 @@ private bool SellPallets(EntityUid gridUid, EntityUid? station, out double amoun

if (station != null)
{
var ev = new EntitySoldEvent(station.Value, toSell);
var ev = new EntitySoldEvent(toSell);
RaiseLocalEvent(ref ev);
}

Expand Down Expand Up @@ -448,4 +448,4 @@ private void SetupTradePost()
/// 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);

0 comments on commit 54e3f4e

Please sign in to comment.