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

SpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/SpaceNinjaServer

feat: implement XPInfo (#200)

852fdcfc
Sainan <sainan@calamity.gg>
提交于

代码差异

2 个文件 +38 -5
Modified src/controllers/stats/viewController.ts +19 -1
@@ -1,11 +1,29 @@
1 1 import { RequestHandler } from "express";
2 import { Inventory } from "@/src/models/inventoryModels/inventoryModel";
2 3 import { IStatsView } from "@/src/types/statTypes";
3 4 import config from "@/config.json";
4 5 import view from "@/static/fixed_responses/view.json";
5 6 import allScans from "@/static/fixed_responses/allScans.json";
6 7
7 const viewController: RequestHandler = (_req, res) => {
8 const viewController: RequestHandler = async (req, res) => {
9 if (!req.query.accountId) {
10 res.status(400).json({ error: "accountId was not provided" });
11 return;
12 }
13 const inventory = await Inventory.findOne({ accountOwnerId: req.query.accountId });
14 if (!inventory) {
15 res.status(400).json({ error: "inventory was undefined" });
16 return;
17 }
18
8 19 const responseJson: IStatsView = view;
20 responseJson.Weapons = [];
21 for (const item of inventory.XPInfo) {
22 responseJson.Weapons.push({
23 type: item.ItemType,
24 xp: item.XP
25 });
26 }
9 27 if (config.unlockAllScans) {
10 28 responseJson.Scans = allScans;
11 29 }
Modified src/services/inventoryService.ts +19 -4
@@ -201,12 +201,27 @@ const addGearExpByCategory = (
201 201 const category = inventory[categoryName];
202 202
203 203 gearArray?.forEach(({ ItemId, XP }) => {
204 const itemIndex = ItemId ? category.findIndex(item => item._id?.equals(ItemId.$oid)) : -1;
205 const item = category[itemIndex];
204 if (!XP) {
205 return;
206 }
206 207
207 if (itemIndex !== -1 && item.XP != undefined) {
208 item.XP += XP || 0;
208 const itemIndex = ItemId ? category.findIndex(item => item._id?.equals(ItemId.$oid)) : -1;
209 if (itemIndex !== -1) {
210 const item = category[itemIndex];
211 item.XP ??= 0;
212 item.XP += XP;
209 213 inventory.markModified(`${categoryName}.${itemIndex}.XP`);
214
215 const xpinfoIndex = inventory.XPInfo.findIndex(x => x.ItemType == item.ItemType);
216 if (xpinfoIndex !== -1) {
217 const xpinfo = inventory.XPInfo[xpinfoIndex];
218 xpinfo.XP += XP;
219 } else {
220 inventory.XPInfo.push({
221 ItemType: item.ItemType,
222 XP: XP
223 });
224 }
210 225 }
211 226 });
212 227 };