Inventory.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import java.util.ArrayList;
  2. public class Inventory {
  3. private Item[] items;
  4. private ArrayList<String> specialItems;
  5. public Inventory(Item[] items) {
  6. super();
  7. this.items = items;
  8. this.specialItems = new ArrayList<String>();
  9. this.specialItems.add("Aged Brie");
  10. this.specialItems.add("Backstage passes to a TAFKAL80ETC concert");
  11. this.specialItems.add("Sulfuras, Hand of Ragnaros");
  12. }
  13. /*
  14. public void updateQuality() {
  15. for (int i = 0; i < items.length; i++) {
  16. //if item at ith index doesnt equal aged brie AND BACKSTAGE PASS
  17. if (!items[i].getName().equals("Aged Brie")
  18. && !items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
  19. //left with normal and sulfuras with qual greater than 0
  20. if (items[i].getQuality() > 0) {
  21. //not sulfurs minus the qual of each -1 but does it factor in time after sell by?
  22. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  23. items[i].setQuality(items[i].getQuality() - 1);
  24. }
  25. }
  26. } else {
  27. if (items[i].getQuality() < 50) {
  28. items[i].setQuality(items[i].getQuality() + 1);
  29. if (items[i].getName() == "Backstage passes to a TAFKAL80ETC concert") {
  30. if (items[i].getSellIn() < 11) {
  31. if (items[i].getQuality() < 50) {
  32. items[i].setQuality(items[i].getQuality() + 1);
  33. }
  34. }
  35. if (items[i].getSellIn() < 6) {
  36. if (items[i].getQuality() < 50) {
  37. items[i].setQuality(items[i].getQuality() + 1);
  38. }
  39. }
  40. }
  41. }
  42. }
  43. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  44. items[i].setSellIn(items[i].getSellIn() - 1);
  45. }
  46. if (items[i].getSellIn() < 0) {
  47. if (!items[i].getName().equals("Aged Brie")) {
  48. if (!items[i].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
  49. if (items[i].getQuality() > 0) {
  50. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  51. items[i].setQuality(items[i].getQuality() - 1);
  52. }
  53. }
  54. } else {
  55. items[i].setQuality(items[i].getQuality()
  56. - items[i].getQuality());
  57. }
  58. } else {
  59. if (items[i].getQuality() < 50) {
  60. items[i].setQuality(items[i].getQuality() + 1);
  61. }
  62. }
  63. }
  64. }
  65. }
  66. */
  67. public void updateQuality() {
  68. for (int i = 0; i < items.length; i++) {
  69. //updateSulfurusQuality(i);
  70. updateNormalItemQuality(i);
  71. updateNormalItemSellIn(i);
  72. updateAgedBrieQuality(i);
  73. updateBackStageQuality(i);
  74. }
  75. }
  76. public void updateSellIn(int i) {
  77. if (!items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  78. items[i].setSellIn(items[i].getSellIn() - 1);
  79. }
  80. }
  81. public boolean determineSpecialQuality(int i) {
  82. if (specialItems.contains(items[i].getName())) {
  83. return true;
  84. }
  85. return false;
  86. }
  87. public boolean pastSellIn(int i) {
  88. if (items[i].getSellIn() < 0) {
  89. return true;
  90. }
  91. return false;
  92. }
  93. public void updateAgedBrieQuality(int index) {
  94. if (items[index].getName().equals("Aged Brie")) {
  95. if (pastSellIn(index)) {
  96. changeQuality(index, 2);
  97. } else {
  98. changeQuality(index, 1);
  99. }
  100. pastMaxQuality(index);
  101. }
  102. }
  103. public void updateBackStageQuality(int index) {
  104. if (items[index].getName().equals("Backstage passes to a TAFKAL80ETC concert")) {
  105. if (items[index].getSellIn() > 10) {
  106. changeQuality(index, 1);
  107. } else if (items[index].getSellIn() > 5) {
  108. changeQuality(index, 2);
  109. } else if (items[index].getSellIn() >= 0) {
  110. changeQuality(index, 3);
  111. } else {
  112. items[index].setQuality(0);
  113. }
  114. pastMaxQuality(index);
  115. }
  116. }
  117. public void updateSulfurusQuality(int i) {
  118. if (items[i].getName().equals("Sulfuras, Hand of Ragnaros")) {
  119. //change nothing
  120. }
  121. }
  122. public void updateNormalItemSellIn(int index) {
  123. if (!determineSpecialQuality(index)) {
  124. updateSellIn(index);
  125. }
  126. }
  127. public void updateNormalItemQuality(int index) {
  128. if (!determineSpecialQuality(index)) {
  129. if (pastSellIn(index)) {
  130. changeQuality(index, -2);
  131. } else {
  132. changeQuality(index, -1);
  133. }
  134. pastZeroQuality(index);
  135. }
  136. }
  137. public void changeQuality(int index, int amount) {
  138. items[index].setQuality(items[index].getQuality() + amount);
  139. }
  140. public void pastMaxQuality(int index) {
  141. if (items[index].getQuality() > 50) {
  142. items[index].setQuality(50);
  143. }
  144. }
  145. public void pastZeroQuality(int index) {
  146. if (items[index].getQuality() < 0) {
  147. items[index].setQuality(0);
  148. }
  149. }
  150. }