public boolean containsItem(String id) { Iterator var3 = this.items.iterator();…
- User
public boolean containsItem(String id) { Iterator var3 = this.items.iterator();
while(var3.hasNext()) { Item item = (Item)var3.next(); if (item.id.equals(id)) { return true; } } return false;}
public Item getItemById(String id) { Iterator var3 = this.items.iterator();
while(var3.hasNext()) { Item item = (Item)var3.next(); if (item.id.equals(id)) { return item; } } return null;}
public boolean mountItem(String id) { Item item = this.getItemById(id.substring(0, id.length() - 3)); if (item != null && Integer.parseInt(id.substring(id.length() - 1, id.length())) == item.modificationIndex) { if (item.itemType == ItemType.WEAPON) { this.mountTurret = item; return true; }
if (item.itemType == ItemType.ARMOR) { this.mountHull = item; return true; } if (item.itemType == ItemType.COLOR) { this.mountColormap = item; return true; } } return false;}
public boolean updateItem(String id) { Item item = this.getItemById(id.substring(0, id.length() - 3)); int modificationID = Integer.parseInt(id.substring(id.length() - 1)); if (modificationID < 3 && item.modificationIndex == modificationID) { ++item.modificationIndex; item.nextPrice = item.modifications[item.modificationIndex + 1 != 4 ? item.modificationIndex + 1 : item.modificationIndex].price; item.nextProperty = item.modifications[item.modificationIndex + 1 != 4 ? item.modificationIndex + 1 : item.modificationIndex].propertys; item.nextRankId = item.modifications[item.modificationIndex + 1 != 4 ? item.modificationIndex + 1 : item.modificationIndex].rank; this.replaceItems(this.getItemById(id.substring(0, id.length() - 3)), item); return true; } else { return false; } }
public boolean buyItem(String id, int count) { Item temp = (Item)GarageItemsLoader.items.get(id.substring(0, id.length() - 3)); if (temp.specialItem) { return false; } else { Item item = temp.clone(); if (!this.items.contains(this.getItemById(id))) { if (item.isInventory) { item.count += count; }
this.items.add(item); return true; } else if (item.isInventory) { Item fromUser = this.getItemById(id); fromUser.count += count; return true; } else { return false; } }}
public Item buyItem(String id, int count, int nul) { id = id.substring(0, id.length() - 3); Item temp = (Item)GarageItemsLoader.items.get(id); if (temp.specialItem) { return null; } else { Item item = temp.clone(); if (!this.items.contains(this.getItemById(id))) { if (item.itemType == ItemType.INVENTORY) { item.count += count; }
this.items.add(item); return item; } else if (item.itemType == ItemType.INVENTORY) { Item fromUser = this.getItemById(id); fromUser.count += count; return fromUser; } else { return null; } }}
private void replaceItems(Item old, Item newItem) { if (this.items.contains(old)) { this.items.set(this.items.indexOf(old), newItem); }
}
public ArrayList getInventoryItems() { ArrayList _items = new ArrayList(); Iterator var3 = this.items.iterator();
while(var3.hasNext()) { Item item = (Item)var3.next(); if (item.itemType == ItemType.INVENTORY) { _items.add(item); } } return _items;}
public void parseJSONData() { JSONObject hulls = new JSONObject(); JSONArray _hulls = new JSONArray(); JSONObject colormaps = new JSONObject(); JSONArray _colormaps = new JSONArray(); JSONObject turrets = new JSONObject(); JSONArray _turrets = new JSONArray(); JSONObject inventory_items = new JSONObject(); JSONArray _inventory = new JSONArray(); JSONObject effects_items = new JSONObject(); JSONArray _effects = new JSONArray(); Iterator var10 = this.items.iterator();
while(var10.hasNext()) { Item item = (Item)var10.next(); JSONObject inventory; if (item.itemType == ItemType.ARMOR) { inventory = new JSONObject(); inventory.put("id", item.id); inventory.put("modification", item.modificationIndex); inventory.put("mounted", item == this.mountHull); _hulls.add(inventory); } if (item.itemType == ItemType.COLOR) { inventory = new JSONObject(); inventory.put("id", item.id); inventory.put("modification", item.modificationIndex); inventory.put("mounted", item == this.mountColormap); _colormaps.add(inventory); } if (item.itemType == ItemType.WEAPON) { inventory = new JSONObject(); inventory.put("id", item.id); inventory.put("modification", item.modificationIndex); inventory.put("mounted", item == this.mountTurret); _turrets.add(inventory); } if (item.itemType == ItemType.INVENTORY) { inventory = new JSONObject(); inventory.put("id", item.id); inventory.put("count", item.count); _inventory.add(inventory); } if (item.itemType == ItemType.PLUGIN) { inventory = new JSONObject(); inventory.put("id", item.id); inventory.put("time", item.time); _effects.add(inventory); } } hulls.put("hulls", _hulls); colormaps.put("colormaps", _colormaps); turrets.put("turrets", _turrets); inventory_items.put("inventory", _inventory); effects_items.put("effects", _effects); this._json_colormaps = colormaps.toJSONString(); this._json_hulls = hulls.toJSONString(); this._json_turrets = turrets.toJSONString(); this._json_inventory = inventory_items.toJSONString(); this._json_effects = effects_items.toJSONString();}
public void unparseJSONData() throws ParseException { this.items.clear(); JSONParser parser = new JSONParser(); JSONObject turrets = (JSONObject)parser.parse(this._json_turrets); JSONObject colormaps = (JSONObject)parser.parse(this._json_colormaps); JSONObject hulls = (JSONObject)parser.parse(this._json_hulls); JSONObject inventory; if (this._json_inventory != null && !this._json_inventory.isEmpty()) { inventory = (JSONObject)parser.parse(this._json_inventory); } else { inventory = null; } JSONObject effects; if ((this._json_effects != null) && (!this._json_effects.isEmpty())) effects = (JSONObject)parser.parse(this._json_effects); else { effects = null; }
Iterator var7 = ((JSONArray)turrets.get("turrets")).iterator(); Object inventory_item; JSONObject _item; Item item; while(var7.hasNext()) { inventory_item = var7.next(); _item = (JSONObject)inventory_item; item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone(); item.modificationIndex = (int)(long)_item.get("modification"); item.nextRankId = item.modifications[item.modificationIndex == 3 ? 3 : item.modificationIndex + 1].rank; item.nextPrice = item.modifications[item.modificationIndex == 3 ? 3 : item.modificationIndex + 1].price; this.items.add(item); if ((Boolean)_item.get("mounted")) { this.mountTurret = item; } } var7 = ((JSONArray)colormaps.get("colormaps")).iterator(); while(var7.hasNext()) { inventory_item = var7.next(); _item = (JSONObject)inventory_item; item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone(); item.modificationIndex = (int)(long)_item.get("modification"); this.items.add(item); if ((Boolean)_item.get("mounted")) { this.mountColormap = item; } } var7 = ((JSONArray)hulls.get("hulls")).iterator(); while(var7.hasNext()) { inventory_item = var7.next(); _item = (JSONObject)inventory_item; item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone(); item.modificationIndex = (int)(long)_item.get("modification"); item.nextRankId = item.modifications[item.modificationIndex == 3 ? 3 : item.modificationIndex + 1].rank; item.nextPrice = item.modifications[item.modificationIndex == 3 ? 3 : item.modificationIndex + 1].price; this.items.add(item); if ((Boolean)_item.get("mounted")) { this.mountHull = item; } } if (inventory != null) { var7 = ((JSONArray)inventory.get("inventory")).iterator(); while(var7.hasNext()) { inventory_item = var7.next(); _item = (JSONObject)inventory_item; item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone(); item.modificationIndex = 0; item.count = (int)(long)_item.get("count"); if (item.itemType == ItemType.INVENTORY) { this.items.add(item); } } } if (effects != null) { var7 = ((JSONArray)effects.get("effects")).iterator(); while (var7.hasNext()) { inventory_item = var7.next(); _item = (JSONObject)inventory_item; item = ((Item)GarageItemsLoader.items.get(_item.get("id"))).clone(); item.modificationIndex = 0; item.time = (long)_item.get("time"); new SimpleTimer(this, item); if (item.itemType == ItemType.PLUGIN) { this.items.add(item); } } }}
public String get_json_turrets() { return this._json_turrets; }
public void set_json_turrets(String _json_turrets) { this._json_turrets = _json_turrets; }
public String get_json_hulls() { return this._json_hulls; }
public void set_json_hulls(String _json_hulls) { this._json_hulls = _json_hulls; }
public String get_json_colormaps() { return this._json_colormaps; }
public void set_json_colormaps(String _json_colormaps) { this._json_colormaps = _json_colormaps; }
public String getUserId() { return this.userId; }
public void setUserId(String userId) { this.userId = userId; }
public String get_json_inventory() { return this._json_inventory; }
public void set_json_inventory(String _json_inventory) { this._json_inventory = _json_inventory; } } как сделать чтобы при покупке предмета с id "1000_scores " он не добавлялся в гараж игрока
- Assistant
Чтобы предотвратить добавление предмета с id "1000_scores" в гараж игрока при покупке, вам нужно внести следующие изменения в метод buyItem:
public boolean buyItem(String id, int count) { if (id.equals("1000_scores")) { return false; } Item temp = (Item)GarageItemsLoader.items.get(id.substring(0, id.length() - 3)); if (temp.specialItem) { return false; } else { Item item = temp.clone(); if (!this.items.contains(this.getItemById(id))) { if (item.isInventory) { item.count += count; } this.items.add(item); return true; } else if (item.isInventory) { Item fromUser = this.getItemById(id); fromUser.count += count; return true; } else { return false; } } }В этой версии метода, перед проверкой наличия предмета с id "1000_scores", мы проверяем сам id. Если id равен "1000_scores", то метод возвращает false и предмет не будет добавлен в гараж игрока.
- User
все равно добавился
- Assistant
Извините за путаницу. Приношу извинения за предыдущую ошибочную информацию.
Для предотвращения добавления предмета с id "1000_scores" в гараж игрока при покупке, вам нужно внести изменения в метод buyItem следующим образом:
public boolean buyItem(String id, int count) { String itemId = id.substring(0, id.length() - 3); if (itemId.equals("1000_scores")) { return false; } Item temp = (Item)GarageItemsLoader.items.get(itemId); if (temp.specialItem) { return false; } else { Item item = temp.clone(); if (!this.items.contains(this.getItemById(itemId))) { if (item.itemType == ItemType.INVENTORY) { item.count += count; } this.items.add(item); return true; } else if (item.itemType == ItemType.INVENTORY) { Item fromUser = this.getItemById(itemId); fromUser.count += count; return true; } else { return false; } } }В этой версии метода, вместо передачи id без удаления последних 3 символов, мы присваиваем его другой переменной с именем itemId. Затем мы проверяем, равен ли itemId "1000_scores", и если да, то метод возвращает false и предмет не будет добавлен в гараж игрока.
- User
все равно же добавилось
- Assistant
Извините за путаницу. Я понимаю вашу проблему. У вас возникают проблемы с добавлением предмета с id "1000_scores". Чтобы предотвратить его добавление в гараж игрока при покупке, вам нужно внести следующие изменения в метод buyItem:
public boolean buyItem(String id, int count) { String itemId = id.substring(0, id.length() - 3); if (itemId.equals("1000_scores")) { return false; } Item temp = (Item)GarageItemsLoader.items.get(itemId); if (temp.specialItem) { return false; } else { Item item = temp.clone(); if (item.itemType != ItemType.INVENTORY) { return false; } Item existingItem = this.getItemById(itemId); if (existingItem != null) { existingItem.count += count; } else { item.count = count; this.items.add(item); } return true; } }В этой версии метода мы сначала проверяем, является ли id "1000_scores". Если это так, то метод возвращает false и предмет не добавляется в гараж игрока.
Затем мы проверяем, является ли предмет типом ItemType.INVENTORY. Если нет, то метод также возвращает false и предмет не добавляется в гараж игрока.
Если предмет является типом ItemType.INVENTORY, мы проверяем, существует ли уже предмет с таким id в гараже игрока. Если да, то увеличиваем его count на указанное значение count. Если нет, то создаем новый предмет с указанным count и добавляем его в гараж игрока.
Проверьте эти изменения и убедитесь, что предмет с id "1000_scores" больше не добавляется в гараж игрока при покупке.
- User
ВСЕ РАВНО ДОБАВЛЯЕТСЯ
- Assistant
Извините за предыдущие путаницу. Чтобы предотвратить добавление предмета с id "1000_scores" в гараж игрока при покупке, вам нужно внести следующие изменения в метод buyItem:
public boolean buyItem(String id, int count) { String itemId = id.substring(0, id.length() - 3); if (itemId.equals("1000_scores")) { return false; } Item temp = (Item)GarageItemsLoader.items.get(itemId); if (temp.specialItem) { return false; } else { Item item = temp.clone(); if (!this.items.contains(this.getItemById(itemId))) { if (item.itemType == ItemType.INVENTORY) { item.count += count; } this.items.add(item); return true; } else if (item.itemType == ItemType.INVENTORY) { Item fromUser = this.getItemById(itemId); fromUser.count += count; return true; } else { return false; } } }В этой версии метода, вместо передачи id без удаления последних 3 символов, мы присваиваем его другой переменной с именем itemId. Затем мы проверяем, равен ли itemId "1000_scores", и если да, то метод возвращает false и предмет не будет добавлен в гараж игрока. Убедитесь, что в платформе, в которой используется этот код, код изменяется корректно и перестает добавлять предмет с id "1000_scores" в гараж иг
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.