//Removes item and returns status public bool DiscardItem(Item item) { if (item.GetType() == typeof(Helm) && helm.Equals(item)) { helm = null; controller.UpdateItemIcons(null, 0); return(true); } else if (item.getItemWeight() == ItemWeight.Heavy && heavyItem.Equals(item)) { heavyItem = null; controller.UpdateItemIcons(null, 1); return(true); } else if (item.getItemWeight() == ItemWeight.Light) { for (int i = 0; i < 3; i++) { if (lightItems[i] == null) { continue; } if (lightItems[i].Equals(item)) { lightItems[i] = null; controller.UpdateItemIcons(null, i + 2); return(true); } } } return(false); }
// commented since it is simply List.Add /* public bool addItemForSale(ItemForSale itemForSale) { itemsForSale.Add(itemForSale); } */ // can not check the input item since it is an instance // use a newly created enum class ItemForSale /* public bool buyItemForSale(Hero hero, Item item) { if (hero != null && item != null && itemsForSale.ContainsKey(item)) { int price = itemsForSale[item]; if(hero.getGold() >= price) { itemsForSale.Remove(item); hero.setGold(hero.getGold() - price); hero.addItem(item); return true; } } return false; } */ public bool buyItemForSale(Hero hero, ItemForSale item) { if (hero != null && itemsForSale.Contains(item)) { int price = 2; if (isMine && hero.getHeroKind() == HeroKind.Dwarf && item == ItemForSale.SP) price = 1; // dwarf get a discount if (hero.getGold() >= price) { Item newItem=new Item(ItemWeight.Light); //ItemWeight.Light as placehoder for initialization if (item== ItemForSale.SP) { hero.setGold(hero.getGold() - price); hero.setStrengthPoints(hero.getStrengthPoints() + 1); return true; } else { if (item == ItemForSale.Wineskin) newItem = new Wineskin(ItemWeight.Light); if (item == ItemForSale.Falcon) newItem = new Falcon(ItemWeight.Heavy); if (item == ItemForSale.Telescope) newItem = new Telescope(ItemWeight.Light); if (item == ItemForSale.Helm) newItem = new Helm(ItemWeight.Light); if (item == ItemForSale.Shield) newItem = new Shield(ItemWeight.Heavy); if (item == ItemForSale.Bow) newItem = new Bow(ItemWeight.Heavy); } hero.setGold(hero.getGold() - price); hero.addItem(newItem); return true; } } return false; }
public void addItem(Item item) { //TODO: Ask if player wants to replace an item if inventory full if (item.GetType() == typeof(Helm)) { helm = (Helm)item; controller.UpdateItemIcons(item, 0); } else if (item.getItemWeight() == ItemWeight.Light) { for (int i = 0; i < 3; i++) { if (lightItems[i] == null) { lightItems[i] = item; controller.UpdateItemIcons(item, i + 2); break; } } } else { heavyItem = item; controller.UpdateItemIcons(item, 1); } //If you have all 3 runestones, get black die if (lightItems.All(i => i != null && i.GetType() == typeof(Runestone))) { if (lightItems.Any(i => ((Runestone)i).getColor() == GemColor.Blue) && lightItems.Any(i => ((Runestone)i).getColor() == GemColor.Green) && lightItems.Any(i => ((Runestone)i).getColor() == GemColor.Yellow)) { numRegularDice--; numBlackDice++; } } //TODO: Check this when dropping/trading items too else if (numBlackDice > 0) { numBlackDice--; numRegularDice++; } item.SetOwner(this); }