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

Implement Ragfair sort by barter (!362)

Not that anyone was clamoring for this, but I noticed it was missing.

Reviewed-on: SPT/Server#362
Co-authored-by: Tyfon <tyfon7@outlook.com>
Co-committed-by: Tyfon <tyfon7@outlook.com>
This commit is contained in:
Tyfon 2024-06-13 09:29:48 +00:00 committed by chomp
parent 3c0887172e
commit 836910c1d5
2 changed files with 14 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import { inject, injectable } from "tsyringe"; import { inject, injectable } from "tsyringe";
import { IRagfairOffer } from "@spt/models/eft/ragfair/IRagfairOffer"; import { IRagfairOffer } from "@spt/models/eft/ragfair/IRagfairOffer";
import { Money } from "@spt/models/enums/Money";
import { RagfairSort } from "@spt/models/enums/RagfairSort"; import { RagfairSort } from "@spt/models/enums/RagfairSort";
import { DatabaseServer } from "@spt/servers/DatabaseServer"; import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { LocaleService } from "@spt/services/LocaleService"; import { LocaleService } from "@spt/services/LocaleService";
@ -29,6 +30,10 @@ export class RagfairSortHelper
offers.sort(this.sortOffersByID); offers.sort(this.sortOffersByID);
break; break;
case RagfairSort.BARTER:
offers.sort(this.sortOffersByBarter);
break;
case RagfairSort.RATING: case RagfairSort.RATING:
offers.sort(this.sortOffersByRating); offers.sort(this.sortOffersByRating);
break; break;
@ -60,6 +65,14 @@ export class RagfairSortHelper
return a.intId - b.intId; return a.intId - b.intId;
} }
protected sortOffersByBarter(a: IRagfairOffer, b: IRagfairOffer): number
{
const moneyTpls = Object.values<string>(Money);
const aIsOnlyMoney = a.requirements.length == 1 && moneyTpls.includes(a.requirements[0]._tpl) ? 1 : 0;
const bIsOnlyMoney = b.requirements.length == 1 && moneyTpls.includes(b.requirements[0]._tpl) ? 1 : 0;
return aIsOnlyMoney - bIsOnlyMoney;
}
protected sortOffersByRating(a: IRagfairOffer, b: IRagfairOffer): number protected sortOffersByRating(a: IRagfairOffer, b: IRagfairOffer): number
{ {
return a.user.rating - b.user.rating; return a.user.rating - b.user.rating;

View File

@ -1,6 +1,7 @@
export enum RagfairSort export enum RagfairSort
{ {
ID = 0, ID = 0,
BARTER = 2,
RATING = 3, RATING = 3,
OFFER_TITLE = 4, OFFER_TITLE = 4,
PRICE = 5, PRICE = 5,