forked from OpenWF/SpaceNinjaServer
		
	fix: ignore purchaseQuantity when getting slots via a bundle (#1151)
Fixes #1149 Reviewed-on: OpenWF/SpaceNinjaServer#1151
This commit is contained in:
		
							parent
							
								
									d24aac2ab2
								
							
						
					
					
						commit
						4e0494f15d
					
				@ -256,7 +256,7 @@ export const handleStoreItemAcquisition = async (
 | 
				
			|||||||
                break;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            case "Types":
 | 
					            case "Types":
 | 
				
			||||||
                purchaseResponse = await handleTypesPurchase(internalName, inventory, quantity);
 | 
					                purchaseResponse = await handleTypesPurchase(internalName, inventory, quantity, ignorePurchaseQuantity);
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            case "Boosters":
 | 
					            case "Boosters":
 | 
				
			||||||
                purchaseResponse = handleBoostersPurchase(storeItemName, inventory, durability);
 | 
					                purchaseResponse = handleBoostersPurchase(storeItemName, inventory, durability);
 | 
				
			||||||
@ -267,16 +267,16 @@ export const handleStoreItemAcquisition = async (
 | 
				
			|||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const slotPurchaseNameToSlotName: SlotPurchase = {
 | 
					export const slotPurchaseNameToSlotName: SlotPurchase = {
 | 
				
			||||||
    SuitSlotItem: { name: "SuitBin", slotsPerPurchase: 1 },
 | 
					    SuitSlotItem: { name: "SuitBin", purchaseQuantity: 1 },
 | 
				
			||||||
    TwoSentinelSlotItem: { name: "SentinelBin", slotsPerPurchase: 2 },
 | 
					    TwoSentinelSlotItem: { name: "SentinelBin", purchaseQuantity: 2 },
 | 
				
			||||||
    TwoWeaponSlotItem: { name: "WeaponBin", slotsPerPurchase: 2 },
 | 
					    TwoWeaponSlotItem: { name: "WeaponBin", purchaseQuantity: 2 },
 | 
				
			||||||
    SpaceSuitSlotItem: { name: "SpaceSuitBin", slotsPerPurchase: 1 },
 | 
					    SpaceSuitSlotItem: { name: "SpaceSuitBin", purchaseQuantity: 1 },
 | 
				
			||||||
    TwoSpaceWeaponSlotItem: { name: "SpaceWeaponBin", slotsPerPurchase: 2 },
 | 
					    TwoSpaceWeaponSlotItem: { name: "SpaceWeaponBin", purchaseQuantity: 2 },
 | 
				
			||||||
    MechSlotItem: { name: "MechBin", slotsPerPurchase: 1 },
 | 
					    MechSlotItem: { name: "MechBin", purchaseQuantity: 1 },
 | 
				
			||||||
    TwoOperatorWeaponSlotItem: { name: "OperatorAmpBin", slotsPerPurchase: 2 },
 | 
					    TwoOperatorWeaponSlotItem: { name: "OperatorAmpBin", purchaseQuantity: 2 },
 | 
				
			||||||
    RandomModSlotItem: { name: "RandomModBin", slotsPerPurchase: 3 },
 | 
					    RandomModSlotItem: { name: "RandomModBin", purchaseQuantity: 3 },
 | 
				
			||||||
    TwoCrewShipSalvageSlotItem: { name: "CrewShipSalvageBin", slotsPerPurchase: 2 },
 | 
					    TwoCrewShipSalvageSlotItem: { name: "CrewShipSalvageBin", purchaseQuantity: 2 },
 | 
				
			||||||
    CrewMemberSlotItem: { name: "CrewMemberBin", slotsPerPurchase: 1 }
 | 
					    CrewMemberSlotItem: { name: "CrewMemberBin", purchaseQuantity: 1 }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// // extra = everything above the base +2 slots (depending on slot type)
 | 
					// // extra = everything above the base +2 slots (depending on slot type)
 | 
				
			||||||
@ -286,7 +286,8 @@ export const slotPurchaseNameToSlotName: SlotPurchase = {
 | 
				
			|||||||
const handleSlotPurchase = (
 | 
					const handleSlotPurchase = (
 | 
				
			||||||
    slotPurchaseNameFull: string,
 | 
					    slotPurchaseNameFull: string,
 | 
				
			||||||
    inventory: TInventoryDatabaseDocument,
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
    quantity: number
 | 
					    quantity: number,
 | 
				
			||||||
 | 
					    ignorePurchaseQuantity: boolean
 | 
				
			||||||
): IPurchaseResponse => {
 | 
					): IPurchaseResponse => {
 | 
				
			||||||
    logger.debug(`slot name ${slotPurchaseNameFull}`);
 | 
					    logger.debug(`slot name ${slotPurchaseNameFull}`);
 | 
				
			||||||
    const slotPurchaseName = parseSlotPurchaseName(
 | 
					    const slotPurchaseName = parseSlotPurchaseName(
 | 
				
			||||||
@ -295,7 +296,10 @@ const handleSlotPurchase = (
 | 
				
			|||||||
    logger.debug(`slot purchase name ${slotPurchaseName}`);
 | 
					    logger.debug(`slot purchase name ${slotPurchaseName}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const slotName = slotPurchaseNameToSlotName[slotPurchaseName].name;
 | 
					    const slotName = slotPurchaseNameToSlotName[slotPurchaseName].name;
 | 
				
			||||||
    const slotsPurchased = slotPurchaseNameToSlotName[slotPurchaseName].slotsPerPurchase * quantity;
 | 
					    let slotsPurchased = quantity;
 | 
				
			||||||
 | 
					    if (!ignorePurchaseQuantity) {
 | 
				
			||||||
 | 
					        slotsPurchased *= slotPurchaseNameToSlotName[slotPurchaseName].purchaseQuantity;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    updateSlots(inventory, slotName, slotsPurchased, slotsPurchased);
 | 
					    updateSlots(inventory, slotName, slotsPurchased, slotsPurchased);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -360,7 +364,8 @@ const handleCreditBundlePurchase = async (
 | 
				
			|||||||
const handleTypesPurchase = async (
 | 
					const handleTypesPurchase = async (
 | 
				
			||||||
    typesName: string,
 | 
					    typesName: string,
 | 
				
			||||||
    inventory: TInventoryDatabaseDocument,
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
    quantity: number
 | 
					    quantity: number,
 | 
				
			||||||
 | 
					    ignorePurchaseQuantity: boolean
 | 
				
			||||||
): Promise<IPurchaseResponse> => {
 | 
					): Promise<IPurchaseResponse> => {
 | 
				
			||||||
    const typeCategory = getStoreItemTypesCategory(typesName);
 | 
					    const typeCategory = getStoreItemTypesCategory(typesName);
 | 
				
			||||||
    logger.debug(`type category ${typeCategory}`);
 | 
					    logger.debug(`type category ${typeCategory}`);
 | 
				
			||||||
@ -370,7 +375,7 @@ const handleTypesPurchase = async (
 | 
				
			|||||||
        case "BoosterPacks":
 | 
					        case "BoosterPacks":
 | 
				
			||||||
            return handleBoosterPackPurchase(typesName, inventory, quantity);
 | 
					            return handleBoosterPackPurchase(typesName, inventory, quantity);
 | 
				
			||||||
        case "SlotItems":
 | 
					        case "SlotItems":
 | 
				
			||||||
            return handleSlotPurchase(typesName, inventory, quantity);
 | 
					            return handleSlotPurchase(typesName, inventory, quantity, ignorePurchaseQuantity);
 | 
				
			||||||
        case "CreditBundles":
 | 
					        case "CreditBundles":
 | 
				
			||||||
            return handleCreditBundlePurchase(typesName, inventory);
 | 
					            return handleCreditBundlePurchase(typesName, inventory);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -105,5 +105,5 @@ export const slotNames = [
 | 
				
			|||||||
export type SlotNames = (typeof slotNames)[number];
 | 
					export type SlotNames = (typeof slotNames)[number];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export type SlotPurchase = {
 | 
					export type SlotPurchase = {
 | 
				
			||||||
    [P in SlotPurchaseName]: { name: SlotNames; slotsPerPurchase: number };
 | 
					    [P in SlotPurchaseName]: { name: SlotNames; purchaseQuantity: number };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user