Improve separation of concerns by moving hideout property gathering code out of updateAreasWithResources() and into own function getHideoutProperties()

Refactored how we get bitcoin count
This commit is contained in:
Dev 2023-06-02 13:54:03 +01:00
parent d12cc4c9db
commit 48ba66f470

View File

@ -196,16 +196,31 @@ export class HideoutHelper
public updatePlayerHideout(sessionID: string): void
{
const pmcData = this.profileHelper.getPmcProfile(sessionID);
const hideoutProperties = {
btcFarmCGs: 0,
isGeneratorOn: false,
waterCollectorHasFilter: false
};
const hideoutProperties = this.getHideoutProperties(pmcData);
this.updateAreasWithResources(sessionID, pmcData, hideoutProperties);
this.updateProductionTimers(pmcData, hideoutProperties);
pmcData.Hideout.sptUpdateLastRunTimestamp = this.timeUtil.getTimestamp();
}
/**
* Get various properties that will be passed to hideout update-related functions
* @param pmcData Player profile
* @returns Properties
*/
protected getHideoutProperties(pmcData: IPmcData): { btcFarmCGs: number; isGeneratorOn: boolean; waterCollectorHasFilter: boolean; }
{
const bitcoinFarm = pmcData.Hideout.Areas.find(x => x.type === HideoutAreas.BITCOIN_FARM);
const bitcoinCount = bitcoinFarm?.slots.filter(slot => slot.item).length ?? 0; // Get slots with an item property
const hideoutProperties = {
btcFarmCGs: bitcoinCount,
isGeneratorOn: pmcData.Hideout.Areas.find(x => x.type === HideoutAreas.GENERATOR)?.active ?? false,
waterCollectorHasFilter: this.doesWaterCollectorHaveFilter(pmcData.Hideout.Areas.find(x => x.type === HideoutAreas.WATER_COLLECTOR))
};
return hideoutProperties;
}
/**
* Update progress timer for water collector
@ -341,18 +356,13 @@ export class HideoutHelper
switch (area.type)
{
case HideoutAreas.GENERATOR:
hideoutProperties.isGeneratorOn = area.active;
if (hideoutProperties.isGeneratorOn)
{
this.updateFuel(area, pmcData);
}
break;
case HideoutAreas.WATER_COLLECTOR:
this.updateWaterCollector(sessionID, pmcData, area, hideoutProperties.isGeneratorOn);
hideoutProperties.waterCollectorHasFilter = this.doesWaterCollectorHaveFilter(area);
break;
case HideoutAreas.AIR_FILTERING:
@ -361,16 +371,6 @@ export class HideoutHelper
this.updateAirFilters(area, pmcData);
}
break;
case HideoutAreas.BITCOIN_FARM:
for (const slot of area.slots)
{
if (slot.item)
{
hideoutProperties.btcFarmCGs++;
}
}
break;
}
}
}