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

fix: alert generation with more filtering (#4355)

fixes towards the previous commit ([3d7d3da876](https://onlyg.it/OpenWF/SpaceNinjaServer/commit/3d7d3da876771d5b5f2845534f48e9f7c6396d0f)): - added more filtering towards different rewards - used [mekael's documentation](https://github.com/mekael/WFClassic/blob/develop/docs/alerts.md) for legacy alerts - new filters for legacy alerts (tileset, faction, description, icons) - fixed rewards that were not given at the end of the mission (skill issue on my end with the previous commit) - tried to change the generation from maths to a seed so everyone has the same alerts at the same time tested with 7.3, 10.3 and 22.13.4 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/4355 Reviewed-by: Sainan <63328889+sainan@users.noreply.github.com> Co-authored-by: Vitruvio <therealzexal@gmail.com> Co-committed-by: Vitruvio <therealzexal@gmail.com>

40bbb2ab
Vitruvio <therealzexal@gmail.com>
提交于

代码差异

4 个文件 +372 -140
Modified src/models/worldStateModel.ts +3 -2
@@ -43,6 +43,9 @@ const alertSchema = new Schema<IAlertDatabase>({
43 43 items: [String],
44 44 countedItems: [typeCountSchema]
45 45 },
46 levelOverride: String,
47 enemySpec: String,
48 extraEnemySpec: String,
46 49 minEnemyLevel: { type: Number, required: true },
47 50 maxEnemyLevel: { type: Number, required: true },
48 51 descText: String,
@@ -51,5 +54,3 @@ const alertSchema = new Schema<IAlertDatabase>({
51 54 });
52 55
53 56 alertSchema.index({ Expiry: 1 }, { expireAfterSeconds: 0 });
54
55 export const Alert = model<IAlertDatabase>("Alert", alertSchema);
Modified src/services/missionInventoryUpdateService.ts +8 -3
@@ -93,7 +93,8 @@ import {
93 93 idToBountyCycle,
94 94 idToDay,
95 95 idToWeek,
96 pushClassicBounties
96 pushClassicBounties,
97 populateAlerts
97 98 } from "./worldStateService.ts";
98 99 import { config } from "./configService.ts";
99 100 import libraryDailyTasks from "../../static/fixed_responses/libraryDailyTasks.json" with { type: "json" };
@@ -1217,7 +1218,9 @@ export const addMissionRewards = async (
1217 1218 let missionCompletionCredits = 0;
1218 1219
1219 1220 if (rewardInfo.alertId) {
1220 const alert = getWorldState(buildLabel).Alerts.find(x => x._id.$oid == rewardInfo.alertId);
1221 const worldState = getWorldState(buildLabel);
1222 await populateAlerts(worldState);
1223 const alert = worldState.Alerts.find(x => x._id.$oid == rewardInfo.alertId);
1221 1224 if (!alert) {
1222 1225 logger.warn(`mission completed unknown alert`, { alertId: rewardInfo.alertId });
1223 1226 } else {
@@ -2519,7 +2522,9 @@ async function getRandomMissionDrops(
2519 2522 }
2520 2523 }
2521 2524 } else if (RewardInfo.alertId) {
2522 const alert = getWorldState(buildLabel).Alerts.find(x => x._id.$oid == RewardInfo.alertId);
2525 const worldState = getWorldState(buildLabel);
2526 await populateAlerts(worldState);
2527 const alert = worldState.Alerts.find(x => x._id.$oid == RewardInfo.alertId);
2523 2528 if (alert && alert.MissionInfo.enemyCacheOverride) {
2524 2529 const deck = ExportRewards[alert.MissionInfo.enemyCacheOverride];
2525 2530 for (let rotation = 0; rotation != RewardInfo.EnemyCachesFound; ++rotation) {
Modified src/services/worldStateService.ts +358 -135
@@ -19,7 +19,6 @@ import type {
19 19 ICalendarEvent,
20 20 ICalendarSeason,
21 21 IAlert,
22 IAlertDatabase,
23 22 IGoal,
24 23 IInvasion,
25 24 ILiteSortie,
@@ -43,7 +42,7 @@ import type {
43 42 } from "../types/worldStateTypes.ts";
44 43 import { toMongoDate2, toOid, toOid2, version_compare } from "../helpers/inventoryHelpers.ts";
45 44 import { logger } from "../utils/logger.ts";
46 import { DailyDeal, Fissure, Alert } from "../models/worldStateModel.ts";
45 import { DailyDeal, Fissure } from "../models/worldStateModel.ts";
47 46 import { toStoreItem, fromStoreItem, getRegions } from "./itemDataService.ts";
48 47 import { factionToInt, getConquest, getMissionTypeForLegacyOverride } from "./conquestService.ts";
49 48 import gameToBuildVersion from "../constants/gameToBuildVersion.ts";
@@ -2146,7 +2145,7 @@ export const getWorldState = (
2146 2145 for (const [key, alert] of Object.entries(configAlerts)) {
2147 2146 if (config.worldState[key as keyof typeof config.worldState]) {
2148 2147 const { minBuildVersion, ...wsAlert } = alert;
2149 if (!minBuildVersion || minBuildVersion >= buildVersionInt) {
2148 if (!minBuildVersion || buildVersionInt >= minBuildVersion) {
2150 2149 if (wsAlert.MissionInfo.missionType == "MT_DEFENSE") {
2151 2150 wsAlert.MissionInfo.maxWaveNum =
2152 2151 defenseWavesPerRotation * (wsAlert.MissionInfo.maxRotations ?? 1);
@@ -5254,18 +5253,7 @@ const alertStandardResources = [
5254 5253 { path: "/Lotus/Types/Items/MiscItems/Plastids", qty: 300 },
5255 5254 { path: "/Lotus/Types/Items/MiscItems/PolymerBundle", qty: 300 },
5256 5255 { path: "/Lotus/Types/Items/MiscItems/Rubedo", qty: 450 },
5257 { path: "/Lotus/Types/Items/MiscItems/Salvage", qty: 300 },
5258 { path: "/Lotus/Types/Items/MiscItems/ArgonCrystal", qty: 1 },
5259 { path: "/Lotus/Types/Items/MiscItems/OxiumAlloy", qty: 300 },
5260 { path: "/Lotus/Types/Items/MiscItems/Tellurium", qty: 1 }
5261 ];
5262
5263 const alertSpecialResources = [
5264 { path: "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg", qty: 1 },
5265 { path: "/Lotus/Types/Game/CatbrowPet/CatbrowGeneticSignature", qty: 5 },
5266 { path: "/Lotus/Types/Items/MiscItems/Eventium", qty: 5 },
5267 { path: "/Lotus/Types/Items/MiscItems/Alertium", qty: 1 },
5268 { path: "/Lotus/Types/Items/MiscItems/VoidTearDrop", qty: 20 }
5256 { path: "/Lotus/Types/Items/MiscItems/Salvage", qty: 300 }
5269 5257 ];
5270 5258
5271 5259 const alertAuras = [
@@ -5485,15 +5473,187 @@ const getEligibleAlertNodes = (): string[] => {
5485 5473 return eligibleNodes;
5486 5474 };
5487 5475
5488 const spawnAlert = async (activeNodes: Set<string>): Promise<any> => {
5489 const eligibleNodes = getEligibleAlertNodes();
5490 if (eligibleNodes.length === 0) return null;
5476 const ALERT_INTERVAL_MS = 25 * 60 * 1000;
5477 const ALERT_BASE_DURATION_MS = 40 * 60 * 1000;
5478
5479 const alertDescTexts: Record<string, string[] | undefined> = {
5480 MT_ASSASSINATION: [
5481 "/Lotus/Language/Alerts/AssassinationDesc1",
5482 "/Lotus/Language/Alerts/AssassinationDesc9",
5483 "/Lotus/Language/Alerts/AssassinationDesc10",
5484 "/Lotus/Language/Alerts/AssassinationDesc11",
5485 "/Lotus/Language/Alerts/AssassinationDesc14"
5486 ],
5487 MT_EXTERMINATION: [
5488 "/Lotus/Language/Alerts/ExterminationDesc3",
5489 "/Lotus/Language/Alerts/ExterminationDesc4",
5490 "/Lotus/Language/Alerts/ExterminationDesc5",
5491 "/Lotus/Language/Alerts/ExterminationDesc6",
5492 "/Lotus/Language/Alerts/ExterminationDesc7",
5493 "/Lotus/Language/Alerts/ExterminationDesc8",
5494 "/Lotus/Language/Alerts/ExterminationDesc9",
5495 "/Lotus/Language/Alerts/ExterminationDesc11",
5496 "/Lotus/Language/Alerts/ExterminationDesc13",
5497 "/Lotus/Language/Alerts/ExterminationDesc14"
5498 ],
5499 MT_SURVIVAL: [
5500 "/Lotus/Language/Alerts/RaidDesc15",
5501 "/Lotus/Language/Alerts/RaidDesc19",
5502 "/Lotus/Language/Alerts/RaidDesc22",
5503 "/Lotus/Language/Alerts/RaidDesc23",
5504 "/Lotus/Language/Alerts/DefenseDesc9",
5505 "/Lotus/Language/Alerts/DefenseDesc15"
5506 ],
5507 MT_RESCUE: [
5508 "/Lotus/Language/Alerts/RescueDesc1",
5509 "/Lotus/Language/Alerts/RescueDesc2",
5510 "/Lotus/Language/Alerts/RescueDesc3",
5511 "/Lotus/Language/Alerts/RescueDesc4",
5512 "/Lotus/Language/Alerts/RescueDesc5",
5513 "/Lotus/Language/Alerts/RescueDesc6",
5514 "/Lotus/Language/Alerts/RescueDesc7",
5515 "/Lotus/Language/Alerts/RescueDesc8",
5516 "/Lotus/Language/Alerts/RescueDesc9",
5517 "/Lotus/Language/Alerts/RescueDesc10",
5518 "/Lotus/Language/Alerts/RescueDesc11",
5519 "/Lotus/Language/Alerts/RescueDesc12",
5520 "/Lotus/Language/Alerts/RescueDesc14"
5521 ],
5522 MT_SABOTAGE: [
5523 "/Lotus/Language/Alerts/SabotageDesc2",
5524 "/Lotus/Language/Alerts/SabotageDesc6",
5525 "/Lotus/Language/Alerts/SabotageDesc7",
5526 "/Lotus/Language/Alerts/SabotageDesc15",
5527 "/Lotus/Language/Alerts/SabotageDesc16",
5528 "/Lotus/Language/Alerts/SabotageDesc17",
5529 "/Lotus/Language/Alerts/SabotageDesc18",
5530 "/Lotus/Language/Alerts/SabotageDesc21",
5531 "/Lotus/Language/Alerts/SabotageDesc23",
5532 "/Lotus/Language/Alerts/SabotageDesc24",
5533 "/Lotus/Language/Alerts/SabotageDesc26",
5534 "/Lotus/Language/Alerts/SabotageDesc28"
5535 ],
5536 MT_CAPTURE: [
5537 "/Lotus/Language/Alerts/CaptureDesc1",
5538 "/Lotus/Language/Alerts/CaptureDesc2",
5539 "/Lotus/Language/Alerts/CaptureDesc3",
5540 "/Lotus/Language/Alerts/CaptureDesc4",
5541 "/Lotus/Language/Alerts/CaptureDesc5",
5542 "/Lotus/Language/Alerts/CaptureDesc9",
5543 "/Lotus/Language/Alerts/CaptureDesc10",
5544 "/Lotus/Language/Alerts/CaptureDesc12",
5545 "/Lotus/Language/Alerts/CaptureDesc14"
5546 ],
5547 MT_COUNTER_INTEL: [
5548 "/Lotus/Language/Alerts/CounterIntelDesc1",
5549 "/Lotus/Language/Alerts/CounterIntelDesc2",
5550 "/Lotus/Language/Alerts/CounterIntelDesc4",
5551 "/Lotus/Language/Alerts/CounterIntelDesc5",
5552 "/Lotus/Language/Alerts/CounterIntelDesc10",
5553 "/Lotus/Language/Alerts/CounterIntelDesc14",
5554 "/Lotus/Language/Alerts/CounterIntelDesc15",
5555 "/Lotus/Language/Alerts/CounterIntelDesc20",
5556 "/Lotus/Language/Alerts/CounterIntelDesc22",
5557 "/Lotus/Language/Alerts/CounterIntelDesc25"
5558 ],
5559 MT_INTEL: [
5560 "/Lotus/Language/Alerts/IntelDesc1",
5561 "/Lotus/Language/Alerts/IntelDesc3",
5562 "/Lotus/Language/Alerts/IntelDesc10",
5563 "/Lotus/Language/Alerts/IntelDesc15",
5564 "/Lotus/Language/Alerts/IntelDesc20",
5565 "/Lotus/Language/Alerts/IntelDesc21",
5566 "/Lotus/Language/Alerts/IntelDesc24",
5567 "/Lotus/Language/Alerts/IntelDesc25",
5568 "/Lotus/Language/Alerts/IntelDesc29",
5569 "/Lotus/Language/Alerts/IntelDesc30",
5570 "/Lotus/Language/Alerts/IntelDesc31",
5571 "/Lotus/Language/Alerts/IntelDesc32",
5572 "/Lotus/Language/Alerts/IntelDesc33",
5573 "/Lotus/Language/Alerts/IntelDesc34",
5574 "/Lotus/Language/Alerts/IntelDesc36",
5575 "/Lotus/Language/Alerts/IntelDesc37",
5576 "/Lotus/Language/Alerts/IntelDesc39",
5577 "/Lotus/Language/Alerts/IntelDesc40",
5578 "/Lotus/Language/Alerts/IntelDesc42",
5579 "/Lotus/Language/Alerts/IntelDesc43",
5580 "/Lotus/Language/Alerts/IntelDesc44",
5581 "/Lotus/Language/Alerts/IntelDesc47"
5582 ],
5583 MT_DEFENSE: ["/Lotus/Language/Alerts/DefenseDesc9", "/Lotus/Language/Alerts/DefenseDesc15"],
5584 MT_MOBILE_DEFENSE: [
5585 "/Lotus/Language/Alerts/DefenseDesc2",
5586 "/Lotus/Language/Alerts/DefenseDesc15",
5587 "/Lotus/Language/Alerts/DefenseDesc19"
5588 ],
5589 MT_TERRITORY: [
5590 "/Lotus/Language/Alerts/IntelDesc26",
5591 "/Lotus/Language/Alerts/IntelDesc25",
5592 "/Lotus/Language/Alerts/CounterIntelDesc2"
5593 ],
5594 MT_RETRIEVAL: [
5595 "/Lotus/Language/Alerts/RaidDesc15",
5596 "/Lotus/Language/Alerts/IntelDesc39",
5597 "/Lotus/Language/Alerts/IntelDesc34"
5598 ],
5599 MT_HIVE: ["/Lotus/Language/Alerts/SabotageDesc6"],
5600 MT_EXCAVATE: ["/Lotus/Language/Alerts/IntelDesc4", "/Lotus/Language/Alerts/IntelDesc22"]
5601 };
5602
5603 const getFilteredAlertHelmets = (buildLabel: string): string[] => {
5604 return alertHelmets.filter(helmet => {
5605 if (helmet.includes("BardAlt")) return version_compare(buildLabel, gameToBuildVersion["20.0.0"]) >= 0;
5606 if (helmet.includes("NidusAlt")) return version_compare(buildLabel, gameToBuildVersion["19.5.3"]) >= 0;
5607 if (helmet.includes("FairyAlt")) return version_compare(buildLabel, gameToBuildVersion["19.0.1"]) >= 0;
5608 if (helmet.includes("WukongAlt")) return version_compare(buildLabel, gameToBuildVersion["18.0.2"]) >= 0;
5609 if (helmet.includes("BrawlerAlt")) return version_compare(buildLabel, gameToBuildVersion["17.7.1"]) >= 0;
5610 if (helmet.includes("SandmanAlt")) return version_compare(buildLabel, gameToBuildVersion["18.5.0"]) >= 0;
5611 if (helmet.includes("NezhaAlt")) return version_compare(buildLabel, gameToBuildVersion["18.0.2"]) >= 0;
5612 if (helmet.includes("RangerAlt")) return version_compare(buildLabel, gameToBuildVersion["18.0.2"]) >= 0;
5613 if (helmet.includes("AnimaAlt")) return version_compare(buildLabel, gameToBuildVersion["17.7.1"]) >= 0;
5614 if (helmet.includes("ChromaAlt") || helmet.includes("DragonAlt"))
5615 return version_compare(buildLabel, gameToBuildVersion["16.0.2"]) >= 0;
5616 if (helmet.includes("MesaAlt") || helmet.includes("CowgirlAlt"))
5617 return version_compare(buildLabel, gameToBuildVersion["15.5.0"]) >= 0;
5618 if (helmet.includes("LimboAlt") || helmet.includes("LimboAristeas"))
5619 return version_compare(buildLabel, gameToBuildVersion["15.0.0"]) >= 0;
5620 if (helmet.includes("HarlequinAlt") || helmet.includes("MirageAlt"))
5621 return version_compare(buildLabel, gameToBuildVersion["14.0.0"]) >= 0;
5622 if (helmet.includes("PirateAlt")) return version_compare(buildLabel, gameToBuildVersion["13.0.0"]) >= 0;
5623 if (helmet.includes("Zephyr")) return version_compare(buildLabel, gameToBuildVersion["12.1.2"]) >= 0;
5624 if (helmet.includes("Oberon")) return version_compare(buildLabel, gameToBuildVersion["11.1.3"]) >= 0;
5625 if (helmet.includes("Valkyr")) return version_compare(buildLabel, gameToBuildVersion["11.1.3"]) >= 0;
5626 if (helmet.includes("Vauban")) return version_compare(buildLabel, gameToBuildVersion["8.0.0"]) >= 0;
5627 return true;
5628 });
5629 };
5630
5631 const generateSeededAlert = (
5632 alertIndex: number,
5633 eligibleNodes: string[],
5634 usedNodes: Set<string>,
5635 buildLabel: string,
5636 regions: Record<string, IRegion>
5637 ): IAlert | undefined => {
5638 const seed = new SRng(alertIndex * 2654435761).randomInt(0, 100_000);
5639 const rng = new SRng(seed);
5640
5641 const availableNodes = eligibleNodes.filter(n => !usedNodes.has(n));
5642 if (availableNodes.length === 0) return undefined;
5643
5644 const nodeId = rng.randomElement(availableNodes)!;
5645 const nodeData = regions[nodeId];
5491 5646
5492 const availableNodes = eligibleNodes.filter(node => !activeNodes.has(node));
5493 const nodeId = getRandomElement(availableNodes.length > 0 ? availableNodes : eligibleNodes)!;
5494 const nodeData = ExportRegions[nodeId];
5647 const isPreU14 = version_compare(buildLabel, gameToBuildVersion["14.0.0"]) < 0;
5648 const isPostU18 = version_compare(buildLabel, gameToBuildVersion["18.0.2"]) >= 0;
5495 5649
5496 const missionTypes = [
5650 const factions: TFaction[] = ["FC_GRINEER", "FC_CORPUS", "FC_INFESTATION"];
5651 let faction: TFaction = rng.randomInt(0, 9) < 7 ? (nodeData.faction as TFaction) : rng.randomElement(factions)!;
5652 if (faction === "FC_OROKIN" && isPostU18) {
5653 faction = "FC_CORRUPTED" as TFaction;
5654 }
5655
5656 const missionTypes: TMissionType[] = [
5497 5657 "MT_SURVIVAL",
5498 5658 "MT_DEFENSE",
5499 5659 "MT_RESCUE",
@@ -5501,46 +5661,110 @@ const spawnAlert = async (activeNodes: Set<string>): Promise<any> => {
5501 5661 "MT_EXTERMINATION",
5502 5662 "MT_SABOTAGE",
5503 5663 "MT_MOBILE_DEFENSE",
5504 "MT_EXCAVATE",
5505 5664 "MT_INTEL"
5506 5665 ];
5507 const missionType = Math.random() < 0.7 ? nodeData.missionType : getRandomElement(missionTypes)!;
5666 let missionType: TMissionType;
5667 let levelOverride = nodeData.levelOverride;
5668 let enemySpec = nodeData.enemySpec;
5669 let extraEnemySpec = nodeData.extraEnemySpec;
5670
5671 if (isPreU14) {
5672 missionType = nodeData.missionType;
5673 } else {
5674 missionType = rng.randomInt(0, 9) < 7 ? nodeData.missionType : rng.randomElement(missionTypes)!;
5675 }
5508 5676
5509 const factions = ["FC_GRINEER", "FC_CORPUS", "FC_INFESTATION", "FC_CORRUPTED"];
5510 let faction = Math.random() < 0.7 ? nodeData.faction : getRandomElement(factions)!;
5511 if (faction === "FC_OROKIN") {
5512 faction = "FC_CORRUPTED";
5677 if (missionType !== nodeData.missionType) {
5678 levelOverride = undefined;
5513 5679 }
5514 5680
5515 const difficulty = parseFloat((0.1 + Math.random() * 0.9).toFixed(2));
5516 const minEnemyLevel = Math.round(10 + difficulty * 20);
5517 const maxEnemyLevel = minEnemyLevel + Math.round(5 + Math.random() * 5);
5681 if (missionType !== nodeData.missionType || faction !== nodeData.faction) {
5682 let foundEnemySpec: string | undefined = undefined;
5683 let foundExtraEnemySpec: string | undefined = undefined;
5684 const searchFaction = (faction as string) === "FC_CORRUPTED" ? "FC_OROKIN" : faction;
5518 5685
5519 let rewardCredits = Math.floor(2000 + difficulty * 18000);
5686 for (const node of Object.values(regions)) {
5687 if (node.faction === searchFaction && node.missionType === missionType && node.enemySpec) {
5688 foundEnemySpec = node.enemySpec;
5689 foundExtraEnemySpec = node.extraEnemySpec;
5690 break;
5691 }
5692 }
5520 5693
5694 if (!foundEnemySpec) {
5695 for (const node of Object.values(regions)) {
5696 if (node.faction === searchFaction && node.enemySpec) {
5697 foundEnemySpec = node.enemySpec;
5698 foundExtraEnemySpec = node.extraEnemySpec;
5699 break;
5700 }
5701 }
5702 }
5703
5704 enemySpec = foundEnemySpec;
5705 extraEnemySpec = foundExtraEnemySpec;
5706 }
5707
5708 const difficulty = rng.randomInt(10, 99) / 100;
5709 const minEnemyLevel = 10 + Math.round(difficulty * 20);
5710 const maxEnemyLevel = minEnemyLevel + rng.randomInt(5, 10);
5711
5712 let rewardCredits = 2000 + Math.round(difficulty * 18000);
5521 5713 let rewardItems: string[] | undefined = undefined;
5522 5714 let rewardCountedItems: { ItemType: string; ItemCount: number }[] | undefined = undefined;
5523 5715 let isNightmare = false;
5524 5716
5525 const categories = [
5717 const filteredStdRes = [...alertStandardResources];
5718 if (version_compare(buildLabel, gameToBuildVersion["14.0.0"]) >= 0) {
5719 filteredStdRes.push({ path: "/Lotus/Types/Items/MiscItems/ArgonCrystal", qty: 1 });
5720 }
5721 if (version_compare(buildLabel, gameToBuildVersion["10.8.0"]) >= 0) {
5722 filteredStdRes.push({ path: "/Lotus/Types/Items/MiscItems/OxiumAlloy", qty: 300 });
5723 }
5724 if (version_compare(buildLabel, gameToBuildVersion["15.5.0"]) >= 0) {
5725 filteredStdRes.push({ path: "/Lotus/Types/Items/MiscItems/Tellurium", qty: 1 });
5726 }
5727
5728 const filteredSpecRes: { path: string; qty: number }[] = [];
5729 if (version_compare(buildLabel, gameToBuildVersion["14.0.0"]) >= 0) {
5730 filteredSpecRes.push({ path: "/Lotus/Types/Game/KubrowPet/Eggs/KubrowEgg", qty: 1 });
5731 }
5732 if (version_compare(buildLabel, gameToBuildVersion["18.5.0"]) >= 0) {
5733 filteredSpecRes.push({ path: "/Lotus/Types/Game/CatbrowPet/CatbrowGeneticSignature", qty: 5 });
5734 }
5735 if (version_compare(buildLabel, gameToBuildVersion["14.0.0"]) >= 0) {
5736 filteredSpecRes.push({ path: "/Lotus/Types/Items/MiscItems/Eventium", qty: 5 });
5737 }
5738 if (version_compare(buildLabel, gameToBuildVersion["18.5.0"]) >= 0) {
5739 filteredSpecRes.push({ path: "/Lotus/Types/Items/MiscItems/Alertium", qty: 1 });
5740 }
5741 if (version_compare(buildLabel, gameToBuildVersion["18.13.3"]) >= 0) {
5742 filteredSpecRes.push({ path: "/Lotus/Types/Items/MiscItems/VoidTearDrop", qty: 20 });
5743 }
5744
5745 const hasNightmare = version_compare(buildLabel, gameToBuildVersion["9.1.0"]) >= 0;
5746 const hasExcavate = version_compare(buildLabel, gameToBuildVersion["14.0.0"]) >= 0;
5747
5748 const categories: { name: string; weight: number }[] = [
5526 5749 { name: "CREDITS", weight: 60 },
5527 5750 { name: "STANDARD_RESOURCES", weight: 120 },
5528 5751 { name: "ENDO", weight: 40 },
5529 5752 { name: "ALT_HELMETS", weight: 80 },
5530 5753 { name: "WEAPONS", weight: 35 },
5531 { name: "NIGHTMARE_MODS", weight: 30 },
5532 5754 { name: "AURAS", weight: 18 },
5533 { name: "SPECIAL_RESOURCES", weight: 10 },
5534 { name: "VAUBAN_PARTS", weight: 7 },
5535 5755 { name: "OROKIN_BP", weight: 4 }
5536 5756 ];
5757 if (hasNightmare) categories.push({ name: "NIGHTMARE_MODS", weight: 30 });
5758 if (filteredSpecRes.length > 0) categories.push({ name: "SPECIAL_RESOURCES", weight: 10 });
5759 if (version_compare(buildLabel, gameToBuildVersion["5.2.0"]) >= 0) {
5760 categories.push({ name: "VAUBAN_PARTS", weight: 7 });
5761 }
5537 5762
5538 5763 let totalWeight = 0;
5539 5764 for (const cat of categories) {
5540 5765 totalWeight += cat.weight;
5541 5766 }
5542
5543 let roll = Math.random() * totalWeight;
5767 let roll = rng.randomInt(0, totalWeight * 100) / 100;
5544 5768 let selectedCategory = "STANDARD_RESOURCES";
5545 5769 for (const cat of categories) {
5546 5770 if (roll < cat.weight) {
@@ -5552,80 +5776,108 @@ const spawnAlert = async (activeNodes: Set<string>): Promise<any> => {
5552 5776
5553 5777 switch (selectedCategory) {
5554 5778 case "CREDITS": {
5555 rewardCredits = Math.floor(5000 + difficulty * 15000);
5779 rewardCredits = 5000 + Math.round(difficulty * 15000);
5556 5780 break;
5557 5781 }
5558 5782 case "STANDARD_RESOURCES": {
5559 const res = getRandomElement(alertStandardResources)!;
5783 const res = rng.randomElement(filteredStdRes)!;
5560 5784 rewardCountedItems = [{ ItemType: res.path, ItemCount: res.qty }];
5561 5785 break;
5562 5786 }
5563 5787 case "ENDO": {
5564 const endoRoll = Math.random() * 100;
5565 let endoPath = "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/AlertFusionBundleSmall";
5566 if (endoRoll < 60) {
5567 endoPath = "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/AlertFusionBundleSmall";
5568 } else if (endoRoll < 90) {
5569 endoPath = "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/AlertFusionBundleMedium";
5788 const isPreU19 = version_compare(buildLabel, gameToBuildVersion["19.0.1"]) < 0;
5789 const endoRoll = rng.randomInt(0, 99);
5790 if (isPreU19) {
5791 let corePath = "/Lotus/Upgrades/Mods/FusionCores/CoreClassCommonThree";
5792 if (endoRoll < 60) {
5793 corePath = "/Lotus/Upgrades/Mods/FusionCores/CoreClassCommonThree";
5794 } else if (endoRoll < 90) {
5795 corePath = "/Lotus/Upgrades/Mods/FusionCores/CoreClassUncommonFive";
5796 } else {
5797 corePath = "/Lotus/Upgrades/Mods/FusionCores/CoreClassRareFive";
5798 }
5799 rewardItems = [toStoreItem(corePath)];
5570 5800 } else {
5571 endoPath = "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/AlertFusionBundleLarge";
5801 let endoPath = "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/AlertFusionBundleSmall";
5802 if (endoRoll < 60) {
5803 endoPath = "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/AlertFusionBundleSmall";
5804 } else if (endoRoll < 90) {
5805 endoPath = "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/AlertFusionBundleMedium";
5806 } else {
5807 endoPath = "/Lotus/StoreItems/Upgrades/Mods/FusionBundles/AlertFusionBundleLarge";
5808 }
5809 rewardItems = [endoPath];
5572 5810 }
5573 rewardItems = [endoPath];
5574 5811 break;
5575 5812 }
5576 5813 case "SPECIAL_RESOURCES": {
5577 const res = getRandomElement(alertSpecialResources)!;
5814 const res = rng.randomElement(filteredSpecRes)!;
5578 5815 rewardCountedItems = [{ ItemType: res.path, ItemCount: res.qty }];
5579 5816 break;
5580 5817 }
5581 5818 case "AURAS": {
5582 const aura = getRandomElement(alertAuras)!;
5819 const aura = rng.randomElement(alertAuras)!;
5583 5820 rewardItems = [toStoreItem(aura)];
5584 5821 break;
5585 5822 }
5586 5823 case "ALT_HELMETS": {
5587 const helmet = getRandomElement(alertHelmets)!;
5824 const filteredHelmets = getFilteredAlertHelmets(buildLabel);
5825 const helmet = rng.randomElement(filteredHelmets)!;
5588 5826 rewardItems = [toStoreItem(helmet)];
5589 5827 break;
5590 5828 }
5591 5829 case "VAUBAN_PARTS": {
5592 const part = getRandomElement(alertVaubanParts)!;
5830 const part = rng.randomElement(alertVaubanParts)!;
5593 5831 rewardItems = [toStoreItem(part)];
5594 5832 break;
5595 5833 }
5596 5834 case "WEAPONS": {
5597 const weapon = getRandomElement(alertWeapons)!;
5835 const weapon = rng.randomElement(alertWeapons)!;
5598 5836 rewardItems = [toStoreItem(weapon)];
5599 5837 break;
5600 5838 }
5601 5839 case "NIGHTMARE_MODS": {
5602 const nmMod = getRandomElement(alertNightmareMods)!;
5840 const nmMod = rng.randomElement(alertNightmareMods)!;
5603 5841 rewardItems = [toStoreItem(nmMod)];
5604 5842 isNightmare = true;
5605 5843 break;
5606 5844 }
5607 5845 case "OROKIN_BP": {
5608 const specialBP = getRandomElement(alertOrokinBP)!;
5846 const specialBP = rng.randomElement(alertOrokinBP)!;
5609 5847 rewardItems = [toStoreItem(specialBP)];
5610 5848 break;
5611 5849 }
5612 5850 }
5613 5851
5614 let durationMin = 30 + Math.random() * 40;
5852 let durationMs = ALERT_BASE_DURATION_MS + rng.randomInt(0, 40) * 60 * 1000;
5615 5853 let multiplier = 1;
5616 5854 if (rewardItems && rewardItems.length > 0) {
5617 5855 multiplier = alertDurationMultipliers.get(fromStoreItem(rewardItems[0])) ?? 1;
5618 5856 } else if (rewardCountedItems && rewardCountedItems.length > 0) {
5619 5857 multiplier = alertDurationMultipliers.get(rewardCountedItems[0].ItemType) ?? 1;
5620 5858 }
5621 durationMin *= multiplier;
5859 durationMs = Math.round(durationMs * multiplier);
5860
5861 const activation = EPOCH + alertIndex * ALERT_INTERVAL_MS;
5862 const expiry = activation + durationMs;
5863
5864 const oid =
5865 ((activation / 1000) & 0xffffffff).toString(16).padStart(8, "0") +
5866 "a1e4" +
5867 seed.toString(16).padStart(5, "0").substring(0, 5) +
5868 (alertIndex & 0xffffff).toString(16).padStart(7, "0");
5622 5869
5623 const activationDate = new Date(Date.now() - 10 * 60 * 1000);
5624 const expiryDate = new Date(activationDate.getTime() + durationMin * 60 * 1000);
5870 const descTexts = alertDescTexts[missionType];
5871 const descText = isPreU14 && descTexts ? rng.randomElement(descTexts) : undefined;
5625 5872
5626 const newAlert = new Alert({
5627 Activation: activationDate,
5628 Expiry: expiryDate,
5873 if (!hasExcavate && missionType === "MT_EXCAVATE") {
5874 return undefined;
5875 }
5876
5877 const alert: IAlert = {
5878 _id: toOid2(oid, buildLabel),
5879 Activation: toMongoDate2(activation, buildLabel),
5880 Expiry: toMongoDate2(expiry, buildLabel),
5629 5881 MissionInfo: {
5630 5882 location: nodeId,
5631 5883 missionType: missionType,
@@ -5636,50 +5888,17 @@ const spawnAlert = async (activeNodes: Set<string>): Promise<any> => {
5636 5888 items: rewardItems,
5637 5889 countedItems: rewardCountedItems
5638 5890 },
5891 levelOverride: levelOverride,
5892 enemySpec: enemySpec,
5893 extraEnemySpec: extraEnemySpec,
5639 5894 minEnemyLevel: minEnemyLevel,
5640 5895 maxEnemyLevel: maxEnemyLevel,
5896 descText: descText,
5641 5897 nightmare: isNightmare || undefined
5642 5898 }
5643 });
5644 return await newAlert.save();
5645 };
5646
5647 const updateAlerts = async (): Promise<void> => {
5648 const alerts = await Alert.find();
5649 const activeAlerts: any[] = [];
5650 const activeNodes = new Set<string>();
5651 let latestActivation = 0;
5652
5653 for (const alert of alerts) {
5654 if (alert.Expiry.getTime() > Date.now()) {
5655 activeAlerts.push(alert);
5656 activeNodes.add(alert.MissionInfo.location);
5657 }
5658 latestActivation = Math.max(latestActivation, alert.Activation.getTime());
5659 }
5660
5661 while (activeAlerts.length < 3) {
5662 const newAlert = (await spawnAlert(activeNodes)) as IAlertDatabase | null;
5663 if (newAlert) {
5664 activeAlerts.push(newAlert);
5665 activeNodes.add(newAlert.MissionInfo.location);
5666 latestActivation = Math.max(latestActivation, newAlert.Activation.getTime());
5667 } else {
5668 break;
5669 }
5670 }
5899 };
5671 5900
5672 if (activeAlerts.length < 5 && latestActivation > 0) {
5673 const timeSinceLastSpawn = Date.now() - latestActivation;
5674 const interval = 20 + Math.random() * 20;
5675 if (timeSinceLastSpawn > interval * 60 * 1000) {
5676 const newAlert = (await spawnAlert(activeNodes)) as IAlertDatabase | null;
5677 if (newAlert) {
5678 activeAlerts.push(newAlert);
5679 activeNodes.add(newAlert.MissionInfo.location);
5680 }
5681 }
5682 }
5901 return alert;
5683 5902 };
5684 5903
5685 5904 export const populateAlerts = async (worldState: IWorldState): Promise<void> => {
@@ -5689,49 +5908,53 @@ export const populateAlerts = async (worldState: IWorldState): Promise<void> =>
5689 5908 (version_compare(buildLabel, gameToBuildVersion["5.1.0"]) >= 0 &&
5690 5909 version_compare(buildLabel, gameToBuildVersion["24.3.0"]) < 0) // alerts were retired with U24.3.0
5691 5910 ) {
5692 const activeAlerts = await Alert.find({ Expiry: { $gt: new Date() } });
5911 const eligibleNodes = getEligibleAlertNodes();
5693 5912 const regions = await getRegions(buildLabel);
5694 for (const dbAlert of activeAlerts) {
5695 if (!(dbAlert.MissionInfo.location in regions)) continue;
5696 let mappedItems: string[] | undefined = undefined;
5697 if (dbAlert.MissionInfo.missionReward.items) {
5698 mappedItems = dbAlert.MissionInfo.missionReward.items.map(item => {
5699 if (item.includes("/Recipes/Helmets/")) {
5700 return getVersionAppropriateHelmet(item, buildLabel);
5913 const validNodes = eligibleNodes.filter(nodeId => {
5914 const region = regions[nodeId] as (typeof regions)[string] | undefined;
5915 return region && isRegionAvailableIn(nodeId, region, buildLabel);
5916 });
5917
5918 if (validNodes.length === 0) return;
5919
5920 const timeMs = worldState.Time * 1000;
5921 const currentAlertIndex = Math.floor((timeMs - EPOCH) / ALERT_INTERVAL_MS);
5922 const activeAlerts: IAlert[] = [];
5923 const usedNodes = new Set<string>();
5924
5925 for (let idx = currentAlertIndex - 8; idx <= currentAlertIndex + 1; idx++) {
5926 const alert = generateSeededAlert(idx, validNodes, usedNodes, buildLabel, regions);
5927 if (alert) {
5928 const activationTime =
5929 "$date" in alert.Activation
5930 ? Number(alert.Activation.$date.$numberLong)
5931 : alert.Activation.sec * 1000;
5932 const expiryTime =
5933 "$date" in alert.Expiry ? Number(alert.Expiry.$date.$numberLong) : alert.Expiry.sec * 1000;
5934
5935 if (timeMs >= activationTime && timeMs < expiryTime) {
5936 usedNodes.add(alert.MissionInfo.location);
5937
5938 if (alert.MissionInfo.missionReward?.items) {
5939 alert.MissionInfo.missionReward.items = alert.MissionInfo.missionReward.items.map(item => {
5940 if (item.includes("/Recipes/Helmets/")) {
5941 return getVersionAppropriateHelmet(item, buildLabel);
5942 }
5943 return item;
5944 });
5701 5945 }
5702 return item;
5703 });
5704 }
5705 5946
5706 worldState.Alerts.push({
5707 _id: toOid2(dbAlert._id.toString(), buildLabel),
5708 Activation:
5709 dbAlert.Activation.getTime() < Date.now()
5710 ? toMongoDate2(1000000000000, buildLabel)
5711 : toMongoDate2(dbAlert.Activation.getTime(), buildLabel),
5712 Expiry: toMongoDate2(dbAlert.Expiry.getTime(), buildLabel),
5713 MissionInfo: {
5714 location: dbAlert.MissionInfo.location,
5715 missionType: dbAlert.MissionInfo.missionType as TMissionType,
5716 faction: dbAlert.MissionInfo.faction as TFaction,
5717 difficulty: dbAlert.MissionInfo.difficulty,
5718 missionReward: {
5719 credits: dbAlert.MissionInfo.missionReward.credits,
5720 items: mappedItems,
5721 countedItems: dbAlert.MissionInfo.missionReward.countedItems
5722 },
5723 minEnemyLevel: dbAlert.MissionInfo.minEnemyLevel,
5724 maxEnemyLevel: dbAlert.MissionInfo.maxEnemyLevel,
5725 descText: dbAlert.MissionInfo.descText,
5726 nightmare: dbAlert.MissionInfo.nightmare || undefined
5947 activeAlerts.push(alert);
5727 5948 }
5728 });
5949 }
5729 5950 }
5951
5952 worldState.Alerts.push(...activeAlerts);
5730 5953 }
5731 5954 };
5732 5955
5733 5956 export const updateWorldStateCollections = async (): Promise<void> => {
5734 await Promise.all([updateFissures(), updateDailyDeal(), updateAlerts()]);
5957 await Promise.all([updateFissures(), updateDailyDeal()]);
5735 5958 };
5736 5959
5737 5960 const pushConclaveDaily = (
Modified src/types/worldStateTypes.ts +3 -0
@@ -132,6 +132,9 @@ export interface IAlertDatabase {
132 132 items?: string[];
133 133 countedItems?: { ItemType: string; ItemCount: number }[];
134 134 };
135 levelOverride?: string;
136 enemySpec?: string;
137 extraEnemySpec?: string;
135 138 minEnemyLevel: number;
136 139 maxEnemyLevel: number;
137 140 descText?: string;