Small improvements to updateFuel()

This commit is contained in:
Dev 2024-02-17 21:55:43 +00:00
parent 8853ff9aad
commit 5386ca8d5a

View File

@ -423,28 +423,30 @@ export class HideoutHelper
{ {
// 1 resource last 14 min 27 sec, 1/14.45/60 = 0.00115 // 1 resource last 14 min 27 sec, 1/14.45/60 = 0.00115
// 10-10-2021 From wiki, 1 resource last 12 minutes 38 seconds, 1/12.63333/60 = 0.00131 // 10-10-2021 From wiki, 1 resource last 12 minutes 38 seconds, 1/12.63333/60 = 0.00131
let fuelDrainRate = this.databaseServer.getTables().hideout.settings.generatorFuelFlowRate let fuelUsedSinceLastTick = this.databaseServer.getTables().hideout.settings.generatorFuelFlowRate
* this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn); * this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
const fuelBonus = pmcData.Bonuses.find((bonus) => bonus.type === BonusType.FUEL_CONSUMPTION); const fuelConsumptionBonus = pmcData.Bonuses.find((bonus) => bonus.type === BonusType.FUEL_CONSUMPTION);
const fuelBonusPercent = 1.0 - (fuelBonus ? Math.abs(fuelBonus.value) : 0) / 100; const fuelConsumptionBonusPercent = 1.0
fuelDrainRate *= fuelBonusPercent; - (fuelConsumptionBonus ? Math.abs(fuelConsumptionBonus.value) : 0) / 100;
fuelUsedSinceLastTick *= fuelConsumptionBonusPercent;
// Hideout management resource consumption bonus: // Hideout management resource consumption bonus:
const hideoutManagementConsumptionBonus = 1.0 - this.getHideoutManagementConsumptionBonus(pmcData); const hideoutManagementConsumptionBonus = 1.0 - this.getHideoutManagementConsumptionBonus(pmcData);
fuelDrainRate *= hideoutManagementConsumptionBonus; fuelUsedSinceLastTick *= hideoutManagementConsumptionBonus;
let hasFuelRemaining = false; let hasFuelRemaining = false;
let pointsConsumed = 0; let pointsConsumed = 0;
for (let i = 0; i < generatorArea.slots.length; i++) for (let i = 0; i < generatorArea.slots.length; i++)
{ {
if (!generatorArea.slots[i]?.item) const generatorSlot = generatorArea.slots[i];
if (!generatorSlot?.item)
{ {
// No item in slot, skip // No item in slot, skip
continue; continue;
} }
const fuelItemInSlot = generatorArea.slots[i]?.item[0]; const fuelItemInSlot = generatorSlot?.item[0];
if (!fuelItemInSlot) if (!fuelItemInSlot)
{ {
// No item in slot, skip // No item in slot, skip
@ -462,14 +464,14 @@ export class HideoutHelper
if (!fuelRemaining) if (!fuelRemaining)
{ {
const fuelItemTemplate = this.itemHelper.getItem(fuelItemInSlot._tpl)[1]; const fuelItemTemplate = this.itemHelper.getItem(fuelItemInSlot._tpl)[1];
pointsConsumed = fuelDrainRate; pointsConsumed = fuelUsedSinceLastTick;
fuelRemaining = fuelItemTemplate._props.MaxResource - fuelDrainRate; fuelRemaining = fuelItemTemplate._props.MaxResource - fuelUsedSinceLastTick;
} }
else else
{ {
// Fuel exists already, deduct fuel from item remaining value // Fuel exists already, deduct fuel from item remaining value
pointsConsumed = (fuelItemInSlot.upd.Resource.UnitsConsumed || 0) + fuelDrainRate; pointsConsumed = (fuelItemInSlot.upd.Resource.UnitsConsumed || 0) + fuelUsedSinceLastTick;
fuelRemaining -= fuelDrainRate; fuelRemaining -= fuelUsedSinceLastTick;
} }
fuelRemaining = Math.round(fuelRemaining * 10000) / 10000; fuelRemaining = Math.round(fuelRemaining * 10000) / 10000;
@ -484,6 +486,7 @@ export class HideoutHelper
if (fuelRemaining > 0) if (fuelRemaining > 0)
{ {
// Deducted all used fuel from this container, clean up and exit loop
fuelItemInSlot.upd = this.getAreaUpdObject(1, fuelRemaining, pointsConsumed); fuelItemInSlot.upd = this.getAreaUpdObject(1, fuelRemaining, pointsConsumed);
this.logger.debug( this.logger.debug(
@ -492,13 +495,14 @@ export class HideoutHelper
); );
hasFuelRemaining = true; hasFuelRemaining = true;
break; // Break here to avoid updating all the fuel tanks break; // Break to avoid updating all the fuel tanks
} }
fuelItemInSlot.upd = this.getAreaUpdObject(1, 0, 0); fuelItemInSlot.upd = this.getAreaUpdObject(1, 0, 0);
// Update remaining resources to be subtracted // Ran out of fuel items to deduct fuel from
fuelDrainRate = Math.abs(fuelRemaining); fuelUsedSinceLastTick = Math.abs(fuelRemaining);
this.logger.debug(`Profile: ${pmcData._id} Generator ran out of fuel`, true);
} }
// Out of fuel, flag generator as offline // Out of fuel, flag generator as offline