From 5edd9a05078f3e966d409f3dacd3b7f2e3506416 Mon Sep 17 00:00:00 2001 From: Sainan <63328889+Sainan@users.noreply.github.com> Date: Fri, 25 Apr 2025 22:19:18 +0200 Subject: [PATCH] feat: gardening setup --- src/controllers/api/getShipController.ts | 65 ++++++++++++++++++++++++ src/models/personalRoomsModel.ts | 49 +++++++++++++++--- src/types/personalRoomsTypes.ts | 6 +-- src/types/shipTypes.ts | 36 +++++++++---- 4 files changed, 135 insertions(+), 21 deletions(-) diff --git a/src/controllers/api/getShipController.ts b/src/controllers/api/getShipController.ts index ac1ebadf..ac0f67a1 100644 --- a/src/controllers/api/getShipController.ts +++ b/src/controllers/api/getShipController.ts @@ -8,10 +8,75 @@ import { toOid } from "@/src/helpers/inventoryHelpers"; import { IGetShipResponse } from "@/src/types/shipTypes"; import { IPersonalRooms } from "@/src/types/personalRoomsTypes"; import { getLoadout } from "@/src/services/loadoutService"; +import { getRandomElement } from "@/src/services/rngService"; export const getShipController: RequestHandler = async (req, res) => { const accountId = await getAccountIdForRequest(req); const personalRoomsDb = await getPersonalRooms(accountId); + + // Setup gardening if it's missing. Maybe should be done as part of some quest completion in the future. + if (personalRoomsDb.Apartment.Gardening.Planters.length == 0) { + const plantTypes = [ + "/Lotus/Types/Items/Plants/MiscItems/DuvxDuviriGrowingPlantA", + "/Lotus/Types/Items/Plants/MiscItems/DuvxDuviriGrowingPlantB", + "/Lotus/Types/Items/Plants/MiscItems/DuvxDuviriGrowingPlantC", + "/Lotus/Types/Items/Plants/MiscItems/DuvxDuviriGrowingPlantD", + "/Lotus/Types/Items/Plants/MiscItems/DuvxDuviriGrowingPlantE", + "/Lotus/Types/Items/Plants/MiscItems/DuvxDuviriGrowingPlantF" + ]; + const endTime = new Date(Date.now() + 79200_000); // Plants will take 22 hours to grow + personalRoomsDb.Apartment.Gardening = { + Planters: [ + { + Name: "Garden0", + Plants: [ + { + PlantType: getRandomElement(plantTypes), + EndTime: endTime, + PlotIndex: 0 + }, + { + PlantType: getRandomElement(plantTypes), + EndTime: endTime, + PlotIndex: 1 + } + ] + }, + { + Name: "Garden1", + Plants: [ + { + PlantType: getRandomElement(plantTypes), + EndTime: endTime, + PlotIndex: 0 + }, + { + PlantType: getRandomElement(plantTypes), + EndTime: endTime, + PlotIndex: 1 + } + ] + }, + { + Name: "Garden2", + Plants: [ + { + PlantType: getRandomElement(plantTypes), + EndTime: endTime, + PlotIndex: 0 + }, + { + PlantType: getRandomElement(plantTypes), + EndTime: endTime, + PlotIndex: 1 + } + ] + } + ] + }; + await personalRoomsDb.save(); + } + const personalRooms = personalRoomsDb.toJSON(); const loadout = await getLoadout(accountId); const ship = await getShip(personalRoomsDb.activeShipId, "ShipAttachments SkinFlavourItem"); diff --git a/src/models/personalRoomsModel.ts b/src/models/personalRoomsModel.ts index 0fcdda72..e6176ead 100644 --- a/src/models/personalRoomsModel.ts +++ b/src/models/personalRoomsModel.ts @@ -1,14 +1,17 @@ -import { toOid } from "@/src/helpers/inventoryHelpers"; +import { toMongoDate, toOid } from "@/src/helpers/inventoryHelpers"; import { colorSchema } from "@/src/models/inventoryModels/inventoryModel"; import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes"; import { IFavouriteLoadoutDatabase, - IGardening, + IGardeningDatabase, IPlacedDecosDatabase, IPictureFrameInfo, IRoom, ITailorShopDatabase, - IApartmentDatabase + IApartmentDatabase, + IPlanterDatabase, + IPlantDatabase, + IPlantClient } from "@/src/types/shipTypes"; import { Schema, model } from "mongoose"; @@ -77,15 +80,45 @@ favouriteLoadoutSchema.set("toJSON", { } }); -const gardeningSchema = new Schema({ - Planters: [Schema.Types.Mixed] //TODO: add when implementing gardening +const plantSchema = new Schema( + { + PlantType: String, + EndTime: Date, + PlotIndex: Number + }, + { _id: false } +); + +plantSchema.set("toJSON", { + virtuals: true, + transform(_doc, obj) { + const client = obj as IPlantClient; + const db = obj as IPlantDatabase; + + client.EndTime = toMongoDate(db.EndTime); + } }); +const planterSchema = new Schema( + { + Name: { type: String, required: true }, + Plants: { type: [plantSchema], default: [] } + }, + { _id: false } +); + +const gardeningSchema = new Schema( + { + Planters: { type: [planterSchema], default: [] } + }, + { _id: false } +); + const apartmentSchema = new Schema( { Rooms: [roomSchema], FavouriteLoadouts: [favouriteLoadoutSchema], - Gardening: gardeningSchema // TODO: ensure this is correct + Gardening: gardeningSchema }, { _id: false } ); @@ -98,7 +131,9 @@ const apartmentDefault: IApartmentDatabase = { { Name: "DuviriHallway", MaxCapacity: 1600 } ], FavouriteLoadouts: [], - Gardening: {} + Gardening: { + Planters: [] + } }; const orbiterSchema = new Schema( diff --git a/src/types/personalRoomsTypes.ts b/src/types/personalRoomsTypes.ts index 68239bb4..df26afdd 100644 --- a/src/types/personalRoomsTypes.ts +++ b/src/types/personalRoomsTypes.ts @@ -1,12 +1,12 @@ import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes"; import { - IApartment, IRoom, IPlacedDecosDatabase, ITailorShop, ITailorShopDatabase, TBootLocation, - IApartmentDatabase + IApartmentDatabase, + IApartmentClient } from "@/src/types/shipTypes"; import { Document, Model, Types } from "mongoose"; @@ -24,7 +24,7 @@ export interface IOrbiter { export interface IPersonalRooms { ShipInteriorColors: IColor; Ship: IOrbiter; - Apartment: IApartment; + Apartment: IApartmentClient; TailorShop: ITailorShop; } diff --git a/src/types/shipTypes.ts b/src/types/shipTypes.ts index a097f3ca..74eaaeae 100644 --- a/src/types/shipTypes.ts +++ b/src/types/shipTypes.ts @@ -1,12 +1,12 @@ import { Types } from "mongoose"; -import { IOid } from "@/src/types/commonTypes"; +import { IMongoDate, IOid } from "@/src/types/commonTypes"; import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes"; import { ILoadoutClient } from "./saveLoadoutTypes"; export interface IGetShipResponse { ShipOwnerId: string; Ship: IShip; - Apartment: IApartment; + Apartment: IApartmentClient; TailorShop: ITailorShop; LoadOutInventory: { LoadOutPresets: ILoadoutClient }; } @@ -51,28 +51,42 @@ export interface IRoom { PlacedDecos?: IPlacedDecosDatabase[]; } -export interface IPlants { +export interface IPlantClient { PlantType: string; - EndTime: IOid; + EndTime: IMongoDate; PlotIndex: number; } -export interface IPlanters { + +export interface IPlantDatabase extends Omit { + EndTime: Date; +} + +export interface IPlanterClient { Name: string; - Plants: IPlants[]; + Plants: IPlantClient[]; } -export interface IGardening { - Planters?: IPlanters[]; +export interface IPlanterDatabase { + Name: string; + Plants: IPlantDatabase[]; } -export interface IApartment { - Gardening: IGardening; +export interface IGardeningClient { + Planters: IPlanterClient[]; +} + +export interface IGardeningDatabase { + Planters: IPlanterDatabase[]; +} + +export interface IApartmentClient { + Gardening: IGardeningClient; Rooms: IRoom[]; FavouriteLoadouts: IFavouriteLoadout[]; } export interface IApartmentDatabase { - Gardening: IGardening; + Gardening: IGardeningDatabase; Rooms: IRoom[]; FavouriteLoadouts: IFavouriteLoadoutDatabase[]; }