import java.util.ArrayList; public class Inventory { private Item[] items; private ArrayList specialItems; public Inventory(Item[] items) { super(); this.items = items; this.specialItems = new ArrayList(); this.specialItems.add("Aged Brie"); this.specialItems.add("Backstage passes to a TAFKAL80ETC concert"); this.specialItems.add("Sulfuras, Hand of Ragnaros"); this.specialItems.add("Conjured"); } /* public void updateQuality() { for (int i = 0; i < items.length; i++) { //if item at ith index doesnt equal aged brie AND BACKSTAGE PASS if (!items[i].getName().equals("Aged Brie") && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) { //left with normal and sulfuras with qual greater than 0 if (items[i].getQuality() > 0) { //not sulfurs minus the qual of each -1 but does it factor in time after sell by? if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) { items[i].setQuality(items[i].getQuality() - 1); } } } else { if (items[i].getQuality() < 50) { items[i].setQuality(items[i].getQuality() + 1); if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") { if (items[i].getSellIn() < 11) { if (items[i].getQuality() < 50) { items[i].setQuality(items[i].getQuality() + 1); } } if (items[i].getSellIn() < 6) { if (items[i].getQuality() < 50) { items[i].setQuality(items[i].getQuality() + 1); } } } } } if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) { items[i].setSellIn(items[i].getSellIn() - 1); } if (items[i].getSellIn() < 0) { if (!items[i].getName().equals("Aged Brie")) { if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) { if (items[i].getQuality() > 0) { if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) { items[i].setQuality(items[i].getQuality() - 1); } } } else { items[i].setQuality(items[i].getQuality() - items[i].getQuality()); } } else { if (items[i].getQuality() < 50) { items[i].setQuality(items[i].getQuality() + 1); } } } } } */ public void updateQuality() { for (int i = 0; i < items.length; i++) { //updateSulfurusQuality(i); updateNormalItemQuality(i); updateAgedBrieQuality(i); updateBackStageQuality(i); updateConjuredQuality(i); updateSellIn(i); } } public void updateSellIn(int i) { if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) { items[i].setSellIn(items[i].getSellIn() - 1); } } public boolean determineSpecialQuality(int i) { if (specialItems.contains(items[i].getName())) { return true; } return false; } public boolean pastSellIn(int i) { if (items[i].getSellIn() < 0) { return true; } return false; } public void updateAgedBrieQuality(int index) { if (items[index].getName().equals("Aged Brie")) { if (pastSellIn(index)) { changeQuality(index, 2); } else { changeQuality(index, 1); } pastMaxQuality(index); } } public void updateBackStageQuality(int index) { if (items[index].getName().equals("Backstage passes to a TAFKAL80ETC concert")) { if (items[index].getSellIn() > 10) { changeQuality(index, 1); } else if (items[index].getSellIn() > 5) { changeQuality(index, 2); } else if (items[index].getSellIn() >= 0) { changeQuality(index, 3); } else { items[index].setQuality(0); } pastMaxQuality(index); } } public void updateConjuredQuality(int index) { if (items[index].getName().equals("Conjured")){ changeQuality(index, -2); pastZeroQuality(index); } } public void updateSulfurusQuality(int i) { if (items[i].getName().equals("Sulfuras, Hand of Ragnaros")) { //change nothing } } public void updateNormalItemQuality(int index) { if (!determineSpecialQuality(index)) { if (pastSellIn(index)) { changeQuality(index, -2); } else { changeQuality(index, -1); } pastZeroQuality(index); } } public void changeQuality(int index, int amount) { items[index].setQuality(items[index].getQuality() + amount); } public void pastMaxQuality(int index) { if (items[index].getQuality() > 50) { items[index].setQuality(50); } } public void pastZeroQuality(int index) { if (items[index].getQuality() < 0) { items[index].setQuality(0); } } }