InventoryComponent now handles the ContainerContentsModifiedMessage sent when the underlying Entity Container system may have removed of of the InventoryComponent's entities. This resolves one of the underlying bugs in https://github.com/space-wizards/space-station-14/issues/254.

Updates engine submodule.
This commit is contained in:
Acruid
2019-09-09 10:46:20 -07:00
parent b9f6ea68ce
commit adb7e1b598
2 changed files with 26 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ using System.Linq;
using Content.Server.GameObjects.EntitySystems;
using Content.Shared.GameObjects;
using Robust.Server.GameObjects.Components.Container;
using Robust.Server.Interfaces.GameObjects;
using Robust.Server.Interfaces.Player;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
@@ -14,6 +15,7 @@ using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefines;
using static Content.Shared.GameObjects.SharedInventoryComponent.ClientInventoryMessage;
using IComponent = Robust.Shared.Interfaces.GameObjects.IComponent;
namespace Content.Server.GameObjects
{
@@ -222,6 +224,24 @@ namespace Content.Server.GameObjects
return SlotContainers.ContainsKey(slot);
}
/// <summary>
/// The underlying Container System just notified us that an entity was removed from it.
/// We need to make sure we process that removed entity as being unequpped from the slot.
/// </summary>
private void ForceUnequip(IContainer container, IEntity entity)
{
// make sure this is one of our containers.
// Technically the correct way would be to enumerate the possible slot names
// comparing with this container, but I might as well put the dictionary to good use.
if (!(container is ContainerSlot slot) || !SlotContainers.ContainsValue(slot))
return;
if (entity.TryGetComponent(out ItemComponent itemComp))
itemComp.RemovedFromSlot();
Dirty();
}
/// <summary>
/// Message that tells us to equip or unequip items from the inventory slots
/// </summary>
@@ -291,6 +311,11 @@ namespace Content.Server.GameObjects
if (item != null && item.Owner.TryGetComponent(out ServerStorageComponent storage))
storage.OpenStorageUI(Owner);
break;
case ContainerContentsModifiedMessage msg:
if (msg.Removed)
ForceUnequip(msg.Container, msg.Entity);
break;
}
}