Fix bitcoin desync between client/server while offline (!225)

The server expects that the total "Progress" when a bitcoin is complete to be the "ProductionTime" value (145000 by default). However the server was using a modified target value, while only adding the actual time change to the Progress.
This results in a drift over time between the client/server while the server is stopped, as the client gets an incorrect value on startup.

If we instead scale the addition to Progress based on the adjusted craft time, and target the base productionTime for completion, we can get a much more accurate progress while offline that matches the client

I used the profile from this ticket for testing: https://dev.sp-tarkov.com/SPT-AKI/Issues/issues/496

The user has both an upgrade and bitcoin going at the same time, so they should progress at the same rate. This is what the code was previously resulting in:
![image](/attachments/fe428a3b-d271-40e1-a3f6-08ef936224b6)

While the server was shut down for 50 minutes (As noted by the upgrade), only 36 minutes was deducted from the bitcoin craft.

This is the result of that same profile after these changes were made:
![image](/attachments/d2ce44e6-1a0e-4991-aa51-3eb340c22ca5)

You can see that ~2 hours 25 minutes was deducted from both the upgrade, as well as the bitcoin craft timer. There is still a slight discrepancy, but in a total bitcoin run it should be minimal

Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com>
Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/225
Co-authored-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
Co-committed-by: DrakiaXYZ <drakiaxyz@noreply.dev.sp-tarkov.com>
This commit is contained in:
DrakiaXYZ 2024-02-15 08:57:26 +00:00 committed by chomp
parent 0cd6622714
commit d77c930396

View File

@ -770,9 +770,6 @@ export class HideoutHelper
if (this.isProduction(btcProd))
{
const timeElapsedSeconds = this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
btcProd.Progress += timeElapsedSeconds;
// The wiki has a wrong formula!
// Do not change unless you validate it with the Client code files!
// This formula was found on the client files:
@ -808,16 +805,21 @@ export class HideoutHelper
}
*/
// BSG finally fixed their settings, they now get loaded from the settings and used in the client
const coinCraftTimeSeconds =
const adjustedCraftTime =
((this.profileHelper.isDeveloperAccount(pmcData.sessionId)) ? 40 : bitcoinProdData.productionTime)
/ (1 + (btcFarmCGs - 1) * this.databaseServer.getTables().hideout.settings.gpuBoostRate);
while (btcProd.Progress >= coinCraftTimeSeconds)
// The progress should be adjusted based on the GPU boost rate, but the target is still the base productionTime
const timeMultiplier = bitcoinProdData.productionTime / adjustedCraftTime;
const timeElapsedSeconds = this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
btcProd.Progress += Math.floor(timeElapsedSeconds * timeMultiplier);
while (btcProd.Progress >= bitcoinProdData.productionTime)
{
if (btcProd.Products.length < coinSlotCount)
{
// Has space to add a coin to production
this.addBtcToProduction(btcProd, coinCraftTimeSeconds);
this.addBtcToProduction(btcProd, bitcoinProdData.productionTime);
}
else
{