const { c, marketlist, getType } = require("./server"); class GarageItem { static…
- User
const { c, market_list, getType } = require("./server"); class GarageItem { static get(id, m = 1) { return new GarageItem(id, 0, m); }
static fromJSON(data) { var item = new GarageItem(c(data.id), c(data.modificationID, 0), c(data.count, 0), c(data.multiCounted)); return item; } static getInfo(id) { for (var i in market_list) { if (market_list[i]["id"] === id) return market_list[i]; } return null; } constructor(id, modificationID = 0, count = 0, multiCounted = false) { this.id = id; var info = GarageItem.getInfo(id); if (info !== null) { this.name = info.name; this.description = info.description; this.discount = info.discount; this.index = info.index; this.modification = info.modification; this.multiCounted = multiCounted; } else { this.name = "null"; this.description = ""; this.discount = ""; this.index = 3; this.modification = []; } this.modificationID = modificationID; this.type = getType(this.id); this.price = 0; this.rank = 0; this.properts = []; if (this.type > 3) this.count = count; var modifications = this.modification; if (typeof (modifications[modificationID]) !== "undefined") { this.price = modifications[modificationID].price; this.rank = modifications[modificationID].rank; this.properts = modifications[modificationID].properts; } if (modificationID >= modifications.length - 1) { this.next_price = this.price; this.next_rank = this.rank; } else { this.next_price = modifications[modificationID + 1].price; this.next_rank = modifications[modificationID + 1].rank; } this.isInventory = this.type === 4; this.multicounted = this.type === 4; } attempt_upgrade(tank) { if (this.type < 3 && this.modificationID < 3 && tank.crystals >= this.price && tank.rank >= this.rank) { tank.crystals -= this.next_price; this.modificationID++; var modificationID = this.modificationID, modifications = this.modification; if (typeof (modifications[modificationID]) !== "undefined") { this.price = modifications[modificationID].price; this.rank = modifications[modificationID].rank; this.properts = modifications[modificationID].properts; } if (modificationID >= modifications.length - 1) { this.next_price = this.price; this.next_rank = this.rank; } else { this.next_price = modifications[modificationID + 1].price; this.next_rank = modifications[modificationID + 1].rank; } return true; } return false; } toObject() { return { id: this.id, count: this.count, modificationID: this.modificationID, multiCounted: this.multiCounted }; }}
module.exports = GarageItem; что если после покупки, пропадает мультипокупка
- Assistant
Если после покупки мультипокупка исчезает, то это может быть связано с тем, что в конструкторе класса GarageItem устанавливается значение поля multiCounted равное false. Если вы хотите, чтобы мультипокупка сохранялась, вам нужно передать этому полю значение true при создании экземпляра класса GarageItem. Например:
return new GarageItem(id, 0, m, true);Таким образом, при покупке элемента, значение multiCounted будет сохраняться и не будет изменяться на false.
- User
а куда это добавить
- Assistant
Вы можете добавить это изменение в конструктор класса GarageItem, как показано ниже:
constructor(id, modificationID = 0, count = 0, multiCounted = false) { this.id = id; var info = GarageItem.getInfo(id); if (info !== null) { this.name = info.name; this.description = info.description; this.discount = info.discount; this.index = info.index; this.modification = info.modification; this.multiCounted = multiCounted; } else { this.name = "null"; this.description = ""; this.discount = ""; this.index = 3; this.modification = []; } this.modificationID = modificationID; this.type = getType(this.id); this.price = 0; this.rank = 0; this.properts = []; if (this.type > 3) this.count = count; var modifications = this.modification; if (typeof (modifications[modificationID]) !== "undefined") { this.price = modifications[modificationID].price; this.rank = modifications[modificationID].rank; this.properts = modifications[modificationID].properts; } if (modificationID >= modifications.length - 1) { this.next_price = this.price; this.next_rank = this.rank; } else { this.next_price = modifications[modificationID + 1].price; this.next_rank = modifications[modificationID + 1].rank; } this.isInventory = this.type === 4; this.multicounted = multiCounted; } - User
к сожалению после покупки мультипокупка все равно пропадает
- Assistant
Если мультипокупка все равно пропадает после покупки, то проблема может быть связана с другой частью вашего кода. Обратите внимание на то, где и как сохраняется экземпляр класса GarageItem после покупки. Убедитесь, что вы правильно сохраняете экземпляр в нужной переменной или структуре данных.
Также, проверьте код, который обрабатывает покупку. Убедитесь, что вы правильно создаете новый экземпляр GarageItem после покупки и передаете правильные значения для параметров, включая multiCounted, чтобы сохранить эту информацию.
Если проблема не решается, рекомендуется более подробно изучить код, связанный с покупкой и использованием класса GarageItem, чтобы найти причину пропадания мультипокупки и найти соответствующее решение.
- User
- Assistant
В данном коде, добавление мультипокупки можно провести путем изменения кода метода
addGarageItemв классеGarage.addGarageItem(id, amount) { var tank = this.tank; var new_item = GarageItem.get(id, 0, true); // Установка значения multiCounted в true if (new_item !== null) { var item = tank.garage.getItem(id); if (item === null) { new_item.count = amount; this.addItem(new_item); } else { item.count += amount; } } return true; }Теперь, при вызове
addGarageItem, экземплярыGarageItemбудут создаваться с установленным значениемmultiCountedравнымtrue, что сохранит мультипокупку при покупке элемента. - User
все равно пропадает мультипокупка
- Assistant
При изучении ваш
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.