From ebb28d56d5b8ad8008a20e294f58417194d8dcc9 Mon Sep 17 00:00:00 2001 From: Sainan Date: Mon, 24 Feb 2025 05:28:43 -0800 Subject: [PATCH] feat: acquisition of resource extractor drones (#998) Related to #793 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/998 Co-authored-by: Sainan Co-committed-by: Sainan --- src/models/inventoryModels/inventoryModel.ts | 30 ++++++++++++++++++-- src/services/inventoryService.ts | 21 +++++++++++++- src/types/inventoryTypes/inventoryTypes.ts | 13 +++++++-- src/types/purchaseTypes.ts | 10 +++---- 4 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 3ec3c3635..0288cf426 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -68,7 +68,9 @@ import { ICalendarProgress, IPendingCouponDatabase, IPendingCouponClient, - ILibraryAvailableDailyTaskInfo + ILibraryAvailableDailyTaskInfo, + IDroneDatabase, + IDroneClient } from "../../types/inventoryTypes/inventoryTypes"; import { IOid } from "../../types/commonTypes"; import { @@ -349,6 +351,27 @@ const TypeXPItemSchema = new Schema( { _id: false } ); +const droneSchema = new Schema( + { + ItemType: String, + CurrentHP: Number, + RepairStart: { type: Date, default: undefined } + }, + { id: false } +); +droneSchema.set("toJSON", { + virtuals: true, + transform(_document, obj) { + const client = obj as IDroneClient; + const db = obj as IDroneDatabase; + + client.ItemId = toOid(db._id); + + delete obj._id; + delete obj.__v; + } +}); + const challengeProgressSchema = new Schema( { Progress: Number, @@ -1148,8 +1171,8 @@ const inventorySchema = new Schema( CompletedSorties: [String], LastSortieReward: [Schema.Types.Mixed], - //Resource_Drone[Uselees stuff] - Drones: [Schema.Types.Mixed], + // Resource Extractor Drones + Drones: [droneSchema], //Active profile ico ActiveAvatarImageType: String, @@ -1299,6 +1322,7 @@ export type InventoryDocumentProps = { PendingRecipes: Types.DocumentArray; WeaponSkins: Types.DocumentArray; QuestKeys: Types.DocumentArray; + Drones: Types.DocumentArray; } & { [K in TEquipmentKey]: Types.DocumentArray }; // eslint-disable-next-line @typescript-eslint/ban-types diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 4b697185c..3721f54de 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -24,7 +24,8 @@ import { IKubrowPetEggDatabase, IKubrowPetEggClient, ILibraryAvailableDailyTaskInfo, - ICalendarProgress + ICalendarProgress, + IDroneClient } from "@/src/types/inventoryTypes/inventoryTypes"; import { IGenericUpdate } from "../types/genericUpdate"; import { @@ -38,6 +39,7 @@ import { IEquipmentClient, IEquipmentDatabase, IItemConfig } from "../types/inve import { ExportArcanes, ExportCustoms, + ExportDrones, ExportFlavour, ExportFusionBundles, ExportGear, @@ -336,6 +338,12 @@ export const addItem = async ( } }; } + if (typeName in ExportDrones) { + const inventoryChanges = addDrone(inventory, typeName); + return { + InventoryChanges: inventoryChanges + }; + } // Path-based duck typing switch (typeName.substr(1).split("/")[1]) { @@ -809,6 +817,17 @@ const addMotorcycle = ( return inventoryChanges; }; +const addDrone = ( + inventory: TInventoryDatabaseDocument, + typeName: string, + inventoryChanges: IInventoryChanges = {} +): IInventoryChanges => { + const index = inventory.Drones.push({ ItemType: typeName, CurrentHP: ExportDrones[typeName].durability }) - 1; + inventoryChanges.Drones ??= []; + inventoryChanges.Drones.push(inventory.Drones[index].toJSON()); + return inventoryChanges; +}; + //TODO: wrong id is not erroring export const addGearExpByCategory = ( inventory: TInventoryDatabaseDocument, diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index 807954183..f6e0c85af 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -39,6 +39,7 @@ export interface IInventoryDatabase | "DialogueHistory" | "KubrowPetEggs" | "PendingCoupon" + | "Drones" | TEquipmentKey >, InventoryDatabaseEquipment { @@ -63,6 +64,7 @@ export interface IInventoryDatabase DialogueHistory?: IDialogueHistoryDatabase; KubrowPetEggs?: IKubrowPetEggDatabase[]; PendingCoupon?: IPendingCouponDatabase; + Drones: IDroneDatabase[]; } export interface IQuestKeyDatabase { @@ -258,7 +260,7 @@ export interface IInventoryClient extends IDailyAffiliations, InventoryClientEqu Alignment: IAlignment; CompletedSorties: string[]; LastSortieReward: ILastSortieReward[]; - Drones: IDrone[]; + Drones: IDroneClient[]; StepSequencers: IStepSequencer[]; ActiveAvatarImageType: string; ShipDecorations: IConsumable[]; @@ -508,13 +510,20 @@ export interface IDiscoveredMarker { discoveryState: number[]; } -export interface IDrone { +export interface IDroneClient { ItemType: string; CurrentHP: number; ItemId: IOid; RepairStart?: IMongoDate; } +export interface IDroneDatabase { + ItemType: string; + CurrentHP: number; + _id: Types.ObjectId; + RepairStart?: Date; +} + export interface ITypeXPItem { ItemType: string; XP: number; diff --git a/src/types/purchaseTypes.ts b/src/types/purchaseTypes.ts index 8dcdb4e86..f1e864be7 100644 --- a/src/types/purchaseTypes.ts +++ b/src/types/purchaseTypes.ts @@ -1,5 +1,5 @@ import { IEquipmentClient } from "./inventoryTypes/commonInventoryTypes"; -import { IInfestedFoundryClient, TEquipmentKey } from "./inventoryTypes/inventoryTypes"; +import { IDroneClient, IInfestedFoundryClient, TEquipmentKey } from "./inventoryTypes/inventoryTypes"; export interface IPurchaseRequest { PurchaseParams: IPurchaseParams; @@ -32,10 +32,10 @@ export type IInventoryChanges = { [_ in SlotNames]?: IBinChanges; } & { [_ in TEquipmentKey]?: IEquipmentClient[]; -} & ICurrencyChanges & { InfestedFoundry?: IInfestedFoundryClient } & Record< - string, - IBinChanges | number | object[] | IInfestedFoundryClient - >; +} & ICurrencyChanges & { + InfestedFoundry?: IInfestedFoundryClient; + Drones?: IDroneClient[]; + } & Record; export interface IAffiliationMods { Tag: string;