Esempio n. 1
0
        public static void AddItem(Client c, int typeId, int amount = 1)
        {
            List <Item> items = c.GetData("inventory_items");

            int invIndex = GetInventoryIndex(c, typeId);

            if (invIndex != -1)
            {
                Item stack = items[invIndex];
                stack.SetAmount(stack.GetAmount() + amount);
                UpdateItemInDb(c, typeId, stack.GetAmount() + amount);
            }
            else
            {
                if (items.Count == 5)
                {
                    c.SendNotification("Du hast die Max. Anzahl von Gegenständen im Inventar erreicht!");
                    return;
                }

                StaticItem itemData = GetItemData(typeId);
                if (itemData != null)
                {
                    items.Add(new Item(typeId, itemData.GetName(), itemData.GetCategory(), itemData.GetRarity(), itemData.GetVolume(), itemData.GetWeight(), amount));
                    AddItemToDb(c, typeId, amount);
                }
            }
        }
Esempio n. 2
0
        public static void SetItemAmount(Client c, int typeId, int amount = 1)
        {
            List <Item> items = c.GetData("inventory_items");

            int invIndex = GetInventoryIndex(c, typeId);

            if (invIndex != -1)
            {
                if (amount >= 1)
                {
                    Item stack = items[invIndex];
                    stack.SetAmount(amount);
                    UpdateItemInDb(c, typeId, amount);
                }
                else
                {
                    items.RemoveAt(invIndex);
                    RemoveItemFromDb(c, typeId);
                }
            }
            else
            {
                StaticItem itemData = GetItemData(typeId);
                if (itemData != null)
                {
                    items.Add(new Item(typeId, itemData.GetName(), itemData.GetCategory(), itemData.GetRarity(), itemData.GetVolume(), itemData.GetWeight(), amount));
                    AddItemToDb(c, typeId, amount);
                }
            }
        }