Inventory.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. public class Inventory {
  2. private Item[] items;
  3. public Inventory(Item[] items) {
  4. super();
  5. this.items = items;
  6. }
  7. public void updateQuality() {
  8. for (int i = 0; i < items.length; i++) {
  9. //handles Sulfuras
  10. if(items[i].getName().equals("Sulfuras, Hand of Ragnaros")){
  11. continue;}
  12. if(items[i].getName().equals("Aged Brie")){
  13. agedBrieUpdate(i);
  14. } else if (items[i].getName().equals("Conjured Mage Water")){
  15. conjuredItemUpdate(i);
  16. }else{regularItemUpdate(i);}
  17. if (items[i].getQuality() < 80) {
  18. items[i].setSellIn(items[i].getSellIn() - 1);
  19. }
  20. }
  21. }
  22. public void agedBrieUpdate(int i){
  23. if(items[i].getSellIn() > 0 && items[i].getQuality() <= 49){
  24. items[i].setQuality(items[i].getQuality() + 1);
  25. } else if(items[i].getSellIn() < 0 && items[i].getQuality() <= 48){
  26. items[i].setQuality(items[i].getQuality() + 2);
  27. }
  28. }
  29. public void regularItemUpdate(int i){
  30. if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
  31. items[i].setQuality(items[i].getQuality() - 1);
  32. } else if(items[i].getSellIn() < 0 && items[i].getQuality() > 1){
  33. items[i].setQuality(items[i].getQuality() - 2);
  34. }
  35. }
  36. public void conjuredItemUpdate(int i){
  37. if(items[i].getSellIn() > 0 && items[i].getQuality() > 0){
  38. items[i].setQuality(items[i].getQuality() - 2);
  39. } else if(items[i].getSellIn() < 0 && items[i].getQuality() > 1){
  40. items[i].setQuality(items[i].getQuality() - 4);
  41. }
  42. }
  43. }