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