From 21db3b5c5d5dffd60c8f57c1818f6bd48ddbe073 Mon Sep 17 00:00:00 2001 From: OrdisPrime <134585663+OrdisPrime@users.noreply.github.com> Date: Sat, 15 Jun 2024 17:39:13 +0200 Subject: [PATCH 1/2] fix: move ship decorations (#300) --- src/models/personalRoomsModel.ts | 3 +- src/services/shipCustomizationsService.ts | 71 ++++++++++++++++++++++- src/types/shipTypes.ts | 12 +++- 3 files changed, 79 insertions(+), 7 deletions(-) diff --git a/src/models/personalRoomsModel.ts b/src/models/personalRoomsModel.ts index 8f4abede..8a7caaf0 100644 --- a/src/models/personalRoomsModel.ts +++ b/src/models/personalRoomsModel.ts @@ -7,7 +7,8 @@ const placedDecosSchema = new Schema( { Type: String, Pos: [Number], - Rot: [Number] + Rot: [Number], + Scale: Number }, { id: false } ); diff --git a/src/services/shipCustomizationsService.ts b/src/services/shipCustomizationsService.ts index 98125e50..d21510e7 100644 --- a/src/services/shipCustomizationsService.ts +++ b/src/services/shipCustomizationsService.ts @@ -6,6 +6,7 @@ import { IShipDecorationsRequest, IShipDecorationsResponse } from "@/src/types/shipTypes"; +import { logger } from "@/src/utils/logger"; import { Types } from "mongoose"; export const setShipCustomizations = async (shipCustomization: ISetShipCustomizationsRequest) => { @@ -37,12 +38,74 @@ export const handleSetShipDecorations = async ( const rooms = placedDecoration.IsApartment ? personalRooms.Apartment.Rooms : personalRooms.Ship.Rooms; - const room = rooms.find(room => room.Name === placedDecoration.Room); + const roomToPlaceIn = rooms.find(room => room.Name === placedDecoration.Room); + + if (!roomToPlaceIn) { + logger.error("room not found"); + throw new Error("room not found"); + } + + if (placedDecoration.MoveId) { + //moved within the same room + if (placedDecoration.OldRoom === placedDecoration.Room) { + const existingDecorationIndex = roomToPlaceIn?.PlacedDecos?.findIndex( + deco => deco._id.toString() === placedDecoration.MoveId + ); + + if (existingDecorationIndex === -1) { + logger.error("decoration to be moved not found"); + throw new Error("decoration to be moved not found"); + } + + roomToPlaceIn.PlacedDecos[existingDecorationIndex].Pos = placedDecoration.Pos; + roomToPlaceIn.PlacedDecos[existingDecorationIndex].Rot = placedDecoration.Rot; + + if (placedDecoration.Scale) { + roomToPlaceIn.PlacedDecos[existingDecorationIndex].Scale = placedDecoration.Scale; + } + + await personalRooms.save(); + return { + OldRoom: placedDecoration.OldRoom, + NewRoom: placedDecoration.Room, + IsApartment: placedDecoration.IsApartment, + MaxCapacityIncrease: 0 // TODO: calculate capacity change upon removal + }; + } + + //moved to a different room + const oldRoom = rooms.find(room => room.Name === placedDecoration.OldRoom); + + if (!oldRoom) { + logger.error("old room not found"); + throw new Error("old room not found"); + } + + oldRoom.PlacedDecos.pull({ _id: placedDecoration.MoveId }); + + const newDecoration = { + Type: placedDecoration.Type, + Pos: placedDecoration.Pos, + Rot: placedDecoration.Rot, + Scale: placedDecoration.Scale || 1, + _id: placedDecoration.MoveId + }; + + //the new room is still roomToPlaceIn + roomToPlaceIn.PlacedDecos.push(newDecoration); + await personalRooms.save(); + return { + OldRoom: placedDecoration.OldRoom, + NewRoom: placedDecoration.Room, + IsApartment: placedDecoration.IsApartment, + MaxCapacityIncrease: 0 // TODO: calculate capacity change upon removal + }; + } //TODO: check whether to remove from shipitems if (placedDecoration.RemoveId) { - room?.PlacedDecos?.pull({ _id: placedDecoration.RemoveId }); + roomToPlaceIn.PlacedDecos.pull({ _id: placedDecoration.RemoveId }); await personalRooms.save(); return { DecoId: placedDecoration.RemoveId, @@ -54,11 +117,13 @@ export const handleSetShipDecorations = async ( // TODO: handle capacity + //place decoration const decoId = new Types.ObjectId(); - room?.PlacedDecos?.push({ + roomToPlaceIn.PlacedDecos?.push({ Type: placedDecoration.Type, Pos: placedDecoration.Pos, Rot: placedDecoration.Rot, + Scale: placedDecoration.Scale || 1, _id: decoId }); diff --git a/src/types/shipTypes.ts b/src/types/shipTypes.ts index 53cf1f87..6b0e019f 100644 --- a/src/types/shipTypes.ts +++ b/src/types/shipTypes.ts @@ -69,6 +69,7 @@ export interface IPlacedDecosDatabase { Type: string; Pos: [number, number, number]; Rot: [number, number, number]; + Scale: number; _id: Types.ObjectId; } @@ -100,12 +101,17 @@ export interface IShipDecorationsRequest { Rot: [number, number, number]; Room: string; IsApartment: boolean; - RemoveId: string; + RemoveId?: string; + MoveId?: string; + OldRoom?: string; + Scale?: number; } export interface IShipDecorationsResponse { - DecoId: string; - Room: string; + DecoId?: string; + Room?: string; IsApartment: boolean; MaxCapacityIncrease?: number; + OldRoom?: string; + NewRoom?: string; } -- 2.47.2 From 6af161817bb9011ae44849b59421392d4948b89d Mon Sep 17 00:00:00 2001 From: Sainan Date: Sat, 15 Jun 2024 18:29:34 +0200 Subject: [PATCH 2/2] feat: implement purchasing of bundles --- package-lock.json | 8 ++-- package.json | 2 +- src/services/purchaseService.ts | 66 +++++++++++++++++++++++---------- 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/package-lock.json b/package-lock.json index 14580188..113407a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1262.74", - "warframe-public-export-plus": "^0.2.2", + "warframe-public-export-plus": "^0.2.3", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" @@ -3909,9 +3909,9 @@ } }, "node_modules/warframe-public-export-plus": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.2.tgz", - "integrity": "sha512-PAsiyiRDqXcsUwZTweihwrSksd+GT3USrbHwS/TrJUC3TqLS0Ng24OfefFKPWOmPfMxDbdkg2zV39uq72iZ/Yg==" + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/warframe-public-export-plus/-/warframe-public-export-plus-0.2.3.tgz", + "integrity": "sha512-Bl4gb3f1LIdGXLEOJg2XTIFYqrialdTIvVhDqDzVJIRfii0PKsy9jsr9vqM14tWz7oVpQMeCUyvisDkkXijTSg==" }, "node_modules/warframe-riven-info": { "version": "0.1.0", diff --git a/package.json b/package.json index 88a71412..9da3bcca 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "express": "^5.0.0-beta.3", "mongoose": "^8.1.1", "warframe-items": "^1.1262.74", - "warframe-public-export-plus": "^0.2.2", + "warframe-public-export-plus": "^0.2.3", "warframe-riven-info": "^0.1.0", "winston": "^3.11.0", "winston-daily-rotate-file": "^4.7.1" diff --git a/src/services/purchaseService.ts b/src/services/purchaseService.ts index ba13666a..b8a1c1ea 100644 --- a/src/services/purchaseService.ts +++ b/src/services/purchaseService.ts @@ -3,6 +3,7 @@ import { getSubstringFromKeyword } from "@/src/helpers/stringHelpers"; import { addItem, addBooster, updateCurrency, updateSlots } from "@/src/services/inventoryService"; import { IPurchaseRequest, SlotPurchase } from "@/src/types/purchaseTypes"; import { logger } from "@/src/utils/logger"; +import { ExportBundles } from "warframe-public-export-plus"; export const getStoreItemCategory = (storeItem: string) => { const storeItemString = getSubstringFromKeyword(storeItem, "StoreItems/"); @@ -21,26 +22,12 @@ export const getStoreItemTypesCategory = (typesItem: string) => { export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountId: string) => { logger.debug("purchase request", purchaseRequest); - const storeCategory = getStoreItemCategory(purchaseRequest.PurchaseParams.StoreItem); - const internalName = purchaseRequest.PurchaseParams.StoreItem.replace("/StoreItems", ""); - logger.debug(`store category ${storeCategory}`); - let purchaseResponse; - switch (storeCategory) { - default: - purchaseResponse = await addItem(accountId, internalName); - break; - case "Types": - purchaseResponse = await handleTypesPurchase( - internalName, - accountId, - purchaseRequest.PurchaseParams.Quantity - ); - break; - case "Boosters": - purchaseResponse = await handleBoostersPurchase(internalName, accountId); - break; - } + const purchaseResponse = await handleStoreItemAcquisition( + purchaseRequest.PurchaseParams.StoreItem, + accountId, + purchaseRequest.PurchaseParams.Quantity + ); if (!purchaseResponse) throw new Error("purchase response was undefined"); @@ -58,6 +45,43 @@ export const handlePurchase = async (purchaseRequest: IPurchaseRequest, accountI return purchaseResponse; }; +const handleStoreItemAcquisition = async ( + storeItemName: string, + accountId: string, + quantity: number +): Promise<{ InventoryChanges: object }> => { + let purchaseResponse = { + InventoryChanges: {} + }; + logger.debug(`handling acquision of ${storeItemName}`); + if (storeItemName in ExportBundles) { + const bundle = ExportBundles[storeItemName]; + logger.debug("acquiring bundle", bundle); + for (const component of bundle.components) { + purchaseResponse = { + ...purchaseResponse, + ...(await handleStoreItemAcquisition(component.typeName, accountId, component.purchaseQuantity)) + }; + } + } else { + const storeCategory = getStoreItemCategory(storeItemName); + const internalName = storeItemName.replace("/StoreItems", ""); + logger.debug(`store category ${storeCategory}`); + switch (storeCategory) { + default: + purchaseResponse = await addItem(accountId, internalName); + break; + case "Types": + purchaseResponse = await handleTypesPurchase(internalName, accountId, quantity); + break; + case "Boosters": + purchaseResponse = await handleBoostersPurchase(internalName, accountId); + break; + } + } + return purchaseResponse; +}; + export const slotPurchaseNameToSlotName: SlotPurchase = { SuitSlotItem: { name: "SuitBin", slotsPerPurchase: 1 }, TwoSentinelSlotItem: { name: "SentinelBin", slotsPerPurchase: 2 }, @@ -122,7 +146,9 @@ const boosterCollection = [ const handleBoostersPurchase = async (boosterStoreName: string, accountId: string) => { const match = boosterStoreName.match(/(\d+)Day/); - if (!match) return; + if (!match) { + return { InventoryChanges: {} }; + } const extractedDigit = Number(match[1]); const ItemType = boosterCollection.find(i => -- 2.47.2