private void OnClick_Sell(object sender, RoutedEventArgs e)
        {
            GroupedInventory groupedInventory = ((FrameworkElement)sender).DataContext as GroupedInventory;

            if (groupedInventory != null)
            {
                Session.CurrentPlayer.ReceiveGold(groupedInventory.Item.Price);
                Session.CurrentTrader.AddItemToInventory(groupedInventory.Item);
                Session.CurrentPlayer.RemoveItemFromInventory(groupedInventory.Item);
            }
        }
Beispiel #2
0
        public void AddItemToInventory(Gameitem item)
        {
            Inventory.Add(item);
            if (item.IsUnique)
            {
                GroupedInventory.Add(new GroupedInventory(item, 1));
            }
            else
            {
                if (!GroupedInventory.Any(gi => gi.Item.TypeID == item.TypeID))
                {
                    GroupedInventory.Add(new GroupedInventory(item, 0));
                }

                GroupedInventory.First(gi => gi.Item.TypeID == item.TypeID).Quantity++;
            }
        }
        private void OnClick_Buy(object sender, RoutedEventArgs e)
        {
            GroupedInventory groupedInventory = ((FrameworkElement)sender).DataContext as GroupedInventory;

            if (groupedInventory != null)
            {
                if (Session.CurrentPlayer.Gold >= groupedInventory.Item.Price)
                {
                    Session.CurrentPlayer.SpendGold(groupedInventory.Item.Price);
                    Session.CurrentTrader.RemoveItemFromInventory(groupedInventory.Item);
                    Session.CurrentPlayer.AddItemToInventory(groupedInventory.Item);
                }
                else
                {
                    MessageBox.Show("You don't have enough gold");
                }
            }
        }
Beispiel #4
0
        public void RemoveItemFromInventory(Gameitem item)
        {
            Inventory.Remove(item);

            GroupedInventory itemToRemove =
                GroupedInventory.FirstOrDefault(gi => gi.Item == item);

            if (itemToRemove != null)
            {
                if (itemToRemove.Quantity == 1)
                {
                    GroupedInventory.Remove(itemToRemove);
                }
                else
                {
                    itemToRemove.Quantity--;
                }
            }
        }
Beispiel #5
0
        public void AddItemToInventory(Item item)
        {
            Inventory.Add(item);

            // if item is unique, create a stack with single item inside of it
            if (item.IsUnique)
            {
                GroupedInventory.Add(new GroupedInventoryItem(item, 1));
            }
            // if it isn't, loop through every item using id to see if passed id is equal then skip. if not, create the stack and add the item to stack inventory
            else
            {
                if (!GroupedInventory.Any(gi => gi.Item.ID == item.ID))
                {
                    GroupedInventory.Add(new GroupedInventoryItem(item, 0));
                }

                GroupedInventory.First(gi => gi.Item.ID == item.ID).Quantity++;
            }
        }
Beispiel #6
0
 public void AddItemToInventory(Item item)
 {
     Inventory.Add(item);
     if (item.IsUnique)
     {
         GroupedInventory.Add(new InventoryItem(item, 1));
     }
     else
     {
         if (!GroupedInventory.Any(gi => gi.GameItem.ItemID == item.ItemID))
         {
             GroupedInventory.Add(new InventoryItem(item, 0));
         }
         GroupedInventory.First(gi => gi.GameItem.ItemID == item.ItemID).Quantity++;
     }
     OnPropertyChanged(nameof(Weapons));
     OnPropertyChanged(nameof(Armors));
     OnPropertyChanged(nameof(Gloves));
     OnPropertyChanged(nameof(Boots));
 }
Beispiel #7
0
        public void RemoveItemFromInventory(Item item)
        {
            Inventory.Remove(item);
            InventoryItem inventoryItemToRemove = GroupedInventory.FirstOrDefault(gi => gi.GameItem == item);

            if (inventoryItemToRemove != null)
            {
                if (inventoryItemToRemove.Quantity == 1)
                {
                    GroupedInventory.Remove(inventoryItemToRemove);
                }
                else
                {
                    inventoryItemToRemove.Quantity--;
                }
            }
            OnPropertyChanged(nameof(Weapons));
            OnPropertyChanged(nameof(Armors));
            OnPropertyChanged(nameof(Gloves));
            OnPropertyChanged(nameof(Boots));
        }
Beispiel #8
0
        public void RemoveItemFromInventory(Item item)
        {
            Inventory.Remove(item);

            // Check if item is unique
            // If unique, return the exact matching item
            // If not unique, return first or default grouped item with same item id in it
            GroupedInventoryItem stackedItemToRemove = item.IsUnique ?
                                                       GroupedInventory.FirstOrDefault(gi => gi.Item == item) :
                                                       GroupedInventory.FirstOrDefault(gi => gi.Item.ID == item.ID);

            if (stackedItemToRemove != null)
            {
                if (stackedItemToRemove.Quantity == 1)
                {
                    GroupedInventory.Remove(stackedItemToRemove);
                }
                else
                {
                    stackedItemToRemove.Quantity--;
                }
            }
        }
Beispiel #9
0
        public void PrintItemSellOptions(int x, int y, Action action, bool isSelling)
        {
            // TODO: fix out of bounds array when 0 is inputted
            // List<Item> filteredList = Inventory.Where(x => x.Type == Item.ItemType.Weapon).ToList();
            if (GameSession.itemChoice < GroupedInventory.Count())
            {
                string name        = GroupedInventory[GameSession.itemChoice].Item.Name;
                string description = GroupedInventory[GameSession.itemChoice].Item.Description;
                int    value       = GroupedInventory[GameSession.itemChoice].Item.Price;

                y++;
                Console.SetCursorPosition(x, y);
                Console.Write($"- {name} -");
                y++;
                Console.SetCursorPosition(x, y);
                Console.Write($"\"{description}\"");
                y++;
                Console.SetCursorPosition(x, y);
                Console.Write($"Value: {value}");
                if (isSelling)
                {
                    y++;
                    Console.SetCursorPosition(x, y);
                    Console.Write($"{action.GetKeybind("sell")}) Sell");
                }
                else
                {
                    y++;
                    Console.SetCursorPosition(x, y);
                    Console.Write($"{action.GetKeybind("buy")}) Buy");
                }
                y++;
                Console.SetCursorPosition(x, y);
                Console.Write($"{action.GetKeybind("cancel")}) Cancel");
            }
        }