From 1fe8351dca08ef3cf20e25db23ac4e63c71af394 Mon Sep 17 00:00:00 2001 From: Sainan Date: Wed, 19 Jun 2024 17:46:12 +0200 Subject: [PATCH] feat: handle purchasing of archwing, archgun, & archmelee (#326) --- src/models/inventoryModels/inventoryModel.ts | 53 ++++++----- src/services/inventoryService.ts | 99 +++++++++++--------- src/types/inventoryTypes/inventoryTypes.ts | 1 + 3 files changed, 88 insertions(+), 65 deletions(-) diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 90c4c844..2dc26ef8 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -197,29 +197,32 @@ ArchonCrystalUpgradeSchema.set("toJSON", { } }); -const EquipmentSchema = new Schema({ - ItemType: String, - Configs: [ItemConfigSchema], - UpgradeVer: Number, - XP: Number, - Features: Number, - Polarized: Number, - Polarity: [polaritySchema], - FocusLens: String, - ModSlotPurchases: Number, - CustomizationSlotPurchases: Number, - UpgradeType: String, - UpgradeFingerprint: String, - ItemName: String, - InfestationDate: Date, - InfestationDays: Number, - InfestationType: String, - ModularParts: [String], - UnlockLevel: Number, - Expiry: Date, - SkillTree: String, - ArchonCrystalUpgrades: { type: [ArchonCrystalUpgradeSchema], default: undefined } -}); +const EquipmentSchema = new Schema( + { + ItemType: String, + Configs: [ItemConfigSchema], + UpgradeVer: Number, + XP: Number, + Features: Number, + Polarized: Number, + Polarity: [polaritySchema], + FocusLens: String, + ModSlotPurchases: Number, + CustomizationSlotPurchases: Number, + UpgradeType: String, + UpgradeFingerprint: String, + ItemName: String, + InfestationDate: Date, + InfestationDays: Number, + InfestationType: String, + ModularParts: { type: [String], default: undefined }, + UnlockLevel: Number, + Expiry: Date, + SkillTree: String, + ArchonCrystalUpgrades: { type: [ArchonCrystalUpgradeSchema], default: undefined } + }, + { id: false } +); EquipmentSchema.virtual("ItemId").get(function () { return { $oid: this._id.toString() } satisfies IOid; @@ -955,6 +958,10 @@ type InventoryDocumentProps = { Sentinels: Types.DocumentArray; Horses: Types.DocumentArray; PendingRecipes: Types.DocumentArray; + SpaceSuits: Types.DocumentArray; + SpaceGuns: Types.DocumentArray; + SpaceMelee: Types.DocumentArray; + SentinelWeapons: Types.DocumentArray; }; // eslint-disable-next-line @typescript-eslint/ban-types diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index c7861130..36bda69e 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -92,33 +92,51 @@ export const addItem = async ( // Path-based duck typing switch (typeName.substr(1).split("/")[1]) { case "Powersuits": - if (typeName.includes("EntratiMech")) { - const mechSuit = await addMechSuit(typeName, accountId); - await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1); - logger.debug("mech suit", mechSuit); - return { - InventoryChanges: { - MechBin: { - count: 1, - platinum: 0, - Slots: -1 - }, - MechSuits: [mechSuit] - } - }; - } - const suit = await addPowerSuit(typeName, accountId); - await updateSlots(accountId, InventorySlot.SUITS, 0, 1); - return { - InventoryChanges: { - SuitBin: { - count: 1, - platinum: 0, - Slots: -1 - }, - Suits: [suit] + switch (typeName.substr(1).split("/")[2]) { + default: { + const suit = await addPowerSuit(typeName, accountId); + await updateSlots(accountId, InventorySlot.SUITS, 0, 1); + return { + InventoryChanges: { + SuitBin: { + count: 1, + platinum: 0, + Slots: -1 + }, + Suits: [suit] + } + }; } - }; + case "Archwing": { + const spaceSuit = await addSpaceSuit(typeName, accountId); + await updateSlots(accountId, InventorySlot.SPACESUITS, 0, 1); + return { + InventoryChanges: { + SpaceSuitBin: { + count: 1, + platinum: 0, + Slots: -1 + }, + SpaceSuits: [spaceSuit] + } + }; + } + case "EntratiMech": { + const mechSuit = await addMechSuit(typeName, accountId); + await updateSlots(accountId, InventorySlot.MECHSUITS, 0, 1); + return { + InventoryChanges: { + MechBin: { + count: 1, + platinum: 0, + Slots: -1 + }, + MechSuits: [mechSuit] + } + }; + } + } + break; case "Weapons": const weaponType = getWeaponType(typeName); const weapon = await addWeapon(weaponType, typeName, accountId); @@ -277,6 +295,13 @@ export const addSpecialItem = async (itemName: string, accountId: string) => { return changedInventory.SpecialItems[specialItemIndex - 1].toJSON(); }; +export const addSpaceSuit = async (spacesuitName: string, accountId: string) => { + const inventory = await getInventory(accountId); + const suitIndex = inventory.SpaceSuits.push({ ItemType: spacesuitName, Configs: [], UpgradeVer: 101, XP: 0 }); + const changedInventory = await inventory.save(); + return changedInventory.SpaceSuits[suitIndex - 1].toJSON(); +}; + export const updateSlots = async (accountId: string, slotName: SlotNames, slotAmount: number, extraAmount: number) => { const inventory = await getInventory(accountId); @@ -391,22 +416,12 @@ export const addWeapon = async ( ): Promise => { const inventory = await getInventory(accountId); - let weaponIndex; - switch (weaponType) { - case "LongGuns": - case "Pistols": - case "Melee": - case "OperatorAmps": - weaponIndex = inventory[weaponType].push({ - ItemType: weaponName, - Configs: [], - XP: 0, - ModularParts: modularParts - }); - break; - default: - throw new Error("unknown weapon type: " + weaponType); - } + const weaponIndex = inventory[weaponType].push({ + ItemType: weaponName, + Configs: [], + XP: 0, + ModularParts: modularParts + }); const changedInventory = await inventory.save(); return changedInventory[weaponType][weaponIndex - 1].toJSON(); diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index a8f30308..28423edb 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -358,6 +358,7 @@ export interface ICombat { export enum InventorySlot { SUITS = "SuitBin", WEAPONS = "WeaponBin", + SPACESUITS = "SpaceSuitBin", MECHSUITS = "MechBin", PVE_LOADOUTS = "PveBonusLoadoutBin", SENTINELS = "SentinelBin"