Cleaned up updateProductionTimers()

This commit is contained in:
Dev 2024-10-15 12:47:17 +01:00
parent f647c8ebce
commit 5496ab9557
3 changed files with 54 additions and 17 deletions

View File

@ -748,7 +748,7 @@ export class HideoutController {
* @param recipeId recipe id to save into Production dict * @param recipeId recipe id to save into Production dict
*/ */
protected addScavCaseRewardsToProfile(pmcData: IPmcData, rewards: IProduct[], recipeId: string): void { protected addScavCaseRewardsToProfile(pmcData: IPmcData, rewards: IProduct[], recipeId: string): void {
pmcData.Hideout.Production[`ScavCase${recipeId}`] = { Products: rewards }; pmcData.Hideout.Production[`ScavCase${recipeId}`] = { Products: rewards, RecipeId: recipeId };
} }
/** /**

View File

@ -253,7 +253,7 @@ export class HideoutHelper {
): void { ): void {
const recipes = this.databaseService.getHideout().production; const recipes = this.databaseService.getHideout().production;
// Check each production // Check each production and handle edge cases if necessary
for (const prodId in pmcData.Hideout.Production) { for (const prodId in pmcData.Hideout.Production) {
const craft = pmcData.Hideout.Production[prodId]; const craft = pmcData.Hideout.Production[prodId];
if (!craft) { if (!craft) {
@ -270,29 +270,26 @@ export class HideoutHelper {
craft.Progress = 0; craft.Progress = 0;
} }
// Craft complete, skip processing (Don't skip continious crafts like bitcoin farm or cultist circle) // Skip processing (Don't skip continious crafts like bitcoin farm or cultist circle)
if ( if (this.isCraftComplete(craft)) {
craft.Progress >= craft.ProductionTime &&
![HideoutHelper.bitcoinFarm, HideoutHelper.cultistCircleCraftId].includes(prodId)
) {
continue; continue;
} }
if (craft.sptIsScavCase) { // Special handling required
if (this.isCraftOfType(craft, HideoutAreas.SCAV_CASE)) {
this.updateScavCaseProductionTimer(pmcData, prodId); this.updateScavCaseProductionTimer(pmcData, prodId);
continue; continue;
} }
// Water collector if (this.isCraftOfType(craft, HideoutAreas.WATER_COLLECTOR)) {
if (prodId === HideoutHelper.waterCollector) {
this.updateWaterCollectorProductionTimer(pmcData, prodId, hideoutProperties); this.updateWaterCollectorProductionTimer(pmcData, prodId, hideoutProperties);
continue; continue;
} }
// Bitcoin farm handling // Continious craft
if (prodId === HideoutHelper.bitcoinFarm) { if (this.isCraftOfType(craft, HideoutAreas.BITCOIN_FARM)) {
this.updateBitcoinFarm( this.updateBitcoinFarm(
pmcData, pmcData,
pmcData.Hideout.Production[prodId], pmcData.Hideout.Production[prodId],
@ -303,8 +300,8 @@ export class HideoutHelper {
continue; continue;
} }
// Cultist circle has no recipe, needs special handling // No recipe, needs special handling
if (craft.sptIsCultistCircle) { if (this.isCraftOfType(craft, HideoutAreas.CIRCLE_OF_CULTISTS)) {
this.updateCultistCircleCraftProgress(pmcData, prodId); this.updateCultistCircleCraftProgress(pmcData, prodId);
continue; continue;
@ -322,6 +319,45 @@ export class HideoutHelper {
} }
} }
/**
* Is a craft from a particular hideout area
* @param craft Craft to check
* @param hideoutType Type to check craft against
* @returns True it is from that area
*/
protected isCraftOfType(craft: IProduction, hideoutType: HideoutAreas) {
switch (hideoutType) {
case HideoutAreas.WATER_COLLECTOR:
return craft.RecipeId === HideoutHelper.waterCollector;
case HideoutAreas.BITCOIN_FARM:
return craft.RecipeId === HideoutHelper.bitcoinFarm;
case HideoutAreas.SCAV_CASE:
return craft.sptIsScavCase;
case HideoutAreas.CIRCLE_OF_CULTISTS:
return craft.sptIsCultistCircle;
default:
this.logger.error(
`Unhandled hideout area: ${hideoutType}, assuming craft: ${craft.RecipeId} is not of this type`,
);
return false;
}
}
/**
* Has the craft completed
* Ignores bitcoin farm/cultist circle as they're continuous crafts
* @param craft Craft to check
* @returns True when craft is compelte
*/
protected isCraftComplete(craft: IProduction) {
return (
craft.Progress >= craft.ProductionTime &&
![HideoutHelper.bitcoinFarm, HideoutHelper.cultistCircleCraftId].includes(craft.RecipeId)
);
}
/** /**
* Update progress timer for water collector * Update progress timer for water collector
* @param pmcData profile to update * @param pmcData profile to update

View File

@ -131,6 +131,7 @@ export interface IHealth {
BodyParts: IBodyPartsHealth; BodyParts: IBodyPartsHealth;
UpdateTime: number; UpdateTime: number;
Immortal?: boolean; Immortal?: boolean;
sptEffectCheckTime: number;
} }
export interface IBodyPartsHealth { export interface IBodyPartsHealth {
@ -338,7 +339,7 @@ export interface IInsuredItem {
} }
export interface IHideout { export interface IHideout {
Production: Record<string, IProductive>; Production: Record<string, IProduction>;
Areas: IBotHideoutArea[]; Areas: IBotHideoutArea[];
Improvements: Record<string, IHideoutImprovement>; Improvements: Record<string, IHideoutImprovement>;
HideoutCounters: IHideoutCounters; HideoutCounters: IHideoutCounters;
@ -391,8 +392,8 @@ export interface IProductive {
export interface IProduction extends IProductive { export interface IProduction extends IProductive {
RecipeId: string; RecipeId: string;
SkipTime: number; SkipTime?: number;
ProductionTime: number; ProductionTime?: number;
} }
export interface IScavCase extends IProductive { export interface IScavCase extends IProductive {