forked from OpenWF/SpaceNinjaServer
		
	feat: identify & repair railjack components (#1664)
Closes #911 Reviewed-on: OpenWF/SpaceNinjaServer#1664 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									51b82df5fd
								
							
						
					
					
						commit
						0ea67ea89a
					
				
							
								
								
									
										41
									
								
								src/controllers/api/crewShipIdentifySalvageController.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/controllers/api/crewShipIdentifySalvageController.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
			
		||||
import { addCrewShipSalvagedWeaponSkin, addCrewShipRawSalvage, getInventory } from "@/src/services/inventoryService";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import { RequestHandler } from "express";
 | 
			
		||||
import { IInnateDamageFingerprint } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { ExportCustoms } from "warframe-public-export-plus";
 | 
			
		||||
import { IFingerprintStat } from "@/src/helpers/rivenHelper";
 | 
			
		||||
import { getJSONfromString } from "@/src/helpers/stringHelpers";
 | 
			
		||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
			
		||||
 | 
			
		||||
export const crewShipIdentifySalvageController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const accountId = await getAccountIdForRequest(req);
 | 
			
		||||
    const inventory = await getInventory(accountId, "CrewShipSalvagedWeaponSkins CrewShipRawSalvage");
 | 
			
		||||
    const payload = getJSONfromString<ICrewShipIdentifySalvageRequest>(String(req.body));
 | 
			
		||||
 | 
			
		||||
    const buffs: IFingerprintStat[] = [];
 | 
			
		||||
    for (const upgrade of ExportCustoms[payload.ItemType].randomisedUpgrades!) {
 | 
			
		||||
        buffs.push({ Tag: upgrade.tag, Value: Math.trunc(Math.random() * 0x40000000) });
 | 
			
		||||
    }
 | 
			
		||||
    const inventoryChanges: IInventoryChanges = addCrewShipSalvagedWeaponSkin(
 | 
			
		||||
        inventory,
 | 
			
		||||
        payload.ItemType,
 | 
			
		||||
        JSON.stringify({ compat: payload.ItemType, buffs } satisfies IInnateDamageFingerprint)
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    inventoryChanges.CrewShipRawSalvage = [
 | 
			
		||||
        {
 | 
			
		||||
            ItemType: payload.ItemType,
 | 
			
		||||
            ItemCount: -1
 | 
			
		||||
        }
 | 
			
		||||
    ];
 | 
			
		||||
    addCrewShipRawSalvage(inventory, inventoryChanges.CrewShipRawSalvage);
 | 
			
		||||
 | 
			
		||||
    await inventory.save();
 | 
			
		||||
    res.json({
 | 
			
		||||
        InventoryChanges: inventoryChanges
 | 
			
		||||
    });
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
interface ICrewShipIdentifySalvageRequest {
 | 
			
		||||
    ItemType: string;
 | 
			
		||||
}
 | 
			
		||||
@ -14,20 +14,23 @@ import {
 | 
			
		||||
import { ExportDojoRecipes } from "warframe-public-export-plus";
 | 
			
		||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
			
		||||
import {
 | 
			
		||||
    addCrewShipWeaponSkin,
 | 
			
		||||
    addItem,
 | 
			
		||||
    addMiscItems,
 | 
			
		||||
    addRecipes,
 | 
			
		||||
    combineInventoryChanges,
 | 
			
		||||
    getInventory,
 | 
			
		||||
    occupySlot,
 | 
			
		||||
    updateCurrency
 | 
			
		||||
} from "@/src/services/inventoryService";
 | 
			
		||||
import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { IMiscItem, InventorySlot } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
			
		||||
import { IInventoryChanges } from "@/src/types/purchaseTypes";
 | 
			
		||||
import { config } from "@/src/services/configService";
 | 
			
		||||
import { GuildPermission, ITechProjectClient } from "@/src/types/guildTypes";
 | 
			
		||||
import { GuildMember } from "@/src/models/guildModel";
 | 
			
		||||
import { toMongoDate } from "@/src/helpers/inventoryHelpers";
 | 
			
		||||
import { logger } from "@/src/utils/logger";
 | 
			
		||||
import { TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
 | 
			
		||||
 | 
			
		||||
export const guildTechController: RequestHandler = async (req, res) => {
 | 
			
		||||
    const accountId = await getAccountIdForRequest(req);
 | 
			
		||||
@ -99,6 +102,8 @@ export const guildTechController: RequestHandler = async (req, res) => {
 | 
			
		||||
                        State: 0,
 | 
			
		||||
                        ReqCredits: recipe.price,
 | 
			
		||||
                        ItemType: data.RecipeType,
 | 
			
		||||
                        ProductCategory: data.TechProductCategory,
 | 
			
		||||
                        CategoryItemId: data.CategoryItemId,
 | 
			
		||||
                        ReqItems: recipe.ingredients
 | 
			
		||||
                    }) - 1
 | 
			
		||||
                ];
 | 
			
		||||
@ -222,12 +227,16 @@ export const guildTechController: RequestHandler = async (req, res) => {
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    } else if (data.Action.split(",")[0] == "Buy") {
 | 
			
		||||
        const purchase = data as IGuildTechBuyRequest;
 | 
			
		||||
        if (purchase.Mode == "Guild") {
 | 
			
		||||
            const guild = await getGuildForRequestEx(req, inventory);
 | 
			
		||||
        if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Fabricator))) {
 | 
			
		||||
            if (
 | 
			
		||||
                !hasAccessToDojo(inventory) ||
 | 
			
		||||
                !(await hasGuildPermission(guild, accountId, GuildPermission.Fabricator))
 | 
			
		||||
            ) {
 | 
			
		||||
                res.status(400).send("-1").end();
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        const purchase = data as IGuildTechBuyRequest;
 | 
			
		||||
            const quantity = parseInt(data.Action.split(",")[1]);
 | 
			
		||||
            const recipeChanges = [
 | 
			
		||||
                {
 | 
			
		||||
@ -249,6 +258,13 @@ export const guildTechController: RequestHandler = async (req, res) => {
 | 
			
		||||
                    Recipes: recipeChanges
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
        } else {
 | 
			
		||||
            const inventoryChanges = claimSalvagedComponent(inventory, purchase.CategoryItemId!);
 | 
			
		||||
            await inventory.save();
 | 
			
		||||
            res.json({
 | 
			
		||||
                inventoryChanges: inventoryChanges
 | 
			
		||||
            });
 | 
			
		||||
        }
 | 
			
		||||
    } else if (data.Action == "Fabricate") {
 | 
			
		||||
        const guild = await getGuildForRequestEx(req, inventory);
 | 
			
		||||
        if (!hasAccessToDojo(inventory) || !(await hasGuildPermission(guild, accountId, GuildPermission.Fabricator))) {
 | 
			
		||||
@ -289,9 +305,18 @@ export const guildTechController: RequestHandler = async (req, res) => {
 | 
			
		||||
        guild.ActiveDojoColorResearch = data.RecipeType;
 | 
			
		||||
        await guild.save();
 | 
			
		||||
        res.end();
 | 
			
		||||
    } else if (data.Action == "Rush" && data.CategoryItemId) {
 | 
			
		||||
        const inventoryChanges: IInventoryChanges = {
 | 
			
		||||
            ...updateCurrency(inventory, 20, true),
 | 
			
		||||
            ...claimSalvagedComponent(inventory, data.CategoryItemId)
 | 
			
		||||
        };
 | 
			
		||||
        await inventory.save();
 | 
			
		||||
        res.json({
 | 
			
		||||
            inventoryChanges: inventoryChanges
 | 
			
		||||
        });
 | 
			
		||||
    } else {
 | 
			
		||||
        logger.debug(`data provided to ${req.path}: ${String(req.body)}`);
 | 
			
		||||
        throw new Error(`unknown guildTech action: ${data.Action}`);
 | 
			
		||||
        throw new Error(`unhandled guildTech request`);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -301,15 +326,15 @@ type TGuildTechRequest =
 | 
			
		||||
    | IGuildTechContributeRequest;
 | 
			
		||||
 | 
			
		||||
interface IGuildTechBasicRequest {
 | 
			
		||||
    Action: "Start" | "Fabricate" | "Pause" | "Unpause";
 | 
			
		||||
    Action: "Start" | "Fabricate" | "Pause" | "Unpause" | "Cancel" | "Rush";
 | 
			
		||||
    Mode: "Guild" | "Personal";
 | 
			
		||||
    RecipeType: string;
 | 
			
		||||
    TechProductCategory?: string;
 | 
			
		||||
    CategoryItemId?: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
interface IGuildTechBuyRequest {
 | 
			
		||||
interface IGuildTechBuyRequest extends Omit<IGuildTechBasicRequest, "Action"> {
 | 
			
		||||
    Action: string;
 | 
			
		||||
    Mode: "Guild";
 | 
			
		||||
    RecipeType: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
interface IGuildTechContributeRequest {
 | 
			
		||||
@ -321,3 +346,30 @@ interface IGuildTechContributeRequest {
 | 
			
		||||
    VaultCredits: number;
 | 
			
		||||
    VaultMiscItems: IMiscItem[];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const claimSalvagedComponent = (inventory: TInventoryDatabaseDocument, itemId: string): IInventoryChanges => {
 | 
			
		||||
    // delete personal tech project
 | 
			
		||||
    const personalTechProjectIndex = inventory.PersonalTechProjects.findIndex(x => x.CategoryItemId?.equals(itemId));
 | 
			
		||||
    if (personalTechProjectIndex != -1) {
 | 
			
		||||
        inventory.PersonalTechProjects.splice(personalTechProjectIndex, 1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // find salved part & delete it
 | 
			
		||||
    const crewShipSalvagedWeaponSkinsIndex = inventory.CrewShipSalvagedWeaponSkins.findIndex(x => x._id.equals(itemId));
 | 
			
		||||
    const crewShipWeaponSkin = inventory.CrewShipSalvagedWeaponSkins[crewShipSalvagedWeaponSkinsIndex];
 | 
			
		||||
    inventory.CrewShipSalvagedWeaponSkins.splice(crewShipSalvagedWeaponSkinsIndex, 1);
 | 
			
		||||
 | 
			
		||||
    // add final item
 | 
			
		||||
    const inventoryChanges = {
 | 
			
		||||
        ...addCrewShipWeaponSkin(inventory, crewShipWeaponSkin.ItemType, crewShipWeaponSkin.UpgradeFingerprint),
 | 
			
		||||
        ...occupySlot(inventory, InventorySlot.RJ_COMPONENT_AND_ARMAMENTS, false)
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    inventoryChanges.RemovedIdItems = [
 | 
			
		||||
        {
 | 
			
		||||
            ItemId: { $oid: itemId }
 | 
			
		||||
        }
 | 
			
		||||
    ];
 | 
			
		||||
 | 
			
		||||
    return inventoryChanges;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -504,6 +504,8 @@ const personalTechProjectSchema = new Schema<IPersonalTechProjectDatabase>({
 | 
			
		||||
    State: Number,
 | 
			
		||||
    ReqCredits: Number,
 | 
			
		||||
    ItemType: String,
 | 
			
		||||
    ProductCategory: String,
 | 
			
		||||
    CategoryItemId: Schema.Types.ObjectId,
 | 
			
		||||
    ReqItems: { type: [typeCountSchema], default: undefined },
 | 
			
		||||
    HasContributions: Boolean,
 | 
			
		||||
    CompletionDate: Date
 | 
			
		||||
@ -522,6 +524,9 @@ personalTechProjectSchema.set("toJSON", {
 | 
			
		||||
        const db = ret as IPersonalTechProjectDatabase;
 | 
			
		||||
        const client = ret as IPersonalTechProjectClient;
 | 
			
		||||
 | 
			
		||||
        if (db.CategoryItemId) {
 | 
			
		||||
            client.CategoryItemId = toOid(db.CategoryItemId);
 | 
			
		||||
        }
 | 
			
		||||
        if (db.CompletionDate) {
 | 
			
		||||
            client.CompletionDate = toMongoDate(db.CompletionDate);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -27,6 +27,7 @@ import { contributeToVaultController } from "@/src/controllers/api/contributeToV
 | 
			
		||||
import { createAllianceController } from "@/src/controllers/api/createAllianceController";
 | 
			
		||||
import { createGuildController } from "@/src/controllers/api/createGuildController";
 | 
			
		||||
import { creditsController } from "@/src/controllers/api/creditsController";
 | 
			
		||||
import { crewShipIdentifySalvageController } from "@/src/controllers/api/crewShipIdentifySalvageController";
 | 
			
		||||
import { customizeGuildRanksController } from "@/src/controllers/api/customizeGuildRanksController";
 | 
			
		||||
import { customObstacleCourseLeaderboardController } from "@/src/controllers/api/customObstacleCourseLeaderboardController";
 | 
			
		||||
import { declineAllianceInviteController } from "@/src/controllers/api/declineAllianceInviteController";
 | 
			
		||||
@ -218,6 +219,7 @@ apiRouter.post("/contributeToDojoComponent.php", contributeToDojoComponentContro
 | 
			
		||||
apiRouter.post("/contributeToVault.php", contributeToVaultController);
 | 
			
		||||
apiRouter.post("/createAlliance.php", createAllianceController);
 | 
			
		||||
apiRouter.post("/createGuild.php", createGuildController);
 | 
			
		||||
apiRouter.post("/crewShipIdentifySalvage.php", crewShipIdentifySalvageController);
 | 
			
		||||
apiRouter.post("/customizeGuildRanks.php", customizeGuildRanksController);
 | 
			
		||||
apiRouter.post("/customObstacleCourseLeaderboard.php", customObstacleCourseLeaderboardController);
 | 
			
		||||
apiRouter.post("/destroyDojoDeco.php", destroyDojoDecoController);
 | 
			
		||||
 | 
			
		||||
@ -426,7 +426,7 @@ export const addItem = async (
 | 
			
		||||
                    );
 | 
			
		||||
                }
 | 
			
		||||
                inventoryChanges = {
 | 
			
		||||
                    ...addCrewShipWeaponSkin(inventory, typeName),
 | 
			
		||||
                    ...addCrewShipWeaponSkin(inventory, typeName, undefined),
 | 
			
		||||
                    ...occupySlot(inventory, InventorySlot.RJ_COMPONENT_AND_ARMAMENTS, premiumPurchase)
 | 
			
		||||
                };
 | 
			
		||||
            }
 | 
			
		||||
@ -1107,12 +1107,14 @@ export const addSkin = (
 | 
			
		||||
    return inventoryChanges;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const addCrewShipWeaponSkin = (
 | 
			
		||||
export const addCrewShipWeaponSkin = (
 | 
			
		||||
    inventory: TInventoryDatabaseDocument,
 | 
			
		||||
    typeName: string,
 | 
			
		||||
    upgradeFingerprint: string | undefined,
 | 
			
		||||
    inventoryChanges: IInventoryChanges = {}
 | 
			
		||||
): IInventoryChanges => {
 | 
			
		||||
    const index = inventory.CrewShipWeaponSkins.push({ ItemType: typeName }) - 1;
 | 
			
		||||
    const index =
 | 
			
		||||
        inventory.CrewShipWeaponSkins.push({ ItemType: typeName, UpgradeFingerprint: upgradeFingerprint }) - 1;
 | 
			
		||||
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
 | 
			
		||||
    inventoryChanges.CrewShipWeaponSkins ??= [];
 | 
			
		||||
    (inventoryChanges.CrewShipWeaponSkins as IUpgradeClient[]).push(
 | 
			
		||||
@ -1121,6 +1123,22 @@ const addCrewShipWeaponSkin = (
 | 
			
		||||
    return inventoryChanges;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export const addCrewShipSalvagedWeaponSkin = (
 | 
			
		||||
    inventory: TInventoryDatabaseDocument,
 | 
			
		||||
    typeName: string,
 | 
			
		||||
    upgradeFingerprint: string | undefined,
 | 
			
		||||
    inventoryChanges: IInventoryChanges = {}
 | 
			
		||||
): IInventoryChanges => {
 | 
			
		||||
    const index =
 | 
			
		||||
        inventory.CrewShipSalvagedWeaponSkins.push({ ItemType: typeName, UpgradeFingerprint: upgradeFingerprint }) - 1;
 | 
			
		||||
    // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
 | 
			
		||||
    inventoryChanges.CrewShipSalvagedWeaponSkins ??= [];
 | 
			
		||||
    (inventoryChanges.CrewShipSalvagedWeaponSkins as IUpgradeClient[]).push(
 | 
			
		||||
        inventory.CrewShipSalvagedWeaponSkins[index].toJSON<IUpgradeClient>()
 | 
			
		||||
    );
 | 
			
		||||
    return inventoryChanges;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
const addCrewShip = (
 | 
			
		||||
    inventory: TInventoryDatabaseDocument,
 | 
			
		||||
    typeName: string,
 | 
			
		||||
 | 
			
		||||
@ -947,15 +947,17 @@ export interface IPersonalTechProjectDatabase {
 | 
			
		||||
    State: number;
 | 
			
		||||
    ReqCredits: number;
 | 
			
		||||
    ItemType: string;
 | 
			
		||||
    ProductCategory?: string;
 | 
			
		||||
    CategoryItemId?: Types.ObjectId;
 | 
			
		||||
    ReqItems: ITypeCount[];
 | 
			
		||||
    HasContributions?: boolean;
 | 
			
		||||
    CompletionDate?: Date;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface IPersonalTechProjectClient extends Omit<IPersonalTechProjectDatabase, "CompletionDate"> {
 | 
			
		||||
    CompletionDate?: IMongoDate;
 | 
			
		||||
    ProductCategory?: string;
 | 
			
		||||
export interface IPersonalTechProjectClient
 | 
			
		||||
    extends Omit<IPersonalTechProjectDatabase, "CategoryItemId" | "CompletionDate"> {
 | 
			
		||||
    CategoryItemId?: IOid;
 | 
			
		||||
    CompletionDate?: IMongoDate;
 | 
			
		||||
    ItemId: IOid;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -43,6 +43,7 @@ export type IInventoryChanges = {
 | 
			
		||||
    Drones?: IDroneClient[];
 | 
			
		||||
    MiscItems?: IMiscItem[];
 | 
			
		||||
    EmailItems?: ITypeCount[];
 | 
			
		||||
    CrewShipRawSalvage?: ITypeCount[];
 | 
			
		||||
    Nemesis?: Partial<INemesisClient>;
 | 
			
		||||
    NewVendorPurchase?: IRecentVendorPurchaseClient; // >= 38.5.0
 | 
			
		||||
    RecentVendorPurchases?: IRecentVendorPurchaseClient; // < 38.5.0
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user