fix: remove ship decos from inventory when placed and vice-versa

This commit is contained in:
Sainan 2025-01-12 05:15:07 +01:00
parent 2cd47c8ae2
commit 056228fd20

View File

@ -8,6 +8,8 @@ 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 { config } from "./configService";
export const setShipCustomizations = async ( export const setShipCustomizations = async (
accountId: string, accountId: string,
@ -106,17 +108,28 @@ export const handleSetShipDecorations = async (
}; };
} }
//TODO: check whether to remove from shipitems
if (placedDecoration.RemoveId) { if (placedDecoration.RemoveId) {
roomToPlaceIn.PlacedDecos.pull({ _id: placedDecoration.RemoveId }); roomToPlaceIn.PlacedDecos.pull({ _id: placedDecoration.RemoveId });
await personalRooms.save(); await personalRooms.save();
if (!config.unlockAllShipDecorations) {
const inventory = await getInventory(accountId);
addShipDecorations(inventory, [{ ItemType: placedDecoration.Type, ItemCount: 1 }]);
await inventory.save();
}
return { return {
DecoId: placedDecoration.RemoveId, DecoId: placedDecoration.RemoveId,
Room: placedDecoration.Room, Room: placedDecoration.Room,
IsApartment: placedDecoration.IsApartment, IsApartment: placedDecoration.IsApartment,
MaxCapacityIncrease: 0 MaxCapacityIncrease: 0
}; };
} else {
if (!config.unlockAllShipDecorations) {
const inventory = await getInventory(accountId);
addShipDecorations(inventory, [{ ItemType: placedDecoration.Type, ItemCount: -1 }]);
await inventory.save();
}
} }
// TODO: handle capacity // TODO: handle capacity