Skip to content

Commit

Permalink
Update: implemented blacklist and ensured live mobs are not sold (inc…
Browse files Browse the repository at this point in the history
…luding you, the player)
  • Loading branch information
AWF committed Mar 29, 2024
1 parent f6ed53a commit bf47726
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
37 changes: 36 additions & 1 deletion Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using Content.Shared.Stacks;
using Robust.Shared.Prototypes;
using Content.Shared.Coordinates;
using Content.Shared.Mobs;

namespace Content.Server.Cargo.Systems;

Expand Down Expand Up @@ -393,7 +394,8 @@ private void GetPalletGoods(EntityUid gridUid, out HashSet<EntityUid> toSell, ou
// - anything anchored (e.g. light fixtures)
// - anything blacklisted (e.g. players).
if (toSell.Contains(ent) ||
(xformQuery.TryGetComponent(ent, out var xform) && xform.Anchored))
xformQuery.TryGetComponent(ent, out var xform) &&
(xform.Anchored || !CanSell(ent, xform)))
continue;

if (blacklistQuery.HasComponent(ent))
Expand All @@ -408,6 +410,39 @@ private void GetPalletGoods(EntityUid gridUid, out HashSet<EntityUid> toSell, ou
}
}

private bool CanSell(EntityUid uid, TransformComponent xform)
{
if (TryComp<MobStateComponent>(uid, out var mobstate))
{
if (mobstate.CurrentState == MobState.Alive)
{
return false;
}

return true;
}

// Recursively check for mobs at any point.
var children = xform.ChildEnumerator;
var xformQuery = GetEntityQuery<TransformComponent>();
while (children.MoveNext(out var child))
{

if (xformQuery.TryGetComponent(child.Value, out var childXform) && !CanSell(child.Value,childXform))
return false;
}

var blacklistQuery = GetEntityQuery<CargoSellBlacklistComponent>();

// Look for blacklisted items and stop the selling of the container.
if (blacklistQuery.HasComponent(uid))
{
return false;
}

return true;
}

private void BuyHooks(EntityUid uid)
{
if (TryComp<MaterialComponent>(uid, out var material) && !HasComp<StackPriceComponent>(uid))
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Cargo/Systems/CargoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Shared.Containers.ItemSlots;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes;
using Content.Shared.Mobs.Components;

namespace Content.Server.Cargo.Systems;

Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Mobs/Player/observer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@
baseSprintSpeed: 8
baseWalkSpeed: 5
- type: MovementIgnoreGravity
- type: CargoSellBlacklist

0 comments on commit bf47726

Please sign in to comment.