Skip to content

Commit

Permalink
Merge pull request #659 from starfi5h/pr-ping
Browse files Browse the repository at this point in the history
Map ping and battle message
  • Loading branch information
starfi5h authored Mar 10, 2024
2 parents 506b96f + 85b1c39 commit ba73bb0
Show file tree
Hide file tree
Showing 29 changed files with 664 additions and 168 deletions.
9 changes: 5 additions & 4 deletions NebulaModel/DataStructures/Chat/ChatMessageType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ public enum ChatMessageType
PlayerMessage = 0,
SystemInfoMessage = 1,
SystemWarnMessage = 2,
CommandUsageMessage = 3,
CommandOutputMessage = 4,
CommandErrorMessage = 5,
PlayerMessagePrivate = 6
BattleMessage = 3,
CommandUsageMessage = 4,
CommandOutputMessage = 5,
CommandErrorMessage = 6,
PlayerMessagePrivate = 7
}
4 changes: 4 additions & 0 deletions NebulaModel/MultiplayerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ public bool StreamerMode
[Category("Chat")]
public bool EnableInfoMessage { get; set; } = true;

[DisplayName("Show battle notification message")]
[Category("Chat")]
public bool EnableBattleMessage { get; set; } = true;

[DisplayName("Default chat position")]
[Category("Chat")]
public ChatPosition DefaultChatPosition { get; set; } = ChatPosition.LeftMiddle;
Expand Down
3 changes: 3 additions & 0 deletions NebulaModel/Utils/ChatUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public static Color GetMessageColor(ChatMessageType messageType)
case ChatMessageType.SystemWarnMessage:
return new Color(1, 0.95f, 0, 1);

case ChatMessageType.BattleMessage:
return Color.cyan;

case ChatMessageType.CommandUsageMessage:
return new Color(1, 0.65f, 0, 1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("DF seed sent out from".Translate(), hiveSystem.starData.astroId);

ref var tinderComponent = ref hiveSystem.tinders.buffer[packet.TinderId];
if (tinderComponent.id != packet.TinderId) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ public class DFGLaunchAssaultProcessor : PacketProcessor<DFGLaunchAssaultPacket>
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())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class DFSLaunchLancerAssaultProcessor : PacketProcessor<DFSLaunchLancerAs
{
protected override void ProcessPacket(DFSLaunchLancerAssaultPacket packet, NebulaConnection conn)
{
Multiplayer.Session.Enemies.DisplayAstroMessage("Space hive is attacking".Translate(), packet.TargetAstroId);
var spaceSector = GameMain.spaceSector;
var hive = spaceSector.GetHiveByAstroId(packet.HiveAstroId);
if (hive == null) return;
Expand Down
2 changes: 1 addition & 1 deletion NebulaPatcher/Patches/Dynamic/DFGBaseComponent_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public static bool LaunchAssault_Prefix(DFGBaseComponent __instance, Vector3 tar
if (Multiplayer.Session.IsClient) return Multiplayer.Session.Combat.IsIncomingRequest.Value;

var packet = new DFGLaunchAssaultPacket(__instance, in tarPos, expandRadius, unitCount0, unitCount1, ap0, ap1, unitThreat);
Multiplayer.Session.Network.SendPacketToStar(packet, __instance.groundSystem.planet.star.id);
Multiplayer.Session.Server.SendPacket(packet);
return true;
}
}
23 changes: 23 additions & 0 deletions NebulaPatcher/Patches/Dynamic/DFRelayComponent_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ public static bool ArriveBase_Prefix(DFRelayComponent __instance)
return true;
}

[HarmonyPostfix]
[HarmonyPatch(nameof(DFRelayComponent.ArriveBase))]
public static void ArriveBase_Postfix(DFRelayComponent __instance)
{
if (!Multiplayer.IsActive) return;

var planet = GameMain.galaxy.PlanetById(__instance.targetAstroId);
if (planet != null && __instance.baseId > 0)
{
Multiplayer.Session.Enemies.DisplayPlanetPingMessage("DF relay landed on planet".Translate(), __instance.targetAstroId, __instance.targetLPos);
}
}

[HarmonyPrefix]
[HarmonyPatch(nameof(DFRelayComponent.ArriveDock))]
public static bool ArriveDock_Prefix(DFRelayComponent __instance)
Expand All @@ -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("DF relay left from planet", __instance.targetAstroId, __instance.targetLPos);
}
}

if (Multiplayer.Session.IsClient) return Multiplayer.Session.Enemies.IsIncomingRelayRequest;

Multiplayer.Session.Network.SendPacket(new DFRelayLeaveBasePacket(__instance));
Expand Down
1 change: 1 addition & 0 deletions NebulaPatcher/Patches/Dynamic/DFTinderComponent_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions NebulaPatcher/Patches/Dynamic/EnemyDFHiveSystem_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using HarmonyLib;
using NebulaAPI.DataStructures;
using NebulaModel.Packets.Combat.DFHive;
using NebulaModel.Packets.Combat.SpaceEnemy;
using NebulaWorld;
Expand Down Expand Up @@ -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;
}

Expand Down
102 changes: 102 additions & 0 deletions NebulaPatcher/Patches/Dynamic/GameCamera_Patch.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#region

using HarmonyLib;
using NebulaModel.DataStructures.Chat;
using NebulaWorld;
using NebulaWorld.GameStates;
using NebulaWorld.MonoBehaviours.Local.Chat;
using UnityEngine;

#endregion

Expand All @@ -17,4 +21,102 @@ public static bool Logic_Prefix()
// prevent NRE while doing a reconnect as a client issued through the chat command
return !(GameStatesManager.DuringReconnect && GameMain.mainPlayer == null);
}

[HarmonyPostfix]
[HarmonyPatch(nameof(GameCamera.Logic))]
public static void Logic_Postfix(GameCamera __instance)
{
if (!Multiplayer.IsActive || GameStatesManager.DuringReconnect) return;

var observingPlayerId = Multiplayer.Session.Gizmos.ObservingPlayerId;
var observingPlanetId = Multiplayer.Session.Gizmos.ObservingPlanetId;
if (observingPlayerId == 0 && observingPlanetId == 0) return;

if (VFInput.escape)
{
Multiplayer.Session.Gizmos.ObservingPlayerId = 0;
Multiplayer.Session.Gizmos.ObservingPlanetId = 0;
VFInput.UseEscape();
return;
}

if (observingPlayerId > 0)
{
TrackingPlayer(__instance, observingPlayerId);
}
if (observingPlanetId > 0)
{
TrakcingPlanetPos(__instance, observingPlanetId, Multiplayer.Session.Gizmos.ObservingPos);
}
}

private static void TrackingPlayer(GameCamera cam, ushort playerId)
{
using (Multiplayer.Session.World.GetRemotePlayersModels(out var models))
{
if (!models.TryGetValue(playerId, out var model))
{
StopTrackingPlayer(string.Format("Can't find player {0}".Translate(), playerId));
return;
}
var planetId = model.Movement.localPlanetId;
if (planetId > 0 && planetId != GameMain.mainPlayer.planetId)
{
StopTrackingPlayer(string.Format("Player {0} is on a different planet".Translate(), playerId));
return;
}
var starId = model.Movement.LocalStarId;
if (planetId == 0 && (starId <= 0 || starId != GameMain.localStar?.id))
{
StopTrackingPlayer(string.Format("Player {0} is too far away".Translate(), playerId));
return;
}
if (GameMain.mainPlayer.planetId > 0)
{
if (planetId == 0 && Multiplayer.Session.IsClient)
{
StopTrackingPlayer(string.Format("Player {0} is too far away".Translate(), playerId));
return;
}
// The local player is on the planet and viewing another player on the same planet or in space
cam.rtsTarget.position = model.PlayerTransform.position;
cam.rtsTarget.eulerAngles = Maths.SphericalRotation(cam.rtsTarget.position, 0f).eulerAngles;
}
else
{
// Both players are in space
StopTrackingPlayer(string.Format("Player {0} is too far away".Translate(), playerId));
}
}
}

private static void StopTrackingPlayer(string text)
{
ChatManager.Instance.SendChatMessage(text, ChatMessageType.CommandOutputMessage);
Multiplayer.Session.Gizmos.ObservingPlayerId = 0;
}

private static void TrakcingPlanetPos(GameCamera cam, int planetId, Vector3 pos)
{
if (planetId > 0 && planetId != GameMain.mainPlayer.planetId)
{
var planet = GameMain.galaxy.PlanetById(planetId);
if (planet != null)
{
UIRoot.instance.uiGame.OpenStarmap();
var map = UIRoot.instance.uiGame.starmap;
var starIdx = planetId / 100 - 1;
map.focusStar = map.starUIs[starIdx];
map.focusPlanet = null;
map.OnCursorFunction2Click(0);
map.screenCameraController.SetViewTarget(planet, null, null, null, VectorLF3.zero,
planet.realRadius * 0.00025 * 6.0, planet.realRadius * 0.00025 * 160.0, true, false);
}
Multiplayer.Session.Gizmos.ObservingPlanetId = 0;
return;
}
cam.rtsTarget.position = pos;
cam.rtsTarget.eulerAngles = Maths.SphericalRotation(pos, 0f).eulerAngles;

}
}
4 changes: 1 addition & 3 deletions NebulaPatcher/Patches/Dynamic/GameData_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}
}

Expand Down
69 changes: 0 additions & 69 deletions NebulaPatcher/Patches/Transpilers/PlayerControlGizmo_Transpiler.cs

This file was deleted.

5 changes: 5 additions & 0 deletions NebulaWorld/Chat/ChatLinks/CopyTextChatLinkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public void OnClick(string data)
GUIUtility.systemCopyBuffer = data;
}

public void OnRightClick(string data)
{
OnClick(data);
}

public void OnHover(string data, ChatLinkTrigger trigger, ref MonoBehaviour tipObject)
{
if (!string.IsNullOrEmpty(data))
Expand Down
2 changes: 2 additions & 0 deletions NebulaWorld/Chat/ChatLinks/IChatLinkHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface IChatLinkHandler
{
void OnClick(string data);

void OnRightClick(string data);

void OnHover(string data, ChatLinkTrigger trigger, ref MonoBehaviour tipObject);

string GetIconName(string data);
Expand Down
Loading

0 comments on commit ba73bb0

Please sign in to comment.