Skip to content

Commit

Permalink
Initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
minusnolldag committed Apr 1, 2023
1 parent 756fe86 commit e95c565
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file added assets/gallery.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions assets/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/the-trader-perfect-food-mod.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"namespace": "the_trader_perfect_food_mod",
"icon": "assets/icon.svg",
"setup": "scripts/setup.mjs"
}
149 changes: 149 additions & 0 deletions scripts/setup.mjs
Original file line number Diff line number Diff line change
@@ -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 ? `<small>${item.name} => ${resource.name}</small>` : `<small>${resource.name} => ${item.name}</small>`;

if (resource.localID == "Food") {
let perfectFoodItem = perfectFood.find(p => p.localID == item.localID + "_Perfect");

if (perfectFoodItem !== undefined) {
text += `<br><small class="text-warning">In Bank:</small> <small>${numberWithCommas(game.bank.getQty(item) + game.bank.getQty(perfectFoodItem))}</small>`;
text += `<br><small class="text-warning">Total found:</small> <small>${numberWithCommas(game.stats.itemFindCount(item) + game.stats.itemFindCount(perfectFoodItem))}</small>`;

if (game.stats.itemFindCount(item) + game.stats.itemFindCount(perfectFoodItem) < 10000) {
text += `<br><small class="text-danger">${templateString(getLangString('TOWNSHIP_MENU', 'TRADER_COUNT_REMAINING'), {
value: `<span class="text-white">${numberWithCommas(10000 - (game.stats.itemFindCount(item) + game.stats.itemFindCount(perfectFoodItem)))}</span>`,
})}</small>`;
}
}
} else {
text += `<br><small class="text-warning">In Bank:</small> <small>${numberWithCommas(game.bank.getQty(item))}</small>`;
text += `<br><small class="text-warning">Total found:</small> <small>${numberWithCommas(game.stats.itemFindCount(item))}</small>`;

if (game.stats.itemFindCount(item) < 10000) {
text += `<br><small class="text-danger">${templateString(getLangString('TOWNSHIP_MENU', 'TRADER_COUNT_REMAINING'), {
value: `<span class="text-white">${numberWithCommas(10000 - game.stats.itemFindCount(item))}</span>`,
})}</small>`;
}
}

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 = `<i class="fa fa-lock text-white"></i>`;
this.convertQuantity.classList.replace('bg-secondary', 'bg-danger');

return;
}
} else {
if (game.stats.itemFindCount(item) < 10000) {
this.convertQuantity.innerHTML = `<i class="fa fa-lock text-white"></i>`;
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`;
});
}

0 comments on commit e95c565

Please sign in to comment.