Refactor updateWaterFilters()
This commit is contained in:
parent
833f17ecdb
commit
60a11b28f2
@ -370,8 +370,12 @@ export class HideoutHelper
|
|||||||
|
|
||||||
protected updateWaterCollector(sessionId: string, pmcData: IPmcData, area: HideoutArea, isGeneratorOn: boolean): void
|
protected updateWaterCollector(sessionId: string, pmcData: IPmcData, area: HideoutArea, isGeneratorOn: boolean): void
|
||||||
{
|
{
|
||||||
if (area.level === 3)
|
// Skip water collector when not level 3
|
||||||
|
if (area.level !== 3)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const prod = pmcData.Hideout.Production[HideoutHelper.waterCollector];
|
const prod = pmcData.Hideout.Production[HideoutHelper.waterCollector];
|
||||||
if (prod && this.isProduction(prod))
|
if (prod && this.isProduction(prod))
|
||||||
{
|
{
|
||||||
@ -391,7 +395,6 @@ export class HideoutHelper
|
|||||||
this.registerProduction(pmcData, recipe, sessionId);
|
this.registerProduction(pmcData, recipe, sessionId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected doesWaterCollectorHaveFilter(waterCollector: HideoutArea): boolean
|
protected doesWaterCollectorHaveFilter(waterCollector: HideoutArea): boolean
|
||||||
{
|
{
|
||||||
@ -489,25 +492,18 @@ export class HideoutHelper
|
|||||||
*/
|
*/
|
||||||
protected updateWaterFilters(waterFilterArea: HideoutArea, production: Production, isGeneratorOn: boolean, pmcData: IPmcData): HideoutArea
|
protected updateWaterFilters(waterFilterArea: HideoutArea, production: Production, isGeneratorOn: boolean, pmcData: IPmcData): HideoutArea
|
||||||
{
|
{
|
||||||
// 100 resources last 8 hrs 20 min, 100/8.33/60/60 = 0.00333
|
let filterDrainRate = this.getWaterFilterDrainRate(pmcData);
|
||||||
let filterDrainRate = 0.00333;
|
const productionTime = this.getProductionTimeSeconds(HideoutHelper.waterCollector);
|
||||||
// Hideout management resource consumption bonus:
|
|
||||||
const hideoutManagementConsumptionBonus = 1.0 - this.getHideoutManagementConsumptionBonus(pmcData);
|
|
||||||
filterDrainRate *= hideoutManagementConsumptionBonus;
|
|
||||||
let productionTime = 0;
|
|
||||||
let pointsConsumed = 0;
|
|
||||||
|
|
||||||
const recipe = this.databaseServer.getTables().hideout.production.find(prod => prod._id === HideoutHelper.waterCollector);
|
|
||||||
productionTime = (recipe.productionTime || 0);
|
|
||||||
|
|
||||||
const timeElapsed = this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
|
const timeElapsed = this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
|
||||||
|
|
||||||
// Get filter drain rate, handle edge case when craft time has gone on longer than total production time
|
// Adjust filter drain rate based on elapsed time, handle edge case when craft time has gone on longer than total production time
|
||||||
filterDrainRate *= timeElapsed > productionTime
|
filterDrainRate *= timeElapsed > productionTime
|
||||||
? (productionTime - production.Progress)
|
? (productionTime - production.Progress)
|
||||||
: timeElapsed;
|
: timeElapsed;
|
||||||
|
|
||||||
// Production hasn't completed
|
// Production hasn't completed
|
||||||
|
let pointsConsumed = 0;
|
||||||
if (production.Progress < productionTime)
|
if (production.Progress < productionTime)
|
||||||
{
|
{
|
||||||
// Check all slots that take water filters
|
// Check all slots that take water filters
|
||||||
@ -546,8 +542,7 @@ export class HideoutHelper
|
|||||||
this.logger.debug(`Water filter: ${resourceValue} filter left on slot ${i + 1}`);
|
this.logger.debug(`Water filter: ${resourceValue} filter left on slot ${i + 1}`);
|
||||||
break; // Break here to avoid updating all filters
|
break; // Break here to avoid updating all filters
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Filter ran out / used up
|
// Filter ran out / used up
|
||||||
delete waterFilterArea.slots[i].item;
|
delete waterFilterArea.slots[i].item;
|
||||||
// Update remaining resources to be subtracted
|
// Update remaining resources to be subtracted
|
||||||
@ -555,12 +550,34 @@ export class HideoutHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return waterFilterArea;
|
return waterFilterArea;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the water filter drain rate based on hideout bonues player has
|
||||||
|
* @param pmcData Player profile
|
||||||
|
* @returns Drain rate
|
||||||
|
*/
|
||||||
|
protected getWaterFilterDrainRate(pmcData: IPmcData): number
|
||||||
|
{
|
||||||
|
// 100 resources last 8 hrs 20 min, 100/8.33/60/60 = 0.00333
|
||||||
|
const filterDrainRate = 0.00333;
|
||||||
|
const hideoutManagementConsumptionBonus = 1.0 - this.getHideoutManagementConsumptionBonus(pmcData);
|
||||||
|
|
||||||
|
return filterDrainRate * hideoutManagementConsumptionBonus;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the production time in seconds for the desired production
|
||||||
|
* @param prodId Id, e.g. Water collector id
|
||||||
|
* @returns seconds to produce item
|
||||||
|
*/
|
||||||
|
protected getProductionTimeSeconds(prodId: string): number
|
||||||
|
{
|
||||||
|
const recipe = this.databaseServer.getTables().hideout.production.find(prod => prod._id === prodId);
|
||||||
|
return (recipe.productionTime || 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a upd object using passed in parameters
|
* Create a upd object using passed in parameters
|
||||||
|
Loading…
Reference in New Issue
Block a user