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:
@@ -1,4 +1,6 @@
|
|||||||
namespace Content.Server.Cargo.Components;
|
using Content.Server.Station.Systems;
|
||||||
|
|
||||||
|
namespace Content.Server.Cargo.Components;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This is used for marking containers as
|
/// This is used for marking containers as
|
||||||
@@ -17,4 +19,10 @@ public sealed partial class CargoBountyLabelComponent : Component
|
|||||||
/// Used to prevent recursion in calculating the price.
|
/// Used to prevent recursion in calculating the price.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Calculating;
|
public bool Calculating;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The Station System to check and remove bounties from
|
||||||
|
/// </summary>
|
||||||
|
[DataField]
|
||||||
|
public EntityUid? AssociatedStationId;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Content.Server.Cargo.Components;
|
|||||||
using Content.Server.Labels;
|
using Content.Server.Labels;
|
||||||
using Content.Server.NameIdentifier;
|
using Content.Server.NameIdentifier;
|
||||||
using Content.Server.Paper;
|
using Content.Server.Paper;
|
||||||
|
using Content.Server.Station.Systems;
|
||||||
using Content.Shared.Cargo;
|
using Content.Shared.Cargo;
|
||||||
using Content.Shared.Cargo.Components;
|
using Content.Shared.Cargo.Components;
|
||||||
using Content.Shared.Cargo.Prototypes;
|
using Content.Shared.Cargo.Prototypes;
|
||||||
@@ -65,16 +66,17 @@ public sealed partial class CargoSystem
|
|||||||
|
|
||||||
var label = Spawn(component.BountyLabelId, Transform(uid).Coordinates);
|
var label = Spawn(component.BountyLabelId, Transform(uid).Coordinates);
|
||||||
component.NextPrintTime = _timing.CurTime + component.PrintDelay;
|
component.NextPrintTime = _timing.CurTime + component.PrintDelay;
|
||||||
SetupBountyLabel(label, bounty.Value);
|
SetupBountyLabel(label, station, bounty.Value);
|
||||||
_audio.PlayPvs(component.PrintSound, uid);
|
_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))
|
if (!Resolve(uid, ref paper, ref label) || !_protoMan.TryIndex<CargoBountyPrototype>(bounty.Bounty, out var prototype))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
label.Id = bounty.Id;
|
label.Id = bounty.Id;
|
||||||
|
label.AssociatedStationId = stationId;
|
||||||
var msg = new FormattedMessage();
|
var msg = new FormattedMessage();
|
||||||
msg.AddText(Loc.GetString("bounty-manifest-header", ("id", bounty.Id)));
|
msg.AddText(Loc.GetString("bounty-manifest-header", ("id", bounty.Id)));
|
||||||
msg.PushNewline();
|
msg.PushNewline();
|
||||||
@@ -103,7 +105,7 @@ 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 || !TryComp<StationCargoBountyDatabaseComponent>(station, out var database))
|
if (component.AssociatedStationId is not { } station || !TryComp<StationCargoBountyDatabaseComponent>(station, out var database))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (database.CheckedBounties.Contains(component.Id))
|
if (database.CheckedBounties.Contains(component.Id))
|
||||||
@@ -131,14 +133,18 @@ public sealed partial class CargoSystem
|
|||||||
if (!TryGetBountyLabel(sold, out _, out var component))
|
if (!TryGetBountyLabel(sold, out _, out var component))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!TryGetBountyFromId(args.Station, component.Id, out var bounty))
|
if (component.AssociatedStationId is not { } station || !TryGetBountyFromId(station, component.Id, out var bounty))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!IsBountyComplete(sold, bounty.Value))
|
if (!IsBountyComplete(sold, bounty.Value))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
TryRemoveBounty(args.Station, bounty.Value);
|
TryRemoveBounty(station, bounty.Value);
|
||||||
FillBountyDatabase(args.Station);
|
FillBountyDatabase(station);
|
||||||
_adminLogger.Add(LogType.Action, LogImpact.Low, $"Bounty \"{bounty.Value.Bounty}\" (id:{bounty.Value.Id}) was fulfilled");
|
_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);
|
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))
|
if (!TryGetBountyLabel(container, out _, out var component))
|
||||||
{
|
{
|
||||||
@@ -204,7 +210,7 @@ public sealed partial class CargoSystem
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
station ??= _station.GetOwningStation(container);
|
var station = component.AssociatedStationId;
|
||||||
if (station == null)
|
if (station == null)
|
||||||
{
|
{
|
||||||
bountyEntities = new();
|
bountyEntities = new();
|
||||||
|
|||||||
@@ -230,9 +230,8 @@ public sealed partial class CargoSystem
|
|||||||
|
|
||||||
#region Station
|
#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);
|
GetPalletGoods(gridUid, out var toSell, out amount);
|
||||||
|
|
||||||
Log.Debug($"Cargo sold {toSell.Count} entities for {amount}");
|
Log.Debug($"Cargo sold {toSell.Count} entities for {amount}");
|
||||||
@@ -240,11 +239,9 @@ public sealed partial class CargoSystem
|
|||||||
if (toSell.Count == 0)
|
if (toSell.Count == 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (station != null)
|
|
||||||
{
|
var ev = new EntitySoldEvent(toSell);
|
||||||
var ev = new EntitySoldEvent(station.Value, toSell);
|
|
||||||
RaiseLocalEvent(ref ev);
|
RaiseLocalEvent(ref ev);
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var ent in toSell)
|
foreach (var ent in toSell)
|
||||||
{
|
{
|
||||||
@@ -299,7 +296,7 @@ public sealed partial class CargoSystem
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var complete = IsBountyComplete(uid, (EntityUid?) null, out var bountyEntities);
|
var complete = IsBountyComplete(uid, out var bountyEntities);
|
||||||
|
|
||||||
// Recursively check for mobs at any point.
|
// Recursively check for mobs at any point.
|
||||||
var children = xform.ChildEnumerator;
|
var children = xform.ChildEnumerator;
|
||||||
@@ -332,7 +329,7 @@ public sealed partial class CargoSystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!SellPallets(gridUid, null, out var price))
|
if (!SellPallets(gridUid, out var price))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var stackPrototype = _protoMan.Index<StackPrototype>(component.CashType);
|
var stackPrototype = _protoMan.Index<StackPrototype>(component.CashType);
|
||||||
@@ -354,4 +351,4 @@ public sealed partial class CargoSystem
|
|||||||
/// deleted but after the price has been calculated.
|
/// deleted but after the price has been calculated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ByRefEvent]
|
[ByRefEvent]
|
||||||
public readonly record struct EntitySoldEvent(EntityUid Station, HashSet<EntityUid> Sold);
|
public readonly record struct EntitySoldEvent(HashSet<EntityUid> Sold);
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public sealed class PriceGunSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if we're scanning a bounty crate
|
// Check if we're scanning a bounty crate
|
||||||
if (_bountySystem.IsBountyComplete(args.Target.Value, (EntityUid?) null, out _))
|
if (_bountySystem.IsBountyComplete(args.Target.Value, out _))
|
||||||
{
|
{
|
||||||
_popupSystem.PopupEntity(Loc.GetString("price-gun-bounty-complete"), args.User, args.User);
|
_popupSystem.PopupEntity(Loc.GetString("price-gun-bounty-complete"), args.User, args.User);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user