Fix uplink item spawning.
Actually spawns for the person who USES the uplink, not who owns it. Can't believe that was an actual bug. Also puts it in your active hand if possible.
This commit is contained in:
@@ -198,14 +198,33 @@ namespace Content.Server.GameObjects.Components.GUI
|
||||
return success;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Drops the item if <paramref name="mob"/> doesn't have hands.
|
||||
/// </summary>
|
||||
public static void PutInHandOrDropStatic(IEntity mob, ItemComponent item, bool mobCheck = true)
|
||||
{
|
||||
if (!mob.TryGetComponent(out HandsComponent? hands))
|
||||
{
|
||||
DropAtFeet(mob, item);
|
||||
return;
|
||||
}
|
||||
|
||||
hands.PutInHandOrDrop(item, mobCheck);
|
||||
}
|
||||
|
||||
public void PutInHandOrDrop(ItemComponent item, bool mobCheck = true)
|
||||
{
|
||||
if (!PutInHand(item, mobCheck))
|
||||
{
|
||||
item.Owner.Transform.Coordinates = Owner.Transform.Coordinates;
|
||||
DropAtFeet(Owner, item);
|
||||
}
|
||||
}
|
||||
|
||||
private static void DropAtFeet(IEntity mob, ItemComponent item)
|
||||
{
|
||||
item.Owner.Transform.Coordinates = mob.Transform.Coordinates;
|
||||
}
|
||||
|
||||
public bool CanPutInHand(ItemComponent item, bool mobCheck = true)
|
||||
{
|
||||
if (mobCheck && !ActionBlockerSystem.CanPickup(Owner))
|
||||
|
||||
@@ -135,12 +135,20 @@ namespace Content.Server.GameObjects.Components.PDA
|
||||
|
||||
case PDAUplinkBuyListingMessage buyMsg:
|
||||
{
|
||||
if (!_uplinkManager.TryPurchaseItem(_syndicateUplinkAccount, buyMsg.ItemId))
|
||||
if (message.Session.AttachedEntity == null)
|
||||
break;
|
||||
|
||||
if (!_uplinkManager.TryPurchaseItem(_syndicateUplinkAccount, buyMsg.ItemId,
|
||||
message.Session.AttachedEntity.Transform.Coordinates, out var entity))
|
||||
{
|
||||
SendNetworkMessage(new PDAUplinkInsufficientFundsMessage(), message.Session.ConnectedClient);
|
||||
break;
|
||||
}
|
||||
|
||||
HandsComponent.PutInHandOrDropStatic(
|
||||
message.Session.AttachedEntity,
|
||||
entity.GetComponent<ItemComponent>());
|
||||
|
||||
SendNetworkMessage(new PDAUplinkBuySuccessMessage(), message.Session.ConnectedClient);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.GameObjects.Components.PDA;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Interfaces.PDA
|
||||
{
|
||||
public interface IPDAUplinkManager
|
||||
{
|
||||
public IReadOnlyDictionary<string, UplinkListingData> FetchListings => null;
|
||||
public IReadOnlyDictionary<string, UplinkListingData> FetchListings { get; }
|
||||
|
||||
void Initialize();
|
||||
|
||||
@@ -13,7 +17,11 @@ namespace Content.Server.Interfaces.PDA
|
||||
|
||||
public bool ChangeBalance(UplinkAccount acc, int amt);
|
||||
|
||||
public bool TryPurchaseItem(UplinkAccount acc, string itemId);
|
||||
public bool TryPurchaseItem(
|
||||
UplinkAccount? acc,
|
||||
string itemId,
|
||||
EntityCoordinates spawnCoords,
|
||||
[NotNullWhen(true)] out IEntity? purchasedItem);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
@@ -8,6 +10,7 @@ using Content.Shared.GameObjects.Components.PDA;
|
||||
using Content.Shared.Prototypes.PDA;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.PDA
|
||||
@@ -17,14 +20,13 @@ namespace Content.Server.PDA
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private List<UplinkAccount> _accounts;
|
||||
private Dictionary<string, UplinkListingData> _listings;
|
||||
private readonly List<UplinkAccount> _accounts = new();
|
||||
private readonly Dictionary<string, UplinkListingData> _listings = new();
|
||||
|
||||
public IReadOnlyDictionary<string, UplinkListingData> FetchListings => _listings;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_listings = new Dictionary<string, UplinkListingData>();
|
||||
foreach (var item in _prototypeManager.EnumeratePrototypes<UplinkStoreListingPrototype>())
|
||||
{
|
||||
var newListing = new UplinkListingData(item.ListingName, item.ItemId, item.Price, item.Category,
|
||||
@@ -32,8 +34,6 @@ namespace Content.Server.PDA
|
||||
|
||||
RegisterUplinkListing(newListing);
|
||||
}
|
||||
|
||||
_accounts = new List<UplinkAccount>();
|
||||
}
|
||||
|
||||
private void RegisterUplinkListing(UplinkListingData listing)
|
||||
@@ -53,7 +53,7 @@ namespace Content.Server.PDA
|
||||
{
|
||||
var entity = _entityManager.GetEntity(acc.AccountHolder);
|
||||
|
||||
if (entity.TryGetComponent(out MindComponent mindComponent) && !mindComponent.HasMind)
|
||||
if (entity.TryGetComponent(out MindComponent? mindComponent) && !mindComponent.HasMind)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -86,8 +86,9 @@ namespace Content.Server.PDA
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryPurchaseItem(UplinkAccount acc, string itemId)
|
||||
public bool TryPurchaseItem(UplinkAccount? acc, string itemId, EntityCoordinates spawnCoords, [NotNullWhen(true)] out IEntity? purchasedItem)
|
||||
{
|
||||
purchasedItem = null;
|
||||
if (acc == null)
|
||||
{
|
||||
return false;
|
||||
@@ -108,10 +109,7 @@ namespace Content.Server.PDA
|
||||
return false;
|
||||
}
|
||||
|
||||
var player = _entityManager.GetEntity(acc.AccountHolder);
|
||||
var hands = player.GetComponent<HandsComponent>();
|
||||
hands.PutInHandOrDrop(_entityManager.SpawnEntity(listing.ItemId,
|
||||
player.Transform.Coordinates).GetComponent<ItemComponent>());
|
||||
purchasedItem = _entityManager.SpawnEntity(listing.ItemId, spawnCoords);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user