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); }
codestatic fromJSON(data) { var item = new GarageItem(c(data.id), c(data.modificationID, 0), c(data.count, 0)); 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) { this.id = id; var info = GarageItem.getInfo(id); if (info !== null) { this.name = info.name; this.description = info.description; this.index = info.index; this.modification = info.modification; } else { this.name = "null"; this.description = ""; 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; } 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 }; } - Assistant
To add multicounted to the GarageItem class, you can modify the constructor and the toObject method as follows:
javascriptclass GarageItem { // ... constructor(id, modificationID = 0, count = 0, multicounted = false) { // ... if (this.type > 3 && multicounted) { this.count = count; } else { this.count = 1; } // ... } // ... toObject() { return { id: this.id, count: this.count, modificationID: this.modificationID, multicounted: this.type > 3 }; } }With this modification, you can now pass an optional
multicountedparameter to the constructor to set thecountproperty if the item type is greater than 3 (indicating it's multicounted). Additionally, themulticountedproperty will be included when converting the GarageItem instance to an object using thetoObjectmethod. - User
- Assistant
To include the
multicountedproperty in theupdateMarketfunction, you can modify it as follows:javascriptupdateMarket() { this.market = { items: [] }; for (var i in market_list) { if (!this.hasItem(market_list[i]["id"]) && market_list[i]["index"] >= 0 && !market_list[i]["multicounted"]) { // Check if item is not multicounted this.market.items.push(market_list[i]); } if (market_list[i]["multicounted"]) { // Check if item is multicounted var info = GarageItem.getInfo(market_list[i]["id"]); if (info !== null) { info.multicounted = true; this.market.items.push(info); } } } }This modification checks if an item is
multicountedand if so, retrieves the item information using the method and adds the property to the item. The item is then added to the market list. - User
- Assistant
To add the
multicountedproperty to theGarageItemclass based on themarket.jsonfile, you can modify thestatic getInfomethod to include themulticountedproperty in the item's information:javascriptstatic getInfo(id) { for (var i in market_list) { if (market_list[i]["id"] === id) { var info = market_list[i]; info.multicounted = market_list[i]["multicounted"]; return info; } } return null; }With this modification, the
multicountedproperty will be included in the item's information when calling thegetInfomethod.Additionally, you can update the
constructorto set the property based on the item's type: - User
- Assistant
To add the
multicountedproperty to theGarageItemclass based on a separate file that contains its value (market.jsonin this case), you can modify thestatic getInfomethod as follows:javascriptconst marketData = require("./market.json"); static getInfo(id) { for (var i in market_list) { if (market_list[i]["id"] === id) { var info = market_list[i]; var multicountedValue = marketData[id]["multicounted"]; // Assuming marketData is an object containing item information from market.json info.multicounted = multicountedValue !== undefined ? multicountedValue : false; // Set multicounted value from marketData, defaults to false if not provided return info; } } return null; } - User
все равно ничего не поменялось не появилось количества предмета, и нету возмжности его купить в нескольких штука
- Assistant
I apologize for the confusion. To enable the ability to specify the quantity of an item and allow purchasing multiple items, you need to make the following modifications to the
GarageItemclass:- In the
constructor, set thecountproperty only if the item has a type greater than 3 (indicating it's a multicounted item):
javascriptthis.count = this.type > 3 ? count : 1;- In the
attempt_upgrademethod, check
- In the