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 { getAccountIdForRequest } from "../../services/loginService.ts";
import { addMiscItems, getInventory2 } from "../../services/inventoryService.ts";
import type { IMiscItem } from "../../types/inventoryTypes/inventoryTypes.ts";
import { colorToShard, combineColors, shardToColor } from "../../helpers/shardHelper.ts";

export const archonFusionController: RequestHandler = async (req, res) => {
    const accountId = await getAccountIdForRequest(req);
    const request = JSON.parse(String(req.body)) as IArchonFusionRequest;
    const inventory = await getInventory2(accountId, "MiscItems");
    request.Consumed.forEach(x => {
        x.ItemCount *= -1;
    });
    addMiscItems(inventory, request.Consumed);
    const newArchons: IMiscItem[] = [];
    switch (request.FusionType) {
        case "AFT_ASCENT":
            newArchons.push({
                ItemType: request.Consumed[0].ItemType + "Mythic",
                ItemCount: 1
            });
            break;

        case "AFT_COALESCENT":
            newArchons.push({
                ItemType:
                    colorToShard[
                        combineColors(
                            shardToColor[request.Consumed[0].ItemType],
                            shardToColor[request.Consumed[1].ItemType]
                        )
                    ],
                ItemCount: 1
            });
            break;

        default:
            throw new Error(`unknown archon fusion type: ${request.FusionType}`);
    }
    addMiscItems(inventory, newArchons);
    await inventory.save();
    res.json({
        NewArchons: newArchons
    });
};

interface IArchonFusionRequest {
    Consumed: IMiscItem[];
    FusionType: string;
    StatResultType: "SRT_NEW_STAT"; // ???
}