Ejemplo n.º 1
0
        //remove single item from entity's inventory
        public void RemoveItemFromInventory(GameItem item)
        {
            inventory.Remove(item);

            //ternary operator goes checks whether to remove by first or second option
            GroupedInventoryItem itemToRemove = item.isUnique ?
                                                groupedInventory.FirstOrDefault(gi => gi.item == item) :
                                                groupedInventory.FirstOrDefault(gi => gi.item.itemTypeID == item.itemTypeID);

            //checks if quantity of item to remove is 1 or more
            //removes item from inventory entirely if 1 and decrements item if more than 1
            if (itemToRemove != null)
            {
                if (itemToRemove.quantity == 1)
                {
                    groupedInventory.Remove(itemToRemove);
                }
                else
                {
                    itemToRemove.quantity--;
                }
            }

            OnPropertyChanged(nameof(Weapons));
            OnPropertyChanged(nameof(Consumables));
            OnPropertyChanged(nameof(hasConsumable));
        }
Ejemplo n.º 2
0
        public void RemoveItemFromInventory(GameItem item)
        {
            Inventory.Remove(item);

            GroupedInventoryItem groupedInventoryItemToRemove = item.IsUnique ?
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item == item) :                      // if true
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item.ItemTypeID == item.ItemTypeID); // if false

            // Conditional operator :? (ternary operator) => condition ? consequent : alternative
            // similar to if/else. It evaluates a Bool expression and returns the result of one of the two expressions (one is for = true, one is for =false)
            // source: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator
            if (groupedInventoryItemToRemove != null)
            {
                if (groupedInventoryItemToRemove.Quantity == 1)
                {
                    GroupedInventory.Remove(groupedInventoryItemToRemove);
                }
                else
                {
                    groupedInventoryItemToRemove.Quantity--;
                }
            }

            OnPropertyChanged(nameof(Weapons));
        }
        public void RemoveItemFromInventory(GameItem item)
        {
            Inventory.Remove(item);

            //gets first item from groupedinventory where the item matches what we've passed in
            //if unique, gets the exact item
            //if not unique, just the ID so that quests can still remove multiple
            GroupedInventoryItem groupedInventoryItemToRemove = item.IsUnique ?
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item == item) :
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item.ItemTypeID == item.ItemTypeID);

            //check we actually got something, should not be null but safety check
            if (groupedInventoryItemToRemove != null)
            {
                //if item's quantity is 1, just remove it
                if (groupedInventoryItemToRemove.Quantity == 1)
                {
                    GroupedInventory.Remove(groupedInventoryItemToRemove);
                }
                //if quantity is not 1, just lower quantity by 1
                else
                {
                    groupedInventoryItemToRemove.Quantity--;
                }
            }

            OnPropertyChanged(nameof(Weapons));
            OnPropertyChanged(nameof(Consumables));
            OnPropertyChanged(nameof(HasConsumable));
        }
Ejemplo n.º 4
0
        public void RemoveItemFromInventory(GameItem item)
        {
            Inventory.Remove(item);

            //Checking to see if the item is unique or not
            GroupedInventoryItem groupedInventoryItemToRemove = item.IsUnique ?
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item == item) :
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item.ItemTypeID == item.ItemTypeID);

            if (groupedInventoryItemToRemove != null)
            {
                // Check to see if the item to remove from player's inventory isn't null
                if (groupedInventoryItemToRemove.Quantity == 1)
                {
                    // If the item in question has a quantity of one, remove it from the screen
                    GroupedInventory.Remove(groupedInventoryItemToRemove);
                }
                else
                {
                    // Otherwise just decrease the quantity by one
                    groupedInventoryItemToRemove.Quantity--;
                }
            }

            OnPropertyChanged(nameof(Weapons));
        }
Ejemplo n.º 5
0
        public void RemoveItemFromInventory(GameItem item)
        {
            Inventory.Remove(item);

            //get the first item from groupinventory where item id matches item id of item we want to remove
            //If item we want to remove is unique, we have to find that exact matching item
            //If not, there's no distinction between the individuzl items.
            //This is a ternary operator - if first part evaluates to true, the first statement is executed.
            GroupedInventoryItem groupedInventoryItemToRemove = item.IsUnique ?
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item == item) :
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item.ItemTypeID == item.ItemTypeID);

            if (groupedInventoryItemToRemove != null) //should never be null but good to check
            {
                //does object have quantity of 1?
                //if so, completely remove item from groupedinventory.
                if (groupedInventoryItemToRemove.Quantity == 1)
                {
                    GroupedInventory.Remove(groupedInventoryItemToRemove);
                }
                else
                {
                    //decrease quantity by 1
                    groupedInventoryItemToRemove.Quantity--;
                }
            }

            OnPropertyChanged(nameof(Weapons));
        }
Ejemplo n.º 6
0
        public void RemoveItemFromInventory(GameItem item)
        {
            Inventory.Remove(item);
            GroupedInventoryItem itemToRemove = GroupedInventory.FirstOrDefault(gi => gi.Item.ItemId == item.ItemId);

            if (itemToRemove.Quantity <= 1)
            {
                GroupedInventory.Remove(itemToRemove);
            }
            else
            {
                itemToRemove.Quantity--;
            }
            OnPropertyChanged(nameof(Weapons));
        }
Ejemplo n.º 7
0
        public void RemoveItemFromInventory(GameItem item)
        {
            Inventory.Remove(item);

            GroupedInventoryItem groupedInventoryItemToRemove = item.IsUnique ? GroupedInventory.FirstOrDefault(gi => gi.Item == item):GroupedInventory.FirstOrDefault(gi => gi.Item.ItemTypeID == item.ItemTypeID);

            if (groupedInventoryItemToRemove != null)
            {
                if (groupedInventoryItemToRemove.Quantity == 1)
                {
                    GroupedInventory.Remove(groupedInventoryItemToRemove);
                }
                else
                {
                    groupedInventoryItemToRemove.Quantity--;
                }
            }
            OnPropertyChanged(nameof(Weapons));
        }
Ejemplo n.º 8
0
        public void RemoveItemFromInventory(GameItem item) // TODO: Overload with GroupedInventoryItem
        {
            Inventory.Remove(item);

            GroupedInventoryItem groupedInventoryItemToRemove = item.IsUnique ?
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item == item) :
                                                                GroupedInventory.FirstOrDefault(gi => gi.Item.ItemTypeID == item.ItemTypeID);

            if (groupedInventoryItemToRemove.Quantity == 1)
            {
                GroupedInventory.Remove(groupedInventoryItemToRemove);
            }
            else
            {
                groupedInventoryItemToRemove.Quantity--;
            }

            OnPropertyChanged(nameof(Weapons));
            OnPropertyChanged(nameof(Consumables));
            OnPropertyChanged(nameof(HasConsumable));
        }