forked from OpenWF/SpaceNinjaServer
		
	improve: handle purchase quantity of gear items (#389)
Co-authored-by: Sainan <Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									887d4eb952
								
							
						
					
					
						commit
						d3004b19dd
					
				
							
								
								
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										8
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@ -12,7 +12,7 @@
 | 
			
		||||
        "copyfiles": "^2.4.1",
 | 
			
		||||
        "express": "^5.0.0-beta.3",
 | 
			
		||||
        "mongoose": "^8.1.1",
 | 
			
		||||
        "warframe-public-export-plus": "^0.3.2",
 | 
			
		||||
        "warframe-public-export-plus": "^0.3.3",
 | 
			
		||||
        "warframe-riven-info": "^0.1.0",
 | 
			
		||||
        "winston": "^3.11.0",
 | 
			
		||||
        "winston-daily-rotate-file": "^4.7.1"
 | 
			
		||||
@ -3669,9 +3669,9 @@
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/warframe-public-export-plus": {
 | 
			
		||||
      "version": "0.3.2",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.3.2.tgz",
 | 
			
		||||
      "integrity": "sha512-0jAStLLrMaz0zm7wfY1/3SWLPmMJcYNNErVTPo8YqBZlot1aikVuDNu+crVmN+LWDDLrn01T7f83EYaw7TYo6w=="
 | 
			
		||||
      "version": "0.3.3",
 | 
			
		||||
      "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.3.3.tgz",
 | 
			
		||||
      "integrity": "sha512-35pSMqXxe9vG4kdA+SnCyZyWO8zRGuPQbNeOPgZm5886kiujR+Qd6iY7TH0fdQYgKCk1M+q8lXonATT9VB9bbQ=="
 | 
			
		||||
    },
 | 
			
		||||
    "node_modules/warframe-riven-info": {
 | 
			
		||||
      "version": "0.1.0",
 | 
			
		||||
 | 
			
		||||
@ -16,7 +16,7 @@
 | 
			
		||||
    "copyfiles": "^2.4.1",
 | 
			
		||||
    "express": "^5.0.0-beta.3",
 | 
			
		||||
    "mongoose": "^8.1.1",
 | 
			
		||||
    "warframe-public-export-plus": "^0.3.2",
 | 
			
		||||
    "warframe-public-export-plus": "^0.3.3",
 | 
			
		||||
    "warframe-riven-info": "^0.1.0",
 | 
			
		||||
    "winston": "^3.11.0",
 | 
			
		||||
    "winston-daily-rotate-file": "^4.7.1"
 | 
			
		||||
 | 
			
		||||
@ -3,7 +3,7 @@ import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { addItem, addBooster, updateCurrency, updateSlots } from "@/src/services/inventoryService";
 | 
			
		||||
import { IPurchaseRequest, SlotPurchase, IInventoryChanges, IBinChanges } from "@/src/types/purchaseTypes";
 | 
			
		||||
import { logger } from "@/src/utils/logger";
 | 
			
		||||
import { ExportBundles, TRarity } from "warframe-public-export-plus";
 | 
			
		||||
import { ExportBundles, ExportGear, TRarity } from "warframe-public-export-plus";
 | 
			
		||||
 | 
			
		||||
export const getStoreItemCategory = (storeItem: string) => {
 | 
			
		||||
    const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/");
 | 
			
		||||
@ -75,7 +75,8 @@ const handleStoreItemAcquisition = async (
 | 
			
		||||
    storeItemName: string,
 | 
			
		||||
    accountId: string,
 | 
			
		||||
    quantity: number,
 | 
			
		||||
    durability: TRarity
 | 
			
		||||
    durability: TRarity,
 | 
			
		||||
    ignorePurchaseQuantity: boolean = false
 | 
			
		||||
): Promise<{ InventoryChanges: IInventoryChanges }> => {
 | 
			
		||||
    let purchaseResponse = {
 | 
			
		||||
        InventoryChanges: {}
 | 
			
		||||
@ -92,7 +93,8 @@ const handleStoreItemAcquisition = async (
 | 
			
		||||
                        component.typeName,
 | 
			
		||||
                        accountId,
 | 
			
		||||
                        component.purchaseQuantity * quantity,
 | 
			
		||||
                        component.durability
 | 
			
		||||
                        component.durability,
 | 
			
		||||
                        true
 | 
			
		||||
                    )
 | 
			
		||||
                ).InventoryChanges
 | 
			
		||||
            );
 | 
			
		||||
@ -101,9 +103,14 @@ const handleStoreItemAcquisition = async (
 | 
			
		||||
        const storeCategory = getStoreItemCategory(storeItemName);
 | 
			
		||||
        const internalName = storeItemName.replace("/StoreItems", "");
 | 
			
		||||
        logger.debug(`store category ${storeCategory}`);
 | 
			
		||||
        if (!ignorePurchaseQuantity) {
 | 
			
		||||
            if (internalName in ExportGear) {
 | 
			
		||||
                quantity *= ExportGear[internalName].purchaseQuantity || 1;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        switch (storeCategory) {
 | 
			
		||||
            default:
 | 
			
		||||
                purchaseResponse = await addItem(accountId, internalName);
 | 
			
		||||
                purchaseResponse = await addItem(accountId, internalName, quantity);
 | 
			
		||||
                break;
 | 
			
		||||
            case "Types":
 | 
			
		||||
                purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user