XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

feat: handle client setting InfestationDate on equipment (#1927)

Closes #1919 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1927 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

3d6c880c
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

4 个文件 +19 -12
Modified src/controllers/custom/addXpController.ts +2 -2
@@ -1,4 +1,4 @@
1 import { addGearExpByCategory, getInventory } from "@/src/services/inventoryService";
1 import { applyClientEquipmentUpdates, getInventory } from "@/src/services/inventoryService";
2 2 import { getAccountIdForRequest } from "@/src/services/loginService";
3 3 import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
4 4 import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
@@ -20,7 +20,7 @@ export const addXpController: RequestHandler = async (req, res) => {
20 20 }
21 21 }
22 22 }
23 addGearExpByCategory(inventory, gear, category as TEquipmentKey);
23 applyClientEquipmentUpdates(inventory, gear, category as TEquipmentKey);
24 24 }
25 25 await inventory.save();
26 26 res.end();
Modified src/helpers/inventoryHelpers.ts +4 -0
@@ -10,6 +10,10 @@ export const toMongoDate = (date: Date): IMongoDate => {
10 10 return { $date: { $numberLong: date.getTime().toString() } };
11 11 };
12 12
13 export const fromMongoData = (date: IMongoDate): Date => {
14 return new Date(parseInt(date.$date.$numberLong));
15 };
16
13 17 export const kubrowWeights: Record<TRarity, number> = {
14 18 COMMON: 6,
15 19 UNCOMMON: 4,
Modified src/services/inventoryService.ts +11 -7
@@ -69,6 +69,7 @@ import {
69 69 import { createShip } from "./shipService";
70 70 import {
71 71 catbrowDetails,
72 fromMongoData,
72 73 kubrowDetails,
73 74 kubrowFurPatternsWeights,
74 75 kubrowWeights,
@@ -1475,21 +1476,20 @@ export const addEmailItem = async (
1475 1476 return inventoryChanges;
1476 1477 };
1477 1478
1478 //TODO: wrong id is not erroring
1479 export const addGearExpByCategory = (
1479 export const applyClientEquipmentUpdates = (
1480 1480 inventory: TInventoryDatabaseDocument,
1481 1481 gearArray: IEquipmentClient[],
1482 1482 categoryName: TEquipmentKey
1483 1483 ): void => {
1484 1484 const category = inventory[categoryName];
1485 1485
1486 gearArray.forEach(({ ItemId, XP }) => {
1487 if (!XP) {
1488 return;
1486 gearArray.forEach(({ ItemId, XP, InfestationDate }) => {
1487 const item = category.id(ItemId.$oid);
1488 if (!item) {
1489 throw new Error(`No item with id ${ItemId.$oid} in ${categoryName}`);
1489 1490 }
1490 1491
1491 const item = category.id(ItemId.$oid);
1492 if (item) {
1492 if (XP) {
1493 1493 item.XP ??= 0;
1494 1494 item.XP += XP;
1495 1495
@@ -1504,6 +1504,10 @@ export const addGearExpByCategory = (
1504 1504 });
1505 1505 }
1506 1506 }
1507
1508 if (InfestationDate) {
1509 item.InfestationDate = fromMongoData(InfestationDate);
1510 }
1507 1511 });
1508 1512 };
1509 1513
Modified src/services/missionInventoryUpdateService.ts +2 -3
@@ -21,7 +21,6 @@ import {
21 21 addFocusXpIncreases,
22 22 addFusionPoints,
23 23 addFusionTreasures,
24 addGearExpByCategory,
25 24 addItem,
26 25 addLevelKeys,
27 26 addLoreFragmentScans,
@@ -32,6 +31,7 @@ import {
32 31 addShipDecorations,
33 32 addSkin,
34 33 addStanding,
34 applyClientEquipmentUpdates,
35 35 combineInventoryChanges,
36 36 generateRewardSeed,
37 37 getCalendarProgress,
@@ -660,9 +660,8 @@ export const addMissionInventoryUpdates = async (
660 660 }
661 661 break;
662 662 default:
663 // Equipment XP updates
664 663 if (equipmentKeys.includes(key as TEquipmentKey)) {
665 addGearExpByCategory(inventory, value as IEquipmentClient[], key as TEquipmentKey);
664 applyClientEquipmentUpdates(inventory, value as IEquipmentClient[], key as TEquipmentKey);
666 665 }
667 666 break;
668 667 // if (