Пример #1
0
        /// <summary>
        /// Takes an item from the inventory.
        /// </summary>
        /// <param name="itemNum">The item num.</param>
        /// <param name="amount">Amount to take.</param>
        /// <param name="ignoreSticky">if set to <c>true</c>, the item will be taken even if it is sticky.</param>
        /// <returns><c>true</c> if the item was successfully taken, otherwise <c>false</c></returns>
        public bool TakeItem(int itemNum, int amount, bool ignoreSticky)
        {
            // Check for subscript out of range
            if (itemNum < 0 || itemNum >= ItemManager.Items.MaxItems)
            {
                return(false);
            }

            for (int i = 1; i <= Inventory.Count; i++)
            {
                if (Inventory.ContainsKey(i))
                {
                    // Check to see if the player has the item
                    if (Inventory[i].Num == itemNum)
                    {
                        return(TakeItemSlot(i, amount, ignoreSticky));
                    }
                }
            }

            if (itemNum == 1)
            {
                if (PlayerData.Money >= amount)
                {
                    PlayerData.Money -= amount;
                    Messenger.UpdateMoney(client);
                    return(true);
                }
            }

            return(false);
        }
Пример #2
0
        public void SetMaxInv(DatabaseConnection dbConnection, int max, bool saveInv)
        {
            MaxInv = max;
            for (int i = 1; i <= MaxInv; i++)
            {
                if (!Inventory.ContainsKey(i))
                {
                    Characters.InventoryItem invItem = new Characters.InventoryItem();
                    playerData.Inventory.Add(i, invItem);
                    Inventory.Add(i, new InventoryItem(invItem));
                }
            }
            Messenger.SendInventory(client);
            //really that easy?

            if (saveInv)
            {
                PlayerDataManager.SavePlayerInventory(dbConnection.Database, playerData);
            }
        }
Пример #3
0
        /// <summary>
        /// Takes the item slot that is in the specified inventory slot.
        /// </summary>
        /// <param name="slot">The slot.</param>
        /// <param name="amount">Amount to take.</param>
        /// <param name="ignoreSticky">if set to <c>true</c>, the item will be taken even if it is sticky.</param>
        /// <returns><c>true</c> if the item was successfully taken, otherwise <c>false</c></returns>
        public bool TakeItemSlot(int slot, int amount, bool ignoreSticky)
        {
            if (amount < 0)
            {
                return(false);
            }
            bool result = false;

            if (slot < 1 || slot > MaxInv)
            {
                return(false);
            }
            if (Inventory.ContainsKey(slot) && Inventory[slot].Num > 0)
            {
                bool TakeItem = false;
                int  itemNum  = Inventory[slot].Num;
                if (ignoreSticky || !Inventory[slot].Sticky)
                {
                    if (ItemManager.Items[itemNum].Type == Enums.ItemType.Currency || ItemManager.Items[itemNum].StackCap > 0)
                    {
                        // Is what we are trying to take away more then what they have?  If so just set it to zero
                        if (amount >= Inventory[slot].Amount)
                        {
                            TakeItem = true;
                        }
                        else
                        {
                            Inventory[slot].Amount = Inventory[slot].Amount - amount;
                            Messenger.SendInventoryUpdate(client, slot);

                            result = true;
                        }
                    }
                    else
                    {
                        TakeItem = true;

                        //n = ItemManager.Items[Inventory[i].Num].Type;
                        // Check if its not an equipable weapon, and if it isn't then take it away
                        //if ((n != Enums.ItemType.Weapon) && (n != Enums.ItemType.Armor) && (n != Enums.ItemType.Helmet) && (n != Enums.ItemType.Shield) && (n != Enums.ItemType.Legs) & (n != Enums.ItemType.Ring) & (n != Enums.ItemType.Necklace)) {
                        //    TakeItem = true;
                        //}
                    }

                    if (TakeItem == true)
                    {
                        result = true;

                        // Check to see if its held by anyone

                        if (GetItemSlotHolder(slot) > -1)//remove from all equippers
                        {
                            RemoveItem(slot, true, false);
                            Messenger.SendWornEquipment(client);
                        }

                        Inventory[slot].Num    = 0;
                        Inventory[slot].Amount = 0;
                        Inventory[slot].Sticky = false;
                        Inventory[slot].Tag    = "";
                        //mInventory[i].Dur = 0;

                        //check if it's held-in-bag, and if it was the last functional copy
                        if (ItemManager.Items[itemNum].Type == Enums.ItemType.HeldInBag && HasItem(itemNum, true) == 0)
                        {
                            for (int j = 0; j < Constants.MAX_ACTIVETEAM; j++)
                            {
                                if (team[j].Loaded)
                                {
                                    //the function auto-checks if it's in the activeItemlist to begin with
                                    team[j].RemoveFromActiveItemList(itemNum);
                                }
                            }
                        }

                        // Send the inventory update
                        Messenger.SendInventoryUpdate(client, slot);
                    }
                }
            }
            return(result);
        }