forked from OpenWF/SpaceNinjaServer
use inventory in unlockShipFeature
This commit is contained in:
parent
a974bcb9fa
commit
23bef17ce1
@ -1,11 +1,20 @@
|
|||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
import { updateShipFeature } from "../../services/personalRoomsService.ts";
|
import { getAccountIdForRequest } from "../../services/loginService.ts";
|
||||||
import type { IUnlockShipFeatureRequest } from "../../types/requestTypes.ts";
|
import { getInventory } from "../../services/inventoryService.ts";
|
||||||
import { parseString } from "../../helpers/general.ts";
|
import { getJSONfromString } from "../../helpers/stringHelpers.ts";
|
||||||
|
import { unlockShipFeature } from "../../services/personalRoomsService.ts";
|
||||||
|
|
||||||
export const unlockShipFeatureController: RequestHandler = async (req, res) => {
|
export const unlockShipFeatureController: RequestHandler = async (req, res) => {
|
||||||
const accountId = parseString(req.query.accountId);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const shipFeatureRequest = JSON.parse((req.body as string).toString()) as IUnlockShipFeatureRequest;
|
const inventory = await getInventory(accountId, "MiscItems accountOwnerId");
|
||||||
await updateShipFeature(accountId, shipFeatureRequest.Feature);
|
const request = getJSONfromString<IUnlockShipFeatureRequest>(String(req.body));
|
||||||
|
|
||||||
|
await unlockShipFeature(inventory, request.Feature);
|
||||||
|
await inventory.save();
|
||||||
res.send([]);
|
res.send([]);
|
||||||
};
|
};
|
||||||
|
interface IUnlockShipFeatureRequest {
|
||||||
|
Feature: string;
|
||||||
|
KeyChain: string;
|
||||||
|
ChainStage: number;
|
||||||
|
}
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
import { PersonalRooms } from "../models/personalRoomsModel.ts";
|
import { PersonalRooms } from "../models/personalRoomsModel.ts";
|
||||||
import { addItem, getInventory } from "./inventoryService.ts";
|
import { addItem } from "./inventoryService.ts";
|
||||||
import type { IGardeningDatabase, TPersonalRoomsDatabaseDocument } from "../types/personalRoomsTypes.ts";
|
import type { IGardeningDatabase, TPersonalRoomsDatabaseDocument } from "../types/personalRoomsTypes.ts";
|
||||||
import { getRandomElement } from "./rngService.ts";
|
import { getRandomElement } from "./rngService.ts";
|
||||||
|
import type { TInventoryDatabaseDocument } from "../models/inventoryModels/inventoryModel.ts";
|
||||||
|
import { logger } from "../utils/logger.ts";
|
||||||
|
|
||||||
export const getPersonalRooms = async (
|
export const getPersonalRooms = async (
|
||||||
accountId: string,
|
accountId: string,
|
||||||
@ -15,19 +17,18 @@ export const getPersonalRooms = async (
|
|||||||
return personalRooms;
|
return personalRooms;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const updateShipFeature = async (accountId: string, shipFeature: string): Promise<void> => {
|
export const unlockShipFeature = async (inventory: TInventoryDatabaseDocument, shipFeature: string): Promise<void> => {
|
||||||
const personalRooms = await getPersonalRooms(accountId);
|
const personalRooms = await getPersonalRooms(inventory.accountOwnerId.toString());
|
||||||
|
|
||||||
if (personalRooms.Ship.Features.includes(shipFeature)) {
|
if (personalRooms.Ship.Features.includes(shipFeature)) {
|
||||||
throw new Error(`ship feature ${shipFeature} already unlocked`);
|
logger.warn(`ship feature ${shipFeature} already unlocked`);
|
||||||
}
|
} else {
|
||||||
|
|
||||||
personalRooms.Ship.Features.push(shipFeature);
|
personalRooms.Ship.Features.push(shipFeature);
|
||||||
await personalRooms.save();
|
await personalRooms.save();
|
||||||
|
|
||||||
const inventory = await getInventory(accountId);
|
const miscItem = inventory.MiscItems.find(x => x.ItemType === shipFeature);
|
||||||
await addItem(inventory, shipFeature, -1);
|
if (miscItem && miscItem.ItemCount > 0) await addItem(inventory, shipFeature, -1);
|
||||||
await inventory.save();
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createGarden = (): IGardeningDatabase => {
|
export const createGarden = (): IGardeningDatabase => {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import { addFixedLevelRewards } from "./missionInventoryUpdateService.ts";
|
|||||||
import type { IInventoryChanges } from "../types/purchaseTypes.ts";
|
import type { IInventoryChanges } from "../types/purchaseTypes.ts";
|
||||||
import questCompletionItems from "../../static/fixed_responses/questCompletionRewards.json" with { type: "json" };
|
import questCompletionItems from "../../static/fixed_responses/questCompletionRewards.json" with { type: "json" };
|
||||||
import type { ITypeCount } from "../types/commonTypes.ts";
|
import type { ITypeCount } from "../types/commonTypes.ts";
|
||||||
import { updateShipFeature } from "./personalRoomsService.ts";
|
import { unlockShipFeature } from "./personalRoomsService.ts";
|
||||||
|
|
||||||
export interface IUpdateQuestRequest {
|
export interface IUpdateQuestRequest {
|
||||||
QuestKeys: IQuestKeyClient[];
|
QuestKeys: IQuestKeyClient[];
|
||||||
@ -298,10 +298,7 @@ const handleQuestCompletion = async (
|
|||||||
|
|
||||||
// Unfaitful fix for "Examine the Reliquary on the Railjack"
|
// Unfaitful fix for "Examine the Reliquary on the Railjack"
|
||||||
if (questKey == "/Lotus/Types/Keys/RailJackBuildQuest/RailjackBuildQuestKeyChain") {
|
if (questKey == "/Lotus/Types/Keys/RailJackBuildQuest/RailjackBuildQuestKeyChain") {
|
||||||
await updateShipFeature(
|
await unlockShipFeature(inventory, "/Lotus/Types/Items/ShipFeatureItems/RailjackKeyShipFeatureItem"); // only works with relog
|
||||||
inventory.accountOwnerId.toString(),
|
|
||||||
"/Lotus/Types/Items/ShipFeatureItems/RailjackKeyShipFeatureItem"
|
|
||||||
); // only works with relog
|
|
||||||
await addItems(inventory, ["/Lotus/Types/Items/ShipFeatureItems/RailjackKeyShipFeatureItem"], inventoryChanges); // required item to trigger cutscene
|
await addItems(inventory, ["/Lotus/Types/Items/ShipFeatureItems/RailjackKeyShipFeatureItem"], inventoryChanges); // required item to trigger cutscene
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -234,11 +234,6 @@ export interface IUpgradeOperation {
|
|||||||
PolarizeValue: ArtifactPolarity;
|
PolarizeValue: ArtifactPolarity;
|
||||||
PolarityRemap: IPolarity[];
|
PolarityRemap: IPolarity[];
|
||||||
}
|
}
|
||||||
export interface IUnlockShipFeatureRequest {
|
|
||||||
Feature: string;
|
|
||||||
KeyChain: string;
|
|
||||||
ChainStage: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IVoidTearParticipantInfo {
|
export interface IVoidTearParticipantInfo {
|
||||||
AccountId: string;
|
AccountId: string;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user