fix: remove ship decos from inventory when placed and vice-versa (#770)

This commit is contained in:
Sainan 2025-01-12 13:38:05 +01:00 committed by GitHub
parent 5cbececb04
commit e201279eee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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