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;
|
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)
|
public void PutInHandOrDrop(ItemComponent item, bool mobCheck = true)
|
||||||
{
|
{
|
||||||
if (!PutInHand(item, mobCheck))
|
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)
|
public bool CanPutInHand(ItemComponent item, bool mobCheck = true)
|
||||||
{
|
{
|
||||||
if (mobCheck && !ActionBlockerSystem.CanPickup(Owner))
|
if (mobCheck && !ActionBlockerSystem.CanPickup(Owner))
|
||||||
|
|||||||
@@ -135,12 +135,20 @@ namespace Content.Server.GameObjects.Components.PDA
|
|||||||
|
|
||||||
case PDAUplinkBuyListingMessage buyMsg:
|
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);
|
SendNetworkMessage(new PDAUplinkInsufficientFundsMessage(), message.Session.ConnectedClient);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HandsComponent.PutInHandOrDropStatic(
|
||||||
|
message.Session.AttachedEntity,
|
||||||
|
entity.GetComponent<ItemComponent>());
|
||||||
|
|
||||||
SendNetworkMessage(new PDAUplinkBuySuccessMessage(), message.Session.ConnectedClient);
|
SendNetworkMessage(new PDAUplinkBuySuccessMessage(), message.Session.ConnectedClient);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
|
#nullable enable
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using Content.Shared.GameObjects.Components.PDA;
|
using Content.Shared.GameObjects.Components.PDA;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
|
||||||
namespace Content.Server.Interfaces.PDA
|
namespace Content.Server.Interfaces.PDA
|
||||||
{
|
{
|
||||||
public interface IPDAUplinkManager
|
public interface IPDAUplinkManager
|
||||||
{
|
{
|
||||||
public IReadOnlyDictionary<string, UplinkListingData> FetchListings => null;
|
public IReadOnlyDictionary<string, UplinkListingData> FetchListings { get; }
|
||||||
|
|
||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
@@ -13,7 +17,11 @@ namespace Content.Server.Interfaces.PDA
|
|||||||
|
|
||||||
public bool ChangeBalance(UplinkAccount acc, int amt);
|
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.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Content.Server.GameObjects.Components.GUI;
|
using Content.Server.GameObjects.Components.GUI;
|
||||||
using Content.Server.GameObjects.Components.Items.Storage;
|
using Content.Server.GameObjects.Components.Items.Storage;
|
||||||
@@ -8,6 +10,7 @@ using Content.Shared.GameObjects.Components.PDA;
|
|||||||
using Content.Shared.Prototypes.PDA;
|
using Content.Shared.Prototypes.PDA;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
namespace Content.Server.PDA
|
namespace Content.Server.PDA
|
||||||
@@ -17,14 +20,13 @@ namespace Content.Server.PDA
|
|||||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||||
|
|
||||||
private List<UplinkAccount> _accounts;
|
private readonly List<UplinkAccount> _accounts = new();
|
||||||
private Dictionary<string, UplinkListingData> _listings;
|
private readonly Dictionary<string, UplinkListingData> _listings = new();
|
||||||
|
|
||||||
public IReadOnlyDictionary<string, UplinkListingData> FetchListings => _listings;
|
public IReadOnlyDictionary<string, UplinkListingData> FetchListings => _listings;
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
_listings = new Dictionary<string, UplinkListingData>();
|
|
||||||
foreach (var item in _prototypeManager.EnumeratePrototypes<UplinkStoreListingPrototype>())
|
foreach (var item in _prototypeManager.EnumeratePrototypes<UplinkStoreListingPrototype>())
|
||||||
{
|
{
|
||||||
var newListing = new UplinkListingData(item.ListingName, item.ItemId, item.Price, item.Category,
|
var newListing = new UplinkListingData(item.ListingName, item.ItemId, item.Price, item.Category,
|
||||||
@@ -32,8 +34,6 @@ namespace Content.Server.PDA
|
|||||||
|
|
||||||
RegisterUplinkListing(newListing);
|
RegisterUplinkListing(newListing);
|
||||||
}
|
}
|
||||||
|
|
||||||
_accounts = new List<UplinkAccount>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegisterUplinkListing(UplinkListingData listing)
|
private void RegisterUplinkListing(UplinkListingData listing)
|
||||||
@@ -53,7 +53,7 @@ namespace Content.Server.PDA
|
|||||||
{
|
{
|
||||||
var entity = _entityManager.GetEntity(acc.AccountHolder);
|
var entity = _entityManager.GetEntity(acc.AccountHolder);
|
||||||
|
|
||||||
if (entity.TryGetComponent(out MindComponent mindComponent) && !mindComponent.HasMind)
|
if (entity.TryGetComponent(out MindComponent? mindComponent) && !mindComponent.HasMind)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -86,8 +86,9 @@ namespace Content.Server.PDA
|
|||||||
return true;
|
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)
|
if (acc == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@@ -108,10 +109,7 @@ namespace Content.Server.PDA
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var player = _entityManager.GetEntity(acc.AccountHolder);
|
purchasedItem = _entityManager.SpawnEntity(listing.ItemId, spawnCoords);
|
||||||
var hands = player.GetComponent<HandsComponent>();
|
|
||||||
hands.PutInHandOrDrop(_entityManager.SpawnEntity(listing.ItemId,
|
|
||||||
player.Transform.Coordinates).GetComponent<ItemComponent>());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user