Fix errors
This commit is contained in:
@@ -32,6 +32,7 @@ namespace Content.Server.Inventory.Components
|
||||
public class InventoryComponent : SharedInventoryComponent, IExAct
|
||||
{
|
||||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!;
|
||||
[Dependency] private readonly IEntityManager _entities = default!;
|
||||
|
||||
[ViewVariables] private readonly Dictionary<Slots, ContainerSlot> _slotContainers = new();
|
||||
|
||||
@@ -62,7 +63,7 @@ namespace Content.Server.Inventory.Components
|
||||
{
|
||||
if (TryGetSlotItem(slot, out ItemComponent? item))
|
||||
{
|
||||
IoCManager.Resolve<IEntityManager>().DeleteEntity(item.Owner);
|
||||
_entities.DeleteEntity(item.Owner);
|
||||
}
|
||||
|
||||
RemoveSlot(slot);
|
||||
@@ -105,7 +106,7 @@ namespace Content.Server.Inventory.Components
|
||||
public IEnumerable<T?> LookupItems<T>() where T : Component
|
||||
{
|
||||
return _slotContainers.Values
|
||||
.SelectMany(x => x.ContainedEntities.Select(e => IoCManager.Resolve<IEntityManager>().GetComponentOrNull<T>(e)))
|
||||
.SelectMany(x => x.ContainedEntities.Select(e => _entities.GetComponentOrNull<T>(e)))
|
||||
.Where(x => x != null);
|
||||
}
|
||||
|
||||
@@ -117,14 +118,14 @@ namespace Content.Server.Inventory.Components
|
||||
}
|
||||
|
||||
var containedEntity = _slotContainers[slot].ContainedEntity;
|
||||
if ((containedEntity != null ? (!IoCManager.Resolve<IEntityManager>().EntityExists(containedEntity) ? EntityLifeStage.Deleted : IoCManager.Resolve<IEntityManager>().GetComponent<MetaDataComponent>(containedEntity).EntityLifeStage) >= EntityLifeStage.Deleted : null) == true)
|
||||
if (containedEntity != null && _entities.GetComponent<MetaDataComponent>(containedEntity.Value).EntityDeleted)
|
||||
{
|
||||
_slotContainers.Remove(slot);
|
||||
containedEntity = null;
|
||||
Dirty();
|
||||
}
|
||||
|
||||
return (containedEntity != null ? IoCManager.Resolve<IEntityManager>().GetComponent<T>(containedEntity) : null);
|
||||
return containedEntity.HasValue ? _entities.GetComponent<T>(containedEntity.Value) : null;
|
||||
}
|
||||
|
||||
public bool TryGetSlotItem<T>(Slots slot, [NotNullWhen(true)] out T? itemComponent) where T : ItemComponent
|
||||
@@ -186,7 +187,7 @@ namespace Content.Server.Inventory.Components
|
||||
Equip(slot, item, mobCheck, out var _);
|
||||
|
||||
public bool Equip(Slots slot, EntityUid entity, bool mobCheck = true) =>
|
||||
Equip(slot, IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(entity), mobCheck);
|
||||
Equip(slot, _entities.GetComponent<ItemComponent>(entity), mobCheck);
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether an item can be put in the specified slot.
|
||||
@@ -218,7 +219,7 @@ namespace Content.Server.Inventory.Components
|
||||
}
|
||||
}
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, out IInventoryController? controller))
|
||||
if (_entities.TryGetComponent(Owner, out IInventoryController? controller))
|
||||
{
|
||||
pass = controller.CanEquip(slot, item.Owner, pass, out var controllerReason);
|
||||
reason = controllerReason ?? reason;
|
||||
@@ -244,7 +245,7 @@ namespace Content.Server.Inventory.Components
|
||||
CanEquip(slot, item, mobCheck, out var _);
|
||||
|
||||
public bool CanEquip(Slots slot, EntityUid entity, bool mobCheck = true) =>
|
||||
CanEquip(slot, IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(entity), mobCheck);
|
||||
CanEquip(slot, _entities.GetComponent<ItemComponent>(entity), mobCheck);
|
||||
|
||||
/// <summary>
|
||||
/// Drops the item in a slot.
|
||||
@@ -260,9 +261,8 @@ namespace Content.Server.Inventory.Components
|
||||
}
|
||||
|
||||
var inventorySlot = _slotContainers[slot];
|
||||
var entity = inventorySlot.ContainedEntity;
|
||||
|
||||
if (entity == null)
|
||||
if (inventorySlot.ContainedEntity is not {Valid: true} entity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -273,7 +273,7 @@ namespace Content.Server.Inventory.Components
|
||||
}
|
||||
|
||||
// TODO: The item should be dropped to the container our owner is in, if any.
|
||||
IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity).AttachParentToContainerOrGrid();
|
||||
_entities.GetComponent<TransformComponent>(entity).AttachParentToContainerOrGrid();
|
||||
|
||||
_entitySystemManager.GetEntitySystem<InteractionSystem>().UnequippedInteraction(Owner, entity, slot);
|
||||
|
||||
@@ -294,16 +294,15 @@ namespace Content.Server.Inventory.Components
|
||||
public void ForceUnequip(Slots slot)
|
||||
{
|
||||
var inventorySlot = _slotContainers[slot];
|
||||
var entity = inventorySlot.ContainedEntity;
|
||||
if (entity == null)
|
||||
if (inventorySlot.ContainedEntity is not {Valid: true} entity)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var item = IoCManager.Resolve<IEntityManager>().GetComponent<ItemComponent>(entity);
|
||||
var item = _entities.GetComponent<ItemComponent>(entity);
|
||||
inventorySlot.ForceRemove(entity);
|
||||
|
||||
var itemTransform = IoCManager.Resolve<IEntityManager>().GetComponent<TransformComponent>(entity);
|
||||
var itemTransform = _entities.GetComponent<TransformComponent>(entity);
|
||||
|
||||
itemTransform.AttachParentToContainerOrGrid();
|
||||
|
||||
@@ -328,7 +327,7 @@ namespace Content.Server.Inventory.Components
|
||||
return false;
|
||||
|
||||
var inventorySlot = _slotContainers[slot];
|
||||
return inventorySlot.ContainedEntity != null && inventorySlot.CanRemove(inventorySlot.ContainedEntity);
|
||||
return inventorySlot.ContainedEntity != null && inventorySlot.CanRemove(inventorySlot.ContainedEntity.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -404,7 +403,7 @@ namespace Content.Server.Inventory.Components
|
||||
if (container is not ContainerSlot slot || !_slotContainers.ContainsValue(slot))
|
||||
return;
|
||||
|
||||
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(entity, out ItemComponent? itemComp))
|
||||
if (_entities.TryGetComponent(entity, out ItemComponent? itemComp))
|
||||
{
|
||||
itemComp.RemovedFromSlot();
|
||||
}
|
||||
@@ -424,10 +423,10 @@ namespace Content.Server.Inventory.Components
|
||||
{
|
||||
case ClientInventoryUpdate.Equip:
|
||||
{
|
||||
var hands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(Owner);
|
||||
var hands = _entities.GetComponent<HandsComponent>(Owner);
|
||||
var activeHand = hands.ActiveHand;
|
||||
var activeItem = hands.GetActiveHand;
|
||||
if (activeHand != null && activeItem != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(activeItem.Owner, out ItemComponent? item))
|
||||
if (activeHand != null && activeItem != null && _entities.TryGetComponent(activeItem.Owner, out ItemComponent? item))
|
||||
{
|
||||
hands.TryDropNoInteraction();
|
||||
if (!Equip(msg.Inventoryslot, item, true, out var reason))
|
||||
@@ -442,7 +441,7 @@ namespace Content.Server.Inventory.Components
|
||||
case ClientInventoryUpdate.Use:
|
||||
{
|
||||
var interactionSystem = _entitySystemManager.GetEntitySystem<InteractionSystem>();
|
||||
var hands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(Owner);
|
||||
var hands = _entities.GetComponent<HandsComponent>(Owner);
|
||||
var activeHand = hands.GetActiveHand;
|
||||
var itemContainedInSlot = GetSlotItem(msg.Inventoryslot);
|
||||
if (itemContainedInSlot != null)
|
||||
@@ -462,7 +461,7 @@ namespace Content.Server.Inventory.Components
|
||||
}
|
||||
case ClientInventoryUpdate.Hover:
|
||||
{
|
||||
var hands = IoCManager.Resolve<IEntityManager>().GetComponent<HandsComponent>(Owner);
|
||||
var hands = _entities.GetComponent<HandsComponent>(Owner);
|
||||
var activeHand = hands.GetActiveHand;
|
||||
if (activeHand != null && GetSlotItem(msg.Inventoryslot) == null)
|
||||
{
|
||||
@@ -504,7 +503,7 @@ namespace Content.Server.Inventory.Components
|
||||
if (!HasSlot(msg.Slot)) // client input sanitization
|
||||
return;
|
||||
var item = GetSlotItem(msg.Slot);
|
||||
if (item != null && IoCManager.Resolve<IEntityManager>().TryGetComponent(item.Owner, out ServerStorageComponent? storage))
|
||||
if (item != null && _entities.TryGetComponent(item.Owner, out ServerStorageComponent? storage))
|
||||
storage.OpenStorageUI(Owner);
|
||||
break;
|
||||
}
|
||||
@@ -515,9 +514,9 @@ namespace Content.Server.Inventory.Components
|
||||
var list = new List<KeyValuePair<Slots, EntityUid>>();
|
||||
foreach (var (slot, container) in _slotContainers)
|
||||
{
|
||||
if (container != null && container.ContainedEntity != null)
|
||||
if (container is {ContainedEntity: { }})
|
||||
{
|
||||
list.Add(new KeyValuePair<Slots, EntityUid>(slot, container.ContainedEntity));
|
||||
list.Add(new KeyValuePair<Slots, EntityUid>(slot, container.ContainedEntity.Value));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -538,7 +537,7 @@ namespace Content.Server.Inventory.Components
|
||||
{
|
||||
foreach (var entity in slot.ContainedEntities)
|
||||
{
|
||||
var exActs = IoCManager.Resolve<IEntityManager>().GetComponents<IExAct>(entity).ToList();
|
||||
var exActs = _entities.GetComponents<IExAct>(entity).ToList();
|
||||
foreach (var exAct in exActs)
|
||||
{
|
||||
exAct.OnExplosion(eventArgs);
|
||||
@@ -549,7 +548,7 @@ namespace Content.Server.Inventory.Components
|
||||
|
||||
public override bool IsEquipped(EntityUid item)
|
||||
{
|
||||
if (item == null) return false;
|
||||
if (item == default) return false;
|
||||
foreach (var containerSlot in _slotContainers.Values)
|
||||
{
|
||||
// we don't want a recursive check here
|
||||
|
||||
Reference in New Issue
Block a user