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

chore: filter alerts by solnodes (#4317)

Re #4316 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4317 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com> Co-committed-by: AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>

b9714118
AMelonInsideLemon <166175391+AMelonInsideLemon@users.noreply.github.com>
提交于

代码差异

3 个文件 +14 -12
Modified src/models/worldStateModel.ts +2 -6
@@ -1,5 +1,6 @@
1 1 import type { IAlertDatabase, IDailyDealDatabase, IFissureDatabase } from "../types/worldStateTypes.ts";
2 2 import { model, Schema } from "mongoose";
3 import { typeCountSchema } from "./inventoryModels/inventoryModel.ts";
3 4
4 5 const fissureSchema = new Schema<IFissureDatabase>({
5 6 Activation: Date,
@@ -40,12 +41,7 @@ const alertSchema = new Schema<IAlertDatabase>({
40 41 missionReward: {
41 42 credits: { type: Number, required: true },
42 43 items: [String],
43 countedItems: [
44 {
45 ItemType: String,
46 ItemCount: Number
47 }
48 ]
44 countedItems: [typeCountSchema]
49 45 },
50 46 minEnemyLevel: { type: Number, required: true },
51 47 maxEnemyLevel: { type: Number, required: true },
Modified src/services/itemDataService.ts +9 -5
@@ -2406,7 +2406,7 @@ const getLegacyDataVersion = async (target: string, buildLabel: string): Promise
2406 2406 const getLegacyData = async <T>(cache: WeakMap<legacyCacheKey, T>, target: string, buildLabel: string): Promise<T> => {
2407 2407 const key = getLegacyCacheKey(target, buildLabel);
2408 2408 if (cache.has(key)) {
2409 logger.debug(`Using cached ${buildLabel} data for ${target}`);
2409 logger.trace(`Using cached ${buildLabel} data for ${target}`);
2410 2410 return cache.get(key)!;
2411 2411 }
2412 2412
@@ -2415,7 +2415,7 @@ const getLegacyData = async <T>(cache: WeakMap<legacyCacheKey, T>, target: strin
2415 2415 const json = JSON.parse(raw) as T;
2416 2416 cache.set(key, json);
2417 2417
2418 logger.debug(`Cached ${buildLabel} data for ${target}`);
2418 logger.trace(`Cached ${buildLabel} data for ${target}`);
2419 2419
2420 2420 return json;
2421 2421 };
@@ -3444,6 +3444,11 @@ export const getPrice = (
3444 3444 };
3445 3445
3446 3446 export const getRegion = async (uniqueName: string, buildLabel: string): Promise<IRegion | undefined> => {
3447 const regions = await getRegions(buildLabel);
3448 return regions[uniqueName];
3449 };
3450
3451 export const getRegions = async (buildLabel: string): Promise<Record<string, IRegion>> => {
3447 3452 // after U27.2.0 OriginSolarMapRedux moved to binary format, so we don't have data for it
3448 3453 if (version_compare(buildLabel, gameToBuildVersion["27.2.0"]) <= 0) {
3449 3454 const target =
@@ -3454,11 +3459,10 @@ export const getRegion = async (uniqueName: string, buildLabel: string): Promise
3454 3459 : "OriginSolarMapRedux";
3455 3460 const version = await getLegacyDataVersion(target, buildLabel);
3456 3461 if (version) {
3457 const legacyData = await getLegacySolarMapData(target, version);
3458 return legacyData[uniqueName];
3462 return await getLegacySolarMapData(target, version);
3459 3463 }
3460 3464 }
3461 return ExportRegions[uniqueName];
3465 return ExportRegions;
3462 3466 };
3463 3467
3464 3468 export const isRegionAvailableIn = (key: string, value: IRegion, buildLabel: string): boolean => {
Modified src/services/worldStateService.ts +3 -1
@@ -44,7 +44,7 @@ import type {
44 44 import { toMongoDate2, toOid, toOid2, version_compare } from "../helpers/inventoryHelpers.ts";
45 45 import { logger } from "../utils/logger.ts";
46 46 import { DailyDeal, Fissure, Alert } from "../models/worldStateModel.ts";
47 import { toStoreItem, fromStoreItem } from "./itemDataService.ts";
47 import { toStoreItem, fromStoreItem, getRegions } from "./itemDataService.ts";
48 48 import { factionToInt, getConquest, getMissionTypeForLegacyOverride } from "./conquestService.ts";
49 49 import gameToBuildVersion from "../constants/gameToBuildVersion.ts";
50 50 import { getDescent } from "./descentService.ts";
@@ -5689,7 +5689,9 @@ export const populateAlerts = async (worldState: IWorldState): Promise<void> =>
5689 5689 version_compare(buildLabel, gameToBuildVersion["24.3.0"]) < 0 // alerts were retired with 23.3.0
5690 5690 ) {
5691 5691 const activeAlerts = await Alert.find({ Expiry: { $gt: new Date() } });
5692 const regions = await getRegions(buildLabel);
5692 5693 for (const dbAlert of activeAlerts) {
5694 if (!(dbAlert.MissionInfo.location in regions)) continue;
5693 5695 let mappedItems: string[] | undefined = undefined;
5694 5696 if (dbAlert.MissionInfo.missionReward.items) {
5695 5697 mappedItems = dbAlert.MissionInfo.missionReward.items.map(item => {