fix: properly convert personal room decos to and from inventory types #2279

Merged
OrdisPrime merged 2 commits from deco-inv into main 2025-06-25 08:03:57 -07:00
3 changed files with 22 additions and 5 deletions
Showing only changes of commit 91a92ee138 - Show all commits

View File

@ -40,6 +40,7 @@ const placedDecosSchema = new Schema<IPlacedDecosDatabase>(
Pos: [Number], Pos: [Number],
Rot: [Number], Rot: [Number],
Scale: Number, Scale: Number,
Sockets: Number,
PictureFrameInfo: { type: pictureFrameInfoSchema, default: undefined } PictureFrameInfo: { type: pictureFrameInfoSchema, default: undefined }
}, },
{ id: false } { id: false }

View File

@ -8,7 +8,7 @@ import {
} from "@/src/types/shipTypes"; } from "@/src/types/shipTypes";
import { logger } from "@/src/utils/logger"; import { logger } from "@/src/utils/logger";
import { Types } from "mongoose"; import { Types } from "mongoose";
import { addShipDecorations, getInventory } from "./inventoryService"; import { addFusionTreasures, addShipDecorations, getInventory } from "./inventoryService";
import { config } from "./configService"; import { config } from "./configService";
import { Guild } from "../models/guildModel"; import { Guild } from "../models/guildModel";
import { hasGuildPermission } from "./guildService"; import { hasGuildPermission } from "./guildService";
@ -102,6 +102,7 @@ export const handleSetShipDecorations = async (
Pos: placedDecoration.Pos, Pos: placedDecoration.Pos,
Rot: placedDecoration.Rot, Rot: placedDecoration.Rot,
Scale: placedDecoration.Scale, Scale: placedDecoration.Scale,
Sockets: placedDecoration.Sockets,
_id: placedDecoration.MoveId _id: placedDecoration.MoveId
}; };
@ -117,13 +118,19 @@ export const handleSetShipDecorations = async (
} }
if (placedDecoration.RemoveId) { if (placedDecoration.RemoveId) {
roomToPlaceIn.PlacedDecos.pull({ _id: placedDecoration.RemoveId }); const decoIndex = roomToPlaceIn.PlacedDecos.findIndex(x => x._id.equals(placedDecoration.RemoveId));
const deco = roomToPlaceIn.PlacedDecos[decoIndex];
roomToPlaceIn.PlacedDecos.splice(decoIndex, 1);
await personalRooms.save(); await personalRooms.save();
if (!config.unlockAllShipDecorations) { if (!config.unlockAllShipDecorations) {
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
const itemType = Object.entries(ExportResources).find(arr => arr[1].deco == placedDecoration.Type)![0]; const itemType = Object.entries(ExportResources).find(arr => arr[1].deco == deco.Type)![0];
if (deco.Sockets !== undefined) {
addFusionTreasures(inventory, [{ ItemType: itemType, Sockets: deco.Sockets, ItemCount: 1 }]);
} else {
addShipDecorations(inventory, [{ ItemType: itemType, ItemCount: 1 }]); addShipDecorations(inventory, [{ ItemType: itemType, ItemCount: 1 }]);
}
await inventory.save(); await inventory.save();
} }
@ -137,7 +144,13 @@ export const handleSetShipDecorations = async (
if (!config.unlockAllShipDecorations) { if (!config.unlockAllShipDecorations) {
const inventory = await getInventory(accountId); const inventory = await getInventory(accountId);
const itemType = Object.entries(ExportResources).find(arr => arr[1].deco == placedDecoration.Type)![0]; const itemType = Object.entries(ExportResources).find(arr => arr[1].deco == placedDecoration.Type)![0];
if (placedDecoration.Sockets !== undefined) {
addFusionTreasures(inventory, [
{ ItemType: itemType, Sockets: placedDecoration.Sockets, ItemCount: -1 }
]);
} else {
addShipDecorations(inventory, [{ ItemType: itemType, ItemCount: -1 }]); addShipDecorations(inventory, [{ ItemType: itemType, ItemCount: -1 }]);
}
await inventory.save(); await inventory.save();
} }
} }
@ -151,6 +164,7 @@ export const handleSetShipDecorations = async (
Pos: placedDecoration.Pos, Pos: placedDecoration.Pos,
Rot: placedDecoration.Rot, Rot: placedDecoration.Rot,
Scale: placedDecoration.Scale, Scale: placedDecoration.Scale,
Sockets: placedDecoration.Sockets,
_id: decoId _id: decoId
}); });

View File

@ -96,6 +96,7 @@ export interface IPlacedDecosDatabase {
Pos: [number, number, number]; Pos: [number, number, number];
Rot: [number, number, number]; Rot: [number, number, number];
Scale?: number; Scale?: number;
Sockets?: number;
PictureFrameInfo?: IPictureFrameInfo; PictureFrameInfo?: IPictureFrameInfo;
_id: Types.ObjectId; _id: Types.ObjectId;
} }
@ -136,6 +137,7 @@ export interface IShipDecorationsRequest {
MoveId?: string; MoveId?: string;
OldRoom?: string; OldRoom?: string;
Scale?: number; Scale?: number;
Sockets?: number;
} }
export interface IShipDecorationsResponse { export interface IShipDecorationsResponse {