feat: gardening setup
This commit is contained in:
		
							parent
							
								
									6f64690b91
								
							
						
					
					
						commit
						5edd9a0507
					
				| @ -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<IPersonalRooms>(); | ||||
|     const loadout = await getLoadout(accountId); | ||||
|     const ship = await getShip(personalRoomsDb.activeShipId, "ShipAttachments SkinFlavourItem"); | ||||
|  | ||||
| @ -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<IGardening>({ | ||||
|     Planters: [Schema.Types.Mixed] //TODO: add when implementing gardening
 | ||||
| const plantSchema = new Schema<IPlantDatabase>( | ||||
|     { | ||||
|         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<IPlanterDatabase>( | ||||
|     { | ||||
|         Name: { type: String, required: true }, | ||||
|         Plants: { type: [plantSchema], default: [] } | ||||
|     }, | ||||
|     { _id: false } | ||||
| ); | ||||
| 
 | ||||
| const gardeningSchema = new Schema<IGardeningDatabase>( | ||||
|     { | ||||
|         Planters: { type: [planterSchema], default: [] } | ||||
|     }, | ||||
|     { _id: false } | ||||
| ); | ||||
| 
 | ||||
| const apartmentSchema = new Schema<IApartmentDatabase>( | ||||
|     { | ||||
|         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<IOrbiter>( | ||||
|  | ||||
| @ -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; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -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<IPlantClient, "EndTime"> { | ||||
|     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[]; | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user