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

Uplink items spawned no longer push player into walls #34835

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
60 changes: 58 additions & 2 deletions Content.Server/Store/Systems/StoreSystem.Ui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@
using Content.Server.Stack;
using Content.Server.Store.Components;
using Content.Shared.Actions;
using Content.Shared.Coordinates.Helpers;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Maps;
using Content.Shared.Mind;
using Content.Shared.Physics;
using Content.Shared.Store;
using Content.Shared.Store.Components;
using Content.Shared.UserInterface;
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;

Expand All @@ -30,6 +35,8 @@ public sealed partial class StoreSystem
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly StackSystem _stack = default!;
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly TurfSystem _turf = default!;
[Dependency] private readonly IMapManager _mapMan = default!;

private void InitializeUi()
{
Expand Down Expand Up @@ -163,6 +170,46 @@ private void OnBuyRequest(EntityUid uid, StoreComponent component, StoreBuyListi
}
}

// For entities that may displace the user when spawned, such as crates
// We need an unblocked tile in front of the player to spawn it if it exists
EntityCoordinates? offsetSpawnCoords = null;
if (listing.ProductEntity != null)
{
var fixtureProduct = Spawn(listing.ProductEntity);
if (TryComp<FixturesComponent>(fixtureProduct, out var fixturesComponent))
{
foreach (var productFixtures in fixturesComponent.Fixtures)
{
if (!productFixtures.Value.Hard)
continue;

if ((productFixtures.Value.CollisionLayer &
(int)(CollisionGroup.Impassable | CollisionGroup.Opaque)) == 0)
continue;

// If the productEntity occupies the impassible or opaque layers,
// check to see if the tile in the direction the buyer is facing isn't blocked
var buyerXform = Transform(buyer);
var offsetValue = buyerXform.LocalRotation.ToWorldVec();
var coords = buyerXform.Coordinates.Offset(offsetValue).SnapToGrid(EntityManager, _mapMan);
var tile = coords.GetTileRef(EntityManager, _mapMan);

if (tile == null)
break;

if (_turf.IsTileBlocked(tile.Value, CollisionGroup.Impassable | CollisionGroup.Opaque))
{
_popup.PopupEntity(Loc.GetString("store-ui-spawn-space-blocked"), buyer, buyer);
return;
}

offsetSpawnCoords = _turf.GetTileCenter(tile.Value);
break;
}
}
QueueDel(fixtureProduct);
}

if (!IsOnStartingMap(uid, component))
component.RefundAllowed = false;

Expand All @@ -179,8 +226,17 @@ private void OnBuyRequest(EntityUid uid, StoreComponent component, StoreBuyListi
//spawn entity
if (listing.ProductEntity != null)
{
var product = Spawn(listing.ProductEntity, Transform(buyer).Coordinates);
_hands.PickupOrDrop(buyer, product);
EntityUid product;

if (offsetSpawnCoords != null)
{
product = Spawn(listing.ProductEntity, offsetSpawnCoords.Value);
}
else
{
product = Spawn(listing.ProductEntity, Transform(buyer).Coordinates);
_hands.PickupOrDrop(buyer, product);
}

HandleRefundComp(uid, component, product);

Expand Down
3 changes: 2 additions & 1 deletion Content.Shared/Maps/TurfSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public bool IsTileBlocked(EntityUid gridUid,

// This is scaled to 95 % so it doesn't encompass walls on other tiles.
var tileAabb = Box2.UnitCentered.Scale(0.95f * size);
var worldBox = new Box2Rotated(tileAabb.Translated(worldPos), gridRot, worldPos);
var worldBox = tileAabb.Translated(worldPos);
// var worldBox = new Box2Rotated(tileAabb.Translated(worldPos), gridRot, worldPos);
tileAabb = tileAabb.Translated(localPos);

var intersectionArea = 0f;
Expand Down
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/store/store.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ store-ui-discount-display-with-currency = {$amount} off on {$currency}
store-ui-discount-display = ({$amount} off!)
store-ui-traitor-flavor = Copyright (C) NT -30643
store-ui-traitor-warning = Operatives must lock their uplinks after use to avoid detection.
store-ui-spawn-space-blocked = Purchase failed, the area in front of you is blocked.


store-withdraw-button-ui = Withdraw {$currency}
store-ui-button-out-of-stock = {""} (Out of Stock)
Expand Down
Loading