feat: gardening #1849
@ -8,10 +8,75 @@ import { toOid } from "@/src/helpers/inventoryHelpers";
 | 
				
			|||||||
import { IGetShipResponse } from "@/src/types/shipTypes";
 | 
					import { IGetShipResponse } from "@/src/types/shipTypes";
 | 
				
			||||||
import { IPersonalRooms } from "@/src/types/personalRoomsTypes";
 | 
					import { IPersonalRooms } from "@/src/types/personalRoomsTypes";
 | 
				
			||||||
import { getLoadout } from "@/src/services/loadoutService";
 | 
					import { getLoadout } from "@/src/services/loadoutService";
 | 
				
			||||||
 | 
					import { getRandomElement } from "@/src/services/rngService";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const getShipController: RequestHandler = async (req, res) => {
 | 
					export const getShipController: RequestHandler = async (req, res) => {
 | 
				
			||||||
    const accountId = await getAccountIdForRequest(req);
 | 
					    const accountId = await getAccountIdForRequest(req);
 | 
				
			||||||
    const personalRoomsDb = await getPersonalRooms(accountId);
 | 
					    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 personalRooms = personalRoomsDb.toJSON<IPersonalRooms>();
 | 
				
			||||||
    const loadout = await getLoadout(accountId);
 | 
					    const loadout = await getLoadout(accountId);
 | 
				
			||||||
    const ship = await getShip(personalRoomsDb.activeShipId, "ShipAttachments SkinFlavourItem");
 | 
					    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 { colorSchema } from "@/src/models/inventoryModels/inventoryModel";
 | 
				
			||||||
import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
 | 
					import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    IFavouriteLoadoutDatabase,
 | 
					    IFavouriteLoadoutDatabase,
 | 
				
			||||||
    IGardening,
 | 
					    IGardeningDatabase,
 | 
				
			||||||
    IPlacedDecosDatabase,
 | 
					    IPlacedDecosDatabase,
 | 
				
			||||||
    IPictureFrameInfo,
 | 
					    IPictureFrameInfo,
 | 
				
			||||||
    IRoom,
 | 
					    IRoom,
 | 
				
			||||||
    ITailorShopDatabase,
 | 
					    ITailorShopDatabase,
 | 
				
			||||||
    IApartmentDatabase
 | 
					    IApartmentDatabase,
 | 
				
			||||||
 | 
					    IPlanterDatabase,
 | 
				
			||||||
 | 
					    IPlantDatabase,
 | 
				
			||||||
 | 
					    IPlantClient
 | 
				
			||||||
} from "@/src/types/shipTypes";
 | 
					} from "@/src/types/shipTypes";
 | 
				
			||||||
import { Schema, model } from "mongoose";
 | 
					import { Schema, model } from "mongoose";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -77,15 +80,45 @@ favouriteLoadoutSchema.set("toJSON", {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const gardeningSchema = new Schema<IGardening>({
 | 
					const plantSchema = new Schema<IPlantDatabase>(
 | 
				
			||||||
    Planters: [Schema.Types.Mixed] //TODO: add when implementing gardening
 | 
					    {
 | 
				
			||||||
 | 
					        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>(
 | 
					const apartmentSchema = new Schema<IApartmentDatabase>(
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Rooms: [roomSchema],
 | 
					        Rooms: [roomSchema],
 | 
				
			||||||
        FavouriteLoadouts: [favouriteLoadoutSchema],
 | 
					        FavouriteLoadouts: [favouriteLoadoutSchema],
 | 
				
			||||||
        Gardening: gardeningSchema // TODO: ensure this is correct
 | 
					        Gardening: gardeningSchema
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    { _id: false }
 | 
					    { _id: false }
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
@ -98,7 +131,9 @@ const apartmentDefault: IApartmentDatabase = {
 | 
				
			|||||||
        { Name: "DuviriHallway", MaxCapacity: 1600 }
 | 
					        { Name: "DuviriHallway", MaxCapacity: 1600 }
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    FavouriteLoadouts: [],
 | 
					    FavouriteLoadouts: [],
 | 
				
			||||||
    Gardening: {}
 | 
					    Gardening: {
 | 
				
			||||||
 | 
					        Planters: []
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const orbiterSchema = new Schema<IOrbiter>(
 | 
					const orbiterSchema = new Schema<IOrbiter>(
 | 
				
			||||||
 | 
				
			|||||||
@ -1,12 +1,12 @@
 | 
				
			|||||||
import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
					import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    IApartment,
 | 
					 | 
				
			||||||
    IRoom,
 | 
					    IRoom,
 | 
				
			||||||
    IPlacedDecosDatabase,
 | 
					    IPlacedDecosDatabase,
 | 
				
			||||||
    ITailorShop,
 | 
					    ITailorShop,
 | 
				
			||||||
    ITailorShopDatabase,
 | 
					    ITailorShopDatabase,
 | 
				
			||||||
    TBootLocation,
 | 
					    TBootLocation,
 | 
				
			||||||
    IApartmentDatabase
 | 
					    IApartmentDatabase,
 | 
				
			||||||
 | 
					    IApartmentClient
 | 
				
			||||||
} from "@/src/types/shipTypes";
 | 
					} from "@/src/types/shipTypes";
 | 
				
			||||||
import { Document, Model, Types } from "mongoose";
 | 
					import { Document, Model, Types } from "mongoose";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -24,7 +24,7 @@ export interface IOrbiter {
 | 
				
			|||||||
export interface IPersonalRooms {
 | 
					export interface IPersonalRooms {
 | 
				
			||||||
    ShipInteriorColors: IColor;
 | 
					    ShipInteriorColors: IColor;
 | 
				
			||||||
    Ship: IOrbiter;
 | 
					    Ship: IOrbiter;
 | 
				
			||||||
    Apartment: IApartment;
 | 
					    Apartment: IApartmentClient;
 | 
				
			||||||
    TailorShop: ITailorShop;
 | 
					    TailorShop: ITailorShop;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,12 +1,12 @@
 | 
				
			|||||||
import { Types } from "mongoose";
 | 
					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 { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
import { ILoadoutClient } from "./saveLoadoutTypes";
 | 
					import { ILoadoutClient } from "./saveLoadoutTypes";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IGetShipResponse {
 | 
					export interface IGetShipResponse {
 | 
				
			||||||
    ShipOwnerId: string;
 | 
					    ShipOwnerId: string;
 | 
				
			||||||
    Ship: IShip;
 | 
					    Ship: IShip;
 | 
				
			||||||
    Apartment: IApartment;
 | 
					    Apartment: IApartmentClient;
 | 
				
			||||||
    TailorShop: ITailorShop;
 | 
					    TailorShop: ITailorShop;
 | 
				
			||||||
    LoadOutInventory: { LoadOutPresets: ILoadoutClient };
 | 
					    LoadOutInventory: { LoadOutPresets: ILoadoutClient };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -51,28 +51,42 @@ export interface IRoom {
 | 
				
			|||||||
    PlacedDecos?: IPlacedDecosDatabase[];
 | 
					    PlacedDecos?: IPlacedDecosDatabase[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IPlants {
 | 
					export interface IPlantClient {
 | 
				
			||||||
    PlantType: string;
 | 
					    PlantType: string;
 | 
				
			||||||
    EndTime: IOid;
 | 
					    EndTime: IMongoDate;
 | 
				
			||||||
    PlotIndex: number;
 | 
					    PlotIndex: number;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
export interface IPlanters {
 | 
					
 | 
				
			||||||
 | 
					export interface IPlantDatabase extends Omit<IPlantClient, "EndTime"> {
 | 
				
			||||||
 | 
					    EndTime: Date;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface IPlanterClient {
 | 
				
			||||||
    Name: string;
 | 
					    Name: string;
 | 
				
			||||||
    Plants: IPlants[];
 | 
					    Plants: IPlantClient[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IGardening {
 | 
					export interface IPlanterDatabase {
 | 
				
			||||||
    Planters?: IPlanters[];
 | 
					    Name: string;
 | 
				
			||||||
 | 
					    Plants: IPlantDatabase[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IApartment {
 | 
					export interface IGardeningClient {
 | 
				
			||||||
    Gardening: IGardening;
 | 
					    Planters: IPlanterClient[];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface IGardeningDatabase {
 | 
				
			||||||
 | 
					    Planters: IPlanterDatabase[];
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export interface IApartmentClient {
 | 
				
			||||||
 | 
					    Gardening: IGardeningClient;
 | 
				
			||||||
    Rooms: IRoom[];
 | 
					    Rooms: IRoom[];
 | 
				
			||||||
    FavouriteLoadouts: IFavouriteLoadout[];
 | 
					    FavouriteLoadouts: IFavouriteLoadout[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export interface IApartmentDatabase {
 | 
					export interface IApartmentDatabase {
 | 
				
			||||||
    Gardening: IGardening;
 | 
					    Gardening: IGardeningDatabase;
 | 
				
			||||||
    Rooms: IRoom[];
 | 
					    Rooms: IRoom[];
 | 
				
			||||||
    FavouriteLoadouts: IFavouriteLoadoutDatabase[];
 | 
					    FavouriteLoadouts: IFavouriteLoadoutDatabase[];
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user