forked from OpenWF/SpaceNinjaServer
		
	For bootstrapper v0.11.11, out now. Reviewed-on: OpenWF/SpaceNinjaServer#2735 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
		
			
				
	
	
		
			47 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import { getInventory } from "../../services/inventoryService.ts";
 | 
						|
import { getAccountIdForRequest } from "../../services/loginService.ts";
 | 
						|
import type { RequestHandler } from "express";
 | 
						|
import { ExportArcanes, ExportUpgrades } from "warframe-public-export-plus";
 | 
						|
import { broadcastInventoryUpdate } from "../../services/wsService.ts";
 | 
						|
 | 
						|
export const addMissingMaxRankModsController: RequestHandler = async (req, res) => {
 | 
						|
    const accountId = await getAccountIdForRequest(req);
 | 
						|
    const inventory = await getInventory(accountId, "Upgrades");
 | 
						|
 | 
						|
    const maxOwnedRanks: Record<string, number> = {};
 | 
						|
    for (const upgrade of inventory.Upgrades) {
 | 
						|
        const fingerprint = JSON.parse(upgrade.UpgradeFingerprint ?? "{}") as { lvl?: number };
 | 
						|
        if (fingerprint.lvl) {
 | 
						|
            maxOwnedRanks[upgrade.ItemType] ??= 0;
 | 
						|
            if (fingerprint.lvl > maxOwnedRanks[upgrade.ItemType]) {
 | 
						|
                maxOwnedRanks[upgrade.ItemType] = fingerprint.lvl;
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    for (const [uniqueName, data] of Object.entries(ExportUpgrades)) {
 | 
						|
        if (data.fusionLimit != 0 && data.type != "PARAZON" && maxOwnedRanks[uniqueName] != data.fusionLimit) {
 | 
						|
            inventory.Upgrades.push({
 | 
						|
                ItemType: uniqueName,
 | 
						|
                UpgradeFingerprint: JSON.stringify({ lvl: data.fusionLimit })
 | 
						|
            });
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    for (const [uniqueName, data] of Object.entries(ExportArcanes)) {
 | 
						|
        if (
 | 
						|
            data.name != "/Lotus/Language/Items/GenericCosmeticEnhancerName" &&
 | 
						|
            maxOwnedRanks[uniqueName] != data.fusionLimit
 | 
						|
        ) {
 | 
						|
            inventory.Upgrades.push({
 | 
						|
                ItemType: uniqueName,
 | 
						|
                UpgradeFingerprint: JSON.stringify({ lvl: data.fusionLimit })
 | 
						|
            });
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    await inventory.save();
 | 
						|
    res.end();
 | 
						|
    broadcastInventoryUpdate(req);
 | 
						|
};
 |