feat: Installation of Focus Lenses (#550)
This commit is contained in:
		
							parent
							
								
									07c2fbcadf
								
							
						
					
					
						commit
						59679c3d56
					
				@ -1,7 +1,7 @@
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { getInventory, addMiscItems, addEquipment } from "@/src/services/inventoryService";
 | 
			
		||||
import { IMiscItem, TFocusPolarity } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { IMiscItem, TFocusPolarity, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { logger } from "@/src/utils/logger";
 | 
			
		||||
import { ExportFocusUpgrades } from "warframe-public-export-plus";
 | 
			
		||||
 | 
			
		||||
@ -14,6 +14,28 @@ export const focusController: RequestHandler = async (req, res) => {
 | 
			
		||||
            logger.debug(req.body.toString());
 | 
			
		||||
            res.end();
 | 
			
		||||
            break;
 | 
			
		||||
        case FocusOperation.InstallLens: {
 | 
			
		||||
            const request = JSON.parse(String(req.body)) as ILensInstallRequest;
 | 
			
		||||
            const inventory = await getInventory(accountId);
 | 
			
		||||
            for (const item of inventory[request.Category]) {
 | 
			
		||||
                if (item._id.toString() == request.WeaponId) {
 | 
			
		||||
                    item.FocusLens = request.LensType;
 | 
			
		||||
                    addMiscItems(inventory, [
 | 
			
		||||
                        {
 | 
			
		||||
                            ItemType: request.LensType,
 | 
			
		||||
                            ItemCount: -1
 | 
			
		||||
                        } satisfies IMiscItem
 | 
			
		||||
                    ]);
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            await inventory.save();
 | 
			
		||||
            res.json({
 | 
			
		||||
                weaponId: request.WeaponId,
 | 
			
		||||
                lensType: request.LensType
 | 
			
		||||
            });
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        case FocusOperation.UnlockWay: {
 | 
			
		||||
            const focusType = (JSON.parse(String(req.body)) as IWayRequest).FocusType;
 | 
			
		||||
            const focusPolarity = focusTypeToPolarity(focusType);
 | 
			
		||||
@ -144,6 +166,7 @@ export const focusController: RequestHandler = async (req, res) => {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
enum FocusOperation {
 | 
			
		||||
    InstallLens = "1",
 | 
			
		||||
    UnlockWay = "2",
 | 
			
		||||
    UnlockUpgrade = "3",
 | 
			
		||||
    LevelUpUpgrade = "4",
 | 
			
		||||
@ -186,6 +209,12 @@ interface ISentTrainingAmplifierRequest {
 | 
			
		||||
    StartingWeaponType: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
interface ILensInstallRequest {
 | 
			
		||||
    LensType: string;
 | 
			
		||||
    Category: TEquipmentKey;
 | 
			
		||||
    WeaponId: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Works for ways & upgrades
 | 
			
		||||
const focusTypeToPolarity = (type: string): TFocusPolarity => {
 | 
			
		||||
    return ("AP_" + type.substr(1).split("/")[3].toUpperCase()) as TFocusPolarity;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user