XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

SpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 1 Star 0
返回提交历史

XFEstudio/SpaceNinjaServer

feat(import): additional fields (#1305)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1305 Reviewed-by: Sainan <sainan@calamity.inc> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>

0085c20e
AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
提交于

代码差异

4 个文件 +160 -71
Modified src/models/inventoryModels/inventoryModel.ts +7 -27
@@ -76,7 +76,6 @@ import {
76 76 IIncentiveState,
77 77 ISongChallenge,
78 78 ILibraryPersonalProgress,
79 ICrewShipWeaponDatabase,
80 79 IRecentVendorPurchaseDatabase,
81 80 IVendorPurchaseHistoryEntryDatabase,
82 81 IVendorPurchaseHistoryEntryClient,
@@ -1118,25 +1117,6 @@ const alignmentSchema = new Schema<IAlignment>(
1118 1117 { _id: false }
1119 1118 );
1120 1119
1121 const crewShipWeaponSchema2 = new Schema<ICrewShipWeaponDatabase>(
1122 {
1123 ItemType: String
1124 },
1125 { id: false }
1126 );
1127
1128 crewShipWeaponSchema2.virtual("ItemId").get(function () {
1129 return { $oid: this._id.toString() } satisfies IOid;
1130 });
1131
1132 crewShipWeaponSchema2.set("toJSON", {
1133 virtuals: true,
1134 transform(_document, returnedObject) {
1135 delete returnedObject._id;
1136 delete returnedObject.__v;
1137 }
1138 });
1139
1140 1120 const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
1141 1121 {
1142 1122 accountOwnerId: Schema.Types.ObjectId,
@@ -1259,20 +1239,20 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
1259 1239
1260 1240 //Default RailJack
1261 1241 CrewShipAmmo: [typeCountSchema],
1262 CrewShipWeapons: [crewShipWeaponSchema2],
1242 CrewShipWeapons: [EquipmentSchema],
1263 1243 CrewShipWeaponSkins: [upgradeSchema],
1244 CrewShipSalvagedWeapons: [EquipmentSchema],
1245 CrewShipSalvagedWeaponSkins: [upgradeSchema],
1264 1246
1265 //NPC Crew and weapon
1247 //RailJack Crew
1266 1248 CrewMembers: [Schema.Types.Mixed],
1267 CrewShipSalvagedWeaponSkins: [Schema.Types.Mixed],
1268 CrewShipSalvagedWeapons: [Schema.Types.Mixed],
1269 1249
1270 1250 //Complete Mission\Quests
1271 1251 Missions: [missionSchema],
1272 1252 QuestKeys: [questKeysSchema],
1273 1253 ActiveQuest: { type: String, default: "" },
1274 1254 //item like DojoKey or Boss missions key
1275 LevelKeys: [Schema.Types.Mixed],
1255 LevelKeys: [typeCountSchema],
1276 1256 //Active quests
1277 1257 Quests: [Schema.Types.Mixed],
1278 1258
@@ -1333,7 +1313,7 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
1333 1313 SpectreLoadouts: { type: [spectreLoadoutsSchema], default: undefined },
1334 1314
1335 1315 //New Quest Email
1336 EmailItems: [TypeXPItemSchema],
1316 EmailItems: [typeCountSchema],
1337 1317
1338 1318 //Profile->Wishlist
1339 1319 Wishlist: [String],
@@ -1527,8 +1507,8 @@ export type InventoryDocumentProps = {
1527 1507 WeaponSkins: Types.DocumentArray<IWeaponSkinDatabase>;
1528 1508 QuestKeys: Types.DocumentArray<IQuestKeyDatabase>;
1529 1509 Drones: Types.DocumentArray<IDroneDatabase>;
1530 CrewShipWeapons: Types.DocumentArray<ICrewShipWeaponDatabase>;
1531 1510 CrewShipWeaponSkins: Types.DocumentArray<IUpgradeDatabase>;
1511 CrewShipSalvagedWeaponsSkins: Types.DocumentArray<IUpgradeDatabase>;
1532 1512 } & { [K in TEquipmentKey]: Types.DocumentArray<IEquipmentDatabase> };
1533 1513
1534 1514 // eslint-disable-next-line @typescript-eslint/ban-types
Modified src/services/importService.ts +145 -8
@@ -23,6 +23,12 @@ import {
23 23 IKubrowPetDetailsDatabase,
24 24 ILoadoutConfigClient,
25 25 ILoadOutPresets,
26 INemesisClient,
27 INemesisDatabase,
28 IPendingRecipeClient,
29 IPendingRecipeDatabase,
30 IQuestKeyClient,
31 IQuestKeyDatabase,
26 32 ISlots,
27 33 IUpgradeClient,
28 34 IUpgradeDatabase,
@@ -144,6 +150,27 @@ const convertKubrowDetails = (client: IKubrowPetDetailsClient): IKubrowPetDetail
144 150 };
145 151 };
146 152
153 const convertQuestKey = (client: IQuestKeyClient): IQuestKeyDatabase => {
154 return {
155 ...client,
156 CompletionDate: convertOptionalDate(client.CompletionDate)
157 };
158 };
159
160 const convertPendingRecipe = (client: IPendingRecipeClient): IPendingRecipeDatabase => {
161 return {
162 ...client,
163 CompletionDate: convertDate(client.CompletionDate)
164 };
165 };
166
167 const convertNemesis = (client: INemesisClient): INemesisDatabase => {
168 return {
169 ...client,
170 d: convertDate(client.d)
171 };
172 };
173
147 174 export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<IInventoryClient>): void => {
148 175 for (const key of equipmentKeys) {
149 176 if (client[key] !== undefined) {
@@ -153,10 +180,22 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
153 180 if (client.WeaponSkins !== undefined) {
154 181 replaceArray<IWeaponSkinDatabase>(db.WeaponSkins, client.WeaponSkins.map(convertWeaponSkin));
155 182 }
156 if (client.Upgrades !== undefined) {
157 replaceArray<IUpgradeDatabase>(db.Upgrades, client.Upgrades.map(convertUpgrade));
183 for (const key of ["Upgrades", "CrewShipSalvagedWeaponSkins", "CrewShipWeaponSkins"] as const) {
184 if (client[key] !== undefined) {
185 replaceArray<IUpgradeDatabase>(db[key], client[key].map(convertUpgrade));
186 }
158 187 }
159 for (const key of ["RawUpgrades", "MiscItems", "Consumables"] as const) {
188 for (const key of [
189 "RawUpgrades",
190 "MiscItems",
191 "Consumables",
192 "Recipes",
193 "LevelKeys",
194 "EmailItems",
195 "ShipDecorations",
196 "CrewShipAmmo",
197 "CrewShipRawSalvage"
198 ] as const) {
160 199 if (client[key] !== undefined) {
161 200 db[key].splice(0, db[key].length);
162 201 client[key].forEach(x => {
@@ -190,8 +229,16 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
190 229 replaceSlots(db[key], client[key]);
191 230 }
192 231 }
193 if (client.UseAdultOperatorLoadout !== undefined) {
194 db.UseAdultOperatorLoadout = client.UseAdultOperatorLoadout;
232 for (const key of [
233 "UseAdultOperatorLoadout",
234 "HasOwnedVoidProjectionsPreviously",
235 "ReceivedStartingGear",
236 "ArchwingEnabled",
237 "PlayedParkourTutorial"
238 ] as const) {
239 if (client[key] !== undefined) {
240 db[key] = client[key];
241 }
195 242 }
196 243 for (const key of [
197 244 "PlayerLevel",
@@ -199,18 +246,37 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
199 246 "PremiumCredits",
200 247 "PremiumCreditsFree",
201 248 "FusionPoints",
202 "PrimeTokens"
249 "PrimeTokens",
250 "TradesRemaining",
251 "GiftsRemaining",
252 "ChallengesFixVersion"
203 253 ] as const) {
204 254 if (client[key] !== undefined) {
205 255 db[key] = client[key];
206 256 }
207 257 }
208 for (const key of ["ThemeStyle", "ThemeBackground", "ThemeSounds", "EquippedInstrument", "FocusAbility"] as const) {
258 for (const key of [
259 "ThemeStyle",
260 "ThemeBackground",
261 "ThemeSounds",
262 "EquippedInstrument",
263 "FocusAbility",
264 "ActiveQuest",
265 "SupportedSyndicate",
266 "ActiveAvatarImageType"
267 ] as const) {
209 268 if (client[key] !== undefined) {
210 269 db[key] = client[key];
211 270 }
212 271 }
213 for (const key of ["EquippedGear", "EquippedEmotes", "NodeIntrosCompleted"] as const) {
272 for (const key of [
273 "EquippedGear",
274 "EquippedEmotes",
275 "NodeIntrosCompleted",
276 "DeathMarks",
277 "Wishlist",
278 "NemesisAbandonedRewards"
279 ] as const) {
214 280 if (client[key] !== undefined) {
215 281 db[key] = client[key];
216 282 }
@@ -242,6 +308,77 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
242 308 if (client.CustomMarkers !== undefined) {
243 309 db.CustomMarkers = client.CustomMarkers;
244 310 }
311 if (client.ChallengeProgress !== undefined) {
312 db.ChallengeProgress = client.ChallengeProgress;
313 }
314 if (client.QuestKeys !== undefined) {
315 replaceArray<IQuestKeyDatabase>(db.QuestKeys, client.QuestKeys.map(convertQuestKey));
316 }
317 if (client.LastRegionPlayed !== undefined) {
318 db.LastRegionPlayed = client.LastRegionPlayed;
319 }
320 if (client.PendingRecipes !== undefined) {
321 replaceArray<IPendingRecipeDatabase>(db.PendingRecipes, client.PendingRecipes.map(convertPendingRecipe));
322 }
323 if (client.TauntHistory !== undefined) {
324 db.TauntHistory = client.TauntHistory;
325 }
326 if (client.LoreFragmentScans !== undefined) {
327 db.LoreFragmentScans = client.LoreFragmentScans;
328 }
329 for (const key of ["PendingSpectreLoadouts", "SpectreLoadouts"] as const) {
330 if (client[key] !== undefined) {
331 db[key] = client[key];
332 }
333 }
334 if (client.FocusXP !== undefined) {
335 db.FocusXP = client.FocusXP;
336 }
337 for (const key of ["Alignment", "AlignmentReplay"] as const) {
338 if (client[key] !== undefined) {
339 db[key] = client[key];
340 }
341 }
342 if (client.StepSequencers !== undefined) {
343 db.StepSequencers = client.StepSequencers;
344 }
345 if (client.CompletedJobChains !== undefined) {
346 db.CompletedJobChains = client.CompletedJobChains;
347 }
348 if (client.Nemesis !== undefined) {
349 db.Nemesis = convertNemesis(client.Nemesis);
350 }
351 if (client.PlayerSkills !== undefined) {
352 db.PlayerSkills = client.PlayerSkills;
353 }
354 if (client.LotusCustomization !== undefined) {
355 db.LotusCustomization = client.LotusCustomization;
356 }
357 if (client.CollectibleSeries !== undefined) {
358 db.CollectibleSeries = client.CollectibleSeries;
359 }
360 for (const key of ["LibraryAvailableDailyTaskInfo", "LibraryActiveDailyTaskInfo"] as const) {
361 if (client[key] !== undefined) {
362 db[key] = client[key];
363 }
364 }
365 if (client.EndlessXP !== undefined) {
366 db.EndlessXP = client.EndlessXP;
367 }
368 if (client.SongChallenges !== undefined) {
369 db.SongChallenges = client.SongChallenges;
370 }
371 if (client.Missions !== undefined) {
372 db.Missions = client.Missions;
373 }
374 if (client.FlavourItems !== undefined) {
375 db.FlavourItems.splice(0, db.FlavourItems.length);
376 client.FlavourItems.forEach(x => {
377 db.FlavourItems.push({
378 ItemType: x.ItemType
379 });
380 });
381 }
245 382 };
246 383
247 384 const convertLoadOutConfig = (client: ILoadoutConfigClient): ILoadoutConfigDatabase => {
Modified src/services/inventoryService.ts +2 -17
@@ -25,8 +25,7 @@ import {
25 25 ILibraryDailyTaskInfo,
26 26 ICalendarProgress,
27 27 IDroneClient,
28 IUpgradeClient,
29 ICrewShipWeaponClient
28 IUpgradeClient
30 29 } from "@/src/types/inventoryTypes/inventoryTypes";
31 30 import { IGenericUpdate, IUpdateNodeIntrosResponse } from "../types/genericUpdate";
32 31 import { IMissionInventoryUpdateRequest, IUpdateChallengeProgressRequest } from "../types/requestTypes";
@@ -434,7 +433,7 @@ export const addItem = async (
434 433 }
435 434 if (typeName in ExportRailjackWeapons) {
436 435 return {
437 ...addCrewShipWeapon(inventory, typeName),
436 ...addEquipment(inventory, ExportRailjackWeapons[typeName].productCategory, typeName),
438 437 ...occupySlot(inventory, InventorySlot.RJ_COMPONENT_AND_ARMAMENTS, premiumPurchase)
439 438 };
440 439 }
@@ -947,20 +946,6 @@ export const addSkin = (
947 946 return inventoryChanges;
948 947 };
949 948
950 const addCrewShipWeapon = (
951 inventory: TInventoryDatabaseDocument,
952 typeName: string,
953 inventoryChanges: IInventoryChanges = {}
954 ): IInventoryChanges => {
955 const index = inventory.CrewShipWeapons.push({ ItemType: typeName, _id: new Types.ObjectId() }) - 1;
956 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
957 inventoryChanges.CrewShipWeapons ??= [];
958 (inventoryChanges.CrewShipWeapons as ICrewShipWeaponClient[]).push(
959 inventory.CrewShipWeapons[index].toJSON<ICrewShipWeaponClient>()
960 );
961 return inventoryChanges;
962 };
963
964 949 const addCrewShipWeaponSkin = (
965 950 inventory: TInventoryDatabaseDocument,
966 951 typeName: string,
Modified src/types/inventoryTypes/inventoryTypes.ts +6 -19
@@ -30,9 +30,8 @@ export interface IInventoryDatabase
30 30 | "Ships"
31 31 | "WeaponSkins"
32 32 | "Upgrades"
33 | "CrewShipSalvagedWeaponSkins"
34 | "CrewShipWeapons"
35 33 | "CrewShipWeaponSkins"
34 | "CrewShipSalvagedWeaponSkins"
36 35 | "AdultOperatorLoadOuts"
37 36 | "OperatorLoadOuts"
38 37 | "KahlLoadOuts"
@@ -60,9 +59,8 @@ export interface IInventoryDatabase
60 59 Ships: Types.ObjectId[];
61 60 WeaponSkins: IWeaponSkinDatabase[];
62 61 Upgrades: IUpgradeDatabase[];
63 CrewShipSalvagedWeaponSkins: IUpgradeDatabase[];
64 CrewShipWeapons: ICrewShipWeaponDatabase[];
65 62 CrewShipWeaponSkins: IUpgradeDatabase[];
63 CrewShipSalvagedWeaponSkins: IUpgradeDatabase[];
66 64 AdultOperatorLoadOuts: IOperatorConfigDatabase[];
67 65 OperatorLoadOuts: IOperatorConfigDatabase[];
68 66 KahlLoadOuts: IOperatorConfigDatabase[];
@@ -114,7 +112,9 @@ export const equipmentKeys = [
114 112 "DataKnives",
115 113 "MechSuits",
116 114 "CrewShipHarnesses",
117 "KubrowPets"
115 "KubrowPets",
116 "CrewShipWeapons",
117 "CrewShipSalvagedWeapons"
118 118 ] as const;
119 119
120 120 export type TEquipmentKey = (typeof equipmentKeys)[number];
@@ -299,10 +299,8 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu
299 299 PersonalTechProjects: IPersonalTechProject[];
300 300 PlayerSkills: IPlayerSkills;
301 301 CrewShipAmmo: ITypeCount[];
302 CrewShipSalvagedWeaponSkins: IUpgradeClient[];
303 CrewShipWeapons: ICrewShipWeaponClient[];
304 CrewShipSalvagedWeapons: IEquipmentClient[];
305 302 CrewShipWeaponSkins: IUpgradeClient[];
303 CrewShipSalvagedWeaponSkins: IUpgradeClient[];
306 304 TradeBannedUntil?: IMongoDate;
307 305 PlayedParkourTutorial: boolean;
308 306 SubscribedToEmailsPersonalized: number;
@@ -538,17 +536,6 @@ export interface ICrewShipWeapon {
538 536 PORT_GUNS: ICrewShipPortGuns;
539 537 }
540 538
541 // inventory.CrewShipWeapons
542 export interface ICrewShipWeaponClient {
543 ItemType: string;
544 ItemId: IOid;
545 }
546
547 export interface ICrewShipWeaponDatabase {
548 ItemType: string;
549 _id: Types.ObjectId;
550 }
551
552 539 export interface ICrewShipPilotWeapon {
553 540 PRIMARY_A: IEquipmentSelection;
554 541 SECONDARY_A: IEquipmentSelection;