Updated water filtering system to correctly check the craft progress against the ProductionTime value stored in the profile instead of the base ProductionTime value in the hideout json.

This is because the base value doesn't take into account any craft bonuses the profile has

After collecting a product from a continious craft, `ProductionTime` in the profiles craft data will be refreshed, this resolves issues with adjusting the `production.json` craft times not applying to continuous crafts
This commit is contained in:
Dev 2024-08-09 16:04:43 +01:00
parent 7b835f1501
commit 8014bdd06f
2 changed files with 76 additions and 57 deletions

View File

@ -227,10 +227,11 @@ export class HideoutController {
// Cleanup temporary fuel usage buffs from mopping floor if wall is complete as it would result in too many bonuses // Cleanup temporary fuel usage buffs from mopping floor if wall is complete as it would result in too many bonuses
// TODO: Clean up all buffs from mopping floor. // TODO: Clean up all buffs from mopping floor.
if (profileHideoutArea.type === HideoutAreas.EMERGENCY_WALL && profileHideoutArea.level === 6) if (profileHideoutArea.type === HideoutAreas.EMERGENCY_WALL && profileHideoutArea.level === 6) {
{
// Get everything except specific fuel consumption buffs // Get everything except specific fuel consumption buffs
pmcData.Bonuses = pmcData.Bonuses.filter(bonus => bonus.type !== BonusType.FUEL_CONSUMPTION && bonus.value >= -10 && bonus.value <= 0); pmcData.Bonuses = pmcData.Bonuses.filter(
(bonus) => bonus.type !== BonusType.FUEL_CONSUMPTION && bonus.value >= -10 && bonus.value <= 0,
);
} }
// Add Skill Points Per Area Upgrade // Add Skill Points Per Area Upgrade
@ -955,6 +956,16 @@ export class HideoutController {
pmcData.Hideout.Production[prodId].sptIsComplete = true; pmcData.Hideout.Production[prodId].sptIsComplete = true;
pmcData.Hideout.Production[prodId].sptIsContinuous = recipe.continuous; pmcData.Hideout.Production[prodId].sptIsContinuous = recipe.continuous;
// Continious recipies need the craft time refreshed as it gets created once on initial craft and stays the same regardless of what
// production.json is set to
if (recipe.continuous) {
pmcData.Hideout.Production[prodId].ProductionTime = this.hideoutHelper.getAdjustedCraftTimeWithSkills(
pmcData,
recipe._id,
true,
);
}
// Flag normal (non continious) crafts as complete // Flag normal (non continious) crafts as complete
if (!recipe.continuous) { if (!recipe.continuous) {
pmcData.Hideout.Production[prodId].inProgress = false; pmcData.Hideout.Production[prodId].inProgress = false;

View File

@ -420,7 +420,10 @@ export class HideoutHelper {
this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn); this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
// Get all fuel consumption bonuses, returns an empty array if none found // Get all fuel consumption bonuses, returns an empty array if none found
const profileFuelConsomptionBonusSum = this.profileHelper.getBonusValueFromProfile(pmcData,BonusType.FUEL_CONSUMPTION) const profileFuelConsomptionBonusSum = this.profileHelper.getBonusValueFromProfile(
pmcData,
BonusType.FUEL_CONSUMPTION,
);
// 0 to 1 // 0 to 1
const fuelConsumptionBonusMultipler = (profileFuelConsomptionBonusSum + 100) / 100; const fuelConsumptionBonusMultipler = (profileFuelConsomptionBonusSum + 100) / 100;
@ -612,72 +615,77 @@ export class HideoutHelper {
pmcData: IPmcData, pmcData: IPmcData,
): void { ): void {
let filterDrainRate = this.getWaterFilterDrainRate(pmcData); let filterDrainRate = this.getWaterFilterDrainRate(pmcData);
const productionTime = this.getTotalProductionTimeSeconds(HideoutHelper.waterCollector); const craftProductionTime = this.getTotalProductionTimeSeconds(HideoutHelper.waterCollector);
const secondsSinceServerTick = this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn); const secondsSinceServerTick = this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
filterDrainRate = this.getTimeAdjustedWaterFilterDrainRate( filterDrainRate = this.getTimeAdjustedWaterFilterDrainRate(
secondsSinceServerTick, secondsSinceServerTick,
productionTime, craftProductionTime,
production.Progress, production.Progress,
filterDrainRate, filterDrainRate,
); );
// Production hasn't completed // Production hasn't completed
let pointsConsumed = 0; let pointsConsumed = 0;
if (production.Progress < productionTime) {
// Check all slots that take water filters until we find one with filter in it
for (let i = 0; i < waterFilterArea.slots.length; i++) {
// No water filter, skip
if (!waterFilterArea.slots[i].item) {
continue;
}
const waterFilterItemInSlot = waterFilterArea.slots[i].item[0]; // Check progress against the productions craft time (dont use base time as it doesnt include any time bonuses profile has)
if (production.Progress > production.ProductionTime) {
// Craft is complete nothing to do
return;
}
// How many units of filter are left // Check all slots that take water filters until we find one with filter in it
let resourceValue = waterFilterItemInSlot.upd?.Resource for (let i = 0; i < waterFilterArea.slots.length; i++) {
? waterFilterItemInSlot.upd.Resource.Value // No water filter in slot, skip
: undefined; if (!waterFilterArea.slots[i].item) {
if (!resourceValue) { continue;
// Missing, is new filter, add default and subtract usage
resourceValue = 100 - filterDrainRate;
pointsConsumed = filterDrainRate;
} else {
pointsConsumed = (waterFilterItemInSlot.upd.Resource.UnitsConsumed || 0) + filterDrainRate;
resourceValue -= filterDrainRate;
}
// Round to get values to 3dp
resourceValue = Math.round(resourceValue * 1000) / 1000;
pointsConsumed = Math.round(pointsConsumed * 1000) / 1000;
// Check units consumed for possible increment of hideout mgmt skill point
if (pmcData && Math.floor(pointsConsumed / 10) >= 1) {
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
pointsConsumed -= 10;
}
// Filter has some fuel left in it after our adjustment
if (resourceValue > 0) {
const isWaterFilterFoundInRaid = waterFilterItemInSlot.upd.SpawnedInSession ?? false;
// Set filters consumed amount
waterFilterItemInSlot.upd = this.getAreaUpdObject(
1,
resourceValue,
pointsConsumed,
isWaterFilterFoundInRaid,
);
this.logger.debug(`Water filter has: ${resourceValue} units left in slot ${i + 1}`);
break; // Break here to avoid iterating other filters now w're done
}
// Filter ran out / used up
delete waterFilterArea.slots[i].item;
// Update remaining resources to be subtracted
filterDrainRate = Math.abs(resourceValue);
} }
const waterFilterItemInSlot = waterFilterArea.slots[i].item[0];
// How many units of filter are left
let resourceValue = waterFilterItemInSlot.upd?.Resource
? waterFilterItemInSlot.upd.Resource.Value
: undefined;
if (!resourceValue) {
// Missing, is new filter, add default and subtract usage
resourceValue = 100 - filterDrainRate;
pointsConsumed = filterDrainRate;
} else {
pointsConsumed = (waterFilterItemInSlot.upd.Resource.UnitsConsumed || 0) + filterDrainRate;
resourceValue -= filterDrainRate;
}
// Round to get values to 3dp
resourceValue = Math.round(resourceValue * 1000) / 1000;
pointsConsumed = Math.round(pointsConsumed * 1000) / 1000;
// Check units consumed for possible increment of hideout mgmt skill point
if (pmcData && Math.floor(pointsConsumed / 10) >= 1) {
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
pointsConsumed -= 10;
}
// Filter has some fuel left in it after our adjustment
if (resourceValue > 0) {
const isWaterFilterFoundInRaid = waterFilterItemInSlot.upd.SpawnedInSession ?? false;
// Set filters consumed amount
waterFilterItemInSlot.upd = this.getAreaUpdObject(
1,
resourceValue,
pointsConsumed,
isWaterFilterFoundInRaid,
);
this.logger.debug(`Water filter has: ${resourceValue} units left in slot ${i + 1}`);
break; // Break here to avoid iterating other filters now w're done
}
// Filter ran out / used up
delete waterFilterArea.slots[i].item;
// Update remaining resources to be subtracted
filterDrainRate = Math.abs(resourceValue);
} }
} }