返回提交历史
Modified
src/controllers/api/nemesisController.ts
+5
-3
Modified
src/controllers/dynamic/getProfileViewingDataController.ts
+14
-11
Modified
src/helpers/inventoryHelpers.ts
+5
-0
Modified
src/models/inventoryModels/inventoryModel.ts
+14
-11
Modified
src/models/inventoryModels/loadoutModel.ts
+15
-12
Modified
src/services/importService.ts
+61
-19
Modified
src/services/inventoryService.ts
+3
-0
Modified
src/services/missionInventoryUpdateService.ts
+2
-6
Modified
src/services/saveLoadoutService.ts
+8
-16
Modified
src/types/equipmentTypes.ts
+37
-17
Modified
src/types/inventoryTypes/inventoryTypes.ts
+3
-1
Modified
src/types/saveLoadoutTypes.ts
+26
-12
XFEstudio/SpaceNinjaServer
chore: avoid using client oid representation in database (#2685)
Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2685 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
dfd1fb83
代码差异
12 个文件
+193
-108
@@ -1,4 +1,4 @@
1
import { version_compare } from "@/src/helpers/inventoryHelpers";
1
import { fromDbOid, version_compare } from "@/src/helpers/inventoryHelpers";
2
2
import {
3
3
antivirusMods,
4
4
decodeNemesisGuess,
@@ -130,7 +130,9 @@ export const nemesisController: RequestHandler = async (req, res) => {
130
130
if (result1 == GUESS_CORRECT || result2 == GUESS_CORRECT || result3 == GUESS_CORRECT) {
131
131
let antivirusGain = 5;
132
132
const loadout = (await Loadout.findById(inventory.LoadOutPresets, "DATAKNIFE"))!;
133
const dataknifeLoadout = loadout.DATAKNIFE.id(inventory.CurrentLoadOutIds[LoadoutIndex.DATAKNIFE].$oid);
133
const dataknifeLoadout = loadout.DATAKNIFE.id(
134
fromDbOid(inventory.CurrentLoadOutIds[LoadoutIndex.DATAKNIFE])
135
);
134
136
const dataknifeConfigIndex = dataknifeLoadout?.s?.mod ?? 0;
135
137
const dataknifeUpgrades = inventory.DataKnives[0].Configs[dataknifeConfigIndex].Upgrades!;
136
138
for (const upgrade of body.knife!.AttachedUpgrades) {
@@ -219,7 +221,7 @@ export const nemesisController: RequestHandler = async (req, res) => {
219
221
// Subtract a charge from all requiem mods installed on parazon
220
222
const loadout = (await Loadout.findById(inventory.LoadOutPresets, "DATAKNIFE"))!;
221
223
const dataknifeLoadout = loadout.DATAKNIFE.id(
222
inventory.CurrentLoadOutIds[LoadoutIndex.DATAKNIFE].$oid
224
fromDbOid(inventory.CurrentLoadOutIds[LoadoutIndex.DATAKNIFE])
223
225
);
224
226
const dataknifeConfigIndex = dataknifeLoadout?.s?.mod ?? 0;
225
227
const dataknifeUpgrades = inventory.DataKnives[0].Configs[dataknifeConfigIndex].Upgrades!;
@@ -1,4 +1,4 @@
1
import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
1
import { fromDbOid, toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
2
2
import { Guild, GuildMember, TGuildDatabaseDocument } from "@/src/models/guildModel";
3
3
import { Inventory, TInventoryDatabaseDocument } from "@/src/models/inventoryModels/inventoryModel";
4
4
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
@@ -13,7 +13,8 @@ import {
13
13
IDailyAffiliations,
14
14
IMission,
15
15
IPlayerSkills,
16
ITypeXPItem
16
ITypeXPItem,
17
LoadoutIndex
17
18
} from "@/src/types/inventoryTypes/inventoryTypes";
18
19
import { RequestHandler } from "express";
19
20
import { catBreadHash, getJSONfromString } from "@/src/helpers/stringHelpers";
@@ -298,30 +299,32 @@ const populateLoadout = async (
298
299
): Promise<void> => {
299
300
if (inventory.CurrentLoadOutIds.length) {
300
301
const loadout = (await Loadout.findById(inventory.LoadOutPresets, "NORMAL"))!;
301
result.LoadOutPreset = loadout.NORMAL.id(inventory.CurrentLoadOutIds[0].$oid)!.toJSON<ILoadoutConfigClient>();
302
result.LoadOutPreset = loadout.NORMAL.id(
303
fromDbOid(inventory.CurrentLoadOutIds[LoadoutIndex.NORMAL])
304
)!.toJSON<ILoadoutConfigClient>();
302
305
result.LoadOutPreset.ItemId = undefined;
303
306
const skins = new Set<string>();
304
if (result.LoadOutPreset.s) {
307
if (result.LoadOutPreset.s?.ItemId) {
305
308
result.LoadOutInventory.Suits = [
306
inventory.Suits.id(result.LoadOutPreset.s.ItemId.$oid)!.toJSON<IEquipmentClient>()
309
inventory.Suits.id(fromDbOid(result.LoadOutPreset.s.ItemId))!.toJSON<IEquipmentClient>()
307
310
];
308
311
resolveAndCollectSkins(inventory, skins, result.LoadOutInventory.Suits[0]);
309
312
}
310
if (result.LoadOutPreset.p) {
313
if (result.LoadOutPreset.p?.ItemId) {
311
314
result.LoadOutInventory.Pistols = [
312
inventory.Pistols.id(result.LoadOutPreset.p.ItemId.$oid)!.toJSON<IEquipmentClient>()
315
inventory.Pistols.id(fromDbOid(result.LoadOutPreset.p.ItemId))!.toJSON<IEquipmentClient>()
313
316
];
314
317
resolveAndCollectSkins(inventory, skins, result.LoadOutInventory.Pistols[0]);
315
318
}
316
if (result.LoadOutPreset.l) {
319
if (result.LoadOutPreset.l?.ItemId) {
317
320
result.LoadOutInventory.LongGuns = [
318
inventory.LongGuns.id(result.LoadOutPreset.l.ItemId.$oid)!.toJSON<IEquipmentClient>()
321
inventory.LongGuns.id(fromDbOid(result.LoadOutPreset.l.ItemId))!.toJSON<IEquipmentClient>()
319
322
];
320
323
resolveAndCollectSkins(inventory, skins, result.LoadOutInventory.LongGuns[0]);
321
324
}
322
if (result.LoadOutPreset.m) {
325
if (result.LoadOutPreset.m?.ItemId) {
323
326
result.LoadOutInventory.Melee = [
324
inventory.Melee.id(result.LoadOutPreset.m.ItemId.$oid)!.toJSON<IEquipmentClient>()
327
inventory.Melee.id(fromDbOid(result.LoadOutPreset.m.ItemId))!.toJSON<IEquipmentClient>()
325
328
];
326
329
resolveAndCollectSkins(inventory, skins, result.LoadOutInventory.Melee[0]);
327
330
}
@@ -44,6 +44,11 @@ export const fromOid = (oid: IOidWithLegacySupport): string => {
44
44
return (oid.$oid ?? oid.$id)!;
45
45
};
46
46
47
// For oids that may have been stored incorrectly
48
export const fromDbOid = (x: Types.ObjectId | IOid): Types.ObjectId => {
49
return "$oid" in x ? new Types.ObjectId(x.$oid) : x;
50
};
51
47
52
export const toMongoDate = (date: Date): IMongoDate => {
48
53
return { $date: { $numberLong: date.getTime().toString() } };
49
54
};
@@ -100,8 +100,8 @@ import {
100
100
IOperatorConfigDatabase,
101
101
IPolarity
102
102
} from "@/src/types/inventoryTypes/commonInventoryTypes";
103
import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
104
import { EquipmentSelectionSchema, oidSchema } from "@/src/models/inventoryModels/loadoutModel";
103
import { fromDbOid, toMongoDate, toOid } from "@/src/helpers/inventoryHelpers";
104
import { EquipmentSelectionSchema } from "@/src/models/inventoryModels/loadoutModel";
105
105
import { ICountedStoreItem } from "warframe-public-export-plus";
106
106
import { colorSchema, shipCustomizationSchema } from "@/src/models/commonModel";
107
107
import {
@@ -109,8 +109,8 @@ import {
109
109
ICrewShipMemberClient,
110
110
ICrewShipMemberDatabase,
111
111
ICrewShipMembersDatabase,
112
ICrewShipWeapon,
113
ICrewShipWeaponEmplacements,
112
ICrewShipWeaponDatabase,
113
ICrewShipWeaponEmplacementsDatabase,
114
114
IEquipmentClient,
115
115
IEquipmentDatabase,
116
116
IKubrowPetDetailsClient,
@@ -847,7 +847,6 @@ const endlessXpProgressSchema = new Schema<IEndlessXpProgressDatabase>(
847
847
},
848
848
{ _id: false }
849
849
);
850
851
850
endlessXpProgressSchema.set("toJSON", {
852
851
transform(_doc, ret: Record<string, any>) {
853
852
const db = ret as IEndlessXpProgressDatabase;
@@ -861,7 +860,8 @@ endlessXpProgressSchema.set("toJSON", {
861
860
}
862
861
}
863
862
});
864
const crewShipWeaponEmplacementsSchema = new Schema<ICrewShipWeaponEmplacements>(
863
864
const crewShipWeaponEmplacementsSchema = new Schema<ICrewShipWeaponEmplacementsDatabase>(
865
865
{
866
866
PRIMARY_A: EquipmentSelectionSchema,
867
867
PRIMARY_B: EquipmentSelectionSchema,
@@ -871,7 +871,7 @@ const crewShipWeaponEmplacementsSchema = new Schema<ICrewShipWeaponEmplacements>
871
871
{ _id: false }
872
872
);
873
873
874
const crewShipWeaponSchema = new Schema<ICrewShipWeapon>(
874
const crewShipWeaponSchema = new Schema<ICrewShipWeaponDatabase>(
875
875
{
876
876
PILOT: crewShipWeaponEmplacementsSchema,
877
877
PORT_GUNS: crewShipWeaponEmplacementsSchema,
@@ -1748,7 +1748,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
1748
1748
HasContributedToDojo: Boolean,
1749
1749
HWIDProtectEnabled: Boolean,
1750
1750
LoadOutPresets: { type: Schema.Types.ObjectId, ref: "Loadout" },
1751
CurrentLoadOutIds: [oidSchema],
1751
CurrentLoadOutIds: [Schema.Types.Mixed], // should be Types.ObjectId[] but might be IOid[] because of old commits
1752
1752
RandomUpgradesIdentified: Number,
1753
1753
BountyScore: Number,
1754
1754
//ChallengeInstanceStates: [Schema.Types.Mixed],
@@ -1808,12 +1808,15 @@ inventorySchema.set("toJSON", {
1808
1808
const inventoryDatabase = returnedObject as Partial<IInventoryDatabase>;
1809
1809
const inventoryResponse = returnedObject as IInventoryClient;
1810
1810
1811
if (inventoryDatabase.TrainingDate) {
1812
inventoryResponse.TrainingDate = toMongoDate(inventoryDatabase.TrainingDate);
1813
}
1814
1811
if (inventoryDatabase.Created) {
1815
1812
inventoryResponse.Created = toMongoDate(inventoryDatabase.Created);
1816
1813
}
1814
if (inventoryDatabase.CurrentLoadOutIds) {
1815
inventoryResponse.CurrentLoadOutIds = inventoryDatabase.CurrentLoadOutIds.map(x => toOid(fromDbOid(x)));
1816
}
1817
if (inventoryDatabase.TrainingDate) {
1818
inventoryResponse.TrainingDate = toMongoDate(inventoryDatabase.TrainingDate);
1819
}
1817
1820
if (inventoryDatabase.GuildId) {
1818
1821
inventoryResponse.GuildId = toOid(inventoryDatabase.GuildId);
1819
1822
}
@@ -1,21 +1,13 @@
1
import { fromDbOid, toOid } from "@/src/helpers/inventoryHelpers";
1
2
import { IOid } from "@/src/types/commonTypes";
2
import { IEquipmentSelection } from "@/src/types/equipmentTypes";
3
import { IEquipmentSelectionClient, IEquipmentSelectionDatabase } from "@/src/types/equipmentTypes";
3
4
import { ILoadoutConfigDatabase, ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
4
5
import { Document, Model, Schema, Types, model } from "mongoose";
5
6
6
export const oidSchema = new Schema<IOid>(
7
{
8
$oid: String
9
},
10
{
11
_id: false
12
}
13
);
14
15
7
//create a mongoose schema based on interface M
16
export const EquipmentSelectionSchema = new Schema<IEquipmentSelection>(
8
export const EquipmentSelectionSchema = new Schema<IEquipmentSelectionDatabase>(
17
9
{
18
ItemId: oidSchema,
10
ItemId: Schema.Types.Mixed, // should be Types.ObjectId but might be IOid because of old commits
19
11
mod: Number,
20
12
cus: Number,
21
13
hide: Boolean
@@ -24,6 +16,17 @@ export const EquipmentSelectionSchema = new Schema<IEquipmentSelection>(
24
16
_id: false
25
17
}
26
18
);
19
EquipmentSelectionSchema.set("toJSON", {
20
virtuals: true,
21
transform(_doc, ret: Record<string, any>) {
22
const db = ret as IEquipmentSelectionDatabase;
23
const client = ret as IEquipmentSelectionClient;
24
25
if (db.ItemId) {
26
client.ItemId = toOid(fromDbOid(db.ItemId));
27
}
28
}
29
});
27
30
28
31
export const loadoutConfigSchema = new Schema<ILoadoutConfigDatabase>(
29
32
{
@@ -39,8 +39,14 @@ import {
39
39
ICrewShipMemberDatabase,
40
40
ICrewShipMembersClient,
41
41
ICrewShipMembersDatabase,
42
ICrewShipWeaponClient,
43
ICrewShipWeaponDatabase,
44
ICrewShipWeaponEmplacementsClient,
45
ICrewShipWeaponEmplacementsDatabase,
42
46
IEquipmentClient,
43
47
IEquipmentDatabase,
48
IEquipmentSelectionClient,
49
IEquipmentSelectionDatabase,
44
50
IKubrowPetDetailsClient,
45
51
IKubrowPetDetailsDatabase
46
52
} from "@/src/types/equipmentTypes";
@@ -84,7 +90,8 @@ const convertEquipment = (client: IEquipmentClient): IEquipmentDatabase => {
84
90
Expiry: convertOptionalDate(client.Expiry),
85
91
UpgradesExpiry: convertOptionalDate(client.UpgradesExpiry),
86
92
UmbraDate: convertOptionalDate(client.UmbraDate),
87
CrewMembers: client.CrewMembers ? convertCrewShipMembers(client.CrewMembers) : undefined,
93
Weapon: client.Weapon ? importCrewShipWeapon(client.Weapon) : undefined,
94
CrewMembers: client.CrewMembers ? importCrewShipMembers(client.CrewMembers) : undefined,
88
95
Details: client.Details ? convertKubrowDetails(client.Details) : undefined,
89
96
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
90
97
Configs: client.Configs
@@ -133,14 +140,43 @@ const replaceSlots = (db: ISlots, client: ISlots): void => {
133
140
db.Slots = client.Slots;
134
141
};
135
142
136
export const importCrewMemberId = (crewMemberId: ICrewShipMemberClient): ICrewShipMemberDatabase => {
143
const convertEquipmentSelection = (es: IEquipmentSelectionClient): IEquipmentSelectionDatabase => {
144
const { ItemId, ...rest } = es;
145
return {
146
...rest,
147
ItemId: ItemId ? new Types.ObjectId(ItemId.$oid) : undefined
148
};
149
};
150
151
const convertCrewShipWeaponEmplacements = (
152
obj: ICrewShipWeaponEmplacementsClient
153
): ICrewShipWeaponEmplacementsDatabase => {
154
return {
155
PRIMARY_A: obj.PRIMARY_A ? convertEquipmentSelection(obj.PRIMARY_A) : undefined,
156
PRIMARY_B: obj.PRIMARY_B ? convertEquipmentSelection(obj.PRIMARY_B) : undefined,
157
SECONDARY_A: obj.SECONDARY_A ? convertEquipmentSelection(obj.SECONDARY_A) : undefined,
158
SECONDARY_B: obj.SECONDARY_B ? convertEquipmentSelection(obj.SECONDARY_B) : undefined
159
};
160
};
161
162
export const importCrewShipWeapon = (weapon: ICrewShipWeaponClient): ICrewShipWeaponDatabase => {
163
return {
164
PILOT: weapon.PILOT ? convertCrewShipWeaponEmplacements(weapon.PILOT) : undefined,
165
PORT_GUNS: weapon.PORT_GUNS ? convertCrewShipWeaponEmplacements(weapon.PORT_GUNS) : undefined,
166
STARBOARD_GUNS: weapon.STARBOARD_GUNS ? convertCrewShipWeaponEmplacements(weapon.STARBOARD_GUNS) : undefined,
167
ARTILLERY: weapon.ARTILLERY ? convertCrewShipWeaponEmplacements(weapon.ARTILLERY) : undefined,
168
SCANNER: weapon.SCANNER ? convertCrewShipWeaponEmplacements(weapon.SCANNER) : undefined
169
};
170
};
171
172
const importCrewMemberId = (crewMemberId: ICrewShipMemberClient): ICrewShipMemberDatabase => {
137
173
if (crewMemberId.ItemId) {
138
174
return { ItemId: new Types.ObjectId(crewMemberId.ItemId.$oid) };
139
175
}
140
176
return { NemesisFingerprint: BigInt(crewMemberId.NemesisFingerprint ?? 0) };
141
177
};
142
178
143
const convertCrewShipMembers = (client: ICrewShipMembersClient): ICrewShipMembersDatabase => {
179
export const importCrewShipMembers = (client: ICrewShipMembersClient): ICrewShipMembersDatabase => {
144
180
return {
145
181
SLOT_A: client.SLOT_A ? importCrewMemberId(client.SLOT_A) : undefined,
146
182
SLOT_B: client.SLOT_B ? importCrewMemberId(client.SLOT_B) : undefined,
@@ -429,34 +465,40 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
429
465
}
430
466
};
431
467
432
const convertLoadOutConfig = (client: ILoadoutConfigClient): ILoadoutConfigDatabase => {
468
export const importLoadOutConfig = (client: ILoadoutConfigClient): ILoadoutConfigDatabase => {
433
469
const { ItemId, ...rest } = client;
434
470
return {
435
471
...rest,
436
_id: new Types.ObjectId(ItemId.$oid)
472
_id: new Types.ObjectId(ItemId.$oid),
473
s: client.s ? convertEquipmentSelection(client.s) : undefined,
474
p: client.p ? convertEquipmentSelection(client.p) : undefined,
475
l: client.l ? convertEquipmentSelection(client.l) : undefined,
476
m: client.m ? convertEquipmentSelection(client.m) : undefined,
477
h: client.h ? convertEquipmentSelection(client.h) : undefined,
478
a: client.a ? convertEquipmentSelection(client.a) : undefined
437
479
};
438
480
};
439
481
440
482
export const importLoadOutPresets = (db: ILoadoutDatabase, client: ILoadOutPresets): void => {
441
db.NORMAL = client.NORMAL.map(convertLoadOutConfig);
442
db.SENTINEL = client.SENTINEL.map(convertLoadOutConfig);
443
db.ARCHWING = client.ARCHWING.map(convertLoadOutConfig);
444
db.NORMAL_PVP = client.NORMAL_PVP.map(convertLoadOutConfig);
445
db.LUNARO = client.LUNARO.map(convertLoadOutConfig);
446
db.OPERATOR = client.OPERATOR.map(convertLoadOutConfig);
447
db.GEAR = client.GEAR?.map(convertLoadOutConfig);
448
db.KDRIVE = client.KDRIVE.map(convertLoadOutConfig);
449
db.DATAKNIFE = client.DATAKNIFE.map(convertLoadOutConfig);
450
db.MECH = client.MECH.map(convertLoadOutConfig);
451
db.OPERATOR_ADULT = client.OPERATOR_ADULT.map(convertLoadOutConfig);
452
db.DRIFTER = client.DRIFTER.map(convertLoadOutConfig);
483
db.NORMAL = client.NORMAL.map(importLoadOutConfig);
484
db.SENTINEL = client.SENTINEL.map(importLoadOutConfig);
485
db.ARCHWING = client.ARCHWING.map(importLoadOutConfig);
486
db.NORMAL_PVP = client.NORMAL_PVP.map(importLoadOutConfig);
487
db.LUNARO = client.LUNARO.map(importLoadOutConfig);
488
db.OPERATOR = client.OPERATOR.map(importLoadOutConfig);
489
db.GEAR = client.GEAR?.map(importLoadOutConfig);
490
db.KDRIVE = client.KDRIVE.map(importLoadOutConfig);
491
db.DATAKNIFE = client.DATAKNIFE.map(importLoadOutConfig);
492
db.MECH = client.MECH.map(importLoadOutConfig);
493
db.OPERATOR_ADULT = client.OPERATOR_ADULT.map(importLoadOutConfig);
494
db.DRIFTER = client.DRIFTER.map(importLoadOutConfig);
453
495
};
454
496
455
497
export const convertCustomizationInfo = (client: ICustomizationInfoClient): ICustomizationInfoDatabase => {
456
498
return {
457
499
...client,
458
LoadOutPreset: client.LoadOutPreset ? convertLoadOutConfig(client.LoadOutPreset) : undefined,
459
VehiclePreset: client.VehiclePreset ? convertLoadOutConfig(client.VehiclePreset) : undefined
500
LoadOutPreset: client.LoadOutPreset ? importLoadOutConfig(client.LoadOutPreset) : undefined,
501
VehiclePreset: client.VehiclePreset ? importLoadOutConfig(client.VehiclePreset) : undefined
460
502
};
461
503
};
462
504
@@ -63,6 +63,7 @@ import {
63
63
import { createShip } from "@/src/services/shipService";
64
64
import {
65
65
catbrowDetails,
66
fromDbOid,
66
67
fromMongoDate,
67
68
fromOid,
68
69
kubrowDetails,
@@ -2232,6 +2233,8 @@ export const setupKahlSyndicate = (inventory: TInventoryDatabaseDocument): void
2232
2233
};
2233
2234
2234
2235
export const cleanupInventory = (inventory: TInventoryDatabaseDocument): void => {
2236
inventory.CurrentLoadOutIds = inventory.CurrentLoadOutIds.map(fromDbOid);
2237
2235
2238
let index = inventory.MiscItems.findIndex(x => x.ItemType == "");
2236
2239
if (index != -1) {
2237
2240
inventory.MiscItems.splice(index, 1);
@@ -65,7 +65,6 @@ import {
65
65
getNemesisPasscode
66
66
} from "@/src/helpers/nemesisHelpers";
67
67
import { Loadout } from "@/src/models/inventoryModels/loadoutModel";
68
import { ILoadoutConfigDatabase } from "@/src/types/saveLoadoutTypes";
69
68
import {
70
69
getLiteSortie,
71
70
getSortie,
@@ -84,6 +83,7 @@ import { ITypeCount } from "@/src/types/commonTypes";
84
83
import { IEquipmentClient } from "@/src/types/equipmentTypes";
85
84
import { Guild } from "@/src/models/guildModel";
86
85
import { handleGuildGoalProgress } from "@/src/services/guildService";
86
import { importLoadOutConfig } from "@/src/services/importService";
87
87
88
88
const getRotations = (rewardInfo: IRewardInfo, tierOverride?: number): number[] => {
89
89
// Disruption missions just tell us (https://onlyg.it/OpenWF/SpaceNinjaServer/issues/2599)
@@ -602,11 +602,7 @@ export const addMissionInventoryUpdates = async (
602
602
const loadout = await Loadout.findOne({ loadoutOwnerId: inventory.accountOwnerId });
603
603
if (loadout) {
604
604
for (const [loadoutId, loadoutConfig] of Object.entries(value.LoadOuts.NORMAL)) {
605
const { ItemId, ...loadoutConfigItemIdRemoved } = loadoutConfig;
606
const loadoutConfigDatabase: ILoadoutConfigDatabase = {
607
_id: new Types.ObjectId(ItemId.$oid),
608
...loadoutConfigItemIdRemoved
609
};
605
const loadoutConfigDatabase = importLoadOutConfig(loadoutConfig);
610
606
const dbConfig = loadout.NORMAL.id(loadoutId);
611
607
if (dbConfig) {
612
608
dbConfig.overwrite(loadoutConfigDatabase);
@@ -2,7 +2,6 @@ import {
2
2
IItemEntry,
3
3
ILoadoutClient,
4
4
ILoadoutEntry,
5
ILoadoutConfigDatabase,
6
5
IOperatorConfigEntry,
7
6
ISaveLoadoutRequestNoUpgradeVer
8
7
} from "@/src/types/saveLoadoutTypes";
@@ -14,7 +13,7 @@ import { isEmptyObject } from "@/src/helpers/general";
14
13
import { logger } from "@/src/utils/logger";
15
14
import { equipmentKeys, TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
16
15
import { IItemConfig } from "@/src/types/inventoryTypes/commonInventoryTypes";
17
import { importCrewMemberId } from "@/src/services/importService";
16
import { importCrewShipMembers, importCrewShipWeapon, importLoadOutConfig } from "@/src/services/importService";
18
17
19
18
//TODO: setup default items on account creation or like originally in giveStartingItems.php
20
19
@@ -88,20 +87,17 @@ export const handleInventoryItemConfigChange = async (
88
87
89
88
const oldLoadoutConfig = loadout[loadoutSlot].id(loadoutId);
90
89
91
const { ItemId, ...loadoutConfigItemIdRemoved } = loadoutConfig;
92
const loadoutConfigDatabase: ILoadoutConfigDatabase = {
93
_id: new Types.ObjectId(ItemId.$oid),
94
...loadoutConfigItemIdRemoved
95
};
90
const loadoutConfigDatabase = importLoadOutConfig(loadoutConfig);
96
91
97
92
// if no config with this id exists, create a new one
98
93
if (!oldLoadoutConfig) {
99
94
//save the new object id and assign it for every ffff return at the end
100
if (ItemId.$oid === "ffffffffffffffffffffffff") {
95
if (loadoutConfigDatabase._id.toString() === "ffffffffffffffffffffffff") {
101
96
if (!newLoadoutId) {
102
97
newLoadoutId = new Types.ObjectId();
103
98
}
104
loadout[loadoutSlot].push({ _id: newLoadoutId, ...loadoutConfigItemIdRemoved });
99
loadoutConfigDatabase._id = newLoadoutId;
100
loadout[loadoutSlot].push(loadoutConfigDatabase);
105
101
continue;
106
102
}
107
103
@@ -218,15 +214,11 @@ export const handleInventoryItemConfigChange = async (
218
214
if ("Customization" in itemConfigEntries) {
219
215
inventoryItem.Customization = itemConfigEntries.Customization;
220
216
}
221
if ("Weapon" in itemConfigEntries) {
222
inventoryItem.Weapon = itemConfigEntries.Weapon;
217
if (itemConfigEntries.Weapon) {
218
inventoryItem.Weapon = importCrewShipWeapon(itemConfigEntries.Weapon);
223
219
}
224
220
if (itemConfigEntries.CrewMembers) {
225
inventoryItem.CrewMembers = {
226
SLOT_A: importCrewMemberId(itemConfigEntries.CrewMembers.SLOT_A ?? {}),
227
SLOT_B: importCrewMemberId(itemConfigEntries.CrewMembers.SLOT_B ?? {}),
228
SLOT_C: importCrewMemberId(itemConfigEntries.CrewMembers.SLOT_C ?? {})
229
};
221
inventoryItem.CrewMembers = importCrewShipMembers(itemConfigEntries.CrewMembers);
230
222
}
231
223
}
232
224
break;
@@ -7,14 +7,18 @@ import {
7
7
IPolarity
8
8
} from "@/src/types/inventoryTypes/commonInventoryTypes";
9
9
10
export interface IEquipmentSelection {
11
ItemId: IOid;
10
export interface IEquipmentSelectionClient {
11
ItemId?: IOid;
12
12
mod?: number;
13
13
cus?: number;
14
14
ItemType?: string;
15
15
hide?: boolean;
16
16
}
17
17
18
export interface IEquipmentSelectionDatabase extends Omit<IEquipmentSelectionClient, "ItemId"> {
19
ItemId?: Types.ObjectId | IOid; // should be Types.ObjectId but might be IOid because of old commits
20
}
21
18
22
export enum EquipmentFeatures {
19
23
DOUBLE_CAPACITY = 1,
20
24
UTILITY_SLOT = 2,
@@ -51,7 +55,7 @@ export interface IEquipmentDatabase {
51
55
UpgradesExpiry?: Date;
52
56
UmbraDate?: Date; // related to scrapped "echoes of umbra" feature
53
57
ArchonCrystalUpgrades?: IArchonCrystalUpgrade[];
54
Weapon?: ICrewShipWeapon;
58
Weapon?: ICrewShipWeaponDatabase;
55
59
Customization?: ICrewShipCustomization;
56
60
RailjackImage?: IFlavourItem;
57
61
CrewMembers?: ICrewShipMembersDatabase;
@@ -64,13 +68,14 @@ export interface IEquipmentDatabase {
64
68
export interface IEquipmentClient
65
69
extends Omit<
66
70
IEquipmentDatabase,
67
"_id" | "InfestationDate" | "Expiry" | "UpgradesExpiry" | "UmbraDate" | "CrewMembers" | "Details"
71
"_id" | "InfestationDate" | "Expiry" | "UpgradesExpiry" | "UmbraDate" | "Weapon" | "CrewMembers" | "Details"
68
72
> {
69
73
ItemId: IOidWithLegacySupport;
70
74
InfestationDate?: IMongoDate;
71
75
Expiry?: IMongoDate;
72
76
UpgradesExpiry?: IMongoDate;
73
77
UmbraDate?: IMongoDate;
78
Weapon?: ICrewShipWeaponClient;
74
79
CrewMembers?: ICrewShipMembersClient;
75
80
Details?: IKubrowPetDetailsClient;
76
81
}
@@ -117,19 +122,34 @@ export enum Status {
117
122
}
118
123
119
124
// inventory.CrewShips[0].Weapon
120
export interface ICrewShipWeapon {
121
PILOT?: ICrewShipWeaponEmplacements;
122
PORT_GUNS?: ICrewShipWeaponEmplacements;
123
STARBOARD_GUNS?: ICrewShipWeaponEmplacements;
124
ARTILLERY?: ICrewShipWeaponEmplacements;
125
SCANNER?: ICrewShipWeaponEmplacements;
126
}
127
128
export interface ICrewShipWeaponEmplacements {
129
PRIMARY_A?: IEquipmentSelection;
130
PRIMARY_B?: IEquipmentSelection;
131
SECONDARY_A?: IEquipmentSelection;
132
SECONDARY_B?: IEquipmentSelection;
125
export interface ICrewShipWeaponClient {
126
PILOT?: ICrewShipWeaponEmplacementsClient;
127
PORT_GUNS?: ICrewShipWeaponEmplacementsClient;
128
STARBOARD_GUNS?: ICrewShipWeaponEmplacementsClient;
129
ARTILLERY?: ICrewShipWeaponEmplacementsClient;
130
SCANNER?: ICrewShipWeaponEmplacementsClient;
131
}
132
133
export interface ICrewShipWeaponDatabase {
134
PILOT?: ICrewShipWeaponEmplacementsDatabase;
135
PORT_GUNS?: ICrewShipWeaponEmplacementsDatabase;
136
STARBOARD_GUNS?: ICrewShipWeaponEmplacementsDatabase;
137
ARTILLERY?: ICrewShipWeaponEmplacementsDatabase;
138
SCANNER?: ICrewShipWeaponEmplacementsDatabase;
139
}
140
141
export interface ICrewShipWeaponEmplacementsClient {
142
PRIMARY_A?: IEquipmentSelectionClient;
143
PRIMARY_B?: IEquipmentSelectionClient;
144
SECONDARY_A?: IEquipmentSelectionClient;
145
SECONDARY_B?: IEquipmentSelectionClient;
146
}
147
148
export interface ICrewShipWeaponEmplacementsDatabase {
149
PRIMARY_A?: IEquipmentSelectionDatabase;
150
PRIMARY_B?: IEquipmentSelectionDatabase;
151
SECONDARY_A?: IEquipmentSelectionDatabase;
152
SECONDARY_B?: IEquipmentSelectionDatabase;
133
153
}
134
154
135
155
export interface ICrewShipMembersClient {
@@ -68,12 +68,14 @@ export interface IInventoryDatabase
68
68
| "LastInventorySync"
69
69
| "EndlessXP"
70
70
| "PersonalGoalProgress"
71
| "CurrentLoadOutIds"
71
72
| TEquipmentKey
72
73
>,
73
74
InventoryDatabaseEquipment,
74
75
IAccountCheats {
75
76
accountOwnerId: Types.ObjectId;
76
77
Created: Date;
78
CurrentLoadOutIds: Types.ObjectId[] | IOid[]; // should be Types.ObjectId[] but might be IOid[] because of old commits
77
79
TrainingDate: Date;
78
80
LoadOutPresets: Types.ObjectId; // LoadOutPresets changed from ILoadOutPresets to Types.ObjectId for population
79
81
//Mailbox?: IMailboxDatabase;
@@ -254,7 +256,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
254
256
ActiveQuest: string;
255
257
FlavourItems: IFlavourItem[];
256
258
LoadOutPresets: ILoadOutPresets;
257
CurrentLoadOutIds: IOid[]; // we store it in the database using this representation as well :/
259
CurrentLoadOutIds: IOid[];
258
260
Missions: IMission[];
259
261
RandomUpgradesIdentified?: number;
260
262
LastRegionPlayed: TSolarMapRegion;
@@ -7,7 +7,12 @@ import {
7
7
IOperatorConfigClient
8
8
} from "@/src/types/inventoryTypes/commonInventoryTypes";
9
9
import { Types } from "mongoose";
10
import { ICrewShipMembersClient, ICrewShipWeapon, IEquipmentSelection } from "@/src/types/equipmentTypes";
10
import {
11
ICrewShipMembersClient,
12
ICrewShipWeaponClient,
13
IEquipmentSelectionClient,
14
IEquipmentSelectionDatabase
15
} from "@/src/types/equipmentTypes";
11
16
12
17
export interface ISaveLoadoutRequest {
13
18
LoadOuts: ILoadoutClient;
@@ -53,10 +58,12 @@ export interface IOperatorConfigEntry {
53
58
[configId: string]: IOperatorConfigClient;
54
59
}
55
60
61
// client
56
62
export interface IItemEntry {
57
63
[itemId: string]: IConfigEntry;
58
64
}
59
65
66
// client
60
67
export type IConfigEntry = {
61
68
[configId in "0" | "1" | "2" | "3" | "4" | "5"]: IItemConfig;
62
69
} & {
@@ -66,7 +73,7 @@ export type IConfigEntry = {
66
73
ItemName?: string;
67
74
RailjackImage?: IFlavourItem;
68
75
Customization?: ICrewShipCustomization;
69
Weapon?: ICrewShipWeapon;
76
Weapon?: ICrewShipWeaponClient;
70
77
CrewMembers?: ICrewShipMembersClient;
71
78
};
72
79
@@ -108,10 +115,6 @@ export interface ILoadoutEntry {
108
115
[key: string]: ILoadoutConfigClient;
109
116
}
110
117
111
export interface ILoadoutConfigDatabase extends Omit<ILoadoutConfigClient, "ItemId"> {
112
_id: Types.ObjectId;
113
}
114
115
118
export enum FocusSchool {
116
119
Attack = "AP_ATTACK",
117
120
Defense = "AP_DEFENSE",
@@ -125,12 +128,23 @@ export interface ILoadoutConfigClient {
125
128
PresetIcon?: string;
126
129
Favorite?: boolean;
127
130
n?: string; // Loadout name
128
s?: IEquipmentSelection; // Suit
129
p?: IEquipmentSelection; // Secondary weapon
130
l?: IEquipmentSelection; // Primary weapon
131
m?: IEquipmentSelection; // Melee weapon
132
h?: IEquipmentSelection; // Gravimag weapon
133
a?: IEquipmentSelection; // Necromech exalted weapon
131
s?: IEquipmentSelectionClient; // Suit
132
p?: IEquipmentSelectionClient; // Secondary weapon
133
l?: IEquipmentSelectionClient; // Primary weapon
134
m?: IEquipmentSelectionClient; // Melee weapon
135
h?: IEquipmentSelectionClient; // Gravimag weapon
136
a?: IEquipmentSelectionClient; // Necromech exalted weapon
134
137
ItemId: IOid;
135
138
Remove?: boolean; // when client wants to remove a config, it only includes ItemId & Remove.
136
139
}
140
141
export interface ILoadoutConfigDatabase
142
extends Omit<ILoadoutConfigClient, "ItemId" | "s" | "p" | "l" | "m" | "h" | "a"> {
143
_id: Types.ObjectId;
144
s?: IEquipmentSelectionDatabase;
145
p?: IEquipmentSelectionDatabase;
146
l?: IEquipmentSelectionDatabase;
147
m?: IEquipmentSelectionDatabase;
148
h?: IEquipmentSelectionDatabase;
149
a?: IEquipmentSelectionDatabase;
150
}