public InventoryStatus GiveItem(ushort id, byte amount = 1)
{
ItemInfo info;
if (DataProvider.Instance.ItemsByID.TryGetValue(id, out info))
{
if (info.Slot == FiestaLib.ItemSlot.Normal)
{
foreach (var i in InventoryItems.Values)
{
if (i.ItemID == id && i.Amount < i.Info.MaxLot)
{
// We found the same item and it can stack more!
byte left = (byte)(i.Info.MaxLot - i.Amount);
if (left > amount)
{
i.Amount += left;
amount -= left;
}
else
{
i.Amount += amount;
amount = 0;
}
Handler12.ModifyInventorySlot(this, 0x24, (byte)i.Slot, (byte)i.Slot, i);
if (amount == 0)
{
break;
}
}
}
// If we have still some stuff left, go ahead and create new stacks!
if (amount > 0)
{
while (amount > 0)
{
sbyte invslot;
if (GetFreeInventorySlot(out invslot))
{
DatabaseItem item = new DatabaseItem();
item.Amount = amount;
item.Character = character;
item.ObjectID = info.ItemID;
item.Slot = invslot;
Program.Entity.AddToDatabaseItems(item);
Item nitem = new Item(item);
InventoryItems.Add(invslot, nitem);
Handler12.ModifyInventorySlot(this, 0x24, (byte)invslot, (byte)invslot, nitem);
amount -= info.MaxLot;
}
else return InventoryStatus.FULL;
}
}
Save();
return InventoryStatus.ADDED;
}
else
{
sbyte invslot;
if (GetFreeInventorySlot(out invslot))
{
DatabaseEquip equip = new DatabaseEquip();
equip.Character = character;
equip.EquipID = info.ItemID;
equip.Slot = invslot;
Program.Entity.AddToDatabaseEquips(equip);
Equip nequip = new Equip(equip);
InventoryItems.Add(invslot, nequip);
Save();
Handler12.ModifyInventorySlot(this, 0x24, (byte)invslot, (byte)invslot, nequip);
return InventoryStatus.ADDED;
}
else return InventoryStatus.FULL;
}
}
else return InventoryStatus.NOT_FOUND;
}