Remove manual container ejection checking code.
This fixes map load when something is in a storage component.
This commit is contained in:
@@ -7,6 +7,7 @@ using Content.Shared.Input;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.GameObjects.Components.Container;
|
using Robust.Server.GameObjects.Components.Container;
|
||||||
|
using Robust.Server.GameObjects.EntitySystemMessages;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Input;
|
using Robust.Shared.Input;
|
||||||
@@ -91,22 +92,6 @@ namespace Content.Server.GameObjects
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public void RemoveHandEntity(IEntity entity)
|
|
||||||
{
|
|
||||||
if (entity == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (var slot in hands.Values)
|
|
||||||
{
|
|
||||||
if (slot.ContainedEntity == entity)
|
|
||||||
{
|
|
||||||
slot.Remove(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Dirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ItemComponent GetHand(string index)
|
public ItemComponent GetHand(string index)
|
||||||
{
|
{
|
||||||
var slot = hands[index];
|
var slot = hands[index];
|
||||||
@@ -504,5 +489,26 @@ namespace Content.Server.GameObjects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HandleSlotModifiedMaybe(ContainerModifiedMessage message)
|
||||||
|
{
|
||||||
|
foreach (var container in hands.Values)
|
||||||
|
{
|
||||||
|
if (container != message.Container)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Dirty();
|
||||||
|
if (!message.Entity.TryGetComponent(out PhysicsComponent physics))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set velocity to zero
|
||||||
|
physics.LinearVelocity = Vector2.Zero;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ using Robust.Shared.GameObjects.EntitySystemMessages;
|
|||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
using Content.Server.GameObjects.Components;
|
using Content.Server.GameObjects.Components;
|
||||||
|
using Robust.Server.GameObjects.EntitySystemMessages;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects
|
namespace Content.Server.GameObjects
|
||||||
{
|
{
|
||||||
@@ -82,14 +83,21 @@ namespace Content.Server.GameObjects
|
|||||||
public bool Remove(IEntity toremove)
|
public bool Remove(IEntity toremove)
|
||||||
{
|
{
|
||||||
_ensureInitialCalculated();
|
_ensureInitialCalculated();
|
||||||
if (storage.Remove(toremove))
|
return storage.Remove(toremove);
|
||||||
{
|
|
||||||
Logger.InfoS("Storage", "Storage (UID {0}) had entity (UID {1}) removed from it.", Owner.Uid, toremove.Uid);
|
|
||||||
StorageUsed -= toremove.GetComponent<StoreableComponent>().ObjectSize;
|
|
||||||
UpdateClientInventories();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
internal void HandleEntityMaybeRemoved(EntRemovedFromContainerMessage message)
|
||||||
|
{
|
||||||
|
if (message.Container != storage)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ensureInitialCalculated();
|
||||||
|
Logger.DebugS("Storage", "Storage (UID {0}) had entity (UID {1}) removed from it.", Owner.Uid,
|
||||||
|
message.Entity.Uid);
|
||||||
|
StorageUsed -= message.Entity.GetComponent<StoreableComponent>().ObjectSize;
|
||||||
|
UpdateClientInventories();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -99,14 +107,21 @@ namespace Content.Server.GameObjects
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(IEntity toinsert)
|
public bool Insert(IEntity toinsert)
|
||||||
{
|
{
|
||||||
if (CanInsert(toinsert) && storage.Insert(toinsert))
|
return CanInsert(toinsert) && storage.Insert(toinsert);
|
||||||
{
|
|
||||||
Logger.InfoS("Storage", "Storage (UID {0}) had entity (UID {1}) inserted into it.", Owner.Uid, toinsert.Uid);
|
|
||||||
StorageUsed += toinsert.GetComponent<StoreableComponent>().ObjectSize;
|
|
||||||
UpdateClientInventories();
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
internal void HandleEntityMaybeInserted(EntInsertedIntoContainerMessage message)
|
||||||
|
{
|
||||||
|
if (message.Container != storage)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_ensureInitialCalculated();
|
||||||
|
Logger.DebugS("Storage", "Storage (UID {0}) had entity (UID {1}) inserted into it.", Owner.Uid,
|
||||||
|
message.Entity.Uid);
|
||||||
|
StorageUsed += message.Entity.GetComponent<StoreableComponent>().ObjectSize;
|
||||||
|
UpdateClientInventories();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -328,6 +343,11 @@ namespace Content.Server.GameObjects
|
|||||||
|
|
||||||
StorageUsed = 0;
|
StorageUsed = 0;
|
||||||
|
|
||||||
|
if (storage == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var entity in storage.ContainedEntities)
|
foreach (var entity in storage.ContainedEntities)
|
||||||
{
|
{
|
||||||
var item = entity.GetComponent<ItemComponent>();
|
var item = entity.GetComponent<ItemComponent>();
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ using Content.Server.GameObjects.Components.Stack;
|
|||||||
using Content.Server.Interfaces.GameObjects;
|
using Content.Server.Interfaces.GameObjects;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.Input;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
|
using Robust.Server.GameObjects.EntitySystemMessages;
|
||||||
using Robust.Server.GameObjects.EntitySystems;
|
using Robust.Server.GameObjects.EntitySystems;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.EntitySystemMessages;
|
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
using Robust.Shared.Input;
|
using Robust.Shared.Input;
|
||||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
|
||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
using Robust.Shared.Interfaces.Timing;
|
using Robust.Shared.Interfaces.Timing;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
@@ -21,7 +21,8 @@ using Robust.Shared.Players;
|
|||||||
|
|
||||||
namespace Content.Server.GameObjects.EntitySystems
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
internal class HandsSystem : EntitySystem
|
[UsedImplicitly]
|
||||||
|
internal sealed class HandsSystem : EntitySystem
|
||||||
{
|
{
|
||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
[Dependency] private readonly IMapManager _mapManager;
|
[Dependency] private readonly IMapManager _mapManager;
|
||||||
@@ -58,31 +59,16 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void SubscribeEvents()
|
public override void SubscribeEvents()
|
||||||
{
|
{
|
||||||
SubscribeEvent<EntParentChangedMessage>(HandleParented);
|
SubscribeEvent<EntRemovedFromContainerMessage>(HandleContainerModified);
|
||||||
|
SubscribeEvent<EntInsertedIntoContainerMessage>(HandleContainerModified);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void HandleParented(object sender, EntitySystemMessage args)
|
private static void HandleContainerModified(object sender, ContainerModifiedMessage args)
|
||||||
{
|
{
|
||||||
var msg = (EntParentChangedMessage) args;
|
if (args.Container.Owner.TryGetComponent(out IHandsComponent handsComponent))
|
||||||
|
|
||||||
// entity is no longer a child of OldParent, therefore it cannot be in the hand of the parent
|
|
||||||
if (msg.OldParent != null && msg.OldParent.IsValid() && msg.OldParent.Transform != msg.Entity.Transform.Parent && msg.OldParent.TryGetComponent(out IHandsComponent handsComp))
|
|
||||||
{
|
{
|
||||||
handsComp.RemoveHandEntity(msg.Entity);
|
handsComponent.HandleSlotModifiedMaybe(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg.Entity.Deleted)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// if item is in a container
|
|
||||||
if (msg.Entity.Transform.IsMapTransform)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!msg.Entity.TryGetComponent(out PhysicsComponent physics))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// set velocity to zero
|
|
||||||
physics.LinearVelocity = Vector2.Zero;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool TryGetAttachedComponent<T>(IPlayerSession session, out T component)
|
private static bool TryGetAttachedComponent<T>(IPlayerSession session, out T component)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Robust.Server.GameObjects.EntitySystemMessages;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.EntitySystemMessages;
|
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
|
||||||
@@ -22,7 +22,8 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
{
|
{
|
||||||
base.SubscribeEvents();
|
base.SubscribeEvents();
|
||||||
|
|
||||||
SubscribeEvent<EntParentChangedMessage>(HandleParentChanged);
|
SubscribeEvent<EntRemovedFromContainerMessage>(HandleEntityRemovedFromContainer);
|
||||||
|
SubscribeEvent<EntInsertedIntoContainerMessage>(HandleEntityInsertedIntoContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -34,22 +35,23 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void HandleParentChanged(object sender, EntitySystemMessage message)
|
private static void HandleEntityRemovedFromContainer(object sender, EntRemovedFromContainerMessage message)
|
||||||
{
|
{
|
||||||
if(!(sender is IEntity childEntity))
|
var oldParentEntity = message.Container.Owner;
|
||||||
return;
|
|
||||||
|
|
||||||
if(!(message is EntParentChangedMessage msg))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var oldParentEntity = msg.OldParent;
|
|
||||||
|
|
||||||
if(oldParentEntity == null || !oldParentEntity.IsValid())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (oldParentEntity.TryGetComponent(out ServerStorageComponent storageComp))
|
if (oldParentEntity.TryGetComponent(out ServerStorageComponent storageComp))
|
||||||
{
|
{
|
||||||
storageComp.Remove(childEntity);
|
storageComp.HandleEntityMaybeRemoved(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void HandleEntityInsertedIntoContainer(object sender, EntInsertedIntoContainerMessage message)
|
||||||
|
{
|
||||||
|
var oldParentEntity = message.Container.Owner;
|
||||||
|
|
||||||
|
if (oldParentEntity.TryGetComponent(out ServerStorageComponent storageComp))
|
||||||
|
{
|
||||||
|
storageComp.HandleEntityMaybeInserted(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Content.Server.GameObjects;
|
|||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Robust.Server.GameObjects.Components.Container;
|
using Robust.Server.GameObjects.Components.Container;
|
||||||
|
using Robust.Server.GameObjects.EntitySystemMessages;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
|
|
||||||
namespace Content.Server.Interfaces.GameObjects
|
namespace Content.Server.Interfaces.GameObjects
|
||||||
@@ -26,12 +27,6 @@ namespace Content.Server.Interfaces.GameObjects
|
|||||||
/// <returns>The item in the held, null if no item is held</returns>
|
/// <returns>The item in the held, null if no item is held</returns>
|
||||||
ItemComponent GetHand(string index);
|
ItemComponent GetHand(string index);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// If any hands are holding this entity, immediately remove the entity without dropping it.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="entity">Entity to be removed.</param>
|
|
||||||
void RemoveHandEntity(IEntity entity);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets item held by the current active hand
|
/// Gets item held by the current active hand
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -195,5 +190,7 @@ namespace Content.Server.Interfaces.GameObjects
|
|||||||
/// <param name="index">The hand name to check.</param>
|
/// <param name="index">The hand name to check.</param>
|
||||||
/// <returns>True if the hand exists, false otherwise.</returns>
|
/// <returns>True if the hand exists, false otherwise.</returns>
|
||||||
bool HasHand(string index);
|
bool HasHand(string index);
|
||||||
|
|
||||||
|
void HandleSlotModifiedMaybe(ContainerModifiedMessage message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user