Inventory.java 5.8KB

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