2025-01-20 12:19:32 +01:00
|
|
|
import { Types } from "mongoose";
|
|
|
|
import {
|
|
|
|
IEquipmentClient,
|
|
|
|
IEquipmentDatabase,
|
|
|
|
IOperatorConfigClient,
|
|
|
|
IOperatorConfigDatabase
|
|
|
|
} from "../types/inventoryTypes/commonInventoryTypes";
|
|
|
|
import { IMongoDate } from "../types/commonTypes";
|
|
|
|
import {
|
|
|
|
equipmentKeys,
|
2025-01-21 20:07:15 +01:00
|
|
|
ICrewShipMemberClient,
|
|
|
|
ICrewShipMemberDatabase,
|
2025-01-20 12:19:32 +01:00
|
|
|
ICrewShipMembersClient,
|
|
|
|
ICrewShipMembersDatabase,
|
|
|
|
IDialogueClient,
|
|
|
|
IDialogueDatabase,
|
|
|
|
IDialogueHistoryClient,
|
|
|
|
IDialogueHistoryDatabase,
|
|
|
|
IInfestedFoundryClient,
|
|
|
|
IInfestedFoundryDatabase,
|
|
|
|
IInventoryClient,
|
2025-01-27 13:18:16 +01:00
|
|
|
IKubrowPetDetailsClient,
|
|
|
|
IKubrowPetDetailsDatabase,
|
2025-01-20 12:19:32 +01:00
|
|
|
ILoadoutConfigClient,
|
|
|
|
ILoadOutPresets,
|
2025-03-23 13:33:26 -07:00
|
|
|
INemesisClient,
|
|
|
|
INemesisDatabase,
|
|
|
|
IPendingRecipeClient,
|
|
|
|
IPendingRecipeDatabase,
|
|
|
|
IQuestKeyClient,
|
|
|
|
IQuestKeyDatabase,
|
2025-01-20 12:19:32 +01:00
|
|
|
ISlots,
|
|
|
|
IUpgradeClient,
|
|
|
|
IUpgradeDatabase,
|
|
|
|
IWeaponSkinClient,
|
|
|
|
IWeaponSkinDatabase
|
|
|
|
} from "../types/inventoryTypes/inventoryTypes";
|
|
|
|
import { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel";
|
|
|
|
import { ILoadoutConfigDatabase, ILoadoutDatabase } from "../types/saveLoadoutTypes";
|
|
|
|
|
|
|
|
const convertDate = (value: IMongoDate): Date => {
|
|
|
|
return new Date(parseInt(value.$date.$numberLong));
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertOptionalDate = (value: IMongoDate | undefined): Date | undefined => {
|
|
|
|
return value ? convertDate(value) : undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
|
|
|
|
const { ItemId, ...rest } = client;
|
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
_id: new Types.ObjectId(ItemId.$oid),
|
|
|
|
InfestationDate: convertOptionalDate(client.InfestationDate),
|
|
|
|
Expiry: convertOptionalDate(client.Expiry),
|
2025-01-27 13:18:16 +01:00
|
|
|
UpgradesExpiry: convertOptionalDate(client.UpgradesExpiry),
|
2025-04-07 05:30:15 -07:00
|
|
|
UmbraDate: convertOptionalDate(client.UmbraDate),
|
2025-01-27 13:18:16 +01:00
|
|
|
CrewMembers: client.CrewMembers ? convertCrewShipMembers(client.CrewMembers) : undefined,
|
|
|
|
Details: client.Details ? convertKubrowDetails(client.Details) : undefined,
|
2025-02-24 20:56:34 -08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
2025-01-27 13:18:16 +01:00
|
|
|
Configs: client.Configs
|
|
|
|
? client.Configs.map(obj =>
|
|
|
|
Object.fromEntries(
|
|
|
|
Object.entries(obj).filter(([_, value]) => !Array.isArray(value) || value.length > 0)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
: []
|
2025-01-20 12:19:32 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertWeaponSkin = (client: IWeaponSkinClient): IWeaponSkinDatabase => {
|
|
|
|
const { ItemId, ...rest } = client;
|
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
_id: new Types.ObjectId(ItemId.$oid)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertUpgrade = (client: IUpgradeClient): IUpgradeDatabase => {
|
|
|
|
const { ItemId, ...rest } = client;
|
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
_id: new Types.ObjectId(ItemId.$oid)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertOperatorConfig = (client: IOperatorConfigClient): IOperatorConfigDatabase => {
|
|
|
|
const { ItemId, ...rest } = client;
|
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
_id: new Types.ObjectId(ItemId.$oid)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const replaceArray = <T>(arr: T[], replacement: T[]): void => {
|
|
|
|
arr.splice(0, arr.length);
|
|
|
|
replacement.forEach(x => {
|
|
|
|
arr.push(x);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const replaceSlots = (db: ISlots, client: ISlots): void => {
|
|
|
|
db.Extra = client.Extra;
|
|
|
|
db.Slots = client.Slots;
|
|
|
|
};
|
|
|
|
|
2025-01-21 20:07:15 +01:00
|
|
|
const convertCrewShipMember = (client: ICrewShipMemberClient): ICrewShipMemberDatabase => {
|
|
|
|
return {
|
|
|
|
...client,
|
|
|
|
ItemId: client.ItemId ? new Types.ObjectId(client.ItemId.$oid) : undefined
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2025-01-20 12:19:32 +01:00
|
|
|
const convertCrewShipMembers = (client: ICrewShipMembersClient): ICrewShipMembersDatabase => {
|
|
|
|
return {
|
2025-01-21 20:07:15 +01:00
|
|
|
SLOT_A: client.SLOT_A ? convertCrewShipMember(client.SLOT_A) : undefined,
|
|
|
|
SLOT_B: client.SLOT_B ? convertCrewShipMember(client.SLOT_B) : undefined,
|
|
|
|
SLOT_C: client.SLOT_C ? convertCrewShipMember(client.SLOT_C) : undefined
|
2025-01-20 12:19:32 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertInfestedFoundry = (client: IInfestedFoundryClient): IInfestedFoundryDatabase => {
|
|
|
|
return {
|
|
|
|
...client,
|
|
|
|
LastConsumedSuit: client.LastConsumedSuit ? convertEquipment(client.LastConsumedSuit) : undefined,
|
|
|
|
AbilityOverrideUnlockCooldown: convertOptionalDate(client.AbilityOverrideUnlockCooldown)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertDialogue = (client: IDialogueClient): IDialogueDatabase => {
|
|
|
|
return {
|
|
|
|
...client,
|
|
|
|
AvailableDate: convertDate(client.AvailableDate),
|
|
|
|
AvailableGiftDate: convertDate(client.AvailableGiftDate),
|
|
|
|
RankUpExpiry: convertDate(client.RankUpExpiry),
|
|
|
|
BountyChemExpiry: convertDate(client.BountyChemExpiry)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertDialogueHistory = (client: IDialogueHistoryClient): IDialogueHistoryDatabase => {
|
|
|
|
return {
|
|
|
|
YearIteration: client.YearIteration,
|
|
|
|
Dialogues: client.Dialogues ? client.Dialogues.map(convertDialogue) : undefined
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2025-01-27 13:18:16 +01:00
|
|
|
const convertKubrowDetails = (client: IKubrowPetDetailsClient): IKubrowPetDetailsDatabase => {
|
|
|
|
return {
|
|
|
|
...client,
|
|
|
|
HatchDate: convertDate(client.HatchDate)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2025-03-23 13:33:26 -07:00
|
|
|
const convertQuestKey = (client: IQuestKeyClient): IQuestKeyDatabase => {
|
|
|
|
return {
|
|
|
|
...client,
|
|
|
|
CompletionDate: convertOptionalDate(client.CompletionDate)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertPendingRecipe = (client: IPendingRecipeClient): IPendingRecipeDatabase => {
|
|
|
|
return {
|
|
|
|
...client,
|
|
|
|
CompletionDate: convertDate(client.CompletionDate)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const convertNemesis = (client: INemesisClient): INemesisDatabase => {
|
|
|
|
return {
|
|
|
|
...client,
|
|
|
|
d: convertDate(client.d)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2025-01-20 12:19:32 +01:00
|
|
|
export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
|
|
|
|
for (const key of equipmentKeys) {
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client[key] !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
replaceArray<IEquipmentDatabase>(db[key], client[key].map(convertEquipment));
|
|
|
|
}
|
|
|
|
}
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client.WeaponSkins !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
replaceArray<IWeaponSkinDatabase>(db.WeaponSkins, client.WeaponSkins.map(convertWeaponSkin));
|
|
|
|
}
|
2025-03-23 13:33:26 -07:00
|
|
|
for (const key of ["Upgrades", "CrewShipSalvagedWeaponSkins", "CrewShipWeaponSkins"] as const) {
|
|
|
|
if (client[key] !== undefined) {
|
|
|
|
replaceArray<IUpgradeDatabase>(db[key], client[key].map(convertUpgrade));
|
|
|
|
}
|
2025-01-20 12:19:32 +01:00
|
|
|
}
|
2025-03-23 13:33:26 -07:00
|
|
|
for (const key of [
|
|
|
|
"RawUpgrades",
|
|
|
|
"MiscItems",
|
|
|
|
"Consumables",
|
|
|
|
"Recipes",
|
|
|
|
"LevelKeys",
|
|
|
|
"EmailItems",
|
|
|
|
"ShipDecorations",
|
|
|
|
"CrewShipAmmo",
|
|
|
|
"CrewShipRawSalvage"
|
|
|
|
] as const) {
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client[key] !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db[key].splice(0, db[key].length);
|
|
|
|
client[key].forEach(x => {
|
|
|
|
db[key].push({
|
|
|
|
ItemType: x.ItemType,
|
|
|
|
ItemCount: x.ItemCount
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2025-01-27 13:18:16 +01:00
|
|
|
for (const key of ["AdultOperatorLoadOuts", "OperatorLoadOuts", "KahlLoadOuts"] as const) {
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client[key] !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
replaceArray<IOperatorConfigDatabase>(db[key], client[key].map(convertOperatorConfig));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const key of [
|
|
|
|
"SuitBin",
|
|
|
|
"WeaponBin",
|
|
|
|
"SentinelBin",
|
|
|
|
"SpaceSuitBin",
|
|
|
|
"SpaceWeaponBin",
|
|
|
|
"PvpBonusLoadoutBin",
|
|
|
|
"PveBonusLoadoutBin",
|
|
|
|
"RandomModBin",
|
|
|
|
"MechBin",
|
|
|
|
"CrewMemberBin",
|
|
|
|
"OperatorAmpBin",
|
|
|
|
"CrewShipSalvageBin"
|
|
|
|
] as const) {
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client[key] !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
replaceSlots(db[key], client[key]);
|
|
|
|
}
|
|
|
|
}
|
2025-03-23 13:33:26 -07:00
|
|
|
for (const key of [
|
|
|
|
"UseAdultOperatorLoadout",
|
|
|
|
"HasOwnedVoidProjectionsPreviously",
|
|
|
|
"ReceivedStartingGear",
|
|
|
|
"ArchwingEnabled",
|
|
|
|
"PlayedParkourTutorial"
|
|
|
|
] as const) {
|
|
|
|
if (client[key] !== undefined) {
|
|
|
|
db[key] = client[key];
|
|
|
|
}
|
2025-01-20 12:19:32 +01:00
|
|
|
}
|
|
|
|
for (const key of [
|
|
|
|
"PlayerLevel",
|
|
|
|
"RegularCredits",
|
|
|
|
"PremiumCredits",
|
|
|
|
"PremiumCreditsFree",
|
|
|
|
"FusionPoints",
|
2025-03-23 13:33:26 -07:00
|
|
|
"PrimeTokens",
|
|
|
|
"TradesRemaining",
|
|
|
|
"GiftsRemaining",
|
|
|
|
"ChallengesFixVersion"
|
2025-01-20 12:19:32 +01:00
|
|
|
] as const) {
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client[key] !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db[key] = client[key];
|
|
|
|
}
|
|
|
|
}
|
2025-03-23 13:33:26 -07:00
|
|
|
for (const key of [
|
|
|
|
"ThemeStyle",
|
|
|
|
"ThemeBackground",
|
|
|
|
"ThemeSounds",
|
|
|
|
"EquippedInstrument",
|
|
|
|
"FocusAbility",
|
|
|
|
"ActiveQuest",
|
|
|
|
"SupportedSyndicate",
|
|
|
|
"ActiveAvatarImageType"
|
|
|
|
] as const) {
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client[key] !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db[key] = client[key];
|
|
|
|
}
|
|
|
|
}
|
2025-03-23 13:33:26 -07:00
|
|
|
for (const key of [
|
|
|
|
"EquippedGear",
|
|
|
|
"EquippedEmotes",
|
|
|
|
"NodeIntrosCompleted",
|
|
|
|
"DeathMarks",
|
|
|
|
"Wishlist",
|
|
|
|
"NemesisAbandonedRewards"
|
|
|
|
] as const) {
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client[key] !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db[key] = client[key];
|
|
|
|
}
|
|
|
|
}
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client.XPInfo !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db.XPInfo = client.XPInfo;
|
|
|
|
}
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client.CurrentLoadOutIds !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db.CurrentLoadOutIds = client.CurrentLoadOutIds;
|
|
|
|
}
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client.Affiliations !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db.Affiliations = client.Affiliations;
|
|
|
|
}
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client.FusionTreasures !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db.FusionTreasures = client.FusionTreasures;
|
|
|
|
}
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client.FocusUpgrades !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db.FocusUpgrades = client.FocusUpgrades;
|
|
|
|
}
|
2025-02-08 22:22:30 -08:00
|
|
|
if (client.EvolutionProgress !== undefined) {
|
|
|
|
db.EvolutionProgress = client.EvolutionProgress;
|
|
|
|
}
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client.InfestedFoundry !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db.InfestedFoundry = convertInfestedFoundry(client.InfestedFoundry);
|
|
|
|
}
|
2025-01-21 20:05:28 +01:00
|
|
|
if (client.DialogueHistory !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db.DialogueHistory = convertDialogueHistory(client.DialogueHistory);
|
|
|
|
}
|
2025-03-23 05:20:48 -07:00
|
|
|
if (client.CustomMarkers !== undefined) {
|
|
|
|
db.CustomMarkers = client.CustomMarkers;
|
|
|
|
}
|
2025-03-23 13:33:26 -07:00
|
|
|
if (client.ChallengeProgress !== undefined) {
|
|
|
|
db.ChallengeProgress = client.ChallengeProgress;
|
|
|
|
}
|
|
|
|
if (client.QuestKeys !== undefined) {
|
|
|
|
replaceArray<IQuestKeyDatabase>(db.QuestKeys, client.QuestKeys.map(convertQuestKey));
|
|
|
|
}
|
|
|
|
if (client.LastRegionPlayed !== undefined) {
|
|
|
|
db.LastRegionPlayed = client.LastRegionPlayed;
|
|
|
|
}
|
|
|
|
if (client.PendingRecipes !== undefined) {
|
|
|
|
replaceArray<IPendingRecipeDatabase>(db.PendingRecipes, client.PendingRecipes.map(convertPendingRecipe));
|
|
|
|
}
|
|
|
|
if (client.TauntHistory !== undefined) {
|
|
|
|
db.TauntHistory = client.TauntHistory;
|
|
|
|
}
|
|
|
|
if (client.LoreFragmentScans !== undefined) {
|
|
|
|
db.LoreFragmentScans = client.LoreFragmentScans;
|
|
|
|
}
|
|
|
|
for (const key of ["PendingSpectreLoadouts", "SpectreLoadouts"] as const) {
|
|
|
|
if (client[key] !== undefined) {
|
|
|
|
db[key] = client[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (client.FocusXP !== undefined) {
|
|
|
|
db.FocusXP = client.FocusXP;
|
|
|
|
}
|
|
|
|
for (const key of ["Alignment", "AlignmentReplay"] as const) {
|
|
|
|
if (client[key] !== undefined) {
|
|
|
|
db[key] = client[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (client.StepSequencers !== undefined) {
|
|
|
|
db.StepSequencers = client.StepSequencers;
|
|
|
|
}
|
|
|
|
if (client.CompletedJobChains !== undefined) {
|
|
|
|
db.CompletedJobChains = client.CompletedJobChains;
|
|
|
|
}
|
|
|
|
if (client.Nemesis !== undefined) {
|
|
|
|
db.Nemesis = convertNemesis(client.Nemesis);
|
|
|
|
}
|
|
|
|
if (client.PlayerSkills !== undefined) {
|
|
|
|
db.PlayerSkills = client.PlayerSkills;
|
|
|
|
}
|
|
|
|
if (client.LotusCustomization !== undefined) {
|
|
|
|
db.LotusCustomization = client.LotusCustomization;
|
|
|
|
}
|
|
|
|
if (client.CollectibleSeries !== undefined) {
|
|
|
|
db.CollectibleSeries = client.CollectibleSeries;
|
|
|
|
}
|
|
|
|
for (const key of ["LibraryAvailableDailyTaskInfo", "LibraryActiveDailyTaskInfo"] as const) {
|
|
|
|
if (client[key] !== undefined) {
|
|
|
|
db[key] = client[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (client.EndlessXP !== undefined) {
|
|
|
|
db.EndlessXP = client.EndlessXP;
|
|
|
|
}
|
|
|
|
if (client.SongChallenges !== undefined) {
|
|
|
|
db.SongChallenges = client.SongChallenges;
|
|
|
|
}
|
|
|
|
if (client.Missions !== undefined) {
|
|
|
|
db.Missions = client.Missions;
|
|
|
|
}
|
|
|
|
if (client.FlavourItems !== undefined) {
|
|
|
|
db.FlavourItems.splice(0, db.FlavourItems.length);
|
|
|
|
client.FlavourItems.forEach(x => {
|
|
|
|
db.FlavourItems.push({
|
|
|
|
ItemType: x.ItemType
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2025-01-20 12:19:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const convertLoadOutConfig = (client: ILoadoutConfigClient): ILoadoutConfigDatabase => {
|
|
|
|
const { ItemId, ...rest } = client;
|
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
_id: new Types.ObjectId(ItemId.$oid)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const importLoadOutPresets = (db: ILoadoutDatabase, client: ILoadOutPresets): void => {
|
|
|
|
db.NORMAL = client.NORMAL.map(convertLoadOutConfig);
|
|
|
|
db.SENTINEL = client.SENTINEL.map(convertLoadOutConfig);
|
|
|
|
db.ARCHWING = client.ARCHWING.map(convertLoadOutConfig);
|
|
|
|
db.NORMAL_PVP = client.NORMAL_PVP.map(convertLoadOutConfig);
|
|
|
|
db.LUNARO = client.LUNARO.map(convertLoadOutConfig);
|
|
|
|
db.OPERATOR = client.OPERATOR.map(convertLoadOutConfig);
|
|
|
|
db.KDRIVE = client.KDRIVE.map(convertLoadOutConfig);
|
|
|
|
db.DATAKNIFE = client.DATAKNIFE.map(convertLoadOutConfig);
|
|
|
|
db.MECH = client.MECH.map(convertLoadOutConfig);
|
|
|
|
db.OPERATOR_ADULT = client.OPERATOR_ADULT.map(convertLoadOutConfig);
|
|
|
|
db.DRIFTER = client.DRIFTER.map(convertLoadOutConfig);
|
|
|
|
};
|