2023-05-19 15:22:48 -03:00
|
|
|
import { RequestHandler } from "express";
|
2024-05-15 21:55:59 +02:00
|
|
|
import { config } from "@/src/services/configService";
|
2024-02-18 13:58:43 +01:00
|
|
|
import allShipFeatures from "@/static/fixed_responses/allShipFeatures.json";
|
2024-05-28 13:45:06 +02:00
|
|
|
import { getAccountIdForRequest } from "@/src/services/loginService";
|
2025-04-26 11:54:06 -07:00
|
|
|
import { createGarden, getPersonalRooms } from "@/src/services/personalRoomsService";
|
2024-02-18 13:58:43 +01:00
|
|
|
import { getShip } from "@/src/services/shipService";
|
|
|
|
import { toOid } from "@/src/helpers/inventoryHelpers";
|
|
|
|
import { IGetShipResponse } from "@/src/types/shipTypes";
|
2025-04-26 11:54:06 -07:00
|
|
|
import { IPersonalRoomsClient } from "@/src/types/personalRoomsTypes";
|
2025-01-20 12:19:32 +01:00
|
|
|
import { getLoadout } from "@/src/services/loadoutService";
|
2023-05-19 15:22:48 -03:00
|
|
|
|
2024-02-18 13:58:43 +01:00
|
|
|
export const getShipController: RequestHandler = async (req, res) => {
|
2024-05-28 13:45:06 +02:00
|
|
|
const accountId = await getAccountIdForRequest(req);
|
2024-12-23 06:21:48 +01:00
|
|
|
const personalRoomsDb = await getPersonalRooms(accountId);
|
2025-04-26 11:54:06 -07:00
|
|
|
|
|
|
|
// 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) {
|
|
|
|
personalRoomsDb.Apartment.Gardening = createGarden();
|
|
|
|
await personalRoomsDb.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
const personalRooms = personalRoomsDb.toJSON<IPersonalRoomsClient>();
|
2024-02-18 13:58:43 +01:00
|
|
|
const loadout = await getLoadout(accountId);
|
2024-12-23 09:15:41 +01:00
|
|
|
const ship = await getShip(personalRoomsDb.activeShipId, "ShipAttachments SkinFlavourItem");
|
2023-12-14 17:34:15 +01:00
|
|
|
|
2024-02-18 13:58:43 +01:00
|
|
|
const getShipResponse: IGetShipResponse = {
|
|
|
|
ShipOwnerId: accountId,
|
|
|
|
LoadOutInventory: { LoadOutPresets: loadout.toJSON() },
|
|
|
|
Ship: {
|
2024-12-23 06:21:48 +01:00
|
|
|
...personalRooms.Ship,
|
|
|
|
ShipId: toOid(personalRoomsDb.activeShipId),
|
2024-02-18 13:58:43 +01:00
|
|
|
ShipInterior: {
|
2024-12-23 09:15:41 +01:00
|
|
|
Colors: personalRooms.ShipInteriorColors,
|
2024-02-18 13:58:43 +01:00
|
|
|
ShipAttachments: ship.ShipAttachments,
|
|
|
|
SkinFlavourItem: ship.SkinFlavourItem
|
2025-04-14 07:16:25 -07:00
|
|
|
},
|
|
|
|
FavouriteLoadoutId: personalRooms.Ship.FavouriteLoadoutId
|
|
|
|
? toOid(personalRooms.Ship.FavouriteLoadoutId)
|
|
|
|
: undefined
|
2024-02-18 13:58:43 +01:00
|
|
|
},
|
2024-12-22 20:32:19 +01:00
|
|
|
Apartment: personalRooms.Apartment,
|
|
|
|
TailorShop: personalRooms.TailorShop
|
2024-02-18 13:58:43 +01:00
|
|
|
};
|
|
|
|
|
2024-06-11 12:56:51 +02:00
|
|
|
if (config.unlockAllShipFeatures) {
|
2024-02-18 13:58:43 +01:00
|
|
|
getShipResponse.Ship.Features = allShipFeatures;
|
2023-06-05 04:16:49 +08:00
|
|
|
}
|
2023-12-14 17:34:15 +01:00
|
|
|
|
2024-02-18 13:58:43 +01:00
|
|
|
res.json(getShipResponse);
|
|
|
|
};
|