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:
parent
d12cc4c9db
commit
48ba66f470
@ -196,17 +196,32 @@ export class HideoutHelper
|
|||||||
public updatePlayerHideout(sessionID: string): void
|
public updatePlayerHideout(sessionID: string): void
|
||||||
{
|
{
|
||||||
const pmcData = this.profileHelper.getPmcProfile(sessionID);
|
const pmcData = this.profileHelper.getPmcProfile(sessionID);
|
||||||
const hideoutProperties = {
|
const hideoutProperties = this.getHideoutProperties(pmcData);
|
||||||
btcFarmCGs: 0,
|
|
||||||
isGeneratorOn: false,
|
|
||||||
waterCollectorHasFilter: false
|
|
||||||
};
|
|
||||||
|
|
||||||
this.updateAreasWithResources(sessionID, pmcData, hideoutProperties);
|
this.updateAreasWithResources(sessionID, pmcData, hideoutProperties);
|
||||||
this.updateProductionTimers(pmcData, hideoutProperties);
|
this.updateProductionTimers(pmcData, hideoutProperties);
|
||||||
pmcData.Hideout.sptUpdateLastRunTimestamp = this.timeUtil.getTimestamp();
|
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
|
* Update progress timer for water collector
|
||||||
* @param pmcData profile to update
|
* @param pmcData profile to update
|
||||||
@ -341,18 +356,13 @@ export class HideoutHelper
|
|||||||
switch (area.type)
|
switch (area.type)
|
||||||
{
|
{
|
||||||
case HideoutAreas.GENERATOR:
|
case HideoutAreas.GENERATOR:
|
||||||
hideoutProperties.isGeneratorOn = area.active;
|
|
||||||
|
|
||||||
if (hideoutProperties.isGeneratorOn)
|
if (hideoutProperties.isGeneratorOn)
|
||||||
{
|
{
|
||||||
this.updateFuel(area, pmcData);
|
this.updateFuel(area, pmcData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HideoutAreas.WATER_COLLECTOR:
|
case HideoutAreas.WATER_COLLECTOR:
|
||||||
this.updateWaterCollector(sessionID, pmcData, area, hideoutProperties.isGeneratorOn);
|
this.updateWaterCollector(sessionID, pmcData, area, hideoutProperties.isGeneratorOn);
|
||||||
hideoutProperties.waterCollectorHasFilter = this.doesWaterCollectorHaveFilter(area);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HideoutAreas.AIR_FILTERING:
|
case HideoutAreas.AIR_FILTERING:
|
||||||
@ -361,16 +371,6 @@ export class HideoutHelper
|
|||||||
this.updateAirFilters(area, pmcData);
|
this.updateAirFilters(area, pmcData);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case HideoutAreas.BITCOIN_FARM:
|
|
||||||
for (const slot of area.slots)
|
|
||||||
{
|
|
||||||
if (slot.item)
|
|
||||||
{
|
|
||||||
hideoutProperties.btcFarmCGs++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user