123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- import java.util.ArrayList;
- public class Inventory {
-
- private Item[] items;
- private ArrayList<String> specialItems;
-
- public Inventory(Item[] items) {
- super();
- this.items = items;
- this.specialItems = new ArrayList<String>();
- this.specialItems.add("Aged Brie");
- this.specialItems.add("Backstage passes to a TAFKAL80ETC concert");
- this.specialItems.add("Sulfuras, Hand of Ragnaros");
- }
- /*
- 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);
- updateNormalItemSellIn(i);
- updateAgedBrieQuality(i);
- updateBackStageQuality(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 updateSulfurusQuality(int i) {
- if (items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
- //change nothing
- }
- }
-
- public void updateNormalItemSellIn(int index) {
- if (!determineSpecialQuality(index)) {
- updateSellIn(index);
- }
- }
-
- 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);
- }
- }
- }
|