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,
|
|
|
|
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),
|
|
|
|
CrewMembers: client.CrewMembers ? convertCrewShipMembers(client.CrewMembers) : undefined,
|
|
|
|
Details: client.Details ? convertKubrowDetails(client.Details) : undefined,
|
|
|
|
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-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-01-21 20:05:28 +01:00
|
|
|
if (client.Upgrades !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
replaceArray<IUpgradeDatabase>(db.Upgrades, client.Upgrades.map(convertUpgrade));
|
|
|
|
}
|
2025-02-04 09:19:14 -08:00
|
|
|
for (const key of ["RawUpgrades", "MiscItems", "Consumables"] 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-01-21 20:05:28 +01:00
|
|
|
if (client.UseAdultOperatorLoadout !== undefined) {
|
2025-01-20 12:19:32 +01:00
|
|
|
db.UseAdultOperatorLoadout = client.UseAdultOperatorLoadout;
|
|
|
|
}
|
|
|
|
for (const key of [
|
|
|
|
"PlayerLevel",
|
|
|
|
"RegularCredits",
|
|
|
|
"PremiumCredits",
|
|
|
|
"PremiumCreditsFree",
|
|
|
|
"FusionPoints",
|
|
|
|
"PrimeTokens"
|
|
|
|
] 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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const key of ["ThemeStyle", "ThemeBackground", "ThemeSounds", "EquippedInstrument", "FocusAbility"] 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];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const key of ["EquippedGear", "EquippedEmotes", "NodeIntrosCompleted"] 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-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);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|