XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
UTF-8
import type { RequestHandler } from "express";
import { ExportResources, ExportVirtuals } from "warframe-public-export-plus";
import { getAccountIdForRequest } from "../../services/loginService.ts";
import { addMiscItem, getInventory } from "../../services/inventoryService.ts";
import { sendWsBroadcastToGame } from "../../services/wsService.ts";

export const unlockAllCapturaScenesController: RequestHandler = async (req, res) => {
    const accountId = await getAccountIdForRequest(req);
    const inventory = await getInventory(accountId, "MiscItems");

    let needSync = false;
    for (const uniqueName of Object.keys(ExportResources)) {
        if (resourceInheritsFrom(uniqueName, "/Lotus/Types/Items/MiscItems/PhotoboothTile")) {
            if (!inventory.MiscItems.some(x => x.ItemType == uniqueName)) {
                addMiscItem(inventory, uniqueName, 1);
            }
            needSync = true;
        }
    }

    await inventory.save();
    res.end();
    if (needSync) {
        sendWsBroadcastToGame(accountId, { sync_inventory: true });
    }
};

const resourceInheritsFrom = (resourceName: string, targetName: string): boolean => {
    let parentName = resourceGetParent(resourceName);
    for (; parentName != undefined; parentName = resourceGetParent(parentName)) {
        if (parentName == targetName) {
            return true;
        }
    }
    return false;
};

const resourceGetParent = (resourceName: string): string | undefined => {
    if (resourceName in ExportResources) {
        return ExportResources[resourceName].parentName;
    }
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
    return ExportVirtuals[resourceName]?.parentName;
};