public Item buyItem(String id, int count, int nul) { id = id.substring(0, id.length() -…
- User
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; } }} как сюда добавить чтобы 1000_scores не добавлялась в гараж после покупки а если точнее заблокировать для этого предмета this.items.add(item);
- Assistant
Для того, чтобы предотвратить добавление предмета "1000_scores" в гараж после покупки, вы можете добавить условие перед строкой
this.items.add(item);, чтобы проверить, что id предмета не равно "1000_scores". Если они равны, тоthis.items.add(item);не выполняется. Ниже приведен измененный код: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; } // Проверка, что id предмета не равен "1000_scores" if (!id.equals("1000_scores")) { 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; } } } - Assistant
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; }
// Проверка, что id предмета не равен "1000_scores" if (!id.equals("1000_scores")) { 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; }} }