0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 01:50:44 -05:00

Improved comments inside ragfairOfferHelper + small refactor of trader offer checks inside getOffersForBuild

This commit is contained in:
Chomp 2024-12-03 10:16:55 +00:00
parent 97edac5a0e
commit 73186a2240

View File

@ -118,6 +118,13 @@ export class RagfairOfferHelper {
}); });
} }
/**
* Disable offer if item is flagged by tiered flea config
* @param tieredFlea Tiered flea settings from ragfair config
* @param offer Ragfair offer to check
* @param tieredFleaLimitTypes Dict of item types with player level to be viewable
* @param playerLevel Level of player viewing offer
*/
protected checkAndLockOfferFromPlayerTieredFlea( protected checkAndLockOfferFromPlayerTieredFlea(
tieredFlea: ITieredFlea, tieredFlea: ITieredFlea,
offer: IRagfairOffer, offer: IRagfairOffer,
@ -218,23 +225,25 @@ export class RagfairOfferHelper {
if (this.isDisplayableOffer(searchRequest, itemsToAdd, traderAssorts, offer, pmcData, playerIsFleaBanned)) { if (this.isDisplayableOffer(searchRequest, itemsToAdd, traderAssorts, offer, pmcData, playerIsFleaBanned)) {
const isTraderOffer = offer.user.memberType === MemberCategory.TRADER; const isTraderOffer = offer.user.memberType === MemberCategory.TRADER;
if (isTraderOffer) {
if (isTraderOffer && this.traderBuyRestrictionReached(offer)) { if (this.traderBuyRestrictionReached(offer)) {
continue; continue;
} }
if (isTraderOffer && this.traderOutOfStock(offer)) { if (this.traderOutOfStock(offer)) {
continue; continue;
} }
if (isTraderOffer && this.traderOfferItemQuestLocked(offer, traderAssorts)) { if (this.traderOfferItemQuestLocked(offer, traderAssorts)) {
continue; continue;
} }
if (isTraderOffer && this.traderOfferLockedBehindLoyaltyLevel(offer, pmcData)) { if (this.traderOfferLockedBehindLoyaltyLevel(offer, pmcData)) {
continue; continue;
} }
}
// Tiered flea and not trader offer
if (tieredFlea.enabled && offer.user.memberType !== MemberCategory.TRADER) { if (tieredFlea.enabled && offer.user.memberType !== MemberCategory.TRADER) {
this.checkAndLockOfferFromPlayerTieredFlea( this.checkAndLockOfferFromPlayerTieredFlea(
tieredFlea, tieredFlea,
@ -253,7 +262,7 @@ export class RagfairOfferHelper {
} }
} }
// get best offer for each item to show on screen // Get best offer for each item to show on screen
for (let possibleOffers of offersMap.values()) { for (let possibleOffers of offersMap.values()) {
// Remove offers with locked = true (quest locked) when > 1 possible offers // Remove offers with locked = true (quest locked) when > 1 possible offers
// single trader item = shows greyed out // single trader item = shows greyed out
@ -300,7 +309,7 @@ export class RagfairOfferHelper {
} }
/** /**
* Has a traders offer ran out of stock to sell to player * Has trader offer ran out of stock to sell to player
* @param offer Offer to check stock of * @param offer Offer to check stock of
* @returns true if out of stock * @returns true if out of stock
*/ */
@ -314,7 +323,7 @@ export class RagfairOfferHelper {
/** /**
* Check if trader offers' BuyRestrictionMax value has been reached * Check if trader offers' BuyRestrictionMax value has been reached
* @param offer offer to check restriction properties of * @param offer Offer to check restriction properties of
* @returns true if restriction reached, false if no restrictions/not reached * @returns true if restriction reached, false if no restrictions/not reached
*/ */
protected traderBuyRestrictionReached(offer: IRagfairOffer): boolean { protected traderBuyRestrictionReached(offer: IRagfairOffer): boolean {
@ -357,7 +366,7 @@ export class RagfairOfferHelper {
* Get an array of flea offers that are inaccessible to player due to their inadequate loyalty level * Get an array of flea offers that are inaccessible to player due to their inadequate loyalty level
* @param offers Offers to check * @param offers Offers to check
* @param pmcProfile Players profile with trader loyalty levels * @param pmcProfile Players profile with trader loyalty levels
* @returns array of offer ids player cannot see * @returns Array of offer ids player cannot see
*/ */
protected getLoyaltyLockedOffers(offers: IRagfairOffer[], pmcProfile: IPmcData): string[] { protected getLoyaltyLockedOffers(offers: IRagfairOffer[], pmcProfile: IPmcData): string[] {
const loyaltyLockedOffers: string[] = []; const loyaltyLockedOffers: string[] = [];
@ -400,10 +409,8 @@ export class RagfairOfferHelper {
boughtAmount = offer.sellResult[0].amount; boughtAmount = offer.sellResult[0].amount;
} }
this.increaseProfileRagfairRating( const ratingToAdd = (offer.summaryCost / totalItemsCount) * boughtAmount;
this.saveServer.getProfile(sessionID), this.increaseProfileRagfairRating(this.saveServer.getProfile(sessionID), ratingToAdd);
(offer.summaryCost / totalItemsCount) * boughtAmount,
);
this.completeOffer(sessionID, offer, boughtAmount); this.completeOffer(sessionID, offer, boughtAmount);
offer.sellResult.splice(0, 1); // Remove the sell result object now its been processed offer.sellResult.splice(0, 1); // Remove the sell result object now its been processed
@ -416,7 +423,7 @@ export class RagfairOfferHelper {
/** /**
* Count up all rootitem StackObjectsCount properties of an array of items * Count up all rootitem StackObjectsCount properties of an array of items
* @param itemsInInventoryToList items to sum up * @param itemsInInventoryToList items to sum up
* @returns Total count * @returns Total stack count
*/ */
public getTotalStackCountSize(itemsInInventoryToList: IItem[][]): number { public getTotalStackCountSize(itemsInInventoryToList: IItem[][]): number {
let total = 0; let total = 0;
@ -581,10 +588,10 @@ export class RagfairOfferHelper {
/** /**
* Check an offer passes the various search criteria the player requested * Check an offer passes the various search criteria the player requested
* @param searchRequest * @param searchRequest Client search request
* @param offer * @param offer Offer to check
* @param pmcData * @param pmcData Player profile
* @returns True * @returns True if offer passes criteria
*/ */
protected passesSearchFilterCriteria( protected passesSearchFilterCriteria(
searchRequest: ISearchRequestData, searchRequest: ISearchRequestData,
@ -679,7 +686,7 @@ export class RagfairOfferHelper {
/** /**
* Check that the passed in offer item is functional * Check that the passed in offer item is functional
* @param offerRootItem The root item of the offer * @param offerRootItem The root item of the offer
* @param offer The flea offer * @param offer Flea offer to check
* @returns True if the given item is functional * @returns True if the given item is functional
*/ */
public isItemFunctional(offerRootItem: IItem, offer: IRagfairOffer): boolean { public isItemFunctional(offerRootItem: IItem, offer: IRagfairOffer): boolean {
@ -752,17 +759,17 @@ export class RagfairOfferHelper {
// commented out as required search "which is for checking offers that are barters" // commented out as required search "which is for checking offers that are barters"
// has info.removeBartering as true, this if statement removed barter items. // has info.removeBartering as true, this if statement removed barter items.
if (searchRequest.removeBartering && !this.paymentHelper.isMoneyTpl(moneyTypeTpl)) { if (searchRequest.removeBartering && !this.paymentHelper.isMoneyTpl(moneyTypeTpl)) {
// don't include barter offers // Don't include barter offers
return false; return false;
} }
if (Number.isNaN(offer.requirementsCost)) { if (Number.isNaN(offer.requirementsCost)) {
// don't include offers with undefined or NaN in it // Don't include offers with undefined or NaN in it
return false; return false;
} }
// Handle trader items to remove items that are not available to the user right now // Handle trader items to remove items that are not available to the user right now
// required search for "lamp" shows 4 items, 3 of which are not available to a new player // e.g. required search for "lamp" shows 4 items, 3 of which are not available to a new player
// filter those out // filter those out
if (isTraderOffer) { if (isTraderOffer) {
if (!(offer.user.id in traderAssorts)) { if (!(offer.user.id in traderAssorts)) {