feat: handle client setting InfestationDate on equipment #1927
@ -1,4 +1,4 @@
|
||||
import { addGearExpByCategory, getInventory } from "@/src/services/inventoryService";
|
||||
import { applyClientEquipmentUpdates, getInventory } from "@/src/services/inventoryService";
|
||||
import { getAccountIdForRequest } from "@/src/services/loginService";
|
||||
import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
|
||||
import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
|
||||
@ -20,7 +20,7 @@ export const addXpController: RequestHandler = async (req, res) => {
|
||||
}
|
||||
}
|
||||
}
|
||||
addGearExpByCategory(inventory, gear, category as TEquipmentKey);
|
||||
applyClientEquipmentUpdates(inventory, gear, category as TEquipmentKey);
|
||||
}
|
||||
await inventory.save();
|
||||
res.end();
|
||||
|
@ -10,6 +10,10 @@ export const toMongoDate = (date: Date): IMongoDate => {
|
||||
return { $date: { $numberLong: date.getTime().toString() } };
|
||||
};
|
||||
|
||||
export const fromMongoData = (date: IMongoDate): Date => {
|
||||
return new Date(parseInt(date.$date.$numberLong));
|
||||
};
|
||||
|
||||
export const kubrowWeights: Record<TRarity, number> = {
|
||||
COMMON: 6,
|
||||
UNCOMMON: 4,
|
||||
|
@ -69,6 +69,7 @@ import {
|
||||
import { createShip } from "./shipService";
|
||||
import {
|
||||
catbrowDetails,
|
||||
fromMongoData,
|
||||
kubrowDetails,
|
||||
kubrowFurPatternsWeights,
|
||||
kubrowWeights,
|
||||
@ -1471,21 +1472,20 @@ export const addEmailItem = async (
|
||||
return inventoryChanges;
|
||||
};
|
||||
|
||||
//TODO: wrong id is not erroring
|
||||
export const addGearExpByCategory = (
|
||||
export const applyClientEquipmentUpdates = (
|
||||
inventory: TInventoryDatabaseDocument,
|
||||
gearArray: IEquipmentClient[],
|
||||
categoryName: TEquipmentKey
|
||||
): void => {
|
||||
const category = inventory[categoryName];
|
||||
|
||||
gearArray.forEach(({ ItemId, XP }) => {
|
||||
if (!XP) {
|
||||
return;
|
||||
gearArray.forEach(({ ItemId, XP, InfestationDate }) => {
|
||||
const item = category.id(ItemId.$oid);
|
||||
if (!item) {
|
||||
throw new Error(`No item with id ${ItemId.$oid} in ${categoryName}`);
|
||||
}
|
||||
|
||||
const item = category.id(ItemId.$oid);
|
||||
if (item) {
|
||||
if (XP) {
|
||||
item.XP ??= 0;
|
||||
item.XP += XP;
|
||||
|
||||
@ -1500,6 +1500,10 @@ export const addGearExpByCategory = (
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (InfestationDate) {
|
||||
item.InfestationDate = fromMongoData(InfestationDate);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,6 @@ import {
|
||||
addFocusXpIncreases,
|
||||
addFusionPoints,
|
||||
addFusionTreasures,
|
||||
addGearExpByCategory,
|
||||
addItem,
|
||||
addLevelKeys,
|
||||
addLoreFragmentScans,
|
||||
@ -32,6 +31,7 @@ import {
|
||||
addShipDecorations,
|
||||
addSkin,
|
||||
addStanding,
|
||||
applyClientEquipmentUpdates,
|
||||
combineInventoryChanges,
|
||||
generateRewardSeed,
|
||||
getCalendarProgress,
|
||||
@ -670,9 +670,8 @@ export const addMissionInventoryUpdates = async (
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Equipment XP updates
|
||||
if (equipmentKeys.includes(key as TEquipmentKey)) {
|
||||
addGearExpByCategory(inventory, value as IEquipmentClient[], key as TEquipmentKey);
|
||||
applyClientEquipmentUpdates(inventory, value as IEquipmentClient[], key as TEquipmentKey);
|
||||
}
|
||||
break;
|
||||
// if (
|
||||
|
Loading…
x
Reference in New Issue
Block a user