Fixes inventories and throwing. (#133)

This commit is contained in:
Acruid
2018-12-13 05:49:05 -08:00
committed by Pieter-Jan Briers
parent 37df61113e
commit 69946c79d8
4 changed files with 18 additions and 12 deletions

View File

@@ -234,7 +234,7 @@ namespace Content.Server.GameObjects
var activehand = hands.GetActiveHand; var activehand = hands.GetActiveHand;
if (activehand != null && activehand.Owner.TryGetComponent(out ClothingComponent clothing)) if (activehand != null && activehand.Owner.TryGetComponent(out ClothingComponent clothing))
{ {
hands.Drop(hands.ActiveIndex, null); hands.Drop(hands.ActiveIndex);
if (!Equip(msg.Inventoryslot, clothing)) if (!Equip(msg.Inventoryslot, clothing))
{ {
hands.PutInHand(clothing); hands.PutInHand(clothing);

View File

@@ -233,7 +233,6 @@ namespace Content.Server.GameObjects
return true; return true;
} }
public bool Drop(IEntity entity) public bool Drop(IEntity entity)
{ {
if (entity == null) if (entity == null)
@@ -252,6 +251,16 @@ namespace Content.Server.GameObjects
public bool Drop(string slot, BaseContainer targetContainer) public bool Drop(string slot, BaseContainer targetContainer)
{ {
if (slot == null)
{
throw new ArgumentNullException(nameof(slot));
}
if (targetContainer == null)
{
throw new ArgumentNullException(nameof(targetContainer));
}
if (!CanDrop(slot)) if (!CanDrop(slot))
{ {
return false; return false;

View File

@@ -127,20 +127,17 @@ namespace Content.Server.GameObjects
{ {
_ensureInitialCalculated(); _ensureInitialCalculated();
Logger.DebugS("Storage", "Storage (UID {0}) attacked by user (UID {1}) with entity (UID {2}).", Owner.Uid, user.Uid, attackwith.Uid); Logger.DebugS("Storage", "Storage (UID {0}) attacked by user (UID {1}) with entity (UID {2}).", Owner.Uid, user.Uid, attackwith.Uid);
var hands = user.GetComponent<HandsComponent>();
if (!user.TryGetComponent(out HandsComponent hands))
return false;
//Check that we can drop the item from our hands first otherwise we obviously cant put it inside //Check that we can drop the item from our hands first otherwise we obviously cant put it inside
if (hands.Drop(hands.ActiveIndex, null)) if (hands.Drop(hands.ActiveIndex))
{ {
var inserted = Insert(attackwith); if (Insert(attackwith))
if (inserted)
{ {
return true; return true;
} }
else
{
//Return the object to the hand since its too big or something like that
hands.PutInHand(attackwith.GetComponent<ItemComponent>());
}
} }
return false; return false;
} }

View File

@@ -154,7 +154,7 @@ namespace Content.Server.GameObjects.EntitySystems
// pop off an item, or throw the single item in hand. // pop off an item, or throw the single item in hand.
if (!throwEnt.TryGetComponent(out StackComponent stackComp) || stackComp.Count < 2) if (!throwEnt.TryGetComponent(out StackComponent stackComp) || stackComp.Count < 2)
{ {
handsComp.Drop(handsComp.ActiveIndex, null); handsComp.Drop(handsComp.ActiveIndex);
} }
else else
{ {