From 44df59a82b9dfcb987429391ec029d9233ca20ab Mon Sep 17 00:00:00 2001 From: starfish <50672801+starfi5h@users.noreply.github.com> Date: Tue, 5 Mar 2024 15:38:57 +0800 Subject: [PATCH] Add EnemyManager.DisplayPlanetPingMessage and DisplayAstroMessage --- .../DFTinder/DFTinderDispatchProcessor.cs | 2 + .../GroundEnemy/DFGLaunchAssaultProcessor.cs | 7 +- .../DFSLaunchLancerAssaultProcessor.cs | 1 + .../Patches/Dynamic/DFGBaseComponent_Patch.cs | 2 +- .../Patches/Dynamic/DFRelayComponent_Patch.cs | 23 ++++++ .../Dynamic/DFTinderComponent_Patch.cs | 1 + .../Dynamic/EnemyDFHiveSystem_Patch.cs | 2 + .../Patches/Dynamic/GameData_Patch.cs | 4 +- NebulaWorld/Combat/EnemyManager.cs | 72 ++++++++++++++----- 9 files changed, 93 insertions(+), 21 deletions(-) diff --git a/NebulaNetwork/PacketProcessors/Combat/DFTinder/DFTinderDispatchProcessor.cs b/NebulaNetwork/PacketProcessors/Combat/DFTinder/DFTinderDispatchProcessor.cs index 4b7b28e13..64d73618c 100644 --- a/NebulaNetwork/PacketProcessors/Combat/DFTinder/DFTinderDispatchProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Combat/DFTinder/DFTinderDispatchProcessor.cs @@ -18,6 +18,8 @@ protected override void ProcessPacket(DFTinderDispatchPacket packet, NebulaConne var hiveSystem = GameMain.spaceSector.GetHiveByAstroId(packet.OriginHiveAstroId); if (hiveSystem == null) return; + Multiplayer.Session.Enemies.DisplayAstroMessage("Dark Fog seed send out from".Translate(), hiveSystem.starData.astroId); + ref var tinderComponent = ref hiveSystem.tinders.buffer[packet.TinderId]; if (tinderComponent.id != packet.TinderId) return; diff --git a/NebulaNetwork/PacketProcessors/Combat/GroundEnemy/DFGLaunchAssaultProcessor.cs b/NebulaNetwork/PacketProcessors/Combat/GroundEnemy/DFGLaunchAssaultProcessor.cs index 81ca718f6..5b65f7241 100644 --- a/NebulaNetwork/PacketProcessors/Combat/GroundEnemy/DFGLaunchAssaultProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Combat/GroundEnemy/DFGLaunchAssaultProcessor.cs @@ -18,7 +18,12 @@ public class DFGLaunchAssaultProcessor : PacketProcessor protected override void ProcessPacket(DFGLaunchAssaultPacket packet, NebulaConnection conn) { var factory = GameMain.galaxy.PlanetById(packet.PlanetId)?.factory; - if (factory == null) return; + if (factory == null) + { + // Display message in chat if it can't show in UIDarkFogMonitor + Multiplayer.Session.Enemies.DisplayPlanetPingMessage("Planetary base is attacking".Translate(), packet.PlanetId, packet.TarPos.ToVector3()); + return; + } using (Multiplayer.Session.Combat.IsIncomingRequest.On()) { diff --git a/NebulaNetwork/PacketProcessors/Combat/SpaceEnemy/DFSLaunchLancerAssaultProcessor.cs b/NebulaNetwork/PacketProcessors/Combat/SpaceEnemy/DFSLaunchLancerAssaultProcessor.cs index aa31e8fd4..629c4d04a 100644 --- a/NebulaNetwork/PacketProcessors/Combat/SpaceEnemy/DFSLaunchLancerAssaultProcessor.cs +++ b/NebulaNetwork/PacketProcessors/Combat/SpaceEnemy/DFSLaunchLancerAssaultProcessor.cs @@ -17,6 +17,7 @@ public class DFSLaunchLancerAssaultProcessor : PacketProcessor 0) + { + Multiplayer.Session.Enemies.DisplayPlanetPingMessage("Relay lands on planet".Translate(), __instance.targetAstroId, __instance.targetLPos); + } + } + [HarmonyPrefix] [HarmonyPatch(nameof(DFRelayComponent.ArriveDock))] public static bool ArriveDock_Prefix(DFRelayComponent __instance) @@ -49,6 +62,16 @@ public static bool ArriveDock_Prefix(DFRelayComponent __instance) public static bool LeaveBase_Prefix(DFRelayComponent __instance) { if (!Multiplayer.IsActive) return true; + + if (Multiplayer.Session.IsServer || Multiplayer.Session.Enemies.IsIncomingRelayRequest) + { + var planet = GameMain.galaxy.PlanetById(__instance.targetAstroId); + if (planet != null) + { + Multiplayer.Session.Enemies.DisplayPlanetPingMessage("Relay leaves from planet", __instance.targetAstroId, __instance.targetLPos); + } + } + if (Multiplayer.Session.IsClient) return Multiplayer.Session.Enemies.IsIncomingRelayRequest; Multiplayer.Session.Network.SendPacket(new DFRelayLeaveBasePacket(__instance)); diff --git a/NebulaPatcher/Patches/Dynamic/DFTinderComponent_Patch.cs b/NebulaPatcher/Patches/Dynamic/DFTinderComponent_Patch.cs index 2308d7301..6a4e8db4f 100644 --- a/NebulaPatcher/Patches/Dynamic/DFTinderComponent_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/DFTinderComponent_Patch.cs @@ -24,6 +24,7 @@ public static bool DispatchFromHive_Prefix(ref DFTinderComponent __instance, int { __instance.targetHiveAstroId = _targetHiveAstroId; Multiplayer.Session.Network.SendPacket(new DFTinderDispatchPacket(__instance)); + Multiplayer.Session.Enemies.DisplayAstroMessage("Dark Fog seed send out from".Translate(), hive1.starData.astroId); } return true; } diff --git a/NebulaPatcher/Patches/Dynamic/EnemyDFHiveSystem_Patch.cs b/NebulaPatcher/Patches/Dynamic/EnemyDFHiveSystem_Patch.cs index 9cff73351..b90350b09 100644 --- a/NebulaPatcher/Patches/Dynamic/EnemyDFHiveSystem_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/EnemyDFHiveSystem_Patch.cs @@ -2,6 +2,7 @@ using System; using HarmonyLib; +using NebulaAPI.DataStructures; using NebulaModel.Packets.Combat.DFHive; using NebulaModel.Packets.Combat.SpaceEnemy; using NebulaWorld; @@ -236,6 +237,7 @@ public static bool LaunchLancerAssault_Prefix(EnemyDFHiveSystem __instance, EAgg var packet = new DFSLaunchLancerAssaultPacket(in __instance, aggressiveLevel, in tarPos, in maxHatredPos, targetAstroId, unitCount0, unitThreat); Multiplayer.Session.Server.SendPacket(packet); + Multiplayer.Session.Enemies.DisplayAstroMessage("Space hive is attacking".Translate(), packet.TargetAstroId); return true; } diff --git a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs index 802ad2e99..d27676b5d 100644 --- a/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs +++ b/NebulaPatcher/Patches/Dynamic/GameData_Patch.cs @@ -320,7 +320,6 @@ public static void GameTick_Postfix(GameData __instance, long time) Multiplayer.Session.Couriers.GameTick(); Multiplayer.Session.Belts.GameTick(); Multiplayer.Session.Combat.GameTick(); - Multiplayer.Session.Enemies.GameTick(time); if (Multiplayer.Session.LocalPlayer.IsHost) { @@ -426,8 +425,7 @@ public static void LeavePlanet_Prefix() { Multiplayer.Session.Trashes.Refresh(); Multiplayer.Session.PowerTowers.ResetAndBroadcast(); - //todo:replace - //GameMain.mainPlayer.mecha.droneLogic.serving.Clear(); + Multiplayer.Session.Enemies.OnLeavePlanet(); } } diff --git a/NebulaWorld/Combat/EnemyManager.cs b/NebulaWorld/Combat/EnemyManager.cs index 65db1d800..918b49d4d 100644 --- a/NebulaWorld/Combat/EnemyManager.cs +++ b/NebulaWorld/Combat/EnemyManager.cs @@ -3,9 +3,14 @@ using System; using System.Collections.Generic; using NebulaModel.DataStructures; +using NebulaModel.DataStructures.Chat; using NebulaModel.Packets.Combat.DFHive; using NebulaModel.Packets.Combat.GroundEnemy; +using NebulaWorld.Chat.ChatLinks; +using NebulaWorld.MonoBehaviours.Local.Chat; +using UnityEngine; #pragma warning disable IDE1006 // Naming Styles +#pragma warning disable CA1822 // Mark members as static #endregion @@ -17,19 +22,13 @@ public class EnemyManager : IDisposable public readonly ToggleSwitch IsIncomingRelayRequest = new(); - public readonly Dictionary GroundTargets = new(); + public readonly Dictionary GroundTargets = []; public const bool DISABLE_DFCommunicator = true; private readonly Dictionary basePackets = []; private readonly Dictionary hivePackets = []; - public EnemyManager() - { - GroundTargets.Clear(); - basePackets.Clear(); - hivePackets.Clear(); - } public void Dispose() { @@ -39,13 +38,6 @@ public void Dispose() GC.SuppressFinalize(this); } - public void GameTick(long gameTick) - { - if (!Multiplayer.Session.IsGameLoaded) return; - // Place holder for future - var _ = gameTick; - } - public void BroadcastBaseStatusPackets(EnemyDFGroundSystem enemySystem, long gameTick) { var factoryIndex = enemySystem.factory.index; @@ -62,9 +54,9 @@ public void BroadcastBaseStatusPackets(EnemyDFGroundSystem enemySystem, long gam basePackets.Add(hashId, packet); } var levelChanged = packet.Level != dFbase.evolve.level; - if (levelChanged || (hashId % 300) == (int)gameTick % 300) + if (levelChanged || (hashId % 120) == (int)gameTick % 120) { - // Update when base level changes, or every 5s + // Update when base level changes, or every 2s to players on that planet packet.Record(in dFbase); var planetId = enemySystem.planet.id; if (levelChanged) @@ -95,6 +87,33 @@ public void BroadcastHiveStatusPackets(EnemyDFHiveSystem hive, long gameTick) } } + public void DisplayPlanetPingMessage(string text, int planetId, Vector3 pos) + { + var planet = GameMain.galaxy.PlanetById(planetId); + if (planet == null) return; + + var message = text + " [" + NavigateChatLinkHandler.FormatNavigateToPlanetPos(planetId, pos, planet.displayName) + "]"; + ChatManager.Instance.SendChatMessage(message, ChatMessageType.BattleMessage); + } + + public void DisplayAstroMessage(string text, int astroId) + { + string displayMessage = null; + + if (GameMain.galaxy.PlanetById(astroId) != null) + { + displayMessage = GameMain.galaxy.PlanetById(astroId).displayName; + } + else if (GameMain.galaxy.StarById(astroId / 100) != null) + { + displayMessage = GameMain.galaxy.StarById(astroId / 100).displayName; + } + if (displayMessage == null) return; + + var message = text + " [" + NavigateChatLinkHandler.FormatNavigateToAstro(astroId, displayMessage) + "]"; + ChatManager.Instance.SendChatMessage(message, ChatMessageType.BattleMessage); + } + public void OnFactoryLoadFinished(PlanetFactory factory) { var planetId = factory.planetId; @@ -111,6 +130,27 @@ public void OnFactoryLoadFinished(PlanetFactory factory) } } + public void OnLeavePlanet() + { + if (Multiplayer.Session.IsServer) return; + + // Reset threat on each base on the loaded factory so it doesn't show on the monitor + for (var factoryIdx = 0; factoryIdx < GameMain.data.factoryCount; factoryIdx++) + { + var factory = GameMain.data.factories[factoryIdx]; + if (factory == null) continue; + + var bases = factory.enemySystem.bases; + for (var baseId = 1; baseId < bases.cursor; baseId++) + { + if (bases[baseId] != null && bases[baseId].id == baseId && !bases[baseId].hasAssaultingUnit) + { + bases[baseId].evolve.threat = 0; + } + } + } + } + public static void SetPlanetFactoryNextEnemyId(PlanetFactory factory, int enemyId) { if (enemyId >= factory.enemyCursor)