Do not progress bitcoin production when power is off

Small cleanup of function to reduce nesting and duplication
This commit is contained in:
Dev 2024-09-20 17:24:22 +01:00
parent 23570f4e2a
commit f333d45d70

View File

@ -890,25 +890,16 @@ export class HideoutHelper {
protected updateBitcoinFarm(pmcData: IPmcData, btcFarmCGs: number, isGeneratorOn: boolean): Production | undefined { protected updateBitcoinFarm(pmcData: IPmcData, btcFarmCGs: number, isGeneratorOn: boolean): Production | undefined {
const btcProd = pmcData.Hideout.Production[HideoutHelper.bitcoinFarm]; const btcProd = pmcData.Hideout.Production[HideoutHelper.bitcoinFarm];
const bitcoinProdData = this.databaseService const isBtcProd = this.isProduction(btcProd);
.getHideout() if (!isBtcProd) {
.production.recipes.find((production) => production._id === HideoutHelper.bitcoinProductionId); return undefined;
const coinSlotCount = this.getBTCSlots(pmcData);
// Full on bitcoins, halt progress
if (this.isProduction(btcProd) && btcProd.Products.length >= coinSlotCount) {
// Set progress to 0
btcProd.Progress = 0;
return btcProd;
} }
if (this.isProduction(btcProd)) { // The wiki has a wrong formula!
// The wiki has a wrong formula! // Do not change unless you validate it with the Client code files!
// Do not change unless you validate it with the Client code files! // This formula was found on the client files:
// This formula was found on the client files: // *******************************************************
// ******************************************************* /*
/*
public override int InstalledSuppliesCount public override int InstalledSuppliesCount
{ {
get get
@ -926,44 +917,61 @@ export class HideoutHelper {
} }
} }
*/ */
// ********************************************************** // **********************************************************
// At the time of writing this comment, this was GClass1667 // At the time of writing this comment, this was GClass1667
// To find it in case of weird results, use DNSpy and look for usages on class AreaData // To find it in case of weird results, use DNSpy and look for usages on class AreaData
// Look for a GClassXXXX that has a method called "InitDetails" and the only parameter is the AreaData // Look for a GClassXXXX that has a method called "InitDetails" and the only parameter is the AreaData
// That should be the bitcoin farm production. To validate, try to find the snippet below: // That should be the bitcoin farm production. To validate, try to find the snippet below:
/* /*
protected override void InitDetails(AreaData data) protected override void InitDetails(AreaData data)
{ {
base.InitDetails(data); base.InitDetails(data);
this.gclass1678_1.Type = EDetailsType.Farming; this.gclass1678_1.Type = EDetailsType.Farming;
} }
*/ */
// BSG finally fixed their settings, they now get loaded from the settings and used in the client // Needs power to function
const adjustedCraftTime = if (!isGeneratorOn) {
(this.profileHelper.isDeveloperAccount(pmcData.sessionId) ? 40 : bitcoinProdData.productionTime) / // Return with no changes
(1 + (btcFarmCGs - 1) * this.databaseService.getHideout().settings.gpuBoostRate); return btcProd;
}
// The progress should be adjusted based on the GPU boost rate, but the target is still the base productionTime const coinSlotCount = this.getBTCSlots(pmcData);
const timeMultiplier = bitcoinProdData.productionTime / adjustedCraftTime;
const timeElapsedSeconds = this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
btcProd.Progress += Math.floor(timeElapsedSeconds * timeMultiplier);
while (btcProd.Progress >= bitcoinProdData.productionTime) { // Full on bitcoins, halt progress
if (btcProd.Products.length < coinSlotCount) { if (btcProd.Products.length >= coinSlotCount) {
// Has space to add a coin to production // Set progress to 0
this.addBtcToProduction(btcProd, bitcoinProdData.productionTime); btcProd.Progress = 0;
} else {
// Filled up bitcoin storage
btcProd.Progress = 0;
}
}
btcProd.StartTimestamp = this.timeUtil.getTimestamp().toString();
return btcProd; return btcProd;
} }
return undefined; const bitcoinProdData = this.databaseService
.getHideout()
.production.recipes.find((production) => production._id === HideoutHelper.bitcoinProductionId);
// BSG finally fixed their settings, they now get loaded from the settings and used in the client
const adjustedCraftTime =
(this.profileHelper.isDeveloperAccount(pmcData.sessionId) ? 40 : bitcoinProdData.productionTime) /
(1 + (btcFarmCGs - 1) * this.databaseService.getHideout().settings.gpuBoostRate);
// 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 rewards
this.addBtcToProduction(btcProd, bitcoinProdData.productionTime);
} else {
// Filled up bitcoin storage
btcProd.Progress = 0;
}
}
btcProd.StartTimestamp = this.timeUtil.getTimestamp().toString();
return btcProd;
} }
/** /**