private bool SelectItem(int index, Game game) { var activeLocation = RightHasFocus ? RightPane : LeftPane; var targetLocation = !RightHasFocus ? RightPane : LeftPane; var items = GetItems(activeLocation); if (index >= items.Count) { return(false); } switch (targetLocation) { case StorageLocation.Equipment: { var equipItemCommand = new EquipItemCommand(); if (!equipItemCommand.CanSelect(items[index])) { return(false); } else { var targetItem = items[index]; var unequipedItem = Game.Hero.Equipment.equip(targetItem); if (unequipedItem != null) { RemoveTransferedItem(index, activeLocation); TryToTransfer(unequipedItem, activeLocation, true); return(false); } else { RemoveTransferedItem(index, activeLocation); return(false); } } return(false); } case StorageLocation.Crucible: { Item targetItem = GetTargetItem(index, activeLocation); var canUse = CanUseItemInRecipe(targetItem); if (!canUse) { return(false); } if (TryToTransfer(targetItem, targetLocation, activeLocation == StorageLocation.Equipment)) { RemoveTransferedItem(index, activeLocation); return(false); } else { return(false); } } default: { Item targetItem = GetTargetItem(index, activeLocation); if (TryToTransfer(targetItem, targetLocation, activeLocation == StorageLocation.Equipment)) { RemoveTransferedItem(index, activeLocation); return(false); } else { return(false); } } } }
private void DrawItems(BufferContainer buffer, int x, int y, List <Item> items, StorageLocation current, StorageLocation target, bool isActive = false) { var i = 0; foreach (var item in items) { var alphabet = "abcdefghijklmnopqrstuvwxyz"; var itemY = i + y; var borderColor = ConsoleColor.DarkGray; var letterColor = ConsoleColor.DarkGray; var textColor = ConsoleColor.DarkGray; var priceColor = ConsoleColor.DarkGray; var glyphColor = ConsoleColor.DarkGray; var attackColor = ConsoleColor.DarkGray; var armourColor = ConsoleColor.DarkGray; var enabled = true; if (isActive) { switch (target) { case StorageLocation.Equipment: { var command = new EquipItemCommand(); var canUse = command.CanSelect(item); if (canUse) { borderColor = ConsoleColor.Gray; letterColor = ConsoleColor.Yellow; textColor = item == null ? ConsoleColor.Gray : ConsoleColor.White; priceColor = ConsoleColor.DarkYellow; glyphColor = item == null ? ConsoleColor.Gray : ColourUtilities.ConvertToConsoleColor(item.Appearance.ForeGroundColor); attackColor = ConsoleColor.Yellow; armourColor = ConsoleColor.Green; } break; } case StorageLocation.Crucible: { var canUse = false; if (item != null) { canUse = CanUseItemInRecipe(item); } if (canUse) { borderColor = ConsoleColor.Gray; letterColor = ConsoleColor.Yellow; textColor = item == null ? ConsoleColor.Gray : ConsoleColor.White; priceColor = ConsoleColor.DarkYellow; glyphColor = item == null ? ConsoleColor.Gray : ColourUtilities.ConvertToConsoleColor(item.Appearance.ForeGroundColor); attackColor = ConsoleColor.Yellow; armourColor = ConsoleColor.Green; } break; } default: { borderColor = ConsoleColor.Gray; letterColor = ConsoleColor.Yellow; textColor = item == null ? ConsoleColor.Gray : ConsoleColor.White; priceColor = ConsoleColor.DarkYellow; glyphColor = item == null ? ConsoleColor.Gray : ColourUtilities.ConvertToConsoleColor(item.Appearance.ForeGroundColor); attackColor = ConsoleColor.Yellow; armourColor = ConsoleColor.Green; break; } } } WriteAt(buffer, x, itemY, " ) ", borderColor); WriteAt(buffer, x, itemY, alphabet[i].ToString(), letterColor); if (item == null) { // what is the location? if (current == StorageLocation.Equipment) { var text = ((EquipementSlot)i) + " slot is empty"; WriteAt(buffer, x + 3, itemY, text, textColor); } } else { if (enabled) { WriteAt(buffer, x + 3, itemY, item.Appearance.Glyph, glyphColor); } var text = item.NounText; if (text.Length > 32) { text = text.Substring(0, 29) + "..."; } WriteAt(buffer, x + 5, itemY, text, textColor); // TODO: Eventually need to handle equipment that gives both an armor and attack bonus. if (item.attack != null) { DrawStat(buffer, x, itemY, "»", item.attack.AverageDamage, attackColor, attackColor, enabled); } else if (item.armor != 0) { DrawStat(buffer, x, itemY, "•", item.armor, armourColor, armourColor, enabled); } if (item.price != 0) { var price = PriceString(item.price); WriteAt(buffer, x + 49 - price.Length, itemY, price, priceColor); } } // Increment the item counter i++; } // If this is the crucible then maybe a recipe has been completed. if (current == StorageLocation.Crucible) { if (completeRecipe != null) { i++; i++; var textColour = ConsoleColor.Yellow; if (isActive) { textColour = ConsoleColor.DarkGray; } var csv = string.Join(", ", completeRecipe.Produces.ToArray()); WriteAt(buffer, 0, y + i++, $"This recipe {csv}!", textColour); WriteAt(buffer, 0, y + i++, "Press[Space] to forge item!", textColour); } } }