XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

fix: acquiring ships (#619)

dda41875
Sainan <sainan@calamity.inc>
提交于

代码差异

11 个文件 +67 -74
Modified src/controllers/api/getShipController.ts +2 -2
@@ -15,7 +15,7 @@ export const getShipController: RequestHandler = async (req, res) => {
15 15 const personalRoomsDb = await getPersonalRooms(accountId);
16 16 const personalRooms = personalRoomsDb.toJSON<IPersonalRooms>();
17 17 const loadout = await getLoadout(accountId);
18 const ship = await getShip(personalRoomsDb.activeShipId, "ShipInteriorColors ShipAttachments SkinFlavourItem");
18 const ship = await getShip(personalRoomsDb.activeShipId, "ShipAttachments SkinFlavourItem");
19 19
20 20 const getShipResponse: IGetShipResponse = {
21 21 ShipOwnerId: accountId,
@@ -24,7 +24,7 @@ export const getShipController: RequestHandler = async (req, res) => {
24 24 ...personalRooms.Ship,
25 25 ShipId: toOid(personalRoomsDb.activeShipId),
26 26 ShipInterior: {
27 Colors: ship.ShipInteriorColors,
27 Colors: personalRooms.ShipInteriorColors,
28 28 ShipAttachments: ship.ShipAttachments,
29 29 SkinFlavourItem: ship.SkinFlavourItem
30 30 }
Modified src/controllers/api/inventoryController.ts +1 -1
@@ -20,7 +20,7 @@ const inventoryController: RequestHandler = async (request, response) => {
20 20
21 21 const inventory = await Inventory.findOne({ accountOwnerId: account._id.toString() })
22 22 .populate<{ LoadOutPresets: ILoadoutDatabase }>("LoadOutPresets")
23 .populate<{ Ships: IShipInventory }>("Ships", "-ShipInteriorColors");
23 .populate<{ Ships: IShipInventory }>("Ships");
24 24
25 25 if (!inventory) {
26 26 response.status(400).json({ error: "inventory was undefined" });
Modified src/controllers/api/setShipCustomizationsController.ts +3 -1
@@ -1,3 +1,4 @@
1 import { getAccountIdForRequest } from "@/src/services/loginService";
1 2 import { setShipCustomizations } from "@/src/services/shipCustomizationsService";
2 3 import { ISetShipCustomizationsRequest } from "@/src/types/shipTypes";
3 4 import { logger } from "@/src/utils/logger";
@@ -5,9 +6,10 @@ import { RequestHandler } from "express";
5 6
6 7 export const setShipCustomizationsController: RequestHandler = async (req, res) => {
7 8 try {
9 const accountId = await getAccountIdForRequest(req);
8 10 const setShipCustomizationsRequest = JSON.parse(req.body as string) as ISetShipCustomizationsRequest;
9 11
10 const setShipCustomizationsResponse = await setShipCustomizations(setShipCustomizationsRequest);
12 const setShipCustomizationsResponse = await setShipCustomizations(accountId, setShipCustomizationsRequest);
11 13 res.json(setShipCustomizationsResponse);
12 14 } catch (error: unknown) {
13 15 if (error instanceof Error) {
Modified src/models/personalRoomsModel.ts +2 -0
@@ -1,4 +1,5 @@
1 1 import { toOid } from "@/src/helpers/inventoryHelpers";
2 import { colorSchema } from "@/src/models/inventoryModels/inventoryModel";
2 3 import { IOrbiter, IPersonalRoomsDatabase, PersonalRoomsModelType } from "@/src/types/personalRoomsTypes";
3 4 import {
4 5 IApartment,
@@ -131,6 +132,7 @@ const tailorShopDefault: ITailorShopDatabase = {
131 132 export const personalRoomsSchema = new Schema<IPersonalRoomsDatabase>({
132 133 personalRoomsOwnerId: Schema.Types.ObjectId,
133 134 activeShipId: Schema.Types.ObjectId,
135 ShipInteriorColors: colorSchema,
134 136 Ship: orbiterSchema,
135 137 Apartment: apartmentSchema,
136 138 TailorShop: { type: tailorShopSchema, default: tailorShopDefault }
Modified src/models/shipModel.ts +0 -1
@@ -8,7 +8,6 @@ const shipSchema = new Schema<IShipDatabase>(
8 8 {
9 9 ItemType: String,
10 10 ShipOwnerId: Schema.Types.ObjectId,
11 ShipInteriorColors: colorSchema,
12 11 ShipExteriorColors: colorSchema,
13 12 AirSupportPower: String,
14 13 ShipAttachments: { HOOD_ORNAMENT: String },
Modified src/services/inventoryService.ts +30 -13
@@ -41,6 +41,7 @@ import {
41 41 ExportResources,
42 42 ExportUpgrades
43 43 } from "warframe-public-export-plus";
44 import { createShip } from "./shipService";
44 45
45 46 export const createInventory = async (
46 47 accountOwnerId: Types.ObjectId,
@@ -129,19 +130,35 @@ export const addItem = async (
129 130 }
130 131 if (typeName in ExportResources) {
131 132 const inventory = await getInventory(accountId);
132 const miscItemChanges = [
133 {
134 ItemType: typeName,
135 ItemCount: quantity
136 } satisfies IMiscItem
137 ];
138 addMiscItems(inventory, miscItemChanges);
139 await inventory.save();
140 return {
141 InventoryChanges: {
142 MiscItems: miscItemChanges
143 }
144 };
133 if (ExportResources[typeName].productCategory == "Ships") {
134 const oid = await createShip(new Types.ObjectId(accountId), typeName);
135 inventory.Ships.push(oid);
136 await inventory.save();
137 return {
138 InventoryChanges: {
139 Ships: [
140 {
141 ItemId: { $oid: oid },
142 ItemType: typeName
143 }
144 ]
145 }
146 };
147 } else {
148 const miscItemChanges = [
149 {
150 ItemType: typeName,
151 ItemCount: quantity
152 } satisfies IMiscItem
153 ];
154 addMiscItems(inventory, miscItemChanges);
155 await inventory.save();
156 return {
157 InventoryChanges: {
158 MiscItems: miscItemChanges
159 }
160 };
161 }
145 162 }
146 163 if (typeName in ExportCustoms) {
147 164 return {
Modified src/services/shipCustomizationsService.ts +17 -17
@@ -2,7 +2,6 @@ import { getPersonalRooms } from "@/src/services/personalRoomsService";
2 2 import { getShip } from "@/src/services/shipService";
3 3 import {
4 4 ISetShipCustomizationsRequest,
5 IShipDatabase,
6 5 IShipDecorationsRequest,
7 6 IShipDecorationsResponse,
8 7 ISetPlacedDecoInfoRequest
@@ -10,25 +9,26 @@ import {
10 9 import { logger } from "@/src/utils/logger";
11 10 import { Types } from "mongoose";
12 11
13 export const setShipCustomizations = async (shipCustomization: ISetShipCustomizationsRequest) => {
14 const ship = await getShip(new Types.ObjectId(shipCustomization.ShipId));
15
16 let shipChanges: Partial<IShipDatabase>;
12 export const setShipCustomizations = async (
13 accountId: string,
14 shipCustomization: ISetShipCustomizationsRequest
15 ): Promise<void> => {
17 16 if (shipCustomization.IsExterior) {
18 shipChanges = {
19 ShipExteriorColors: shipCustomization.Customization.Colors,
20 SkinFlavourItem: shipCustomization.Customization.SkinFlavourItem,
21 ShipAttachments: shipCustomization.Customization.ShipAttachments,
22 AirSupportPower: shipCustomization.AirSupportPower!
23 };
17 const ship = await getShip(new Types.ObjectId(shipCustomization.ShipId));
18 if (ship.ShipOwnerId.toString() == accountId) {
19 ship.set({
20 ShipExteriorColors: shipCustomization.Customization.Colors,
21 SkinFlavourItem: shipCustomization.Customization.SkinFlavourItem,
22 ShipAttachments: shipCustomization.Customization.ShipAttachments,
23 AirSupportPower: shipCustomization.AirSupportPower!
24 });
25 await ship.save();
26 }
24 27 } else {
25 shipChanges = {
26 ShipInteriorColors: shipCustomization.Customization.Colors
27 };
28 const personalRooms = await getPersonalRooms(accountId);
29 personalRooms.ShipInteriorColors = shipCustomization.Customization.Colors;
30 await personalRooms.save();
28 31 }
29 ship.set(shipChanges);
30
31 await ship.save();
32 32 };
33 33
34 34 export const handleSetShipDecorations = async (
Modified src/services/shipService.ts +7 -4
@@ -3,10 +3,13 @@ import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
3 3 import { logger } from "@/src/utils/logger";
4 4 import { Types } from "mongoose";
5 5
6 export const createShip = async (accountOwnerId: Types.ObjectId) => {
6 export const createShip = async (
7 accountOwnerId: Types.ObjectId,
8 typeName: string = "/Lotus/Types/Items/Ships/DefaultShip"
9 ) => {
7 10 try {
8 11 const ship = new Ship({
9 ItemType: "/Lotus/Types/Items/Ships/DefaultShip",
12 ItemType: typeName,
10 13 ShipOwnerId: accountOwnerId
11 14 });
12 15 const newShip = await ship.save();
@@ -23,8 +26,8 @@ export const getShip = async (shipId: Types.ObjectId, fieldSelection: string = "
23 26 const ship = await Ship.findOne({ _id: shipId }, fieldSelection);
24 27
25 28 if (!ship) {
26 logger.error(`error finding a ship for account ${shipId}`);
27 throw new Error(`error finding a ship for account ${shipId}`);
29 logger.error(`error finding a ship with id ${shipId}`);
30 throw new Error(`error finding a ship with id ${shipId}`);
28 31 }
29 32
30 33 return ship;
Modified src/types/personalRoomsTypes.ts +3 -0
@@ -1,3 +1,4 @@
1 import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
1 2 import {
2 3 IApartment,
3 4 IRoom,
@@ -16,12 +17,14 @@ export interface IOrbiter {
16 17 }
17 18
18 19 export interface IPersonalRooms {
20 ShipInteriorColors: IColor;
19 21 Ship: IOrbiter;
20 22 Apartment: IApartment;
21 23 TailorShop: ITailorShop;
22 24 }
23 25
24 26 export interface IPersonalRoomsDatabase {
27 ShipInteriorColors: IColor;
25 28 personalRoomsOwnerId: Types.ObjectId;
26 29 activeShipId: Types.ObjectId;
27 30 Ship: IOrbiter;
Modified src/types/shipTypes.ts +2 -3
@@ -1,4 +1,4 @@
1 import { Schema, Types } from "mongoose";
1 import { Types } from "mongoose";
2 2 import { IOid } from "@/src/types/commonTypes";
3 3 import { IColor } from "@/src/types/inventoryTypes/commonInventoryTypes";
4 4 import { ILoadoutClient } from "./saveLoadoutTypes";
@@ -34,8 +34,7 @@ export interface IShip {
34 34
35 35 export interface IShipDatabase {
36 36 ItemType: string;
37 ShipOwnerId: Schema.Types.ObjectId;
38 ShipInteriorColors?: IColor;
37 ShipOwnerId: Types.ObjectId;
39 38 ShipExteriorColors?: IColor;
40 39 AirSupportPower: string;
41 40 ShipAttachments?: IShipAttachments;
Deleted static/fixed_responses/getShip.json +0 -32
@@ -1,32 +0,0 @@
1 {
2 "ShipOwnerId": "647bce8a1caba352f90b6a09",
3 "Ship": {
4 "Rooms": [
5 { "Name": "AlchemyRoom", "MaxCapacity": 1600 },
6 { "Name": "BridgeRoom", "MaxCapacity": 1600 },
7 { "Name": "LisetRoom", "MaxCapacity": 1000 },
8 { "Name": "OperatorChamberRoom", "MaxCapacity": 1600 },
9 { "Name": "OutsideRoom", "MaxCapacity": 1600 },
10 { "Name": "PersonalQuartersRoom", "MaxCapacity": 1600 }
11 ],
12 "ContentUrlSignature": "removed",
13 "Features": [
14 "/Lotus/Types/Items/ShipFeatureItems/EarthNavigationFeatureItem",
15 "/Lotus/Types/Items/ShipFeatureItems/ArsenalFeatureItem",
16 "/Lotus/Types/Items/ShipFeatureItems/SocialMenuFeatureItem",
17 "/Lotus/Types/Items/ShipFeatureItems/ModsFeatureItem",
18 "/Lotus/Types/Items/ShipFeatureItems/FoundryFeatureItem",
19 "/Lotus/Types/Items/ShipFeatureItems/MercuryNavigationFeatureItem"
20 ]
21 },
22 "Apartment": {
23 "Rooms": [
24 { "Name": "ElevatorLanding", "MaxCapacity": 1600 },
25 { "Name": "ApartmentRoomA", "MaxCapacity": 1000 },
26 { "Name": "ApartmentRoomB", "MaxCapacity": 1600 },
27 { "Name": "ApartmentRoomC", "MaxCapacity": 1600 },
28 { "Name": "DuviriHallway", "MaxCapacity": 1600 }
29 ],
30 "FavouriteLoadouts": []
31 }
32 }