2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 19:21:17 +02:00
|
|
|
import { InventoryHelper } from "@spt-aki/helpers/InventoryHelper";
|
2024-01-29 16:55:43 +01:00
|
|
|
import { ItemHelper } from "@spt-aki/helpers/ItemHelper";
|
2023-10-19 19:21:17 +02:00
|
|
|
import { ProfileHelper } from "@spt-aki/helpers/ProfileHelper";
|
|
|
|
import { IPmcData } from "@spt-aki/models/eft/common/IPmcData";
|
2023-11-07 16:17:38 +01:00
|
|
|
import { HideoutArea, IHideoutImprovement, Production, Productive } from "@spt-aki/models/eft/common/tables/IBotBase";
|
2024-01-13 17:41:06 +01:00
|
|
|
import { Item, Upd } from "@spt-aki/models/eft/common/tables/IItem";
|
2023-10-19 19:21:17 +02:00
|
|
|
import { StageBonus } from "@spt-aki/models/eft/hideout/IHideoutArea";
|
|
|
|
import { IHideoutContinuousProductionStartRequestData } from "@spt-aki/models/eft/hideout/IHideoutContinuousProductionStartRequestData";
|
|
|
|
import { IHideoutProduction } from "@spt-aki/models/eft/hideout/IHideoutProduction";
|
|
|
|
import { IHideoutSingleProductionStartRequestData } from "@spt-aki/models/eft/hideout/IHideoutSingleProductionStartRequestData";
|
|
|
|
import { IHideoutTakeProductionRequestData } from "@spt-aki/models/eft/hideout/IHideoutTakeProductionRequestData";
|
2024-02-01 10:58:04 +01:00
|
|
|
import { IAddItemsDirectRequest } from "@spt-aki/models/eft/inventory/IAddItemsDirectRequest";
|
2023-10-19 19:21:17 +02:00
|
|
|
import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse";
|
2024-01-29 11:42:02 +01:00
|
|
|
import { BonusType } from "@spt-aki/models/enums/BonusType";
|
2023-10-19 19:21:17 +02:00
|
|
|
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
|
|
|
import { HideoutAreas } from "@spt-aki/models/enums/HideoutAreas";
|
|
|
|
import { SkillTypes } from "@spt-aki/models/enums/SkillTypes";
|
|
|
|
import { IHideoutConfig } from "@spt-aki/models/spt/config/IHideoutConfig";
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { EventOutputHolder } from "@spt-aki/routers/EventOutputHolder";
|
|
|
|
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { LocalisationService } from "@spt-aki/services/LocalisationService";
|
|
|
|
import { PlayerService } from "@spt-aki/services/PlayerService";
|
|
|
|
import { HashUtil } from "@spt-aki/utils/HashUtil";
|
|
|
|
import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil";
|
|
|
|
import { TimeUtil } from "@spt-aki/utils/TimeUtil";
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class HideoutHelper
|
|
|
|
{
|
|
|
|
public static bitcoinFarm = "5d5c205bd582a50d042a3c0e";
|
2024-01-29 17:05:32 +01:00
|
|
|
public static bitcoinProductionId = "5d5c205bd582a50d042a3c0e";
|
2023-03-03 16:23:46 +01:00
|
|
|
public static waterCollector = "5d5589c1f934db045e6c5492";
|
2024-01-30 14:24:46 +01:00
|
|
|
public static bitcoinTpl = "59faff1d86f7746c51718c9c";
|
2023-03-03 16:23:46 +01:00
|
|
|
public static expeditionaryFuelTank = "5d1b371186f774253763a656";
|
|
|
|
public static maxSkillPoint = 5000;
|
|
|
|
|
|
|
|
protected hideoutConfig: IHideoutConfig;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
|
|
|
@inject("HashUtil") protected hashUtil: HashUtil,
|
|
|
|
@inject("TimeUtil") protected timeUtil: TimeUtil,
|
|
|
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
|
|
|
@inject("EventOutputHolder") protected eventOutputHolder: EventOutputHolder,
|
|
|
|
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
|
|
|
|
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
|
|
|
|
@inject("InventoryHelper") protected inventoryHelper: InventoryHelper,
|
|
|
|
@inject("PlayerService") protected playerService: PlayerService,
|
|
|
|
@inject("LocalisationService") protected localisationService: LocalisationService,
|
2024-01-29 16:55:43 +01:00
|
|
|
@inject("ItemHelper") protected itemHelper: ItemHelper,
|
2023-11-16 02:35:05 +01:00
|
|
|
@inject("ConfigServer") protected configServer: ConfigServer,
|
2023-03-03 16:23:46 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
this.hideoutConfig = this.configServer.getConfig(ConfigTypes.HIDEOUT);
|
|
|
|
}
|
|
|
|
|
2023-06-01 11:46:16 +02:00
|
|
|
/**
|
|
|
|
* Add production to profiles' Hideout.Production array
|
|
|
|
* @param pmcData Profile to add production to
|
|
|
|
* @param body Production request
|
|
|
|
* @param sessionID Session id
|
|
|
|
* @returns client response
|
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
public registerProduction(
|
|
|
|
pmcData: IPmcData,
|
|
|
|
body: IHideoutSingleProductionStartRequestData | IHideoutContinuousProductionStartRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IItemEventRouterResponse
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
const recipe = this.databaseServer.getTables().hideout.production.find((p) => p._id === body.recipeId);
|
2023-03-03 16:23:46 +01:00
|
|
|
if (!recipe)
|
|
|
|
{
|
|
|
|
this.logger.error(this.localisationService.getText("hideout-missing_recipe_in_db", body.recipeId));
|
|
|
|
|
|
|
|
return this.httpResponse.appendErrorToOutput(this.eventOutputHolder.getOutput(sessionID));
|
|
|
|
}
|
|
|
|
|
2024-02-04 00:40:20 +01:00
|
|
|
let modifiedProductionTime = recipe.productionTime
|
2023-11-16 02:35:05 +01:00
|
|
|
- this.getCraftingSkillProductionTimeReduction(pmcData, recipe.productionTime);
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
// @Important: Here we need to be very exact:
|
|
|
|
// - normal recipe: Production time value is stored in attribute "productionType" with small "p"
|
|
|
|
// - scav case recipe: Production time value is stored in attribute "ProductionType" with capital "P"
|
2023-07-31 20:18:29 +02:00
|
|
|
if (!pmcData.Hideout.Production)
|
|
|
|
{
|
|
|
|
pmcData.Hideout.Production = {};
|
|
|
|
}
|
2024-02-04 00:40:20 +01:00
|
|
|
|
|
|
|
if (modifiedProductionTime > 0 && this.profileHelper.isDeveloperAccount(sessionID))
|
|
|
|
{
|
|
|
|
modifiedProductionTime = 40;
|
|
|
|
}
|
|
|
|
|
2023-11-16 02:35:05 +01:00
|
|
|
pmcData.Hideout.Production[body.recipeId] = this.initProduction(
|
|
|
|
body.recipeId,
|
|
|
|
modifiedProductionTime,
|
|
|
|
recipe.needFuelForAllProductionTime,
|
|
|
|
);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This convenience function initializes new Production Object
|
|
|
|
* with all the constants.
|
|
|
|
*/
|
2023-10-10 13:03:20 +02:00
|
|
|
public initProduction(recipeId: string, productionTime: number, needFuelForAllProductionTime: boolean): Production
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return {
|
|
|
|
Progress: 0,
|
|
|
|
inProgress: true,
|
|
|
|
RecipeId: recipeId,
|
2023-10-10 13:03:20 +02:00
|
|
|
StartTimestamp: this.timeUtil.getTimestamp(),
|
2023-03-03 16:23:46 +01:00
|
|
|
ProductionTime: productionTime,
|
2023-10-10 13:03:20 +02:00
|
|
|
Products: [],
|
|
|
|
GivenItemsInStart: [],
|
|
|
|
Interrupted: false,
|
|
|
|
NeedFuelForAllProductionTime: needFuelForAllProductionTime, // Used when sending to client
|
|
|
|
needFuelForAllProductionTime: needFuelForAllProductionTime, // used when stored in production.json
|
2023-11-16 02:35:05 +01:00
|
|
|
SkipTime: 0,
|
2023-03-03 16:23:46 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-24 16:52:55 +02:00
|
|
|
/**
|
|
|
|
* Is the provided object a Production type
|
2023-11-16 02:35:05 +01:00
|
|
|
* @param productive
|
|
|
|
* @returns
|
2023-07-24 16:52:55 +02:00
|
|
|
*/
|
2023-03-03 16:23:46 +01:00
|
|
|
public isProductionType(productive: Productive): productive is Production
|
|
|
|
{
|
|
|
|
return (productive as Production).Progress !== undefined || (productive as Production).RecipeId !== undefined;
|
|
|
|
}
|
|
|
|
|
2023-08-02 16:55:33 +02:00
|
|
|
/**
|
|
|
|
* Apply bonus to player profile given after completing hideout upgrades
|
|
|
|
* @param pmcData Profile to add bonus to
|
|
|
|
* @param bonus Bonus to add to profile
|
|
|
|
*/
|
2023-03-03 16:23:46 +01:00
|
|
|
public applyPlayerUpgradesBonuses(pmcData: IPmcData, bonus: StageBonus): void
|
|
|
|
{
|
2023-08-02 16:55:33 +02:00
|
|
|
// Handle additional changes some bonuses need before being added
|
2023-03-03 16:23:46 +01:00
|
|
|
switch (bonus.type)
|
|
|
|
{
|
2024-01-29 11:42:02 +01:00
|
|
|
case BonusType.STASH_SIZE:
|
2023-11-16 02:35:05 +01:00
|
|
|
{
|
2023-08-02 16:55:33 +02:00
|
|
|
// Find stash item and adjust tpl to new tpl from bonus
|
2023-11-16 02:35:05 +01:00
|
|
|
const stashItem = pmcData.Inventory.items.find((x) => x._id === pmcData.Inventory.stash);
|
2023-08-02 16:55:33 +02:00
|
|
|
if (!stashItem)
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
this.logger.warning(
|
|
|
|
`Unable to apply StashSize bonus, stash with id: ${pmcData.Inventory.stash} not found`,
|
|
|
|
);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
2023-08-02 16:55:33 +02:00
|
|
|
|
|
|
|
stashItem._tpl = bonus.templateId;
|
2023-03-03 16:23:46 +01:00
|
|
|
break;
|
2023-08-02 16:55:33 +02:00
|
|
|
}
|
2024-01-29 11:42:02 +01:00
|
|
|
case BonusType.MAXIMUM_ENERGY_RESERVE:
|
2023-08-02 16:55:33 +02:00
|
|
|
// Amend max energy in profile
|
|
|
|
pmcData.Health.Energy.Maximum += bonus.value;
|
2023-03-03 16:23:46 +01:00
|
|
|
break;
|
2024-01-29 11:42:02 +01:00
|
|
|
case BonusType.TEXT_BONUS:
|
2023-11-16 02:35:05 +01:00
|
|
|
// Delete values before they're added to profile
|
2023-08-02 16:55:33 +02:00
|
|
|
delete bonus.passive;
|
|
|
|
delete bonus.production;
|
|
|
|
delete bonus.visible;
|
2023-03-03 16:23:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-08-02 16:55:33 +02:00
|
|
|
// Add bonus to player bonuses array in profile
|
|
|
|
// EnergyRegeneration, HealthRegeneration, RagfairCommission, ScavCooldownTimer, SkillGroupLevelingBoost, ExperienceRate, QuestMoneyReward etc
|
2024-01-29 10:59:22 +01:00
|
|
|
this.logger.debug(`Adding bonus: ${bonus.type} to profile, value: ${bonus.value ?? ""}`);
|
2023-03-03 16:23:46 +01:00
|
|
|
pmcData.Bonuses.push(bonus);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process a players hideout, update areas that use resources + increment production timers
|
|
|
|
* @param sessionID Session id
|
|
|
|
*/
|
|
|
|
public updatePlayerHideout(sessionID: string): void
|
|
|
|
{
|
|
|
|
const pmcData = this.profileHelper.getPmcProfile(sessionID);
|
2023-06-02 14:54:03 +02:00
|
|
|
const hideoutProperties = this.getHideoutProperties(pmcData);
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
this.updateAreasWithResources(sessionID, pmcData, hideoutProperties);
|
|
|
|
this.updateProductionTimers(pmcData, hideoutProperties);
|
|
|
|
pmcData.Hideout.sptUpdateLastRunTimestamp = this.timeUtil.getTimestamp();
|
|
|
|
}
|
2023-06-02 14:54:03 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get various properties that will be passed to hideout update-related functions
|
|
|
|
* @param pmcData Player profile
|
|
|
|
* @returns Properties
|
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
protected getHideoutProperties(
|
|
|
|
pmcData: IPmcData,
|
|
|
|
): { btcFarmCGs: number; isGeneratorOn: boolean; waterCollectorHasFilter: boolean; }
|
2023-06-02 14:54:03 +02:00
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
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
|
2023-06-02 14:54:03 +02:00
|
|
|
|
|
|
|
const hideoutProperties = {
|
|
|
|
btcFarmCGs: bitcoinCount,
|
2023-11-16 02:35:05 +01:00
|
|
|
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),
|
|
|
|
),
|
2023-06-02 14:54:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return hideoutProperties;
|
|
|
|
}
|
2023-07-31 20:18:29 +02:00
|
|
|
|
|
|
|
protected doesWaterCollectorHaveFilter(waterCollector: HideoutArea): boolean
|
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
if (waterCollector.level === 3)
|
|
|
|
{ // can put filters in from L3
|
2023-07-31 20:18:29 +02:00
|
|
|
// Has filter in at least one slot
|
2023-11-16 02:35:05 +01:00
|
|
|
return waterCollector.slots.some((x) => x.item);
|
2023-07-31 20:18:29 +02:00
|
|
|
}
|
2023-11-16 02:35:05 +01:00
|
|
|
|
2023-07-31 20:18:29 +02:00
|
|
|
// No Filter
|
|
|
|
return false;
|
|
|
|
}
|
2023-11-16 02:35:05 +01:00
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
/**
|
|
|
|
* Update progress timer for water collector
|
|
|
|
* @param pmcData profile to update
|
|
|
|
* @param productionId id of water collection production to update
|
|
|
|
* @param hideoutProperties Hideout properties
|
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
protected updateWaterCollectorProductionTimer(
|
|
|
|
pmcData: IPmcData,
|
|
|
|
productionId: string,
|
|
|
|
hideoutProperties: { btcFarmCGs?: number; isGeneratorOn: boolean; waterCollectorHasFilter: boolean; },
|
|
|
|
): void
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
2023-04-23 20:40:42 +02:00
|
|
|
const timeElapsed = this.getTimeElapsedSinceLastServerTick(pmcData, hideoutProperties.isGeneratorOn);
|
2023-03-03 16:23:46 +01:00
|
|
|
if (hideoutProperties.waterCollectorHasFilter)
|
|
|
|
{
|
|
|
|
pmcData.Hideout.Production[productionId].Progress += timeElapsed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate over productions and update their progress timers
|
|
|
|
* @param pmcData Profile to check for productions and update
|
|
|
|
* @param hideoutProperties Hideout properties
|
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
protected updateProductionTimers(
|
|
|
|
pmcData: IPmcData,
|
|
|
|
hideoutProperties: { btcFarmCGs: number; isGeneratorOn: boolean; waterCollectorHasFilter: boolean; },
|
|
|
|
): void
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
const recipes = this.databaseServer.getTables().hideout.production;
|
|
|
|
|
|
|
|
// Check each production
|
|
|
|
for (const prodId in pmcData.Hideout.Production)
|
|
|
|
{
|
|
|
|
const craft = pmcData.Hideout.Production[prodId];
|
2023-10-28 18:48:37 +02:00
|
|
|
if (!craft)
|
|
|
|
{
|
|
|
|
// Craft value is null, get rid of it (could be from cancelling craft that needs cleaning up)
|
|
|
|
delete pmcData.Hideout.Production[prodId];
|
2023-11-11 21:15:46 +01:00
|
|
|
|
|
|
|
continue;
|
2023-10-28 18:48:37 +02:00
|
|
|
}
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2023-12-03 15:50:01 +01:00
|
|
|
if (craft.Progress === undefined || craft.Progress === null)
|
2023-11-10 20:18:58 +01:00
|
|
|
{
|
|
|
|
this.logger.warning(`Craft ${prodId} has an undefined progress value, defaulting to 0`);
|
|
|
|
craft.Progress = 0;
|
|
|
|
}
|
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
// Craft complete, skip processing (Don't skip continious crafts like bitcoin farm)
|
|
|
|
if (craft.Progress >= craft.ProductionTime && prodId !== HideoutHelper.bitcoinFarm)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (craft.sptIsScavCase)
|
|
|
|
{
|
|
|
|
this.updateScavCaseProductionTimer(pmcData, prodId);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prodId === HideoutHelper.waterCollector)
|
|
|
|
{
|
|
|
|
this.updateWaterCollectorProductionTimer(pmcData, prodId, hideoutProperties);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prodId === HideoutHelper.bitcoinFarm)
|
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
pmcData.Hideout.Production[prodId] = this.updateBitcoinFarm(
|
|
|
|
pmcData,
|
|
|
|
hideoutProperties.btcFarmCGs,
|
|
|
|
hideoutProperties.isGeneratorOn,
|
|
|
|
);
|
2023-03-03 16:23:46 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Other recipes not covered by above
|
2023-11-16 02:35:05 +01:00
|
|
|
const recipe = recipes.find((r) => r._id === prodId);
|
2023-03-03 16:23:46 +01:00
|
|
|
if (!recipe)
|
|
|
|
{
|
|
|
|
this.logger.error(this.localisationService.getText("hideout-missing_recipe_for_area", prodId));
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.updateProductionProgress(pmcData, prodId, recipe, hideoutProperties);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update a productions progress value based on the amount of time that has passed
|
|
|
|
* @param pmcData Player profile
|
|
|
|
* @param prodId Production id being crafted
|
|
|
|
* @param recipe Recipe data being crafted
|
2023-11-16 02:35:05 +01:00
|
|
|
* @param hideoutProperties
|
2023-03-03 16:23:46 +01:00
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
protected updateProductionProgress(
|
|
|
|
pmcData: IPmcData,
|
|
|
|
prodId: string,
|
|
|
|
recipe: IHideoutProduction,
|
|
|
|
hideoutProperties: { btcFarmCGs?: number; isGeneratorOn: boolean; waterCollectorHasFilter?: boolean; },
|
|
|
|
): void
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
// Production is complete, no need to do any calculations
|
|
|
|
if (this.doesProgressMatchProductionTime(pmcData, prodId))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-04-23 20:24:00 +02:00
|
|
|
// Get seconds since last hideout update + now
|
2023-10-10 13:03:20 +02:00
|
|
|
const timeElapsed = this.getTimeElapsedSinceLastServerTick(pmcData, hideoutProperties.isGeneratorOn, recipe);
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
// Increment progress by time passed
|
2023-04-23 20:47:39 +02:00
|
|
|
const production = pmcData.Hideout.Production[prodId];
|
2023-11-08 17:17:14 +01:00
|
|
|
production.Progress += (production.needFuelForAllProductionTime && !hideoutProperties.isGeneratorOn)
|
|
|
|
? 0
|
|
|
|
: timeElapsed; // Some items NEED power to craft (e.g. DSP)
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
// Limit progress to total production time if progress is over (dont run for continious crafts))
|
|
|
|
if (!recipe.continuous)
|
|
|
|
{
|
2023-04-23 20:47:39 +02:00
|
|
|
// If progress is larger than prod time, return ProductionTime, hard cap the vaue
|
|
|
|
production.Progress = Math.min(production.Progress, production.ProductionTime);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a productions progress value matches its corresponding recipes production time value
|
|
|
|
* @param pmcData Player profile
|
|
|
|
* @param prodId Production id
|
|
|
|
* @param recipe Recipe being crafted
|
|
|
|
* @returns progress matches productionTime from recipe
|
|
|
|
*/
|
|
|
|
protected doesProgressMatchProductionTime(pmcData: IPmcData, prodId: string): boolean
|
|
|
|
{
|
|
|
|
return pmcData.Hideout.Production[prodId].Progress === pmcData.Hideout.Production[prodId].ProductionTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update progress timer for scav case
|
|
|
|
* @param pmcData Profile to update
|
|
|
|
* @param productionId Id of scav case production to update
|
|
|
|
*/
|
|
|
|
protected updateScavCaseProductionTimer(pmcData: IPmcData, productionId: string): void
|
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
const timeElapsed = (this.timeUtil.getTimestamp() - pmcData.Hideout.Production[productionId].StartTimestamp)
|
|
|
|
- pmcData.Hideout.Production[productionId].Progress;
|
2023-03-03 16:23:46 +01:00
|
|
|
pmcData.Hideout.Production[productionId].Progress += timeElapsed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate over hideout areas that use resources (fuel/filters etc) and update associated values
|
|
|
|
* @param sessionID Session id
|
|
|
|
* @param pmcData Profile to update areas of
|
|
|
|
* @param hideoutProperties hideout properties
|
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
protected updateAreasWithResources(
|
|
|
|
sessionID: string,
|
|
|
|
pmcData: IPmcData,
|
|
|
|
hideoutProperties: { btcFarmCGs: number; isGeneratorOn: boolean; waterCollectorHasFilter: boolean; },
|
|
|
|
): void
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
for (const area of pmcData.Hideout.Areas)
|
|
|
|
{
|
|
|
|
switch (area.type)
|
|
|
|
{
|
|
|
|
case HideoutAreas.GENERATOR:
|
|
|
|
if (hideoutProperties.isGeneratorOn)
|
|
|
|
{
|
2024-01-29 16:55:43 +01:00
|
|
|
this.updateFuel(area, pmcData, hideoutProperties.isGeneratorOn);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HideoutAreas.WATER_COLLECTOR:
|
|
|
|
this.updateWaterCollector(sessionID, pmcData, area, hideoutProperties.isGeneratorOn);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HideoutAreas.AIR_FILTERING:
|
|
|
|
if (hideoutProperties.isGeneratorOn)
|
|
|
|
{
|
2024-01-29 17:05:32 +01:00
|
|
|
this.updateAirFilters(area, pmcData, hideoutProperties.isGeneratorOn);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-29 16:55:43 +01:00
|
|
|
/**
|
|
|
|
* Decrease fuel from generator slots based on amount of time since last time this occured
|
|
|
|
* @param generatorArea Hideout area
|
|
|
|
* @param pmcData Player profile
|
|
|
|
* @param isGeneratorOn Is the generator turned on since last update
|
|
|
|
*/
|
|
|
|
protected updateFuel(generatorArea: HideoutArea, pmcData: IPmcData, isGeneratorOn: boolean): void
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
// 1 resource last 14 min 27 sec, 1/14.45/60 = 0.00115
|
|
|
|
// 10-10-2021 From wiki, 1 resource last 12 minutes 38 seconds, 1/12.63333/60 = 0.00131
|
2023-11-16 02:35:05 +01:00
|
|
|
let fuelDrainRate = this.databaseServer.getTables().hideout.settings.generatorFuelFlowRate
|
2024-01-29 16:55:43 +01:00
|
|
|
* this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
|
2024-02-02 19:54:07 +01:00
|
|
|
|
2024-01-29 11:42:02 +01:00
|
|
|
const fuelBonus = pmcData.Bonuses.find((bonus) => bonus.type === BonusType.FUEL_CONSUMPTION);
|
2023-03-03 16:23:46 +01:00
|
|
|
const fuelBonusPercent = 1.0 - (fuelBonus ? Math.abs(fuelBonus.value) : 0) / 100;
|
|
|
|
fuelDrainRate *= fuelBonusPercent;
|
2024-02-02 19:54:07 +01:00
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
// Hideout management resource consumption bonus:
|
|
|
|
const hideoutManagementConsumptionBonus = 1.0 - this.getHideoutManagementConsumptionBonus(pmcData);
|
|
|
|
fuelDrainRate *= hideoutManagementConsumptionBonus;
|
|
|
|
let hasFuelRemaining = false;
|
|
|
|
let pointsConsumed = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < generatorArea.slots.length; i++)
|
|
|
|
{
|
2024-01-29 17:40:58 +01:00
|
|
|
if (!generatorArea.slots[i]?.item)
|
|
|
|
{
|
|
|
|
// No item in slot, skip
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const fuelItemInSlot = generatorArea.slots[i]?.item[0];
|
2024-01-29 16:55:43 +01:00
|
|
|
if (!fuelItemInSlot)
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
2024-01-29 16:55:43 +01:00
|
|
|
// No item in slot, skip
|
|
|
|
continue;
|
|
|
|
}
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2024-01-29 16:55:43 +01:00
|
|
|
let fuelRemaining = fuelItemInSlot.upd?.Resource?.Value;
|
|
|
|
if (fuelRemaining === 0)
|
|
|
|
{
|
|
|
|
// No fuel left, skip
|
|
|
|
continue;
|
|
|
|
}
|
2024-02-02 19:54:07 +01:00
|
|
|
|
2024-01-29 16:55:43 +01:00
|
|
|
// Undefined fuel, fresh fuel item and needs its max fuel amount looked up
|
|
|
|
if (!fuelRemaining)
|
|
|
|
{
|
|
|
|
const fuelItemTemplate = this.itemHelper.getItem(fuelItemInSlot._tpl)[1];
|
|
|
|
pointsConsumed = fuelDrainRate;
|
2024-02-02 19:54:07 +01:00
|
|
|
fuelRemaining = fuelItemTemplate._props.MaxResource - fuelDrainRate;
|
2024-01-29 16:55:43 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Fuel exists already, deduct fuel from item remaining value
|
|
|
|
pointsConsumed = (fuelItemInSlot.upd.Resource.UnitsConsumed || 0) + fuelDrainRate;
|
|
|
|
fuelRemaining -= fuelDrainRate;
|
|
|
|
}
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2024-01-29 16:55:43 +01:00
|
|
|
fuelRemaining = Math.round(fuelRemaining * 10000) / 10000;
|
|
|
|
pointsConsumed = Math.round(pointsConsumed * 10000) / 10000;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2024-01-29 16:55:43 +01:00
|
|
|
// Fuel consumed / 10 is over 1, add hideout management skill point
|
|
|
|
if (pmcData && Math.floor(pointsConsumed / 10) >= 1)
|
|
|
|
{
|
|
|
|
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
|
|
|
|
pointsConsumed -= 10;
|
|
|
|
}
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2024-01-29 16:55:43 +01:00
|
|
|
if (fuelRemaining > 0)
|
|
|
|
{
|
|
|
|
fuelItemInSlot.upd = this.getAreaUpdObject(1, fuelRemaining, pointsConsumed);
|
2023-04-26 23:29:08 +02:00
|
|
|
|
2024-02-02 19:54:07 +01:00
|
|
|
this.logger.debug(
|
2024-02-10 11:07:40 +01:00
|
|
|
`Profile: ${pmcData._id} Generator has: ${fuelRemaining} fuel left in slot ${i + 1}`,
|
|
|
|
true,
|
2024-02-02 19:54:07 +01:00
|
|
|
);
|
2024-01-29 16:55:43 +01:00
|
|
|
hasFuelRemaining = true;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2024-01-29 16:55:43 +01:00
|
|
|
break; // Break here to avoid updating all the fuel tanks
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
2024-01-29 16:55:43 +01:00
|
|
|
|
|
|
|
fuelItemInSlot.upd = this.getAreaUpdObject(1, 0, 0);
|
|
|
|
|
|
|
|
// Update remaining resources to be subtracted
|
|
|
|
fuelDrainRate = Math.abs(fuelRemaining);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
2024-01-29 16:55:43 +01:00
|
|
|
// Out of fuel, flag generator as offline
|
2023-03-03 16:23:46 +01:00
|
|
|
if (!hasFuelRemaining)
|
|
|
|
{
|
|
|
|
generatorArea.active = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-16 02:35:05 +01:00
|
|
|
protected updateWaterCollector(
|
|
|
|
sessionId: string,
|
|
|
|
pmcData: IPmcData,
|
|
|
|
area: HideoutArea,
|
|
|
|
isGeneratorOn: boolean,
|
|
|
|
): void
|
2023-07-31 20:18:29 +02:00
|
|
|
{
|
|
|
|
// Skip water collector when not level 3 (cant collect until 3)
|
|
|
|
if (area.level !== 3)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Canister with purified water craft exists
|
|
|
|
const prod = pmcData.Hideout.Production[HideoutHelper.waterCollector];
|
|
|
|
if (prod && this.isProduction(prod))
|
|
|
|
{
|
2024-01-29 12:10:26 +01:00
|
|
|
this.updateWaterFilters(area, prod, isGeneratorOn, pmcData);
|
2023-07-31 20:18:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// continuousProductionStart()
|
|
|
|
// seem to not trigger consistently
|
|
|
|
const recipe: IHideoutSingleProductionStartRequestData = {
|
|
|
|
recipeId: HideoutHelper.waterCollector,
|
|
|
|
Action: "HideoutSingleProductionStart",
|
|
|
|
items: [],
|
2023-11-16 02:35:05 +01:00
|
|
|
timestamp: this.timeUtil.getTimestamp(),
|
2023-07-31 20:18:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
this.registerProduction(pmcData, recipe, sessionId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
/**
|
|
|
|
* Adjust water filter objects resourceValue or delete when they reach 0 resource
|
|
|
|
* @param waterFilterArea water filter area to update
|
|
|
|
* @param production production object
|
|
|
|
* @param isGeneratorOn is generator enabled
|
|
|
|
* @param pmcData Player profile
|
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
protected updateWaterFilters(
|
|
|
|
waterFilterArea: HideoutArea,
|
|
|
|
production: Production,
|
|
|
|
isGeneratorOn: boolean,
|
|
|
|
pmcData: IPmcData,
|
2024-01-29 12:10:26 +01:00
|
|
|
): void
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
2023-04-23 22:23:44 +02:00
|
|
|
let filterDrainRate = this.getWaterFilterDrainRate(pmcData);
|
2023-10-10 13:03:20 +02:00
|
|
|
const productionTime = this.getTotalProductionTimeSeconds(HideoutHelper.waterCollector);
|
|
|
|
const secondsSinceServerTick = this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
|
2023-11-16 02:35:05 +01:00
|
|
|
|
|
|
|
filterDrainRate = this.adjustWaterFilterDrainRate(
|
|
|
|
secondsSinceServerTick,
|
|
|
|
productionTime,
|
|
|
|
production.Progress,
|
|
|
|
filterDrainRate,
|
|
|
|
);
|
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
// Production hasn't completed
|
2023-04-23 22:23:44 +02:00
|
|
|
let pointsConsumed = 0;
|
2023-03-03 16:23:46 +01:00
|
|
|
if (production.Progress < productionTime)
|
|
|
|
{
|
|
|
|
// Check all slots that take water filters
|
2023-07-31 20:18:29 +02:00
|
|
|
// Must loop to find first water filter and use that
|
2023-03-03 16:23:46 +01:00
|
|
|
for (let i = 0; i < waterFilterArea.slots.length; i++)
|
|
|
|
{
|
|
|
|
// Has a water filter installed into slot
|
|
|
|
if (waterFilterArea.slots[i].item)
|
|
|
|
{
|
2023-10-10 13:03:20 +02:00
|
|
|
// How many units of filter are left
|
2023-03-03 16:23:46 +01:00
|
|
|
let resourceValue = (waterFilterArea.slots[i].item[0].upd?.Resource)
|
|
|
|
? waterFilterArea.slots[i].item[0].upd.Resource.Value
|
|
|
|
: null;
|
|
|
|
if (!resourceValue)
|
|
|
|
{
|
2023-10-10 13:03:20 +02:00
|
|
|
// None left
|
2023-03-03 16:23:46 +01:00
|
|
|
resourceValue = 100 - filterDrainRate;
|
|
|
|
pointsConsumed = filterDrainRate;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
pointsConsumed = (waterFilterArea.slots[i].item[0].upd.Resource.UnitsConsumed || 0)
|
|
|
|
+ filterDrainRate;
|
2023-03-03 16:23:46 +01:00
|
|
|
resourceValue -= filterDrainRate;
|
|
|
|
}
|
2023-10-10 13:03:20 +02:00
|
|
|
|
|
|
|
// Round to get values to 3dp
|
2023-03-03 16:23:46 +01:00
|
|
|
resourceValue = Math.round(resourceValue * 10000) / 10000;
|
|
|
|
pointsConsumed = Math.round(pointsConsumed * 10000) / 10000;
|
|
|
|
|
2023-10-10 13:03:20 +02:00
|
|
|
// Check amount of units consumed for possible increment of hideout mgmt skill point
|
2023-03-03 16:23:46 +01:00
|
|
|
if (pmcData && Math.floor(pointsConsumed / 10) >= 1)
|
|
|
|
{
|
2023-11-07 12:20:25 +01:00
|
|
|
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
|
2023-03-03 16:23:46 +01:00
|
|
|
pointsConsumed -= 10;
|
|
|
|
}
|
|
|
|
|
2023-10-10 13:03:20 +02:00
|
|
|
// Filter has some juice left in it after we adjusted it
|
2023-03-03 16:23:46 +01:00
|
|
|
if (resourceValue > 0)
|
|
|
|
{
|
2023-07-31 20:18:29 +02:00
|
|
|
// Set filter consumed amount
|
2023-03-03 16:23:46 +01:00
|
|
|
waterFilterArea.slots[i].item[0].upd = this.getAreaUpdObject(1, resourceValue, pointsConsumed);
|
2023-10-10 13:03:20 +02:00
|
|
|
this.logger.debug(`Water filter has: ${resourceValue} units left in slot ${i + 1}`);
|
2023-07-31 20:18:29 +02:00
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
break; // Break here to avoid updating all filters
|
|
|
|
}
|
2023-04-23 22:23:44 +02:00
|
|
|
|
|
|
|
// Filter ran out / used up
|
|
|
|
delete waterFilterArea.slots[i].item;
|
|
|
|
// Update remaining resources to be subtracted
|
|
|
|
filterDrainRate = Math.abs(resourceValue);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-10 13:03:20 +02:00
|
|
|
/**
|
2023-11-16 02:35:05 +01:00
|
|
|
* Get an adjusted water filter drain rate based on time elapsed since last run,
|
2023-10-10 13:03:20 +02:00
|
|
|
* handle edge case when craft time has gone on longer than total production time
|
|
|
|
* @param secondsSinceServerTick Time passed
|
|
|
|
* @param totalProductionTime Total time collecting water
|
2023-11-16 02:35:05 +01:00
|
|
|
* @param productionProgress how far water collector has progressed
|
|
|
|
* @param baseFilterDrainRate Base drain rate
|
|
|
|
* @returns
|
2023-10-10 13:03:20 +02:00
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
protected adjustWaterFilterDrainRate(
|
|
|
|
secondsSinceServerTick: number,
|
|
|
|
totalProductionTime: number,
|
|
|
|
productionProgress: number,
|
|
|
|
baseFilterDrainRate: number,
|
|
|
|
): number
|
2023-10-10 13:03:20 +02:00
|
|
|
{
|
|
|
|
const drainRateMultiplier = secondsSinceServerTick > totalProductionTime
|
|
|
|
? (totalProductionTime - productionProgress) // more time passed than prod time, get total minus the current progress
|
|
|
|
: secondsSinceServerTick;
|
|
|
|
|
|
|
|
// Multiply drain rate by calculated multiplier
|
|
|
|
baseFilterDrainRate *= drainRateMultiplier;
|
|
|
|
|
|
|
|
return baseFilterDrainRate;
|
|
|
|
}
|
|
|
|
|
2023-04-23 22:23:44 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2023-04-23 15:02:46 +02:00
|
|
|
|
2023-04-23 22:23:44 +02:00
|
|
|
/**
|
|
|
|
* Get the production time in seconds for the desired production
|
|
|
|
* @param prodId Id, e.g. Water collector id
|
|
|
|
* @returns seconds to produce item
|
|
|
|
*/
|
2023-10-10 13:03:20 +02:00
|
|
|
protected getTotalProductionTimeSeconds(prodId: string): number
|
2023-04-23 22:23:44 +02:00
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
const recipe = this.databaseServer.getTables().hideout.production.find((prod) => prod._id === prodId);
|
2023-04-26 23:29:08 +02:00
|
|
|
|
2023-04-23 22:23:44 +02:00
|
|
|
return (recipe.productionTime || 0);
|
|
|
|
}
|
2023-04-23 15:02:46 +02:00
|
|
|
|
2023-04-23 20:40:42 +02:00
|
|
|
/**
|
|
|
|
* Create a upd object using passed in parameters
|
2023-11-16 02:35:05 +01:00
|
|
|
* @param stackCount
|
|
|
|
* @param resourceValue
|
|
|
|
* @param resourceUnitsConsumed
|
2023-04-23 20:40:42 +02:00
|
|
|
* @returns Upd
|
|
|
|
*/
|
2023-03-03 16:23:46 +01:00
|
|
|
protected getAreaUpdObject(stackCount: number, resourceValue: number, resourceUnitsConsumed: number): Upd
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
StackObjectsCount: stackCount,
|
2023-11-16 02:35:05 +01:00
|
|
|
Resource: { Value: resourceValue, UnitsConsumed: resourceUnitsConsumed },
|
2023-03-03 16:23:46 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-01-29 17:05:32 +01:00
|
|
|
protected updateAirFilters(airFilterArea: HideoutArea, pmcData: IPmcData, isGeneratorOn: boolean): void
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
// 300 resources last 20 hrs, 300/20/60/60 = 0.00416
|
|
|
|
/* 10-10-2021 from WIKI (https://escapefromtarkov.fandom.com/wiki/FP-100_filter_absorber)
|
|
|
|
Lasts for 17 hours 38 minutes and 49 seconds (23 hours 31 minutes and 45 seconds with elite hideout management skill),
|
|
|
|
300/17.64694/60/60 = 0.004722
|
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
let filterDrainRate = this.databaseServer.getTables().hideout.settings.airFilterUnitFlowRate
|
2024-01-29 17:05:32 +01:00
|
|
|
* this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
|
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
// Hideout management resource consumption bonus:
|
|
|
|
const hideoutManagementConsumptionBonus = 1.0 - this.getHideoutManagementConsumptionBonus(pmcData);
|
|
|
|
filterDrainRate *= hideoutManagementConsumptionBonus;
|
|
|
|
let pointsConsumed = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < airFilterArea.slots.length; i++)
|
|
|
|
{
|
|
|
|
if (airFilterArea.slots[i].item)
|
|
|
|
{
|
|
|
|
let resourceValue = (airFilterArea.slots[i].item[0].upd?.Resource)
|
|
|
|
? airFilterArea.slots[i].item[0].upd.Resource.Value
|
|
|
|
: null;
|
|
|
|
if (!resourceValue)
|
|
|
|
{
|
|
|
|
resourceValue = 300 - filterDrainRate;
|
|
|
|
pointsConsumed = filterDrainRate;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pointsConsumed = (airFilterArea.slots[i].item[0].upd.Resource.UnitsConsumed || 0) + filterDrainRate;
|
|
|
|
resourceValue -= filterDrainRate;
|
|
|
|
}
|
|
|
|
resourceValue = Math.round(resourceValue * 10000) / 10000;
|
|
|
|
pointsConsumed = Math.round(pointsConsumed * 10000) / 10000;
|
|
|
|
|
2023-11-16 02:35:05 +01:00
|
|
|
// check unit consumed for increment skill point
|
2023-03-03 16:23:46 +01:00
|
|
|
if (pmcData && Math.floor(pointsConsumed / 10) >= 1)
|
|
|
|
{
|
2023-11-07 12:20:25 +01:00
|
|
|
this.profileHelper.addSkillPointsToPlayer(pmcData, SkillTypes.HIDEOUT_MANAGEMENT, 1);
|
2023-03-03 16:23:46 +01:00
|
|
|
pointsConsumed -= 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (resourceValue > 0)
|
|
|
|
{
|
|
|
|
airFilterArea.slots[i].item[0].upd = {
|
|
|
|
StackObjectsCount: 1,
|
2023-11-16 02:35:05 +01:00
|
|
|
Resource: { Value: resourceValue, UnitsConsumed: pointsConsumed },
|
2023-03-03 16:23:46 +01:00
|
|
|
};
|
|
|
|
this.logger.debug(`Air filter: ${resourceValue} filter left on slot ${i + 1}`);
|
|
|
|
break; // Break here to avoid updating all filters
|
|
|
|
}
|
2024-01-29 17:05:32 +01:00
|
|
|
|
|
|
|
delete airFilterArea.slots[i].item;
|
|
|
|
// Update remaining resources to be subtracted
|
|
|
|
filterDrainRate = Math.abs(resourceValue);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-11-16 02:35:05 +01:00
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
protected updateBitcoinFarm(pmcData: IPmcData, btcFarmCGs: number, isGeneratorOn: boolean): Production
|
|
|
|
{
|
|
|
|
const btcProd = pmcData.Hideout.Production[HideoutHelper.bitcoinFarm];
|
2024-02-09 23:01:19 +01:00
|
|
|
const bitcoinProdData = this.databaseServer.getTables().hideout.production.find((production) =>
|
|
|
|
production._id === HideoutHelper.bitcoinProductionId
|
2023-11-16 02:35:05 +01:00
|
|
|
);
|
2023-03-03 16:23:46 +01:00
|
|
|
const coinSlotCount = this.getBTCSlots(pmcData);
|
|
|
|
|
|
|
|
// Full on bitcoins, halt progress
|
|
|
|
if (this.isProduction(btcProd) && btcProd.Products.length >= coinSlotCount)
|
|
|
|
{
|
|
|
|
// Set progress to 0
|
|
|
|
btcProd.Progress = 0;
|
2023-04-26 23:29:08 +02:00
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
return btcProd;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.isProduction(btcProd))
|
|
|
|
{
|
2023-04-23 20:40:42 +02:00
|
|
|
const timeElapsedSeconds = this.getTimeElapsedSinceLastServerTick(pmcData, isGeneratorOn);
|
2023-03-03 16:23:46 +01:00
|
|
|
btcProd.Progress += timeElapsedSeconds;
|
|
|
|
|
|
|
|
// The wiki has a wrong formula!
|
|
|
|
// Do not change unless you validate it with the Client code files!
|
|
|
|
// This formula was found on the client files:
|
|
|
|
// *******************************************************
|
|
|
|
/*
|
|
|
|
public override int InstalledSuppliesCount
|
2023-04-23 15:02:46 +02:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return this.int_1;
|
|
|
|
}
|
|
|
|
protected set
|
|
|
|
{
|
|
|
|
if (this.int_1 === value)
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.int_1 = value;
|
|
|
|
base.Single_0 = ((this.int_1 === 0) ? 0f : (1f + (float)(this.int_1 - 1) * this.float_4));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// **********************************************************
|
|
|
|
// At the time of writing this comment, this was GClass1667
|
|
|
|
// To find it in case of weird results, use DNSpy and look for usages on class AreaData
|
|
|
|
// Look for a GClassXXXX that has a method called "InitDetails" and the only parameter is the AreaData
|
|
|
|
// That should be the bitcoin farm production. To validate, try to find the snippet below:
|
|
|
|
/*
|
|
|
|
protected override void InitDetails(AreaData data)
|
|
|
|
{
|
|
|
|
base.InitDetails(data);
|
|
|
|
this.gclass1678_1.Type = EDetailsType.Farming;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// BSG finally fixed their settings, they now get loaded from the settings and used in the client
|
2024-02-09 23:01:19 +01:00
|
|
|
const coinCraftTimeSeconds =
|
|
|
|
((this.profileHelper.isDeveloperAccount(pmcData.sessionId)) ? 40 : bitcoinProdData.productionTime)
|
2023-11-16 02:35:05 +01:00
|
|
|
/ (1 + (btcFarmCGs - 1) * this.databaseServer.getTables().hideout.settings.gpuBoostRate);
|
2024-02-09 23:01:19 +01:00
|
|
|
|
|
|
|
while (btcProd.Progress >= coinCraftTimeSeconds)
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
if (btcProd.Products.length < coinSlotCount)
|
|
|
|
{
|
2023-04-26 23:29:08 +02:00
|
|
|
// Has space to add a coin to production
|
|
|
|
this.addBtcToProduction(btcProd, coinCraftTimeSeconds);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-02-09 23:01:19 +01:00
|
|
|
// Filled up bitcoin storage
|
2023-03-03 16:23:46 +01:00
|
|
|
btcProd.Progress = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
btcProd.StartTimestamp = this.timeUtil.getTimestamp();
|
|
|
|
|
|
|
|
return btcProd;
|
|
|
|
}
|
2024-01-29 12:11:44 +01:00
|
|
|
|
|
|
|
return null;
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
2023-04-26 23:29:08 +02:00
|
|
|
/**
|
|
|
|
* Add bitcoin object to btc production products array and set progress time
|
|
|
|
* @param btcProd Bitcoin production object
|
|
|
|
* @param coinCraftTimeSeconds Time to craft a bitcoin
|
|
|
|
*/
|
|
|
|
protected addBtcToProduction(btcProd: Production, coinCraftTimeSeconds: number): void
|
|
|
|
{
|
|
|
|
btcProd.Products.push({
|
|
|
|
_id: this.hashUtil.generate(),
|
2024-01-30 14:24:46 +01:00
|
|
|
_tpl: HideoutHelper.bitcoinTpl,
|
2023-11-16 02:35:05 +01:00
|
|
|
upd: { StackObjectsCount: 1 },
|
2023-04-26 23:29:08 +02:00
|
|
|
});
|
|
|
|
|
2024-02-09 23:01:19 +01:00
|
|
|
// Deduct time spent crafting from progress
|
2023-04-26 23:29:08 +02:00
|
|
|
btcProd.Progress -= coinCraftTimeSeconds;
|
|
|
|
}
|
|
|
|
|
2023-04-23 20:40:42 +02:00
|
|
|
/**
|
|
|
|
* Get number of ticks that have passed since hideout areas were last processed, reduced when generator is off
|
|
|
|
* @param pmcData Player profile
|
|
|
|
* @param isGeneratorOn Is the generator on for the duration of elapsed time
|
2023-10-10 13:03:20 +02:00
|
|
|
* @param recipe Hideout production recipe being crafted we need the ticks for
|
2023-04-23 20:40:42 +02:00
|
|
|
* @returns Amount of time elapsed in seconds
|
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
protected getTimeElapsedSinceLastServerTick(
|
|
|
|
pmcData: IPmcData,
|
|
|
|
isGeneratorOn: boolean,
|
|
|
|
recipe: IHideoutProduction = null,
|
|
|
|
): number
|
2023-04-23 20:40:42 +02:00
|
|
|
{
|
|
|
|
// Reduce time elapsed (and progress) when generator is off
|
|
|
|
let timeElapsed = this.timeUtil.getTimestamp() - pmcData.Hideout.sptUpdateLastRunTimestamp;
|
2023-10-10 13:03:20 +02:00
|
|
|
|
2023-11-16 02:35:05 +01:00
|
|
|
if (recipe?.areaType === HideoutAreas.LAVATORY)
|
2024-02-09 23:01:19 +01:00
|
|
|
{
|
|
|
|
// Lavatory works at 100% when power is on / off
|
2023-10-10 13:03:20 +02:00
|
|
|
return timeElapsed;
|
|
|
|
}
|
|
|
|
|
2023-04-23 20:40:42 +02:00
|
|
|
if (!isGeneratorOn)
|
|
|
|
{
|
|
|
|
timeElapsed *= this.databaseServer.getTables().hideout.settings.generatorSpeedWithoutFuel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return timeElapsed;
|
|
|
|
}
|
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
/**
|
2024-01-30 13:16:27 +01:00
|
|
|
* Get a count of how many possible BTC can be gathered by the profile
|
2023-03-03 16:23:46 +01:00
|
|
|
* @param pmcData Profile to look up
|
2024-01-30 13:16:27 +01:00
|
|
|
* @returns Coin slot count
|
2023-03-03 16:23:46 +01:00
|
|
|
*/
|
|
|
|
protected getBTCSlots(pmcData: IPmcData): number
|
|
|
|
{
|
2024-01-30 13:16:27 +01:00
|
|
|
const bitcoinProductions = this.databaseServer.getTables().hideout.production.find((production) =>
|
|
|
|
production._id === HideoutHelper.bitcoinFarm
|
2023-11-16 02:35:05 +01:00
|
|
|
);
|
2024-01-30 13:16:27 +01:00
|
|
|
const productionSlots = bitcoinProductions?.productionLimitCount || 3; // Default to 3 if none found
|
2023-11-07 10:58:58 +01:00
|
|
|
const hasManagementSkillSlots = this.profileHelper.hasEliteSkillLevel(SkillTypes.HIDEOUT_MANAGEMENT, pmcData);
|
2024-01-30 13:16:27 +01:00
|
|
|
const managementSlotsCount = this.getEliteSkillAdditionalBitcoinSlotCount() || 2;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
return productionSlots + (hasManagementSkillSlots ? managementSlotsCount : 0);
|
|
|
|
}
|
|
|
|
|
2023-07-13 11:26:47 +02:00
|
|
|
/**
|
2024-01-30 13:16:27 +01:00
|
|
|
* Get a count of how many additional bitcoins player hideout can hold with elite skill
|
2023-07-13 11:26:47 +02:00
|
|
|
*/
|
2024-01-30 13:16:27 +01:00
|
|
|
protected getEliteSkillAdditionalBitcoinSlotCount(): number
|
2023-07-13 11:26:47 +02:00
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
return this.databaseServer.getTables().globals.config.SkillsSettings.HideoutManagement.EliteSlots.BitcoinFarm
|
|
|
|
.Container;
|
2023-07-13 11:26:47 +02:00
|
|
|
}
|
|
|
|
|
2023-10-10 13:03:20 +02:00
|
|
|
/**
|
|
|
|
* HideoutManagement skill gives a consumption bonus the higher the level
|
|
|
|
* 0.5% per level per 1-51, (25.5% at max)
|
|
|
|
* @param pmcData Profile to get hideout consumption level level from
|
|
|
|
* @returns consumption bonus
|
|
|
|
*/
|
2023-03-03 16:23:46 +01:00
|
|
|
protected getHideoutManagementConsumptionBonus(pmcData: IPmcData): number
|
|
|
|
{
|
2023-11-07 16:17:38 +01:00
|
|
|
const hideoutManagementSkill = this.profileHelper.getSkillFromProfile(pmcData, SkillTypes.HIDEOUT_MANAGEMENT);
|
2023-03-03 16:23:46 +01:00
|
|
|
if (!hideoutManagementSkill)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2023-10-10 13:03:20 +02:00
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
// If the level is 51 we need to round it at 50 so on elite you dont get 25.5%
|
|
|
|
// at level 1 you already get 0.5%, so it goes up until level 50. For some reason the wiki
|
|
|
|
// says that it caps at level 51 with 25% but as per dump data that is incorrect apparently
|
2023-10-10 13:03:20 +02:00
|
|
|
let roundedLevel = Math.floor(hideoutManagementSkill.Progress / 100);
|
2023-11-16 02:35:05 +01:00
|
|
|
roundedLevel = (roundedLevel === 51) ? roundedLevel - 1 : roundedLevel;
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2023-11-16 02:35:05 +01:00
|
|
|
return (roundedLevel
|
|
|
|
* this.databaseServer.getTables().globals.config.SkillsSettings.HideoutManagement
|
|
|
|
.ConsumptionReductionPerLevel) / 100;
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adjust craft time based on crafting skill level found in player profile
|
|
|
|
* @param pmcData Player profile
|
|
|
|
* @param productionTime Time to complete hideout craft in seconds
|
|
|
|
* @returns Adjusted craft time in seconds
|
|
|
|
*/
|
|
|
|
protected getCraftingSkillProductionTimeReduction(pmcData: IPmcData, productionTime: number): number
|
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
const craftingSkill = pmcData.Skills.Common.find((x) => x.Id === SkillTypes.CRAFTING);
|
2023-03-03 16:23:46 +01:00
|
|
|
if (!craftingSkill)
|
|
|
|
{
|
|
|
|
return productionTime;
|
|
|
|
}
|
|
|
|
const roundedLevel = Math.floor(Math.min(HideoutHelper.maxSkillPoint, craftingSkill.Progress) / 100);
|
|
|
|
const percentageToDrop = roundedLevel * 0.75;
|
|
|
|
|
|
|
|
return (productionTime * percentageToDrop) / 100;
|
|
|
|
}
|
|
|
|
|
|
|
|
public isProduction(productive: Productive): productive is Production
|
|
|
|
{
|
|
|
|
return (productive as Production).Progress !== undefined || (productive as Production).RecipeId !== undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gather crafted BTC from hideout area and add to inventory
|
|
|
|
* Reset production start timestamp if hideout area at full coin capacity
|
|
|
|
* @param pmcData Player profile
|
|
|
|
* @param request Take production request
|
|
|
|
* @param sessionId Session id
|
2024-01-30 13:16:27 +01:00
|
|
|
* @param output Output object to update
|
2023-03-03 16:23:46 +01:00
|
|
|
*/
|
2023-11-16 02:35:05 +01:00
|
|
|
public getBTC(
|
|
|
|
pmcData: IPmcData,
|
|
|
|
request: IHideoutTakeProductionRequestData,
|
|
|
|
sessionId: string,
|
2024-02-02 19:54:07 +01:00
|
|
|
output: IItemEventRouterResponse,
|
2024-02-01 13:47:48 +01:00
|
|
|
): void
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
// Get how many coins were crafted and ready to pick up
|
|
|
|
const craftedCoinCount = pmcData.Hideout.Production[HideoutHelper.bitcoinFarm].Products.length;
|
|
|
|
if (!craftedCoinCount)
|
|
|
|
{
|
|
|
|
const errorMsg = this.localisationService.getText("hideout-no_bitcoins_to_collect");
|
|
|
|
this.logger.error(errorMsg);
|
2023-11-16 02:35:05 +01:00
|
|
|
|
2024-02-01 13:47:48 +01:00
|
|
|
this.httpResponse.appendErrorToOutput(output, errorMsg);
|
|
|
|
|
|
|
|
return;
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
2024-02-01 00:39:01 +01:00
|
|
|
|
|
|
|
const itemsToAdd: Item[][] = [];
|
2024-01-30 14:24:46 +01:00
|
|
|
for (let index = 0; index < craftedCoinCount; index++)
|
|
|
|
{
|
2024-02-02 19:54:07 +01:00
|
|
|
itemsToAdd.push([{
|
|
|
|
_id: this.hashUtil.generate(),
|
|
|
|
_tpl: HideoutHelper.bitcoinTpl,
|
|
|
|
upd: { StackObjectsCount: 1 },
|
|
|
|
}]);
|
2024-02-01 00:39:01 +01:00
|
|
|
}
|
|
|
|
|
2024-02-01 10:58:04 +01:00
|
|
|
// Create request for what we want to add to stash
|
|
|
|
const addItemsRequest: IAddItemsDirectRequest = {
|
|
|
|
itemsWithModsToAdd: itemsToAdd,
|
|
|
|
foundInRaid: true,
|
|
|
|
useSortingTable: false,
|
2024-02-02 19:54:07 +01:00
|
|
|
callback: null,
|
2024-02-01 10:58:04 +01:00
|
|
|
};
|
2024-01-30 14:24:46 +01:00
|
|
|
|
2024-02-01 10:58:04 +01:00
|
|
|
// Add FiR coins to player inventory
|
|
|
|
this.inventoryHelper.addItemsToStash(sessionId, addItemsRequest, pmcData, output);
|
|
|
|
if (output.warnings.length > 0)
|
|
|
|
{
|
2024-02-01 13:47:48 +01:00
|
|
|
return;
|
2024-01-30 14:24:46 +01:00
|
|
|
}
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2024-02-01 10:58:04 +01:00
|
|
|
// Is at max capacity + we collected all coins - reset production start time
|
2023-03-03 16:23:46 +01:00
|
|
|
const coinSlotCount = this.getBTCSlots(pmcData);
|
2024-01-30 14:24:46 +01:00
|
|
|
if (pmcData.Hideout.Production[HideoutHelper.bitcoinFarm].Products.length >= coinSlotCount)
|
|
|
|
{
|
|
|
|
// Set start to now
|
|
|
|
pmcData.Hideout.Production[HideoutHelper.bitcoinFarm].StartTimestamp = this.timeUtil.getTimestamp();
|
|
|
|
}
|
2023-03-03 16:23:46 +01:00
|
|
|
|
2024-01-30 14:24:46 +01:00
|
|
|
// Remove crafted coins from production in profile now they've been collected
|
|
|
|
// Can only collect all coins, not individially
|
|
|
|
pmcData.Hideout.Production[HideoutHelper.bitcoinFarm].Products = [];
|
2023-04-26 23:29:08 +02:00
|
|
|
}
|
|
|
|
|
2023-03-03 16:23:46 +01:00
|
|
|
/**
|
2023-10-10 13:03:20 +02:00
|
|
|
* Upgrade hideout wall from starting level to interactable level if necessary stations have been upgraded
|
2023-03-03 16:23:46 +01:00
|
|
|
* @param pmcProfile Profile to upgrade wall in
|
|
|
|
*/
|
|
|
|
public unlockHideoutWallInProfile(pmcProfile: IPmcData): void
|
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
const waterCollector = pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.WATER_COLLECTOR);
|
|
|
|
const medStation = pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.MEDSTATION);
|
|
|
|
const wall = pmcProfile.Hideout.Areas.find((x) => x.type === HideoutAreas.EMERGENCY_WALL);
|
2023-03-06 13:02:21 +01:00
|
|
|
|
2023-10-10 13:03:20 +02:00
|
|
|
// No collector or med station, skip
|
|
|
|
if (!(waterCollector && medStation))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2023-03-06 13:02:21 +01:00
|
|
|
|
2023-10-10 13:03:20 +02:00
|
|
|
// If medstation > level 1 AND water collector > level 1 AND wall is level 0
|
|
|
|
if (waterCollector?.level >= 1 && medStation?.level >= 1 && wall?.level <= 0)
|
|
|
|
{
|
|
|
|
wall.level = 3;
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hideout improvement is flagged as complete
|
|
|
|
* @param improvement hideout improvement object
|
|
|
|
* @returns true if complete
|
|
|
|
*/
|
|
|
|
protected hideoutImprovementIsComplete(improvement: IHideoutImprovement): boolean
|
|
|
|
{
|
2023-11-16 02:35:05 +01:00
|
|
|
return improvement?.completed ? true : false;
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Iterate over hideout improvements not completed and check if they need to be adjusted
|
|
|
|
* @param pmcProfile Profile to adjust
|
|
|
|
*/
|
|
|
|
public setHideoutImprovementsToCompleted(pmcProfile: IPmcData): void
|
|
|
|
{
|
2023-10-10 13:03:20 +02:00
|
|
|
for (const improvementId in pmcProfile.Hideout.Improvement)
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
2023-10-10 13:03:20 +02:00
|
|
|
const improvementDetails = pmcProfile.Hideout.Improvement[improvementId];
|
2023-11-16 02:35:05 +01:00
|
|
|
if (
|
|
|
|
improvementDetails.completed === false
|
|
|
|
&& improvementDetails.improveCompleteTimestamp < this.timeUtil.getTimestamp()
|
|
|
|
)
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
improvementDetails.completed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-13 17:41:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add/remove bonus combat skill based on number of dogtags in place of fame hideout area
|
|
|
|
* @param pmcData Player profile
|
|
|
|
*/
|
|
|
|
public applyPlaceOfFameDogtagBonus(pmcData: IPmcData): void
|
|
|
|
{
|
2024-02-02 19:54:07 +01:00
|
|
|
const fameAreaProfile = pmcData.Hideout.Areas.find((area) => area.type === HideoutAreas.PLACE_OF_FAME);
|
2024-01-13 17:41:06 +01:00
|
|
|
|
|
|
|
// Get hideout area 16 bonus array
|
2024-02-02 19:54:07 +01:00
|
|
|
const fameAreaDb = this.databaseServer.getTables().hideout.areas.find((area) =>
|
|
|
|
area.type === HideoutAreas.PLACE_OF_FAME
|
|
|
|
);
|
2024-01-13 17:41:06 +01:00
|
|
|
|
|
|
|
// Get SkillGroupLevelingBoost object
|
2024-02-02 19:54:07 +01:00
|
|
|
const combatBoostBonusDb = fameAreaDb.stages[fameAreaProfile.level].bonuses.find((bonus) =>
|
|
|
|
bonus.type === "SkillGroupLevelingBoost"
|
|
|
|
);
|
2024-01-13 17:41:06 +01:00
|
|
|
|
|
|
|
// Get SkillGroupLevelingBoost object in profile
|
2024-02-02 19:54:07 +01:00
|
|
|
const combatBonusProfile = pmcData.Bonuses.find((bonus) => bonus.id === combatBoostBonusDb.id);
|
2024-01-13 17:41:06 +01:00
|
|
|
|
|
|
|
// Get all slotted dogtag items
|
2024-02-02 19:54:07 +01:00
|
|
|
const activeDogtags = pmcData.Inventory.items.filter((item) => item?.slotId?.startsWith("dogtag"));
|
2024-01-13 17:41:06 +01:00
|
|
|
|
|
|
|
// Calculate bonus percent (apply hideoutManagement bonus)
|
|
|
|
const hideoutManagementSkill = this.profileHelper.getSkillFromProfile(pmcData, SkillTypes.HIDEOUT_MANAGEMENT);
|
|
|
|
const hideoutManagementSkillBonusPercent = 1 + (hideoutManagementSkill.Progress / 10000); // 5100 becomes 0.51, add 1 to it, 1.51
|
2024-02-02 19:54:07 +01:00
|
|
|
const bonus = this.getDogtagCombatSkillBonusPercent(pmcData, activeDogtags)
|
|
|
|
* hideoutManagementSkillBonusPercent;
|
2024-01-13 17:41:06 +01:00
|
|
|
|
|
|
|
// Update bonus value to above calcualted value
|
|
|
|
combatBonusProfile.value = Number.parseFloat(bonus.toFixed(2));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the raw dogtag combat skill bonus for place of fame based on number of dogtags
|
|
|
|
* Reverse engineered from client code
|
|
|
|
* @param pmcData Player profile
|
|
|
|
* @param activeDogtags Active dogtags in place of fame dogtag slots
|
|
|
|
* @returns combat bonus
|
|
|
|
*/
|
|
|
|
protected getDogtagCombatSkillBonusPercent(pmcData: IPmcData, activeDogtags: Item[]): number
|
|
|
|
{
|
|
|
|
// Not own dogtag
|
|
|
|
// Side = opposite of player
|
|
|
|
let result = 0;
|
|
|
|
for (const dogtag of activeDogtags)
|
|
|
|
{
|
2024-01-29 16:56:35 +01:00
|
|
|
if (!dogtag.upd.Dogtag)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-02-02 19:54:07 +01:00
|
|
|
if (Number.parseInt(dogtag.upd.Dogtag?.AccountId) === pmcData.aid)
|
2024-01-13 17:41:06 +01:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
result += 0.01 * dogtag.upd.Dogtag.Level;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2023-11-16 02:35:05 +01:00
|
|
|
}
|