diff --git a/src/controllers/api/missionInventoryUpdateController.ts b/src/controllers/api/missionInventoryUpdateController.ts index 2c8aaffb..e53ff359 100644 --- a/src/controllers/api/missionInventoryUpdateController.ts +++ b/src/controllers/api/missionInventoryUpdateController.ts @@ -22,7 +22,7 @@ import { IMissionInventoryUpdateRequest } from "@/src/types/requestTypes"; - [ ] CurrentLoadOutIds - [ ] AliveTime - [ ] MissionTime -- [ ] Missions +- [x] Missions - [ ] CompletedAlerts - [ ] LastRegionPlayed - [ ] GameModeId diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 06b50858..16b24aba 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -11,6 +11,7 @@ import { IFlavourItem, IInventoryDatabaseDocument, IMiscItem, + IMission, IRawUpgrade } from "@/src/types/inventoryTypes/inventoryTypes"; import { IGenericUpdate } from "../types/genericUpdate"; @@ -228,11 +229,24 @@ const addChallenges = (inventory: IInventoryDatabaseDocument, itemsArray: IChall }); }; +const addMissionComplate = (inventory: IInventoryDatabaseDocument, { Tag, Completes }: IMission) => { + const { Missions } = inventory; + const itemIndex = Missions.findIndex(item => item.Tag === Tag); + + if (itemIndex !== -1) { + Missions[itemIndex].Completes += Completes; + inventory.markModified(`Missions.${itemIndex}.Completes`); + } else { + Missions.push({ Tag, Completes }); + } +}; + const gearKeys = ["Suits", "Pistols", "LongGuns", "Melee"] as const; type GearKeysType = (typeof gearKeys)[number]; export const missionInventoryUpdate = async (data: IMissionInventoryUpdateRequest, accountId: string) => { - const { RawUpgrades, MiscItems, RegularCredits, ChallengeProgress, FusionPoints, Consumables, Recipes } = data; + const { RawUpgrades, MiscItems, RegularCredits, ChallengeProgress, FusionPoints, Consumables, Recipes, Missions } = + data; const inventory = await getInventory(accountId); // credits @@ -250,6 +264,7 @@ export const missionInventoryUpdate = async (data: IMissionInventoryUpdateReques addConsumables(inventory, Consumables); addRecipes(inventory, Recipes); addChallenges(inventory, ChallengeProgress); + addMissionComplate(inventory, Missions!); const changedInventory = await inventory.save(); return changedInventory.toJSON(); diff --git a/src/services/missionInventoryUpdateService .ts b/src/services/missionInventoryUpdateService .ts index 9ec22c51..cfee223a 100644 --- a/src/services/missionInventoryUpdateService .ts +++ b/src/services/missionInventoryUpdateService .ts @@ -45,19 +45,19 @@ const getRewards = ({ drops.push(...guaranteedDrops); } - const testDrops = [ - { chance: 7.69, name: "Lith W3 Relic", rotation: "B" }, - { chance: 7.69, name: "Lith W3 Relic", rotation: "B" }, - { chance: 10.82, name: "2X Orokin Cell", rotation: "C" }, - { chance: 10.82, name: "Arrow Mutation", rotation: "C" }, - { chance: 10.82, name: "200 Endo", rotation: "C" }, - { chance: 10.82, name: "200 Endo", rotation: "C" }, - { chance: 10.82, name: "2,000,000 Credits Cache", rotation: "C" }, - { chance: 7.69, name: "Health Restore (Large)", rotation: "C" }, - { chance: 7.69, name: "Vapor Specter Blueprint", rotation: "C" } - ]; - console.log("Mission rewards:", testDrops); - return formatRewardsToInventoryType(testDrops); + // const testDrops = [ + // { chance: 7.69, name: "Lith W3 Relic", rotation: "B" }, + // { chance: 7.69, name: "Lith W3 Relic", rotation: "B" }, + // { chance: 10.82, name: "2X Orokin Cell", rotation: "C" }, + // { chance: 10.82, name: "Arrow Mutation", rotation: "C" }, + // { chance: 10.82, name: "200 Endo", rotation: "C" }, + // { chance: 10.82, name: "200 Endo", rotation: "C" }, + // { chance: 10.82, name: "2,000,000 Credits Cache", rotation: "C" }, + // { chance: 7.69, name: "Health Restore (Large)", rotation: "C" }, + // { chance: 7.69, name: "Vapor Specter Blueprint", rotation: "C" } + // ]; + // console.log("Mission rewards:", testDrops); + // return formatRewardsToInventoryType(testDrops); console.log("Mission rewards:", drops); return formatRewardsToInventoryType(drops); diff --git a/src/types/requestTypes.ts b/src/types/requestTypes.ts index fbb7cded..050955d9 100644 --- a/src/types/requestTypes.ts +++ b/src/types/requestTypes.ts @@ -4,6 +4,7 @@ import { IConsumable, ICrewShipSalvagedWeaponSkin, IMiscItem, + IMission, IRawUpgrade } from "./inventoryTypes/inventoryTypes"; import { IWeaponDatabase } from "./inventoryTypes/weaponTypes"; @@ -31,6 +32,7 @@ interface IMissionInventoryUpdateRequest { ChallengeProgress?: IChallengeProgress[]; RewardInfo?: IMissionInventoryUpdateRequestRewardInfo; FusionPoints?: number; + Missions?: IMission; } interface IMissionInventoryUpdateRequestRewardInfo {