forked from OpenWF/SpaceNinjaServer
move migration to cleanupInventory
This commit is contained in:
parent
f2d3837dc0
commit
3a3d5de5dc
@ -5,17 +5,15 @@ import { Inventory } from "../../models/inventoryModels/inventoryModel.ts";
|
||||
import { config } from "../../services/configService.ts";
|
||||
import allDialogue from "../../../static/fixed_responses/allDialogue.json" with { type: "json" };
|
||||
import type { ILoadoutDatabase } from "../../types/saveLoadoutTypes.ts";
|
||||
import type { IInventoryClient, IShipInventory, IWeaponSkinClient } from "../../types/inventoryTypes/inventoryTypes.ts";
|
||||
import type { IInventoryClient, IShipInventory } from "../../types/inventoryTypes/inventoryTypes.ts";
|
||||
import { equipmentKeys } from "../../types/inventoryTypes/inventoryTypes.ts";
|
||||
import type { IPolarity } from "../../types/inventoryTypes/commonInventoryTypes.ts";
|
||||
import { ArtifactPolarity } from "../../types/inventoryTypes/commonInventoryTypes.ts";
|
||||
import type { ICountedItem } from "warframe-public-export-plus";
|
||||
import { ExportCustoms } from "warframe-public-export-plus";
|
||||
import { applyCheatsToInfestedFoundry, handleSubsumeCompletion } from "../../services/infestedFoundryService.ts";
|
||||
import {
|
||||
addEmailItem,
|
||||
addItem,
|
||||
addItems,
|
||||
addMiscItems,
|
||||
allDailyAffiliationKeys,
|
||||
checkCalendarAutoAdvance,
|
||||
@ -24,7 +22,7 @@ import {
|
||||
getCalendarProgress
|
||||
} from "../../services/inventoryService.ts";
|
||||
import { logger } from "../../utils/logger.ts";
|
||||
import { addString, catBreadHash } from "../../helpers/stringHelpers.ts";
|
||||
import { addString } from "../../helpers/stringHelpers.ts";
|
||||
import { Types } from "mongoose";
|
||||
import { getNemesisManifest } from "../../helpers/nemesisHelpers.ts";
|
||||
import { getPersonalRooms } from "../../services/personalRoomsService.ts";
|
||||
@ -178,7 +176,7 @@ export const inventoryController: RequestHandler = async (request, response) =>
|
||||
}
|
||||
}
|
||||
|
||||
cleanupInventory(inventory);
|
||||
await cleanupInventory(inventory);
|
||||
|
||||
inventory.NextRefill = new Date((today + 1) * 86400000); // tomorrow at 0 UTC
|
||||
//await inventory.save();
|
||||
@ -269,65 +267,6 @@ export const inventoryController: RequestHandler = async (request, response) =>
|
||||
}
|
||||
}
|
||||
inventory.LastInventorySync = new Types.ObjectId();
|
||||
|
||||
const weaponMap = new Map<string, string>();
|
||||
for (const skin of inventory.WeaponSkins) {
|
||||
weaponMap.set(skin.ItemType, skin._id.toString());
|
||||
}
|
||||
|
||||
const itemsToAdd = new Set<string>();
|
||||
|
||||
for (const key of equipmentKeys) {
|
||||
if (key in inventory) {
|
||||
for (const equipment of inventory[key]) {
|
||||
for (const config of equipment.Configs) {
|
||||
if (config.Skins) collectSkins(config.Skins, weaponMap, itemsToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of ["AdultOperatorLoadOuts", "OperatorLoadOuts", "KahlLoadOuts"] as const) {
|
||||
if (key in inventory) {
|
||||
for (const loadOut of inventory[key]) {
|
||||
if (loadOut.Skins) collectSkins(loadOut.Skins, weaponMap, itemsToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory.LotusCustomization?.Skins) collectSkins(inventory.LotusCustomization.Skins, weaponMap, itemsToAdd);
|
||||
|
||||
if (itemsToAdd.size > 0) {
|
||||
logger.debug(`Adding ${itemsToAdd.size} items due to migration from unlockAllSkins cheat`);
|
||||
const inventoryChanges = await addItems(inventory, Array.from(itemsToAdd));
|
||||
|
||||
if (inventoryChanges.WeaponSkins) {
|
||||
for (const skin of inventoryChanges.WeaponSkins as IWeaponSkinClient[]) {
|
||||
weaponMap.set(skin.ItemType, skin.ItemId.toString());
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of equipmentKeys) {
|
||||
if (key in inventory) {
|
||||
for (const equipment of inventory[key]) {
|
||||
for (const config of equipment.Configs) {
|
||||
if (config.Skins) replaceSkinIds(config.Skins, weaponMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of ["AdultOperatorLoadOuts", "OperatorLoadOuts", "KahlLoadOuts"] as const) {
|
||||
if (key in inventory) {
|
||||
for (const loadOut of inventory[key]) {
|
||||
if (loadOut.Skins) replaceSkinIds(loadOut.Skins, weaponMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory.LotusCustomization?.Skins) replaceSkinIds(inventory.LotusCustomization.Skins, weaponMap);
|
||||
}
|
||||
|
||||
await inventory.save();
|
||||
|
||||
response.json(
|
||||
@ -520,27 +459,3 @@ const getExpRequiredForMr = (rank: number): number => {
|
||||
}
|
||||
return 2_250_000 + 147_500 * (rank - 30);
|
||||
};
|
||||
|
||||
const skinLookupTable: Record<number, string> = {};
|
||||
for (const key of Object.keys(ExportCustoms)) {
|
||||
skinLookupTable[catBreadHash(key)] = key;
|
||||
}
|
||||
|
||||
const collectSkins = (skins: string[], weaponMap: Map<string, string>, itemsToAdd: Set<string>): void => {
|
||||
for (const skinId of skins) {
|
||||
if (skinId.startsWith("ca70ca70ca70ca70")) {
|
||||
const typeName = skinLookupTable[parseInt(skinId.slice(16), 16)];
|
||||
if (!weaponMap.has(typeName)) itemsToAdd.add(typeName);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const replaceSkinIds = (skins: string[], weaponMap: Map<string, string>): void => {
|
||||
for (let i = 0; i < skins.length; i++) {
|
||||
const skinId = skins[i];
|
||||
if (skinId.startsWith("ca70ca70ca70ca70")) {
|
||||
const inventoryId = weaponMap.get(skinLookupTable[parseInt(skinId.slice(16), 16)]);
|
||||
if (inventoryId) skins[i] = inventoryId;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -83,7 +83,7 @@ import type { INemesisProfile } from "../helpers/nemesisHelpers.ts";
|
||||
import { generateNemesisProfile } from "../helpers/nemesisHelpers.ts";
|
||||
import type { TAccountDocument } from "./loginService.ts";
|
||||
import { unixTimesInMs } from "../constants/timeConstants.ts";
|
||||
import { addString } from "../helpers/stringHelpers.ts";
|
||||
import { addString, catBreadHash } from "../helpers/stringHelpers.ts";
|
||||
import type {
|
||||
IEquipmentClient,
|
||||
IEquipmentDatabase,
|
||||
@ -2254,7 +2254,7 @@ export const setupKahlSyndicate = (inventory: TInventoryDatabaseDocument): void
|
||||
});
|
||||
};
|
||||
|
||||
export const cleanupInventory = (inventory: TInventoryDatabaseDocument): void => {
|
||||
export const cleanupInventory = async (inventory: TInventoryDatabaseDocument): Promise<void> => {
|
||||
inventory.CurrentLoadOutIds = inventory.CurrentLoadOutIds.map(fromDbOid);
|
||||
|
||||
let index = inventory.MiscItems.findIndex(x => x.ItemType == "");
|
||||
@ -2308,6 +2308,67 @@ export const cleanupInventory = (inventory: TInventoryDatabaseDocument): void =>
|
||||
logger.debug(`removed ModularParts from ${numFixed} non-modular items`);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const weaponMap = new Map<string, string>();
|
||||
for (const skin of inventory.WeaponSkins) {
|
||||
weaponMap.set(skin.ItemType, skin._id.toString());
|
||||
}
|
||||
|
||||
const itemsToAdd = new Set<string>();
|
||||
|
||||
for (const key of equipmentKeys) {
|
||||
if (key in inventory) {
|
||||
for (const equipment of inventory[key]) {
|
||||
for (const config of equipment.Configs) {
|
||||
if (config.Skins) collectSkins(config.Skins, weaponMap, itemsToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of ["AdultOperatorLoadOuts", "OperatorLoadOuts", "KahlLoadOuts"] as const) {
|
||||
if (key in inventory) {
|
||||
for (const loadOut of inventory[key]) {
|
||||
if (loadOut.Skins) collectSkins(loadOut.Skins, weaponMap, itemsToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory.LotusCustomization?.Skins)
|
||||
collectSkins(inventory.LotusCustomization.Skins, weaponMap, itemsToAdd);
|
||||
|
||||
if (itemsToAdd.size > 0) {
|
||||
logger.debug(`Adding ${itemsToAdd.size} items due to migration from unlockAllSkins cheat`);
|
||||
const inventoryChanges = await addItems(inventory, Array.from(itemsToAdd));
|
||||
|
||||
if (inventoryChanges.WeaponSkins) {
|
||||
for (const skin of inventoryChanges.WeaponSkins as IWeaponSkinClient[]) {
|
||||
weaponMap.set(skin.ItemType, skin.ItemId.toString());
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of equipmentKeys) {
|
||||
if (key in inventory) {
|
||||
for (const equipment of inventory[key]) {
|
||||
for (const config of equipment.Configs) {
|
||||
if (config.Skins) replaceSkinIds(config.Skins, weaponMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of ["AdultOperatorLoadOuts", "OperatorLoadOuts", "KahlLoadOuts"] as const) {
|
||||
if (key in inventory) {
|
||||
for (const loadOut of inventory[key]) {
|
||||
if (loadOut.Skins) replaceSkinIds(loadOut.Skins, weaponMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (inventory.LotusCustomization?.Skins) replaceSkinIds(inventory.LotusCustomization.Skins, weaponMap);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getDialogue = (inventory: TInventoryDatabaseDocument, dialogueName: string): IDialogueDatabase => {
|
||||
@ -2499,3 +2560,27 @@ export const updateEntratiVault = (inventory: TInventoryDatabaseDocument): void
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const skinLookupTable: Record<number, string> = {};
|
||||
for (const key of Object.keys(ExportCustoms)) {
|
||||
skinLookupTable[catBreadHash(key)] = key;
|
||||
}
|
||||
|
||||
const collectSkins = (skins: string[], weaponMap: Map<string, string>, itemsToAdd: Set<string>): void => {
|
||||
for (const skinId of skins) {
|
||||
if (skinId.startsWith("ca70ca70ca70ca70")) {
|
||||
const typeName = skinLookupTable[parseInt(skinId.slice(16), 16)];
|
||||
if (!weaponMap.has(typeName)) itemsToAdd.add(typeName);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const replaceSkinIds = (skins: string[], weaponMap: Map<string, string>): void => {
|
||||
for (let i = 0; i < skins.length; i++) {
|
||||
const skinId = skins[i];
|
||||
if (skinId.startsWith("ca70ca70ca70ca70")) {
|
||||
const inventoryId = weaponMap.get(skinLookupTable[parseInt(skinId.slice(16), 16)]);
|
||||
if (inventoryId) skins[i] = inventoryId;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user