Use dynamic ragfair pricing for insurance deletion sorting (!294)
Change sort value for insured attachments to use dynamic ragfair prices. Small change to method to return directly instead of setting passed-by-value parameter. https://dev.sp-tarkov.com/SPT-AKI/Issues/issues/618 Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/294 Co-authored-by: Brent <wiggyvidyadev@gmail.com> Co-committed-by: Brent <wiggyvidyadev@gmail.com>
This commit is contained in:
parent
cd911bdd0d
commit
c71aaa7fb3
@ -23,6 +23,7 @@ import { SaveServer } from "@spt-aki/servers/SaveServer";
|
||||
import { InsuranceService } from "@spt-aki/services/InsuranceService";
|
||||
import { MailSendService } from "@spt-aki/services/MailSendService";
|
||||
import { PaymentService } from "@spt-aki/services/PaymentService";
|
||||
import { RagfairPriceService } from "@spt-aki/services/RagfairPriceService";
|
||||
import { HashUtil } from "@spt-aki/utils/HashUtil";
|
||||
import { MathUtil } from "@spt-aki/utils/MathUtil";
|
||||
import { RandomUtil } from "@spt-aki/utils/RandomUtil";
|
||||
@ -50,6 +51,7 @@ export class InsuranceController
|
||||
@inject("PaymentService") protected paymentService: PaymentService,
|
||||
@inject("InsuranceService") protected insuranceService: InsuranceService,
|
||||
@inject("MailSendService") protected mailSendService: MailSendService,
|
||||
@inject("RagfairPriceService") protected ragfairPriceService: RagfairPriceService,
|
||||
@inject("ConfigServer") protected configServer: ConfigServer,
|
||||
)
|
||||
{
|
||||
@ -459,7 +461,7 @@ export class InsuranceController
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts the attachment items by their max price in descending order.
|
||||
* Sorts the attachment items by their dynamic price in descending order.
|
||||
*
|
||||
* @param attachments The array of attachments items.
|
||||
* @returns An array of items enriched with their max price and common locale-name.
|
||||
@ -469,8 +471,8 @@ export class InsuranceController
|
||||
return attachments.map((item) => ({
|
||||
...item,
|
||||
name: this.itemHelper.getItemName(item._tpl),
|
||||
maxPrice: this.itemHelper.getItemMaxPrice(item._tpl),
|
||||
})).sort((a, b) => b.maxPrice - a.maxPrice);
|
||||
dynamicPrice: this.ragfairPriceService.getDynamicItemPrice(item._tpl, this.roubleTpl, item, null, false),
|
||||
})).sort((a, b) => b.dynamicPrice - a.dynamicPrice);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -483,7 +485,7 @@ export class InsuranceController
|
||||
let index = 1;
|
||||
for (const attachment of attachments)
|
||||
{
|
||||
this.logger.debug(`Attachment ${index}: "${attachment.name}" - Price: ${attachment.maxPrice}`);
|
||||
this.logger.debug(`Attachment ${index}: "${attachment.name}" - Price: ${attachment.dynamicPrice}`);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
@ -521,8 +523,8 @@ export class InsuranceController
|
||||
const valuableChild = attachments.find(({ _id }) => _id === attachmentsId);
|
||||
if (valuableChild)
|
||||
{
|
||||
const { name, maxPrice } = valuableChild;
|
||||
this.logger.debug(`Marked attachment "${name}" for removal - Max Price: ${maxPrice}`);
|
||||
const { name, dynamicPrice } = valuableChild;
|
||||
this.logger.debug(`Marked attachment "${name}" for removal - Dyanmic Price: ${dynamicPrice}`);
|
||||
toDelete.add(attachmentsId);
|
||||
}
|
||||
}
|
||||
@ -723,9 +725,9 @@ export class InsuranceController
|
||||
}
|
||||
}
|
||||
|
||||
// Represents an insurance item that has had it's common locale-name and max price added to it.
|
||||
// Represents an insurance item that has had it's common locale-name and value added to it.
|
||||
interface EnrichedItem extends Item
|
||||
{
|
||||
name: string;
|
||||
maxPrice: number;
|
||||
dynamicPrice: number;
|
||||
}
|
||||
|
@ -428,9 +428,7 @@ export class RagfairPriceService implements OnLoad
|
||||
{
|
||||
// const itemDetails = this.itemHelper.getItem(itemTpl);
|
||||
// this.logger.debug(`item below handbook price ${itemDetails[1]._name} handbook: ${itemHandbookPrice} flea: ${itemPrice} ${priceDifferencePercent}%`);
|
||||
itemPrice = Math.round(
|
||||
itemHandbookPrice * this.ragfairConfig.dynamic.offerAdjustment.handbookPriceMultipier,
|
||||
);
|
||||
return Math.round(itemHandbookPrice * this.ragfairConfig.dynamic.offerAdjustment.handbookPriceMultipier);
|
||||
}
|
||||
|
||||
return itemPrice;
|
||||
|
@ -983,7 +983,7 @@ describe("InsuranceController", () =>
|
||||
|
||||
describe("sortAttachmentsByPrice", () =>
|
||||
{
|
||||
it("should sort the attachments array by maxPrice in descending order", () =>
|
||||
it("should sort the attachments array by dynamicPrice in descending order", () =>
|
||||
{
|
||||
const insured = insuranceFixture[0];
|
||||
const itemsMap = insuranceController.itemHelper.generateItemsMap(insured.items);
|
||||
@ -1001,14 +1001,14 @@ describe("InsuranceController", () =>
|
||||
// Verify the length of the sorted attachments array is unchanged
|
||||
expect(sortedAttachments.length).toBe(attachmentCount);
|
||||
|
||||
// Verify that the attachments are sorted by maxPrice in descending order
|
||||
// Verify that the attachments are sorted by dynamicPrice in descending order
|
||||
for (let i = 1; i < sortedAttachments.length; i++)
|
||||
{
|
||||
expect(sortedAttachments[i - 1].maxPrice).toBeGreaterThanOrEqual(sortedAttachments[i].maxPrice);
|
||||
expect(sortedAttachments[i - 1].dynamicPrice).toBeGreaterThanOrEqual(sortedAttachments[i].dynamicPrice);
|
||||
}
|
||||
});
|
||||
|
||||
it("should place attachments with null maxPrice at the bottom of the sorted list", () =>
|
||||
it("should place attachments with null dynamicPrice at the bottom of the sorted list", () =>
|
||||
{
|
||||
const insured = insuranceFixture[0];
|
||||
const itemsMap = insuranceController.itemHelper.generateItemsMap(insured.items);
|
||||
@ -1019,23 +1019,23 @@ describe("InsuranceController", () =>
|
||||
);
|
||||
const attachments = parentAttachmentsMap.entries().next().value;
|
||||
|
||||
// Set the maxPrice of the first attachment to null.
|
||||
vi.spyOn(insuranceController.itemHelper, "getItemMaxPrice").mockReturnValue(666).mockReturnValueOnce(null);
|
||||
// Set the dynamicPrice of the first attachment to null.
|
||||
vi.spyOn(insuranceController.ragfairPriceService, "getDynamicItemPrice").mockReturnValue(666).mockReturnValueOnce(null);
|
||||
|
||||
// Execute the method.
|
||||
const sortedAttachments = insuranceController.sortAttachmentsByPrice(attachments);
|
||||
|
||||
// Verify that the attachments with null maxPrice are at the bottom of the list
|
||||
// Verify that the attachments with null dynamicPrice are at the bottom of the list
|
||||
const nullPriceAttachments = sortedAttachments.slice(-1);
|
||||
for (const attachment of nullPriceAttachments)
|
||||
{
|
||||
expect(attachment.maxPrice).toBeNull();
|
||||
expect(attachment.dynamicPrice).toBeNull();
|
||||
}
|
||||
|
||||
// Verify that the rest of the attachments are sorted by maxPrice in descending order
|
||||
// Verify that the rest of the attachments are sorted by dynamicPrice in descending order
|
||||
for (let i = 1; i < sortedAttachments.length - 2; i++)
|
||||
{
|
||||
expect(sortedAttachments[i - 1].maxPrice).toBeGreaterThanOrEqual(sortedAttachments[i].maxPrice);
|
||||
expect(sortedAttachments[i - 1].dynamicPrice).toBeGreaterThanOrEqual(sortedAttachments[i].dynamicPrice);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -1044,10 +1044,10 @@ describe("InsuranceController", () =>
|
||||
{
|
||||
it("should log details for each attachment", () =>
|
||||
{
|
||||
const attachments = [{ _id: "item1", name: "Item 1", maxPrice: 100 }, {
|
||||
const attachments = [{ _id: "item1", name: "Item 1", dynamicPrice: 100 }, {
|
||||
_id: "item2",
|
||||
name: "Item 2",
|
||||
maxPrice: 200,
|
||||
dynamicPrice: 200,
|
||||
}];
|
||||
|
||||
// Mock the logger.debug function.
|
||||
|
Loading…
Reference in New Issue
Block a user