From 52d32a67b4652e643746882f9e9417d73ae507ea Mon Sep 17 00:00:00 2001 From: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Date: Mon, 22 Jul 2024 10:09:22 +0200 Subject: [PATCH] fix: loc-pin saving --- src/models/inventoryModels/inventoryModel.ts | 35 +++++ src/services/inventoryService.ts | 148 ++++++++++++++++++ src/services/missionInventoryUpdateService.ts | 14 ++ src/types/inventoryTypes/inventoryTypes.ts | 21 +++ src/types/requestTypes.ts | 4 + 5 files changed, 222 insertions(+) diff --git a/src/models/inventoryModels/inventoryModel.ts b/src/models/inventoryModels/inventoryModel.ts index 43587f96..df41ceeb 100644 --- a/src/models/inventoryModels/inventoryModel.ts +++ b/src/models/inventoryModels/inventoryModel.ts @@ -61,6 +61,9 @@ import { IKubrowPetDetailsClient, IKubrowPetEggDatabase, IKubrowPetEggClient + ICustomMarkers, + IMarkerInfo, + IMarker } from "../../types/inventoryTypes/inventoryTypes"; import { IOid } from "../../types/commonTypes"; import { @@ -849,6 +852,35 @@ infestedFoundrySchema.set("toJSON", { } }); +const markerSchema = new Schema( + { + anchorName: String, + color: Number, + label: String, + x: Number, + y: Number, + z: Number, + showInHud: Boolean + }, + { _id: false } +); + +const markerInfoSchema = new Schema( + { + icon: String, + markers: [markerSchema] + }, + { _id: false } +); + +const CustomMarkersSchema = new Schema( + { + tag: String, + markerInfos: [markerInfoSchema] + }, + { _id: false } +); + const inventorySchema = new Schema( { accountOwnerId: Schema.Types.ObjectId, @@ -1133,6 +1165,9 @@ const inventorySchema = new Schema( //https://warframe.fandom.com/wiki/Incarnon EvolutionProgress: { type: [evolutionProgressSchema], default: undefined }, + //https://warframe.fandom.com/wiki/Loc-Pin + CustomMarkers: [CustomMarkersSchema], + //Unknown and system DuviriInfo: DuviriInfoSchema, Mailbox: MailboxSchema, diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 30c1acd4..4f8009f7 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -1057,6 +1057,32 @@ export const updateSyndicate = ( syndicateUpdate: IMissionInventoryUpdateRequest["AffiliationChanges"] ): void => { syndicateUpdate?.forEach(affiliation => { +export const missionInventoryUpdate = async (data: IMissionInventoryUpdateRequest, accountId: string) => { + const { + RawUpgrades, + MiscItems, + RegularCredits, + ChallengeProgress, + FusionPoints, + Consumables, + Recipes, + Missions, + FusionTreasures, + AffiliationChanges, + EvolutionProgress, + LastRegionPlayed, + CustomMarkers + } = data; + const inventory = await getInventory(accountId); + + // credits + inventory.RegularCredits += RegularCredits || 0; + + // endo + inventory.FusionPoints += FusionPoints || 0; + + // syndicate + AffiliationChanges?.forEach(affiliation => { const syndicate = inventory.Affiliations.find(x => x.Tag == affiliation.Tag); if (syndicate !== undefined) { syndicate.Standing += affiliation.Standing; @@ -1100,4 +1126,126 @@ export const addKeyChainItems = async ( await addItems(inventory, nonStoreItems); return inventoryChanges; + + // Gear XP + equipmentKeys.forEach(key => addGearExpByCategory(inventory, data[key], key)); + + // Incarnon Challenges + if (EvolutionProgress) { + for (const evoProgress of EvolutionProgress) { + const entry = inventory.EvolutionProgress + ? inventory.EvolutionProgress.find(entry => entry.ItemType == evoProgress.ItemType) + : undefined; + if (entry) { + entry.Progress = evoProgress.Progress; + entry.Rank = evoProgress.Rank; + } else { + inventory.EvolutionProgress ??= []; + inventory.EvolutionProgress.push(evoProgress); + } + } + } + + // LastRegionPlayed + if (LastRegionPlayed) { + inventory.LastRegionPlayed = LastRegionPlayed; + } + + if (CustomMarkers) { + CustomMarkers.forEach(markers => { + const map = inventory.CustomMarkers + ? inventory.CustomMarkers.find(entry => entry.tag == markers.tag) + : undefined; + if (map) { + map.markerInfos = markers.markerInfos; + } else { + inventory.CustomMarkers ??= []; + inventory.CustomMarkers.push(markers); + } + }); + } + + // other + addMods(inventory, RawUpgrades); + addMiscItems(inventory, MiscItems); + addConsumables(inventory, Consumables); + addRecipes(inventory, Recipes); + addChallenges(inventory, ChallengeProgress); + addFusionTreasures(inventory, FusionTreasures); + if (Missions) { + addMissionComplete(inventory, Missions); + } + + const changedInventory = await inventory.save(); + return changedInventory.toJSON(); +}; + +export const addBooster = async (ItemType: string, time: number, accountId: string): Promise => { + const currentTime = Math.floor(Date.now() / 1000) - 129600; // Value is wrong without 129600. Figure out why, please. :) + + const inventory = await getInventory(accountId); + const { Boosters } = inventory; + + const itemIndex = Boosters.findIndex(booster => booster.ItemType === ItemType); + + if (itemIndex !== -1) { + const existingBooster = Boosters[itemIndex]; + existingBooster.ExpiryDate = Math.max(existingBooster.ExpiryDate, currentTime) + time; + inventory.markModified(`Boosters.${itemIndex}.ExpiryDate`); + } else { + Boosters.push({ ItemType, ExpiryDate: currentTime + time }) - 1; + } + + await inventory.save(); +}; + +export const upgradeMod = async (artifactsData: IArtifactsRequest, accountId: string): Promise => { + const { Upgrade, LevelDiff, Cost, FusionPointCost } = artifactsData; + try { + const inventory = await getInventory(accountId); + const { Upgrades, RawUpgrades } = inventory; + const { ItemType, UpgradeFingerprint, ItemId } = Upgrade; + + const safeUpgradeFingerprint = UpgradeFingerprint || '{"lvl":0}'; + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const parsedUpgradeFingerprint = JSON.parse(safeUpgradeFingerprint); + parsedUpgradeFingerprint.lvl += LevelDiff; + const stringifiedUpgradeFingerprint = JSON.stringify(parsedUpgradeFingerprint); + + let itemIndex = Upgrades.findIndex(upgrade => upgrade._id?.equals(ItemId!.$oid)); + + if (itemIndex !== -1) { + Upgrades[itemIndex].UpgradeFingerprint = stringifiedUpgradeFingerprint; + inventory.markModified(`Upgrades.${itemIndex}.UpgradeFingerprint`); + } else { + itemIndex = + Upgrades.push({ + UpgradeFingerprint: stringifiedUpgradeFingerprint, + ItemType + }) - 1; + + const rawItemIndex = RawUpgrades.findIndex(rawUpgrade => rawUpgrade.ItemType === ItemType); + RawUpgrades[rawItemIndex].ItemCount--; + if (RawUpgrades[rawItemIndex].ItemCount > 0) { + inventory.markModified(`RawUpgrades.${rawItemIndex}.UpgradeFingerprint`); + } else { + RawUpgrades.splice(rawItemIndex, 1); + } + } + + inventory.RegularCredits -= Cost; + inventory.FusionPoints -= FusionPointCost; + + const changedInventory = await inventory.save(); + const itemId = changedInventory.toJSON().Upgrades[itemIndex]?.ItemId?.$oid; + + if (!itemId) { + throw new Error("Item Id not found in upgradeMod"); + } + + return itemId; + } catch (error) { + console.error("Error in upgradeMod:", error); + throw error; + } }; diff --git a/src/services/missionInventoryUpdateService.ts b/src/services/missionInventoryUpdateService.ts index 547b63ef..32d55d54 100644 --- a/src/services/missionInventoryUpdateService.ts +++ b/src/services/missionInventoryUpdateService.ts @@ -155,6 +155,20 @@ export const addMissionInventoryUpdates = ( inventory.PlayerSkills.LPP_DRIFTER += value.LPP_DRIFTER; break; } + case "CustomMarkers": { + value.forEach(markers => { + const map = inventory.CustomMarkers + ? inventory.CustomMarkers.find(entry => entry.tag == markers.tag) + : undefined; + if (map) { + map.markerInfos = markers.markerInfos; + } else { + inventory.CustomMarkers ??= []; + inventory.CustomMarkers.push(markers); + } + }); + break; + } default: // Equipment XP updates if (equipmentKeys.includes(key as TEquipmentKey)) { diff --git a/src/types/inventoryTypes/inventoryTypes.ts b/src/types/inventoryTypes/inventoryTypes.ts index 0657ebad..256f8231 100644 --- a/src/types/inventoryTypes/inventoryTypes.ts +++ b/src/types/inventoryTypes/inventoryTypes.ts @@ -343,6 +343,7 @@ export interface IInventoryClient extends IDailyAffiliations { LastInventorySync: IOid; NextRefill: IMongoDate; // Next time argon crystals will have a decay tick FoundToday?: IMiscItem[]; // for Argon Crystals + CustomMarkers: ICustomMarkers[]; ActiveLandscapeTraps: any[]; EvolutionProgress?: IEvolutionProgress[]; RepVotes: any[]; @@ -1056,3 +1057,23 @@ export interface ICompletedDialogue { Booleans: string[]; Choices: number[]; } + +export interface ICustomMarkers { + tag: string; + markerInfos: IMarkerInfo[]; +} + +export interface IMarkerInfo { + icon: string; + markers: IMarker[]; +} + +export interface IMarker { + anchorName: string; + color: number; + label?: string; + x: number; + y: number; + z: number; + showInHud: boolean; +} diff --git a/src/types/requestTypes.ts b/src/types/requestTypes.ts index 54363969..7e78a7cd 100644 --- a/src/types/requestTypes.ts +++ b/src/types/requestTypes.ts @@ -11,6 +11,9 @@ import { TSolarMapRegion, TEquipmentKey, IFusionTreasure, + IQuestKeyClient, + IPlayerSkills, + ICustomMarkers, IPlayerSkills, IQuestKeyDatabase } from "./inventoryTypes/inventoryTypes"; @@ -75,6 +78,7 @@ export type IMissionInventoryUpdateRequest = { EvolutionProgress?: IEvolutionProgress[]; FocusXpIncreases?: number[]; PlayerSkillGains: IPlayerSkills; + CustomMarkers?: ICustomMarkers[]; } & { [K in TEquipmentKey]?: IEquipmentClient[]; };