|
@ -13,9 +13,7 @@ import java.util.Scanner; |
|
|
public class CollectCommand implements CommandAPI { |
|
|
public class CollectCommand implements CommandAPI { |
|
|
@Override |
|
|
@Override |
|
|
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { |
|
|
public void performCommand(Scanner scanner, boolean isRunning, String message, TravelEngine travelEngine) { |
|
|
StringBuilder s = new StringBuilder(); |
|
|
|
|
|
JsonParser jp = new JsonParser(); |
|
|
|
|
|
JSONObject o = jp.getJSONObject("playerconfig.json"); |
|
|
|
|
|
|
|
|
JSONObject o = JsonParser.getJSONObject("src/main/resources/playerconfig.json"); |
|
|
JSONArray inventory = o.getJSONArray("inventory"); |
|
|
JSONArray inventory = o.getJSONArray("inventory"); |
|
|
|
|
|
|
|
|
ArrayList<Item> location = travelEngine.getPlayer().getLocation().getItemList(); |
|
|
ArrayList<Item> location = travelEngine.getPlayer().getLocation().getItemList(); |
|
@ -25,9 +23,9 @@ public class CollectCommand implements CommandAPI { |
|
|
String item = new String(); |
|
|
String item = new String(); |
|
|
item = scanner.nextLine(); |
|
|
item = scanner.nextLine(); |
|
|
|
|
|
|
|
|
collectItem(location, item, jp, o, inventory,getInventory); |
|
|
|
|
|
|
|
|
collectItem(location, item, o, inventory,getInventory); |
|
|
} |
|
|
} |
|
|
public void collectItem(ArrayList<Item> location, String item, JsonParser jp, JSONObject o, JSONArray inventory, ArrayList<Item> getInventory) { |
|
|
|
|
|
|
|
|
public void collectItem(ArrayList<Item> location, String item, JSONObject o, JSONArray inventory, ArrayList<Item> getInventory) { |
|
|
for (int i = 0; i < location.size(); i++) { |
|
|
for (int i = 0; i < location.size(); i++) { |
|
|
if (item.equals(location.get(i).getName())) { |
|
|
if (item.equals(location.get(i).getName())) { |
|
|
JSONObject o1 = new JSONObject(); |
|
|
JSONObject o1 = new JSONObject(); |
|
@ -36,29 +34,28 @@ public class CollectCommand implements CommandAPI { |
|
|
getInventory.get(j).setAmount(getInventory.get(j).getAmount() + 1); |
|
|
getInventory.get(j).setAmount(getInventory.get(j).getAmount() + 1); |
|
|
for (int k = 0; k < inventory.length(); k++) { |
|
|
for (int k = 0; k < inventory.length(); k++) { |
|
|
if (inventory.getJSONObject(k).getString("name").equals(item)) { |
|
|
if (inventory.getJSONObject(k).getString("name").equals(item)) { |
|
|
increaseAmountInPlayerConfig(inventory,k,jp,o); |
|
|
|
|
|
|
|
|
increaseAmountInPlayerConfig(inventory,k,o); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
writeNewItem(location, getInventory, o1, inventory, i, jp, o); |
|
|
|
|
|
|
|
|
writeNewItem(location, getInventory, o1, inventory, i, o); |
|
|
} |
|
|
} |
|
|
} System.out.println("Es gibt kein Item, dass du einsammeln kannst."); |
|
|
} System.out.println("Es gibt kein Item, dass du einsammeln kannst."); |
|
|
} |
|
|
} |
|
|
public void writeNewItem(ArrayList<Item> location, ArrayList<Item> getInventory, JSONObject o1, JSONArray inventory, int i, JsonParser jp, JSONObject o){ |
|
|
|
|
|
|
|
|
public void writeNewItem(ArrayList<Item> location, ArrayList<Item> getInventory, JSONObject o1, JSONArray inventory, int i, JSONObject o){ |
|
|
o1.put("name", location.get(i).getName()).put("doesDamage", location.get(i).doesDamage()).put("damage", location.get(i).getDamage()).put("amount", 1).put("durability", 1000); |
|
|
o1.put("name", location.get(i).getName()).put("doesDamage", location.get(i).doesDamage()).put("damage", location.get(i).getDamage()).put("amount", 1).put("durability", 1000); |
|
|
inventory.put(o1); |
|
|
inventory.put(o1); |
|
|
jp.writeObject("playerconfig.json", o); |
|
|
|
|
|
|
|
|
JsonParser.writeObject("playerconfig.json", o); |
|
|
getInventory.add(location.get(i)); |
|
|
getInventory.add(location.get(i)); |
|
|
location.remove(i); |
|
|
location.remove(i); |
|
|
} |
|
|
} |
|
|
public void increaseAmountInPlayerConfig(JSONArray inventory, int k, JsonParser jp, JSONObject o){ |
|
|
|
|
|
JSONObject o2 = new JSONObject(); |
|
|
|
|
|
|
|
|
public void increaseAmountInPlayerConfig(JSONArray inventory, int k, JSONObject o){ |
|
|
int amountItemsInPlayerconfig = 0; |
|
|
int amountItemsInPlayerconfig = 0; |
|
|
amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); |
|
|
amountItemsInPlayerconfig = inventory.getJSONObject(k).getInt("amount"); |
|
|
inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); |
|
|
inventory.getJSONObject(k).put("amount", amountItemsInPlayerconfig + 1); |
|
|
jp.writeObject("playerconfig.json", o); |
|
|
|
|
|
|
|
|
JsonParser.writeObject("playerconfig.json", o); |
|
|
System.out.println(Colors.ANSI_YELLOW +"Du hast das Item eingesammelt."+ Colors.ANSI_RESET); |
|
|
System.out.println(Colors.ANSI_YELLOW +"Du hast das Item eingesammelt."+ Colors.ANSI_RESET); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|