fix: not consuming ItemPrices from server-side vendor #798
@ -47,6 +47,7 @@ export const handlePurchase = async (
|
|||||||
): Promise<IPurchaseResponse> => {
|
): Promise<IPurchaseResponse> => {
|
||||||
logger.debug("purchase request", purchaseRequest);
|
logger.debug("purchase request", purchaseRequest);
|
||||||
|
|
||||||
|
const inventoryChanges: IInventoryChanges = {};
|
||||||
if (purchaseRequest.PurchaseParams.Source == 7) {
|
if (purchaseRequest.PurchaseParams.Source == 7) {
|
||||||
const manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!);
|
const manifest = getVendorManifestByOid(purchaseRequest.PurchaseParams.SourceId!);
|
||||||
if (!manifest) {
|
if (!manifest) {
|
||||||
@ -57,6 +58,14 @@ export const handlePurchase = async (
|
|||||||
if (!offer) {
|
if (!offer) {
|
||||||
throw new Error(`unknown vendor offer: ${ItemId}`);
|
throw new Error(`unknown vendor offer: ${ItemId}`);
|
||||||
}
|
}
|
||||||
|
if (offer.ItemPrices) {
|
||||||
|
await handleItemPrices(
|
||||||
|
accountId,
|
||||||
|
offer.ItemPrices,
|
||||||
|
purchaseRequest.PurchaseParams.Quantity,
|
||||||
|
inventoryChanges
|
||||||
|
);
|
||||||
|
}
|
||||||
purchaseRequest.PurchaseParams.Quantity *= offer.QuantityMultiplier;
|
purchaseRequest.PurchaseParams.Quantity *= offer.QuantityMultiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,6 +74,7 @@ export const handlePurchase = async (
|
|||||||
accountId,
|
accountId,
|
||||||
purchaseRequest.PurchaseParams.Quantity
|
purchaseRequest.PurchaseParams.Quantity
|
||||||
);
|
);
|
||||||
|
combineInventoryChanges(purchaseResponse.InventoryChanges, inventoryChanges);
|
||||||
|
|
||||||
if (!purchaseResponse) throw new Error("purchase response was undefined");
|
if (!purchaseResponse) throw new Error("purchase response was undefined");
|
||||||
|
|
||||||
@ -117,27 +127,12 @@ export const handlePurchase = async (
|
|||||||
const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId!];
|
const vendor = ExportVendors[purchaseRequest.PurchaseParams.SourceId!];
|
||||||
const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem);
|
const offer = vendor.items.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem);
|
||||||
if (offer) {
|
if (offer) {
|
||||||
const inventory = await getInventory(accountId);
|
await handleItemPrices(
|
||||||
for (const item of offer.itemPrices) {
|
accountId,
|
||||||
const invItem: IMiscItem = {
|
offer.itemPrices,
|
||||||
ItemType: item.ItemType,
|
purchaseRequest.PurchaseParams.Quantity,
|
||||||
ItemCount: item.ItemCount * purchaseRequest.PurchaseParams.Quantity * -1
|
purchaseResponse.InventoryChanges
|
||||||
};
|
|
||||||
|
|
||||||
addMiscItems(inventory, [invItem]);
|
|
||||||
|
|
||||||
purchaseResponse.InventoryChanges.MiscItems ??= [];
|
|
||||||
const change = (purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).find(
|
|
||||||
x => x.ItemType == item.ItemType
|
|
||||||
);
|
);
|
||||||
if (change) {
|
|
||||||
change.ItemCount += invItem.ItemCount;
|
|
||||||
} else {
|
|
||||||
(purchaseResponse.InventoryChanges.MiscItems as IMiscItem[]).push(invItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await inventory.save();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -176,6 +171,32 @@ export const handlePurchase = async (
|
|||||||
return purchaseResponse;
|
return purchaseResponse;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleItemPrices = async (
|
||||||
|
accountId: string,
|
||||||
|
itemPrices: IMiscItem[],
|
||||||
|
purchaseQuantity: number,
|
||||||
|
inventoryChanges: IInventoryChanges
|
||||||
|
): Promise<void> => {
|
||||||
|
const inventory = await getInventory(accountId);
|
||||||
|
for (const item of itemPrices) {
|
||||||
|
const invItem: IMiscItem = {
|
||||||
|
ItemType: item.ItemType,
|
||||||
|
ItemCount: item.ItemCount * purchaseQuantity * -1
|
||||||
|
};
|
||||||
|
|
||||||
|
addMiscItems(inventory, [invItem]);
|
||||||
|
|
||||||
|
inventoryChanges.MiscItems ??= [];
|
||||||
|
const change = (inventoryChanges.MiscItems as IMiscItem[]).find(x => x.ItemType == item.ItemType);
|
||||||
|
if (change) {
|
||||||
|
change.ItemCount += invItem.ItemCount;
|
||||||
|
} else {
|
||||||
|
(inventoryChanges.MiscItems as IMiscItem[]).push(invItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await inventory.save();
|
||||||
|
};
|
||||||
|
|
||||||
export const handleStoreItemAcquisition = async (
|
export const handleStoreItemAcquisition = async (
|
||||||
storeItemName: string,
|
storeItemName: string,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
@ -254,7 +275,7 @@ const handleSlotPurchase = async (
|
|||||||
slotPurchaseNameFull: string,
|
slotPurchaseNameFull: string,
|
||||||
accountId: string,
|
accountId: string,
|
||||||
quantity: number
|
quantity: number
|
||||||
): Promise<{ InventoryChanges: IInventoryChanges }> => {
|
): Promise<IPurchaseResponse> => {
|
||||||
logger.debug(`slot name ${slotPurchaseNameFull}`);
|
logger.debug(`slot name ${slotPurchaseNameFull}`);
|
||||||
const slotPurchaseName = parseSlotPurchaseName(
|
const slotPurchaseName = parseSlotPurchaseName(
|
||||||
slotPurchaseNameFull.substring(slotPurchaseNameFull.lastIndexOf("/") + 1)
|
slotPurchaseNameFull.substring(slotPurchaseNameFull.lastIndexOf("/") + 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user