fix: booster packs not showing what items were gained after purchase (#635)
This commit is contained in:
		
							parent
							
								
									735f0b885d
								
							
						
					
					
						commit
						4d1bbff99e
					
				@ -28,12 +28,10 @@ import {
 | 
				
			|||||||
} from "../types/requestTypes";
 | 
					} from "../types/requestTypes";
 | 
				
			||||||
import { logger } from "@/src/utils/logger";
 | 
					import { logger } from "@/src/utils/logger";
 | 
				
			||||||
import { getWeaponType, getExalted } from "@/src/services/itemDataService";
 | 
					import { getWeaponType, getExalted } from "@/src/services/itemDataService";
 | 
				
			||||||
import { getRandomWeightedReward } from "@/src/services/rngService";
 | 
					 | 
				
			||||||
import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes";
 | 
					import { ISyndicateSacrifice, ISyndicateSacrificeResponse } from "../types/syndicateTypes";
 | 
				
			||||||
import { IEquipmentClient, IItemConfig } from "../types/inventoryTypes/commonInventoryTypes";
 | 
					import { IEquipmentClient, IItemConfig } from "../types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    ExportArcanes,
 | 
					    ExportArcanes,
 | 
				
			||||||
    ExportBoosterPacks,
 | 
					 | 
				
			||||||
    ExportCustoms,
 | 
					    ExportCustoms,
 | 
				
			||||||
    ExportFlavour,
 | 
					    ExportFlavour,
 | 
				
			||||||
    ExportGear,
 | 
					    ExportGear,
 | 
				
			||||||
@ -183,21 +181,6 @@ export const addItem = async (
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (typeName in ExportBoosterPacks) {
 | 
					 | 
				
			||||||
        const pack = ExportBoosterPacks[typeName];
 | 
					 | 
				
			||||||
        const InventoryChanges = {};
 | 
					 | 
				
			||||||
        for (const weights of pack.rarityWeightsPerRoll) {
 | 
					 | 
				
			||||||
            const result = getRandomWeightedReward(pack.components, weights);
 | 
					 | 
				
			||||||
            if (result) {
 | 
					 | 
				
			||||||
                logger.debug(`booster pack rolled`, result);
 | 
					 | 
				
			||||||
                combineInventoryChanges(
 | 
					 | 
				
			||||||
                    InventoryChanges,
 | 
					 | 
				
			||||||
                    (await addItem(accountId, result.type, result.itemCount)).InventoryChanges
 | 
					 | 
				
			||||||
                );
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
        return { InventoryChanges };
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    if (typeName in ExportUpgrades || typeName in ExportArcanes) {
 | 
					    if (typeName in ExportUpgrades || typeName in ExportArcanes) {
 | 
				
			||||||
        const inventory = await getInventory(accountId);
 | 
					        const inventory = await getInventory(accountId);
 | 
				
			||||||
        const changes = [
 | 
					        const changes = [
 | 
				
			||||||
 | 
				
			|||||||
@ -9,12 +9,14 @@ import {
 | 
				
			|||||||
    updateCurrency,
 | 
					    updateCurrency,
 | 
				
			||||||
    updateSlots
 | 
					    updateSlots
 | 
				
			||||||
} from "@/src/services/inventoryService";
 | 
					} from "@/src/services/inventoryService";
 | 
				
			||||||
 | 
					import { getRandomWeightedReward } from "@/src/services/rngService";
 | 
				
			||||||
import { getVendorManifestByOid } from "@/src/services/serversideVendorsService";
 | 
					import { getVendorManifestByOid } from "@/src/services/serversideVendorsService";
 | 
				
			||||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
import { IPurchaseRequest, IPurchaseResponse, SlotPurchase, IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
					import { IPurchaseRequest, IPurchaseResponse, SlotPurchase, IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
				
			||||||
import { logger } from "@/src/utils/logger";
 | 
					import { logger } from "@/src/utils/logger";
 | 
				
			||||||
import worldState from "@/static/fixed_responses/worldState.json";
 | 
					import worldState from "@/static/fixed_responses/worldState.json";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
 | 
					    ExportBoosterPacks,
 | 
				
			||||||
    ExportBundles,
 | 
					    ExportBundles,
 | 
				
			||||||
    ExportGear,
 | 
					    ExportGear,
 | 
				
			||||||
    ExportResources,
 | 
					    ExportResources,
 | 
				
			||||||
@ -38,7 +40,10 @@ export const getStoreItemTypesCategory = (typesItem: string) => {
 | 
				
			|||||||
    return typeElements[1];
 | 
					    return typeElements[1];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountId: string) => {
 | 
					export const handlePurchase = async (
 | 
				
			||||||
 | 
					    purchaseRequest: IPurchaseRequest,
 | 
				
			||||||
 | 
					    accountId: string
 | 
				
			||||||
 | 
					): Promise<IPurchaseResponse> => {
 | 
				
			||||||
    logger.debug("purchase request", purchaseRequest);
 | 
					    logger.debug("purchase request", purchaseRequest);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (purchaseRequest.PurchaseParams.Source == 7) {
 | 
					    if (purchaseRequest.PurchaseParams.Source == 7) {
 | 
				
			||||||
@ -259,17 +264,43 @@ const handleSlotPurchase = async (
 | 
				
			|||||||
    };
 | 
					    };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const handleBoosterPackPurchase = async (typeName: string, accountId: string): Promise<IPurchaseResponse> => {
 | 
				
			||||||
 | 
					    const pack = ExportBoosterPacks[typeName];
 | 
				
			||||||
 | 
					    if (!pack) {
 | 
				
			||||||
 | 
					        throw new Error(`unknown booster pack: ${typeName}`);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    const purchaseResponse: IPurchaseResponse = {
 | 
				
			||||||
 | 
					        BoosterPackItems: "",
 | 
				
			||||||
 | 
					        InventoryChanges: {}
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					    for (const weights of pack.rarityWeightsPerRoll) {
 | 
				
			||||||
 | 
					        const result = getRandomWeightedReward(pack.components, weights);
 | 
				
			||||||
 | 
					        if (result) {
 | 
				
			||||||
 | 
					            logger.debug(`booster pack rolled`, result);
 | 
				
			||||||
 | 
					            purchaseResponse.BoosterPackItems +=
 | 
				
			||||||
 | 
					                result.type.split("/Lotus/").join("/Lotus/StoreItems/") + ',{"lvl":0};';
 | 
				
			||||||
 | 
					            combineInventoryChanges(
 | 
				
			||||||
 | 
					                purchaseResponse.InventoryChanges,
 | 
				
			||||||
 | 
					                (await addItem(accountId, result.type, result.itemCount)).InventoryChanges
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return purchaseResponse;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//TODO: change to getInventory, apply changes then save at the end
 | 
					//TODO: change to getInventory, apply changes then save at the end
 | 
				
			||||||
const handleTypesPurchase = async (
 | 
					const handleTypesPurchase = async (
 | 
				
			||||||
    typesName: string,
 | 
					    typesName: string,
 | 
				
			||||||
    accountId: string,
 | 
					    accountId: string,
 | 
				
			||||||
    quantity: number
 | 
					    quantity: number
 | 
				
			||||||
): Promise<{ InventoryChanges: IInventoryChanges }> => {
 | 
					): Promise<IPurchaseResponse> => {
 | 
				
			||||||
    const typeCategory = getStoreItemTypesCategory(typesName);
 | 
					    const typeCategory = getStoreItemTypesCategory(typesName);
 | 
				
			||||||
    logger.debug(`type category ${typeCategory}`);
 | 
					    logger.debug(`type category ${typeCategory}`);
 | 
				
			||||||
    switch (typeCategory) {
 | 
					    switch (typeCategory) {
 | 
				
			||||||
        default:
 | 
					        default:
 | 
				
			||||||
            return await addItem(accountId, typesName, quantity);
 | 
					            return await addItem(accountId, typesName, quantity);
 | 
				
			||||||
 | 
					        case "BoosterPacks":
 | 
				
			||||||
 | 
					            return await handleBoosterPackPurchase(typesName, accountId);
 | 
				
			||||||
        case "SlotItems":
 | 
					        case "SlotItems":
 | 
				
			||||||
            return await handleSlotPurchase(typesName, accountId);
 | 
					            return await handleSlotPurchase(typesName, accountId);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -25,6 +25,7 @@ export interface IPurchaseResponse {
 | 
				
			|||||||
        Tag: string;
 | 
					        Tag: string;
 | 
				
			||||||
        Standing: number;
 | 
					        Standing: number;
 | 
				
			||||||
    }[];
 | 
					    }[];
 | 
				
			||||||
 | 
					    BoosterPackItems?: string;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type IBinChanges = {
 | 
					export type IBinChanges = {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user