Clean up Drop and fix IDropped.Dropped (#2057)

This commit is contained in:
ShadowCommander
2020-09-10 04:46:56 -07:00
committed by GitHub
parent 25ca386d26
commit 0ebc14f743

View File

@@ -224,8 +224,10 @@ namespace Content.Server.GameObjects.Components.GUI
if (!interactionSystem.TryDroppedInteraction(Owner, item.Owner)) if (!interactionSystem.TryDroppedInteraction(Owner, item.Owner))
return false; return false;
} }
else
interactionSystem.DroppedInteraction(Owner, item.Owner); {
interactionSystem.DroppedInteraction(Owner, item.Owner);
}
return true; return true;
} }
@@ -248,7 +250,7 @@ namespace Content.Server.GameObjects.Components.GUI
public bool Drop(string slot, EntityCoordinates coords, bool doMobChecks = true) public bool Drop(string slot, EntityCoordinates coords, bool doMobChecks = true)
{ {
var hand = GetHand(slot); var hand = GetHand(slot);
if (!CanDrop(slot) || hand?.Entity == null) if (!CanDrop(slot, doMobChecks) || hand?.Entity == null)
{ {
return false; return false;
} }
@@ -260,12 +262,17 @@ namespace Content.Server.GameObjects.Components.GUI
return false; return false;
} }
if (!DroppedInteraction(item, doMobChecks)) if (!DroppedInteraction(item, false))
return false; return false;
item.RemovedFromSlot(); item.RemovedFromSlot();
item.Owner.Transform.Coordinates = coords; item.Owner.Transform.Coordinates = coords;
if (item.Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
{
spriteComponent.RenderOrder = item.Owner.EntityManager.CurrentTick.Value;
}
if (ContainerHelpers.TryGetContainer(Owner, out var container)) if (ContainerHelpers.TryGetContainer(Owner, out var container))
{ {
container.Insert(item.Owner); container.Insert(item.Owner);
@@ -294,39 +301,7 @@ namespace Content.Server.GameObjects.Components.GUI
public bool Drop(string slot, bool mobChecks = true) public bool Drop(string slot, bool mobChecks = true)
{ {
var hand = GetHand(slot); return Drop(slot, Owner.Transform.Coordinates, mobChecks);
if (!CanDrop(slot, mobChecks) || hand?.Entity == null)
{
return false;
}
var item = hand.Entity.GetComponent<ItemComponent>();
if (!DroppedInteraction(item, mobChecks))
return false;
if (!hand.Container.Remove(hand.Entity))
{
return false;
}
item.RemovedFromSlot();
item.Owner.Transform.Coordinates = Owner.Transform.Coordinates;
if (item.Owner.TryGetComponent<SpriteComponent>(out var spriteComponent))
{
spriteComponent.RenderOrder = item.Owner.EntityManager.CurrentTick.Value;
}
if (ContainerHelpers.TryGetContainer(Owner, out var container))
{
container.Insert(item.Owner);
}
OnItemChanged?.Invoke();
Dirty();
return true;
} }
public bool Drop(IEntity entity, bool mobChecks = true) public bool Drop(IEntity entity, bool mobChecks = true)
@@ -341,7 +316,7 @@ namespace Content.Server.GameObjects.Components.GUI
throw new ArgumentException("Entity must be held in one of our hands.", nameof(entity)); throw new ArgumentException("Entity must be held in one of our hands.", nameof(entity));
} }
return Drop(slot, mobChecks); return Drop(slot, Owner.Transform.Coordinates, mobChecks);
} }
public bool Drop(string slot, BaseContainer targetContainer, bool doMobChecks = true) public bool Drop(string slot, BaseContainer targetContainer, bool doMobChecks = true)
@@ -357,16 +332,11 @@ namespace Content.Server.GameObjects.Components.GUI
} }
var hand = GetHand(slot); var hand = GetHand(slot);
if (!CanDrop(slot) || hand?.Entity == null) if (!CanDrop(slot, doMobChecks) || hand?.Entity == null)
{ {
return false; return false;
} }
var item = hand.Entity.GetComponent<ItemComponent>();
if (!DroppedInteraction(item, doMobChecks))
return false;
if (!hand.Container.CanRemove(hand.Entity)) if (!hand.Container.CanRemove(hand.Entity))
{ {
return false; return false;
@@ -377,11 +347,16 @@ namespace Content.Server.GameObjects.Components.GUI
return false; return false;
} }
var item = hand.Entity.GetComponent<ItemComponent>();
if (!hand.Container.Remove(hand.Entity)) if (!hand.Container.Remove(hand.Entity))
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
if (!DroppedInteraction(item, doMobChecks))
return false;
item.RemovedFromSlot(); item.RemovedFromSlot();
if (!targetContainer.Insert(item.Owner)) if (!targetContainer.Insert(item.Owner))