/// <summary>
/// Picks an item up after client request
/// </summary>
/// <returns>true if the item was picked up, or false if the player could not pick up the item.</returns>
public bool PickUp(Item item)
{
System.Diagnostics.Debug.Assert(!_inventoryGrid.Contains(item) && !_equipment.IsItemEquipped(item), "Item already in inventory");
// TODO: Autoequip when equipment slot is empty
// If Item is Stackable try to add the amount
if (item.IsStackable())
{
// Find items of same type (GBID) and try to add it to one of them
List<Item> baseItems = FindSameItems(item.GBHandle.GBID);
foreach (Item baseItem in baseItems)
{
if (baseItem.Attributes[GameAttribute.ItemStackQuantityLo] + item.Attributes[GameAttribute.ItemStackQuantityLo] < baseItem.ItemDefinition.MaxStackAmount)
{
baseItem.Attributes[GameAttribute.ItemStackQuantityLo] += item.Attributes[GameAttribute.ItemStackQuantityLo];
baseItem.Attributes.SendChangedMessage(_owner.InGameClient);
// Item amount successful added. Don't place item in inventory instead destroy it.
item.Destroy();
return true;
}
}
}
bool success = false;
if (!_inventoryGrid.HasFreeSpace(item))
{
// Inventory full
_owner.InGameClient.SendMessage(new ACDPickupFailedMessage()
{
ItemID = item.DynamicID,
Reason = ACDPickupFailedMessage.Reasons.InventoryFull
});
}
else
{
item.CurrentState = ItemState.PickingUp;
if (item.HasWorldLocation && item.World != null)
{
item.Owner = _owner;
item.World.Leave(item);
}
_inventoryGrid.AddItem(item);
if (_owner.GroundItems.ContainsKey(item.DynamicID))
_owner.GroundItems.Remove(item.DynamicID);
success = true;
item.CurrentState = ItemState.Normal;
AcceptMoveRequest(item);
}
return success;
}