diff --git a/README.md b/README.md new file mode 100644 index 0000000..3171245 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# The Trader - Perfect Food Mod +This mod changes the Township skill in Melvor Idle to allow perfect food to count towards the 10,000 item requirement at the trading post, instead of only normal food counting. + +## Installation +Subscribe to the mod using the in-game mod manager or at [mod.io](https://mod.io/g/melvoridle/m/the-trader-perfect-food-mod) and refresh the game. + +## Compatibility +This mod is compatible with version 1.1.1 of Melvor Idle. + +## Contributing +If you find any bugs or issues with the mod, please report them on the mod repository or GitHub. Additionally you can submit a pull request with a fix. +Goto [Mod Creation/Getting Started](https://wiki.melvoridle.com/w/Mod_Creation/Getting_Started) get started. + +## License +This mod is released under the [GNU General Public License v3.0](https://github.com/minusnolldag/the-trader-perfect-food-mod/blob/main/LICENSE). + +## Credits +Massive thanks to the Melvor Idle development team for creating such a great game. \ No newline at end of file diff --git a/assets/gallery.png b/assets/gallery.png new file mode 100644 index 0000000..069a148 Binary files /dev/null and b/assets/gallery.png differ diff --git a/assets/icon.svg b/assets/icon.svg new file mode 100644 index 0000000..8f9e8e9 --- /dev/null +++ b/assets/icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/assets/the-trader-perfect-food-mod.png b/assets/the-trader-perfect-food-mod.png new file mode 100644 index 0000000..1c8eb97 Binary files /dev/null and b/assets/the-trader-perfect-food-mod.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..2e86373 --- /dev/null +++ b/manifest.json @@ -0,0 +1,5 @@ +{ + "namespace": "the_trader_perfect_food_mod", + "icon": "assets/icon.svg", + "setup": "scripts/setup.mjs" +} \ No newline at end of file diff --git a/scripts/setup.mjs b/scripts/setup.mjs new file mode 100644 index 0000000..b029c34 --- /dev/null +++ b/scripts/setup.mjs @@ -0,0 +1,149 @@ +export function setup({ patch }) { + let perfectFood = game.items.food.filter((item) => { + return item.localID.includes('_Perfect'); + }); + + // township.js + patch(TownshipUI, "updateConvertVisibility").replace(function(o) { + this.township.resources.forEach((resource) => { + const conversions = this.conversionElements.get(resource); + + if (conversions === undefined) { + return; + } + + resource.itemConversions.forEach((item, i) => { + if (resource.localID == "Food") { + let perfectFoodItem = perfectFood.find(p => p.localID == item.localID + "_Perfect"); + + if (perfectFoodItem !== undefined) { + if (game.stats.itemFindCount(item) > 0 || game.stats.itemFindCount(perfectFoodItem)) { + showElement(conversions.convertTo[i]); + + if (game.stats.itemFindCount(item) + game.stats.itemFindCount(perfectFoodItem) < 10000 && this.township.convertType === 1) { + conversions.convertTo[i].convertButton.classList.replace('no-bg', 'bg-trader-locked'); + } else { + conversions.convertTo[i].convertButton.classList.replace('bg-trader-locked', 'no-bg'); + } + } else { + hideElement(conversions.convertTo[i]); + } + } else { + hideElement(conversions.convertTo[i]); + } + } else { + if (game.stats.itemFindCount(item) > 0) { + showElement(conversions.convertTo[i]); + + if (game.stats.itemFindCount(item) < 10000 && this.township.convertType === 1) { + conversions.convertTo[i].convertButton.classList.replace('no-bg', 'bg-trader-locked'); + } else { + conversions.convertTo[i].convertButton.classList.replace('bg-trader-locked', 'no-bg'); + } + } else { + hideElement(conversions.convertTo[i]); + } + } + }); + }); + }); + + // townshipMenus.js + patch(TownshipConversionElement, "getTooltip").replace(function(o, resource, item) { + let text = game.township.convertType === 0 ? `${item.name} => ${resource.name}` : `${resource.name} => ${item.name}`; + + if (resource.localID == "Food") { + let perfectFoodItem = perfectFood.find(p => p.localID == item.localID + "_Perfect"); + + if (perfectFoodItem !== undefined) { + text += `
In Bank: ${numberWithCommas(game.bank.getQty(item) + game.bank.getQty(perfectFoodItem))}`; + text += `
Total found: ${numberWithCommas(game.stats.itemFindCount(item) + game.stats.itemFindCount(perfectFoodItem))}`; + + if (game.stats.itemFindCount(item) + game.stats.itemFindCount(perfectFoodItem) < 10000) { + text += `
${templateString(getLangString('TOWNSHIP_MENU', 'TRADER_COUNT_REMAINING'), { + value: `${numberWithCommas(10000 - (game.stats.itemFindCount(item) + game.stats.itemFindCount(perfectFoodItem)))}`, + })}`; + } + } + } else { + text += `
In Bank: ${numberWithCommas(game.bank.getQty(item))}`; + text += `
Total found: ${numberWithCommas(game.stats.itemFindCount(item))}`; + + if (game.stats.itemFindCount(item) < 10000) { + text += `
${templateString(getLangString('TOWNSHIP_MENU', 'TRADER_COUNT_REMAINING'), { + value: `${numberWithCommas(10000 - game.stats.itemFindCount(item))}`, + })}`; + } + } + + return text; + }); + + // townshipMenus.js + patch(TownshipConversionElement, "createConvertFromSwal").replace(function(o, resource, item, township) { + if (resource.localID == "Food") { + let perfectFoodItem = perfectFood.find(p => p.localID == item.localID + "_Perfect"); + + if (game.stats.itemFindCount(item) + game.stats.itemFindCount(perfectFoodItem) < 10000) { + return; + } + } else { + if (game.stats.itemFindCount(item) < 10000) { + return; + } + } + + if (game.settings.enableQuickConvert) { + township.updateConvertFromQty(township.convertQtyPercent, resource, item); + township.processConversionFromTownship(item, resource); + return; + } + const element = new TownshipConversionSwalTemplate(); + element.setConvertFromImage(resource.media); + element.setConvertToImage(item.media); + element.setConvertToRatioQuantity(1); + element.setConvertFromRatioQuantity(township.getBaseConvertFromTownshipRatio(resource, item)); + element.setConvertButtons(resource, item, 1); + const ratio = game.township.getConvertToTownshipRatio(resource, item); + const resourceQty = Math.floor(resource.amount); + element.setConvertFromQuantity(ratio, resourceQty); + element.setConvertToQuantity(township.convertQty); + element.setConvertFromQuantityInput(township.convertQty, resource, item); + element.setTraderStock(township); + SwalLocale.fire({ + title: item.name, + html: element, + showCancelButton: true, + confirmButtonText: getLangString('MENU_TEXT', 'CONFIRM'), + }).then((result)=>{ + if (result.isConfirmed) + township.processConversionFromTownship(item, resource); + } + ); + }); + + // townshipMenus.js + patch(TownshipConversionElement, "updateConvertFromRatio").replace(function(o, resource, item, township) { + if (resource.localID == "Food") { + let perfectFoodItem = perfectFood.find(p => p.localID == item.localID + "_Perfect"); + + if (game.stats.itemFindCount(item) + game.stats.itemFindCount(perfectFoodItem) < 10000) { + this.convertQuantity.innerHTML = ``; + this.convertQuantity.classList.replace('bg-secondary', 'bg-danger'); + + return; + } + } else { + if (game.stats.itemFindCount(item) < 10000) { + this.convertQuantity.innerHTML = ``; + this.convertQuantity.classList.replace('bg-secondary', 'bg-danger'); + + return; + } + } + + this.convertQuantity.classList.replace('bg-danger', 'bg-secondary'); + const ratio = township.getBaseConvertFromTownshipRatio(resource, item); + this.convertQuantity.textContent = `${numberWithCommas(ratio)} => 1`; + }); +} \ No newline at end of file