Add comments to various functions
Remove redundant function `isWeaponTemplate()` log warning message when `reparentPresets()` reassigns root item tpl
This commit is contained in:
parent
bda6d66e92
commit
88c4cf949c
@ -25,7 +25,7 @@ export class BundleCallbacks
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public sendBundle(sessionID: string, req: any, resp: any, body: any): any
|
||||
public sendBundle(sessionID: string, req: any, resp: any, body: any): void
|
||||
{
|
||||
this.logger.info(`[BUNDLE]: ${req.url}`);
|
||||
|
||||
|
@ -6,7 +6,6 @@ import { TraderAssortHelper } from "@spt-aki/helpers/TraderAssortHelper";
|
||||
import { UtilityHelper } from "@spt-aki/helpers/UtilityHelper";
|
||||
import { Item } from "@spt-aki/models/eft/common/tables/IItem";
|
||||
import { ITraderAssort } from "@spt-aki/models/eft/common/tables/ITrader";
|
||||
import { IGetOffersResult } from "@spt-aki/models/eft/ragfair/IGetOffersResult";
|
||||
import { ISearchRequestData } from "@spt-aki/models/eft/ragfair/ISearchRequestData";
|
||||
import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes";
|
||||
import { Money } from "@spt-aki/models/enums/Money";
|
||||
@ -60,27 +59,27 @@ export class RagfairHelper
|
||||
}
|
||||
}
|
||||
|
||||
public filterCategories(sessionID: string, info: ISearchRequestData): string[]
|
||||
public filterCategories(sessionID: string, request: ISearchRequestData): string[]
|
||||
{
|
||||
let result: string[] = [];
|
||||
|
||||
// Case: weapon builds
|
||||
if (info.buildCount)
|
||||
if (request.buildCount)
|
||||
{
|
||||
return Object.keys(info.buildItems);
|
||||
return Object.keys(request.buildItems);
|
||||
}
|
||||
|
||||
// Case: search
|
||||
if (info.linkedSearchId)
|
||||
if (request.linkedSearchId)
|
||||
{
|
||||
const data = this.ragfairLinkedItemService.getLinkedItems(info.linkedSearchId);
|
||||
const data = this.ragfairLinkedItemService.getLinkedItems(request.linkedSearchId);
|
||||
result = !data ? [] : [...data];
|
||||
}
|
||||
|
||||
// Case: category
|
||||
if (info.handbookId)
|
||||
if (request.handbookId)
|
||||
{
|
||||
const handbook = this.getCategoryList(info.handbookId);
|
||||
const handbook = this.getCategoryList(request.handbookId);
|
||||
|
||||
if (result.length)
|
||||
{
|
||||
@ -183,6 +182,12 @@ export class RagfairHelper
|
||||
return [...[rootItem], ...list];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the symbol for a currency
|
||||
* e.g. 5449016a4bdc2d6f028b456f return ₽
|
||||
* @param currencyTpl currency to get symbol for
|
||||
* @returns symbol of currency
|
||||
*/
|
||||
public getCurrencySymbol(currencyTpl: string): string
|
||||
{
|
||||
switch (currencyTpl)
|
||||
|
@ -354,6 +354,7 @@ export class RagfairOfferHelper
|
||||
const profileRagfairInfo = this.saveServer.getProfile(sessionID).characters.pmc.RagfairInfo;
|
||||
const index = profileRagfairInfo.offers.findIndex((o) => o._id === offerId);
|
||||
profileRagfairInfo.offers.splice(index, 1);
|
||||
|
||||
// Also delete from ragfair
|
||||
this.ragfairOfferService.removeOfferById(offerId);
|
||||
}
|
||||
@ -437,15 +438,14 @@ export class RagfairOfferHelper
|
||||
};
|
||||
|
||||
const stacks = this.itemHelper.splitStack(requestedItem);
|
||||
|
||||
for (const item of stacks)
|
||||
{
|
||||
const outItems = [item];
|
||||
|
||||
// TODO - is this code used?, may have been when adding barters to flea was still possible for player
|
||||
if (requirement.onlyFunctional)
|
||||
{
|
||||
const presetItems = this.ragfairServerHelper.getPresetItemsByTpl(item);
|
||||
|
||||
if (presetItems.length)
|
||||
{
|
||||
outItems.push(presetItems[0]);
|
||||
|
@ -13,6 +13,7 @@ import { MessageType } from "@spt-aki/models/enums/MessageType";
|
||||
import { Traders } from "@spt-aki/models/enums/Traders";
|
||||
import { IQuestConfig } from "@spt-aki/models/spt/config/IQuestConfig";
|
||||
import { IRagfairConfig } from "@spt-aki/models/spt/config/IRagfairConfig";
|
||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
||||
import { SaveServer } from "@spt-aki/servers/SaveServer";
|
||||
@ -35,6 +36,7 @@ export class RagfairServerHelper
|
||||
protected static goodsReturnedTemplate = "5bdabfe486f7743e1665df6e 0"; // Your item was not sold
|
||||
|
||||
constructor(
|
||||
@inject("WinstonLogger") protected logger: ILogger,
|
||||
@inject("RandomUtil") protected randomUtil: RandomUtil,
|
||||
@inject("HashUtil") protected hashUtil: HashUtil,
|
||||
@inject("TimeUtil") protected timeUtil: TimeUtil,
|
||||
@ -236,6 +238,11 @@ export class RagfairServerHelper
|
||||
return MemberCategory.DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a player or traders nickname from their profile by their user id
|
||||
* @param userID Sessionid/userid
|
||||
* @returns Nickname of individual
|
||||
*/
|
||||
public getNickname(userID: string): string
|
||||
{
|
||||
if (this.isPlayer(userID))
|
||||
@ -257,16 +264,25 @@ export class RagfairServerHelper
|
||||
return (name.length > 15) ? this.getNickname(userID) : name;
|
||||
}
|
||||
|
||||
public getPresetItems(item: any): Item[]
|
||||
/**
|
||||
* Given a preset id from globals.json, return an array of items[] with unique ids
|
||||
* @param item Preset item
|
||||
* @returns Array of weapon and its children
|
||||
*/
|
||||
public getPresetItems(item: Item): Item[]
|
||||
{
|
||||
const preset = this.jsonUtil.clone(this.databaseServer.getTables().globals.ItemPresets[item._id]._items);
|
||||
return this.reparentPresets(item, preset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible bug, returns all items associated with an items tpl, could be multiple presets from globals.json
|
||||
* @param item Preset item
|
||||
* @returns
|
||||
*/
|
||||
public getPresetItemsByTpl(item: Item): Item[]
|
||||
{
|
||||
const presets = [];
|
||||
|
||||
for (const itemId in this.databaseServer.getTables().globals.ItemPresets)
|
||||
{
|
||||
if (this.databaseServer.getTables().globals.ItemPresets[itemId]._items[0]._tpl === item._tpl)
|
||||
@ -282,17 +298,17 @@ export class RagfairServerHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate new unique ids for the children while preserving hierarchy
|
||||
* @param item base item
|
||||
* @param preset
|
||||
* Generate new unique ids for child items while preserving hierarchy
|
||||
* @param rootItem Base/primary item of preset
|
||||
* @param preset Primary item + children of primary item
|
||||
* @returns Item array with new IDs
|
||||
*/
|
||||
public reparentPresets(item: Item, preset: Item[]): Item[]
|
||||
public reparentPresets(rootItem: Item, preset: Item[]): Item[]
|
||||
{
|
||||
const oldRootId = preset[0]._id;
|
||||
const idMappings = {};
|
||||
|
||||
idMappings[oldRootId] = item._id;
|
||||
idMappings[oldRootId] = rootItem._id;
|
||||
|
||||
for (const mod of preset)
|
||||
{
|
||||
@ -314,8 +330,13 @@ export class RagfairServerHelper
|
||||
}
|
||||
}
|
||||
|
||||
// force item's details into first location of presetItems
|
||||
preset[0] = item;
|
||||
// Force item's details into first location of presetItems
|
||||
if (preset[0]._tpl !== rootItem._tpl)
|
||||
{
|
||||
this.logger.warning(`Reassigning root item from ${preset[0]._tpl} to ${rootItem._tpl}`);
|
||||
}
|
||||
|
||||
preset[0] = rootItem;
|
||||
|
||||
return preset;
|
||||
}
|
||||
|
@ -48,6 +48,7 @@ export class RepairHelper
|
||||
): void
|
||||
{
|
||||
this.logger.debug(`Adding ${amountToRepair} to ${itemToRepairDetails._name} using kit: ${useRepairKit}`);
|
||||
|
||||
const itemMaxDurability = this.jsonUtil.clone(itemToRepair.upd.Repairable.MaxDurability);
|
||||
const itemCurrentDurability = this.jsonUtil.clone(itemToRepair.upd.Repairable.Durability);
|
||||
const itemCurrentMaxDurability = this.jsonUtil.clone(itemToRepair.upd.Repairable.MaxDurability);
|
||||
@ -105,6 +106,14 @@ export class RepairHelper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Repairing armor reduces the total durability value slightly, get a randomised (to 2dp) amount based on armor material
|
||||
* @param armorMaterial What material is the armor being repaired made of
|
||||
* @param isRepairKit Was a repair kit used
|
||||
* @param armorMax Max amount of durability item can have
|
||||
* @param traderQualityMultipler Different traders produce different loss values
|
||||
* @returns Amount to reduce max durability by
|
||||
*/
|
||||
protected getRandomisedArmorRepairDegradationValue(
|
||||
armorMaterial: string,
|
||||
isRepairKit: boolean,
|
||||
@ -112,6 +121,7 @@ export class RepairHelper
|
||||
traderQualityMultipler: number,
|
||||
): number
|
||||
{
|
||||
// Degradation value is based on the armor material
|
||||
const armorMaterialSettings = this.databaseServer.getTables().globals.config.ArmorMaterials[armorMaterial];
|
||||
|
||||
const minMultiplier = isRepairKit
|
||||
@ -128,6 +138,14 @@ export class RepairHelper
|
||||
return Number(duraLossMultipliedByTraderMultiplier.toFixed(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Repairing weapons reduces the total durability value slightly, get a randomised (to 2dp) amount
|
||||
* @param itemProps Weapon properties
|
||||
* @param isRepairKit Was a repair kit used
|
||||
* @param weaponMax ax amount of durability item can have
|
||||
* @param traderQualityMultipler Different traders produce different loss values
|
||||
* @returns Amount to reduce max durability by
|
||||
*/
|
||||
protected getRandomisedWeaponRepairDegradationValue(
|
||||
itemProps: Props,
|
||||
isRepairKit: boolean,
|
||||
@ -149,19 +167,4 @@ export class RepairHelper
|
||||
|
||||
return Number(duraLossMultipliedByTraderMultiplier.toFixed(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the supplied tpl a weapon
|
||||
* @param tpl tplId to check is a weapon
|
||||
* @returns true if tpl is a weapon
|
||||
*/
|
||||
public isWeaponTemplate(tpl: string): boolean
|
||||
{
|
||||
const itemTemplates = this.databaseServer.getTables().templates.items;
|
||||
const baseItem = itemTemplates[tpl];
|
||||
const baseNode = itemTemplates[baseItem._parent];
|
||||
const parentNode = itemTemplates[baseNode._parent];
|
||||
|
||||
return parentNode._id === BaseClasses.WEAPON;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,11 @@ export class SecureContainerHelper
|
||||
constructor(@inject("ItemHelper") protected itemHelper: ItemHelper)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Get an array of the item IDs (NOT tpls) inside a secure container
|
||||
* @param items Inventory items to look for secure container in
|
||||
* @returns Array of ids
|
||||
*/
|
||||
public getSecureContainerItems(items: Item[]): string[]
|
||||
{
|
||||
const secureContainer = items.find((x) => x.slotId === "SecuredContainer");
|
||||
|
@ -120,7 +120,7 @@ export class TradeHelper
|
||||
this.incrementAssortBuyCount(itemPurchased, buyRequestData.count);
|
||||
}
|
||||
|
||||
this.logger.debug(`Bought item: ${buyRequestData.item_id} from ${buyRequestData.tid}`);
|
||||
this.logger.debug(`Bought item: ${buyRequestData.item_id} from: ${Traders[buyRequestData.tid]}`);
|
||||
};
|
||||
|
||||
return this.inventoryHelper.addItem(pmcData, newReq, output, sessionID, callback, foundInRaid, upd);
|
||||
@ -184,12 +184,18 @@ export class TradeHelper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Traders allow a limited number of purchases per refresh cycle (default 60 mins)
|
||||
* @param assortBeingPurchased the item from trader being bought
|
||||
* @param assortId Id of assort being purchased
|
||||
* @param count How many are being bought
|
||||
*/
|
||||
protected checkPurchaseIsWithinTraderItemLimit(assortBeingPurchased: Item, assortId: string, count: number): void
|
||||
{
|
||||
if ((assortBeingPurchased.upd.BuyRestrictionCurrent + count) > assortBeingPurchased.upd?.BuyRestrictionMax)
|
||||
{
|
||||
throw new Error(
|
||||
`Unable to purchase ${count} items, this would exceed your purchase limit of ${assortBeingPurchased.upd.BuyRestrictionMax} from the trader this refresh`,
|
||||
`Unable to purchase ${count} items, this would exceed your purchase limit of ${assortBeingPurchased.upd.BuyRestrictionMax} from the traders assort: ${assortId} this refresh`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -149,6 +149,12 @@ export class TraderHelper
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the starting standing of a trader based on the current profiles type (e.g. EoD, Standard etc)
|
||||
* @param traderId Trader id to get standing for
|
||||
* @param rawProfileTemplate Raw profile from profiles.json to look up standing from
|
||||
* @returns Standing value
|
||||
*/
|
||||
protected getStartingStanding(traderId: string, rawProfileTemplate: ProfileTraderTemplate): number
|
||||
{
|
||||
// Edge case for Lightkeeper, 0 standing means seeing `Make Amends - Buyout` quest
|
||||
@ -303,6 +309,7 @@ export class TraderHelper
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
public addTraderPurchasesToPlayerProfile(
|
||||
sessionID: string,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
newPurchaseDetails: { items: { item_id: string; count: number; }[]; tid: string; },
|
||||
): void
|
||||
{
|
||||
|
@ -18,6 +18,11 @@ export class WeightedRandomHelper
|
||||
return chosenItem.item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Choos an item from the passed in array based on the weightings of each
|
||||
* @param itemArray Items and weights to use
|
||||
* @returns Chosen item from array
|
||||
*/
|
||||
public getWeightedValue<T>(itemArray: { [key: string]: unknown; } | ArrayLike<unknown>): T
|
||||
{
|
||||
const itemKeys = Object.keys(itemArray);
|
||||
|
Loading…
Reference in New Issue
Block a user