From 94d3699ce4aeec641884b6708edcb478534ef080 Mon Sep 17 00:00:00 2001 From: real_tabasco_sauce Date: Tue, 28 Oct 2025 20:57:53 -0600 Subject: [PATCH] Fix market exploit by basing the price change on the amount purchased. Fix credit to Atrik Credit for test fix goes to Itms Fixes #6760 --- binaries/data/mods/public/simulation/components/Barter.js | 2 +- .../mods/public/simulation/components/tests/test_Barter.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/binaries/data/mods/public/simulation/components/Barter.js b/binaries/data/mods/public/simulation/components/Barter.js index b22a6ace91..51d61af1ee 100644 --- a/binaries/data/mods/public/simulation/components/Barter.js +++ b/binaries/data/mods/public/simulation/components/Barter.js @@ -113,7 +113,7 @@ Barter.prototype.ExchangeResources = function(playerID, resourceToSell, resource cmpStatisticsTracker.IncreaseResourcesBoughtCounter(resourceToBuy, amountToAdd); } - const difference = this.DIFFERENCE_PER_DEAL * amount / this.DEAL_AMOUNT; + const difference = this.DIFFERENCE_PER_DEAL * amountToAdd / this.DEAL_AMOUNT; // Overall price difference (dynamic +/- constant) can't exceed +-99%. const maxDifference = this.DEAL_AMOUNT * 0.99; diff --git a/binaries/data/mods/public/simulation/components/tests/test_Barter.js b/binaries/data/mods/public/simulation/components/tests/test_Barter.js index 67a5944150..0f821bd3d8 100644 --- a/binaries/data/mods/public/simulation/components/tests/test_Barter.js +++ b/binaries/data/mods/public/simulation/components/tests/test_Barter.js @@ -100,7 +100,7 @@ cmpBarter.priceDifferences = { "wood": 0, "stone": 0, "metal": 0 }; cmpBarter.ExchangeResources(playerID, "wood", "stone", 100); TS_ASSERT_EQUALS(cmpBarter.restoreTimer, 7); TS_ASSERT(timerActivated); -TS_ASSERT_UNEVAL_EQUALS(cmpBarter.priceDifferences, { "wood": -cmpBarter.DIFFERENCE_PER_DEAL, "stone": cmpBarter.DIFFERENCE_PER_DEAL, "metal": 0 }); +TS_ASSERT_UNEVAL_EQUALS(cmpBarter.priceDifferences, { "wood": -cmpBarter.DIFFERENCE_PER_DEAL * bought / 100, "stone": cmpBarter.DIFFERENCE_PER_DEAL * bought / 100, "metal": 0 }); TS_ASSERT_EQUALS(sold, 100); TS_ASSERT_EQUALS(bought, Math.round(100 * (100 - cmpBarter.CONSTANT_DIFFERENCE + 0) / (100 + cmpBarter.CONSTANT_DIFFERENCE + 0))); @@ -125,12 +125,12 @@ TS_ASSERT_EQUALS(bought, 0); cmpBarter.priceDifferences = { "wood": 0, "stone": 99 - cmpBarter.CONSTANT_DIFFERENCE, "metal": 0 }; cmpBarter.ExchangeResources(playerID, "wood", "stone", 100); -TS_ASSERT_UNEVAL_EQUALS(cmpBarter.priceDifferences, { "wood": -cmpBarter.DIFFERENCE_PER_DEAL, "stone": 99 - cmpBarter.CONSTANT_DIFFERENCE, "metal": 0 }); +TS_ASSERT_UNEVAL_EQUALS(cmpBarter.priceDifferences, { "wood": -cmpBarter.DIFFERENCE_PER_DEAL * bought / 100, "stone": 99 - cmpBarter.CONSTANT_DIFFERENCE, "metal": 0 }); TS_ASSERT_EQUALS(bought, Math.round(100 * (100 - cmpBarter.CONSTANT_DIFFERENCE + 0) / (100 + cmpBarter.CONSTANT_DIFFERENCE + 99 - cmpBarter.CONSTANT_DIFFERENCE))); cmpBarter.priceDifferences = { "wood": -99 + cmpBarter.CONSTANT_DIFFERENCE, "stone": 0, "metal": 0 }; cmpBarter.ExchangeResources(playerID, "wood", "stone", 100); -TS_ASSERT_UNEVAL_EQUALS(cmpBarter.priceDifferences, { "wood": -99 + cmpBarter.CONSTANT_DIFFERENCE, "stone": cmpBarter.DIFFERENCE_PER_DEAL, "metal": 0 }); +TS_ASSERT_UNEVAL_EQUALS(cmpBarter.priceDifferences, { "wood": -99 + cmpBarter.CONSTANT_DIFFERENCE, "stone": cmpBarter.DIFFERENCE_PER_DEAL * bought / 100, "metal": 0 }); TS_ASSERT_EQUALS(bought, Math.round(100 * (100 - cmpBarter.CONSTANT_DIFFERENCE - 99 + cmpBarter.CONSTANT_DIFFERENCE) / (100 + cmpBarter.CONSTANT_DIFFERENCE + 0))); cmpBarter.priceDifferences = { "wood": 0, "stone": 0, "metal": 0 };