fix: acquiring ships

This commit is contained in:
Sainan 2024-12-23 06:43:16 +01:00
parent 39ac1d8276
commit 0e74968587
2 changed files with 35 additions and 15 deletions

View File

@ -41,6 +41,7 @@ import {
ExportResources,
ExportUpgrades
} from "warframe-public-export-plus";
import { createShip } from "./shipService";
export const createInventory = async (
accountOwnerId: Types.ObjectId,
@ -129,6 +130,21 @@ export const addItem = async (
}
if (typeName in ExportResources) {
const inventory = await getInventory(accountId);
if (ExportResources[typeName].productCategory == "Ships") {
const oid = await createShip(new Types.ObjectId(accountId), typeName);
inventory.Ships.push(oid);
await inventory.save();
return {
InventoryChanges: {
Ships: [
{
ItemId: { $oid: oid },
ItemType: typeName
}
]
}
};
} else {
const miscItemChanges = [
{
ItemType: typeName,
@ -143,6 +159,7 @@ export const addItem = async (
}
};
}
}
if (typeName in ExportCustoms) {
return {
InventoryChanges: {

View File

@ -3,10 +3,13 @@ import { ILoadoutDatabase } from "@/src/types/saveLoadoutTypes";
import { logger } from "@/src/utils/logger";
import { Types } from "mongoose";
export const createShip = async (accountOwnerId: Types.ObjectId) => {
export const createShip = async (
accountOwnerId: Types.ObjectId,
typeName: string = "/Lotus/Types/Items/Ships/DefaultShip"
) => {
try {
const ship = new Ship({
ItemType: "/Lotus/Types/Items/Ships/DefaultShip",
ItemType: typeName,
ShipOwnerId: accountOwnerId
});
const newShip = await ship.save();