fix: loc-pin saving

This commit is contained in:
AMelonInsideLemon 2024-07-22 10:09:22 +02:00 committed by Sainan
parent 53ce6ccce2
commit 52d32a67b4
5 changed files with 222 additions and 0 deletions

View File

@ -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<IMarker>(
{
anchorName: String,
color: Number,
label: String,
x: Number,
y: Number,
z: Number,
showInHud: Boolean
},
{ _id: false }
);
const markerInfoSchema = new Schema<IMarkerInfo>(
{
icon: String,
markers: [markerSchema]
},
{ _id: false }
);
const CustomMarkersSchema = new Schema<ICustomMarkers>(
{
tag: String,
markerInfos: [markerInfoSchema]
},
{ _id: false }
);
const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
{
accountOwnerId: Schema.Types.ObjectId,
@ -1133,6 +1165,9 @@ const inventorySchema = new Schema<IInventoryDatabase, InventoryDocumentProps>(
//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,

View File

@ -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<void> => {
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<string | undefined> => {
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;
}
};

View File

@ -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)) {

View File

@ -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;
}

View File

@ -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[];
};