Index: binaries/data/mods/public/gui/session/menu.js =================================================================== --- binaries/data/mods/public/gui/session/menu.js +++ binaries/data/mods/public/gui/session/menu.js @@ -31,7 +31,7 @@ /** * Quantity of goods to sell per click. */ -const g_BarterResourceSellQuantity = 100; +const g_BarterResourceSellQuantity = 1; /** * Multiplier to be applied when holding the massbarter hotkey. Index: binaries/data/mods/public/simulation/components/Barter.js =================================================================== --- binaries/data/mods/public/simulation/components/Barter.js +++ binaries/data/mods/public/simulation/components/Barter.js @@ -94,7 +94,6 @@ { var amountToAdd = Math.round(prices["sell"][resourceToSell] / prices["buy"][resourceToBuy] * amount); cmpPlayer.AddResource(resourceToBuy, amountToAdd); - var numberOfDeals = Math.round(amount / 100); // Display chat message to observers var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); @@ -116,11 +115,12 @@ } // Increase price difference for both exchange resources. - // Overal price difference (constant + dynamic) can't exceed +-99% + // Overall price difference (constant + dynamic) can't exceed +-99% // so both buy/sell prices limited to [1%; 199%] interval. - this.priceDifferences[resourceToSell] -= this.DIFFERENCE_PER_DEAL * numberOfDeals; + var difference = this.DIFFERENCE_PER_DEAL * Math.ceil(amount / 100) + this.priceDifferences[resourceToSell] -= difference; this.priceDifferences[resourceToSell] = Math.min(99 - this.CONSTANT_DIFFERENCE, Math.max(this.CONSTANT_DIFFERENCE - 99, this.priceDifferences[resourceToSell])); - this.priceDifferences[resourceToBuy] += this.DIFFERENCE_PER_DEAL * numberOfDeals; + this.priceDifferences[resourceToBuy] += difference; this.priceDifferences[resourceToBuy] = Math.min(99 - this.CONSTANT_DIFFERENCE, Math.max(this.CONSTANT_DIFFERENCE - 99, this.priceDifferences[resourceToBuy])); } Index: binaries/data/mods/public/simulation/components/tests/test_Barter.js =================================================================== --- binaries/data/mods/public/simulation/components/tests/test_Barter.js +++ binaries/data/mods/public/simulation/components/tests/test_Barter.js @@ -82,7 +82,7 @@ TS_ASSERT(cmpBarter.PlayerHasMarket(11)); // ExchangeResources -// Price differences magnitude are caped by 99 - CONSTANT_DIFFERENCE. +// Price differences magnitude are capped by 99 - CONSTANT_DIFFERENCE. // If we have a bigger DIFFERENCE_PER_DEAL than 99 - CONSTANT_DIFFERENCE at each deal we reach the cap. TS_ASSERT(cmpBarter.DIFFERENCE_PER_DEAL < 99 - cmpBarter.CONSTANT_DIFFERENCE); @@ -94,12 +94,12 @@ TS_ASSERT_EQUALS(sold, 100); TS_ASSERT_EQUALS(bought, Math.round(100 * (100 - cmpBarter.CONSTANT_DIFFERENCE + 0) / (100 + cmpBarter.CONSTANT_DIFFERENCE + 0))); -// With an amount which is not a multiple of 100, price differences are not updated. That sounds wrong. +// If the amount is not a multiple of 100. cmpBarter.priceDifferences = { "wood": 0, "stone": 0, "metal": 0 }; cmpBarter.ExchangeResources(11, "wood", "stone", 40); TS_ASSERT_EQUALS(cmpBarter.restoreTimer, 7); TS_ASSERT(timerActivated); -TS_ASSERT_UNEVAL_EQUALS(cmpBarter.priceDifferences, { "wood": 0, "stone": 0, "metal": 0 }); +TS_ASSERT_UNEVAL_EQUALS(cmpBarter.priceDifferences, { "wood": -cmpBarter.DIFFERENCE_PER_DEAL, "stone": cmpBarter.DIFFERENCE_PER_DEAL, "metal": 0 }); TS_ASSERT_EQUALS(sold, 40); TS_ASSERT_EQUALS(bought, Math.round(40 * (100 - cmpBarter.CONSTANT_DIFFERENCE + 0) / (100 + cmpBarter.CONSTANT_DIFFERENCE + 0)));