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:
parent
3c0887172e
commit
836910c1d5
@ -1,5 +1,6 @@
|
||||
import { inject, injectable } from "tsyringe";
|
||||
import { IRagfairOffer } from "@spt/models/eft/ragfair/IRagfairOffer";
|
||||
import { Money } from "@spt/models/enums/Money";
|
||||
import { RagfairSort } from "@spt/models/enums/RagfairSort";
|
||||
import { DatabaseServer } from "@spt/servers/DatabaseServer";
|
||||
import { LocaleService } from "@spt/services/LocaleService";
|
||||
@ -29,6 +30,10 @@ export class RagfairSortHelper
|
||||
offers.sort(this.sortOffersByID);
|
||||
break;
|
||||
|
||||
case RagfairSort.BARTER:
|
||||
offers.sort(this.sortOffersByBarter);
|
||||
break;
|
||||
|
||||
case RagfairSort.RATING:
|
||||
offers.sort(this.sortOffersByRating);
|
||||
break;
|
||||
@ -60,6 +65,14 @@ export class RagfairSortHelper
|
||||
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
|
||||
{
|
||||
return a.user.rating - b.user.rating;
|
||||
|
@ -1,6 +1,7 @@
|
||||
export enum RagfairSort
|
||||
{
|
||||
ID = 0,
|
||||
BARTER = 2,
|
||||
RATING = 3,
|
||||
OFFER_TITLE = 4,
|
||||
PRICE = 5,
|
||||
|
Loading…
x
Reference in New Issue
Block a user