From 4f8d334b115dc74edd8c916dd121fa95f3af2537 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Fri, 14 Feb 2025 23:39:25 -0500 Subject: [PATCH 01/32] Added boilerplate for DeathMarkers setting --- .../DeathMarkersChangedProcessor.cs | 19 +++++++++ .../InitialSync/PlayerInitialSyncProcessor.cs | 6 +++ NitroxClient/GameLogic/LocalPlayer.cs | 3 +- NitroxModel/Packets/DeathMarkersChanged.cs | 10 +++++ NitroxModel/Packets/InitialPlayerSync.cs | 9 ++++- .../Serialization/SubnauticaServerConfig.cs | 3 ++ .../ConsoleCommands/SetDeathMarkersCommand.cs | 39 +++++++++++++++++++ 7 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 NitroxClient/Communication/Packets/Processors/DeathMarkersChangedProcessor.cs create mode 100644 NitroxModel/Packets/DeathMarkersChanged.cs create mode 100644 NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs diff --git a/NitroxClient/Communication/Packets/Processors/DeathMarkersChangedProcessor.cs b/NitroxClient/Communication/Packets/Processors/DeathMarkersChangedProcessor.cs new file mode 100644 index 0000000000..c80a9954d4 --- /dev/null +++ b/NitroxClient/Communication/Packets/Processors/DeathMarkersChangedProcessor.cs @@ -0,0 +1,19 @@ +using NitroxClient.Communication.Packets.Processors.Abstract; +using NitroxClient.GameLogic; +using NitroxModel.Packets; + +namespace NitroxClient.Communication.Packets.Processors; +public class DeathMarkersChangedProcessor : ClientPacketProcessor +{ + private readonly LocalPlayer localPlayer; + + public DeathMarkersChangedProcessor(LocalPlayer localPlayer) + { + this.localPlayer = localPlayer; + } + + public override void Process(DeathMarkersChanged packet) + { + localPlayer.MarkDeathPointsWithBeacon = packet.MarkDeathPointsWithBeacon; + } +} diff --git a/NitroxClient/GameLogic/InitialSync/PlayerInitialSyncProcessor.cs b/NitroxClient/GameLogic/InitialSync/PlayerInitialSyncProcessor.cs index 7444dff7bc..66e67a10c7 100644 --- a/NitroxClient/GameLogic/InitialSync/PlayerInitialSyncProcessor.cs +++ b/NitroxClient/GameLogic/InitialSync/PlayerInitialSyncProcessor.cs @@ -35,6 +35,7 @@ public PlayerInitialSyncProcessor(Items item, ItemContainers itemContainers, Loc AddStep(sync => SetPlayerStats(sync.PlayerStatsData)); AddStep(sync => SetPlayerGameMode(sync.GameMode)); AddStep(sync => SetPlayerKeepInventoryOnDeath(sync.KeepInventoryOnDeath)); + AddStep(sync => SetPlayerMarkDeathPointsWithBeacon(sync.MarkDeathPointsWithBeacon)); } private void SetPlayerPermissions(Perms permissions) @@ -141,4 +142,9 @@ private void SetPlayerKeepInventoryOnDeath(bool keepInventoryOnDeath) { localPlayer.KeepInventoryOnDeath = keepInventoryOnDeath; } + + private void SetPlayerMarkDeathPointsWithBeacon(bool markDeathPointsWithBeacon) + { + localPlayer.MarkDeathPointsWithBeacon = markDeathPointsWithBeacon; + } } diff --git a/NitroxClient/GameLogic/LocalPlayer.cs b/NitroxClient/GameLogic/LocalPlayer.cs index 7a2bbbf3df..59cac65a85 100644 --- a/NitroxClient/GameLogic/LocalPlayer.cs +++ b/NitroxClient/GameLogic/LocalPlayer.cs @@ -37,10 +37,10 @@ public class LocalPlayer : ILocalNitroxPlayer /// public ushort? PlayerId => multiplayerSession?.Reservation?.PlayerId; public PlayerSettings PlayerSettings => multiplayerSession.PlayerSettings; - public Perms Permissions { get; set; } public IntroCinematicMode IntroCinematicMode { get; set; } public bool KeepInventoryOnDeath { get; set; } + public bool MarkDeathPointsWithBeacon { get; set; } public LocalPlayer(IMultiplayerSession multiplayerSession, IPacketSender packetSender, ThrottledPacketSender throttledPacketSender) { @@ -53,6 +53,7 @@ public LocalPlayer(IMultiplayerSession multiplayerSession, IPacketSender packetS Permissions = Perms.PLAYER; IntroCinematicMode = IntroCinematicMode.NONE; KeepInventoryOnDeath = false; + MarkDeathPointsWithBeacon = false; } public void BroadcastLocation(Vector3 location, Vector3 velocity, Quaternion bodyRotation, Quaternion aimingRotation) diff --git a/NitroxModel/Packets/DeathMarkersChanged.cs b/NitroxModel/Packets/DeathMarkersChanged.cs new file mode 100644 index 0000000000..80aae04c2c --- /dev/null +++ b/NitroxModel/Packets/DeathMarkersChanged.cs @@ -0,0 +1,10 @@ +namespace NitroxModel.Packets; +public class DeathMarkersChanged : Packet +{ + public bool MarkDeathPointsWithBeacon { get; } + + public DeathMarkersChanged(bool markDeathPointsWithBeacon) + { + MarkDeathPointsWithBeacon = markDeathPointsWithBeacon; + } +} diff --git a/NitroxModel/Packets/InitialPlayerSync.cs b/NitroxModel/Packets/InitialPlayerSync.cs index ad647d2930..190cdcd652 100644 --- a/NitroxModel/Packets/InitialPlayerSync.cs +++ b/NitroxModel/Packets/InitialPlayerSync.cs @@ -36,6 +36,7 @@ public class InitialPlayerSync : Packet public bool IsFirstPlayer { get; } public Dictionary BuildOperationIds { get; } public bool KeepInventoryOnDeath { get; } + public bool MarkDeathPointsWithBeacon { get; } public InitialPlayerSync(NitroxId playerGameObjectId, bool firstTimeConnecting, @@ -59,7 +60,8 @@ public InitialPlayerSync(NitroxId playerGameObjectId, TimeData timeData, bool isFirstPlayer, Dictionary buildOperationIds, - bool keepInventoryOnDeath) + bool keepInventoryOnDeath, + bool markDeathPointsWithBeacon) { AssignedEscapePodId = assignedEscapePodId; PlayerGameObjectId = playerGameObjectId; @@ -84,6 +86,7 @@ public InitialPlayerSync(NitroxId playerGameObjectId, IsFirstPlayer = isFirstPlayer; BuildOperationIds = buildOperationIds; KeepInventoryOnDeath = keepInventoryOnDeath; + MarkDeathPointsWithBeacon = markDeathPointsWithBeacon; } /// Used for deserialization @@ -110,7 +113,8 @@ public InitialPlayerSync( TimeData timeData, bool isFirstPlayer, Dictionary buildOperationIds, - bool keepInventoryOnDeath) + bool keepInventoryOnDeath, + bool markDeathPointsWithBeacon) { AssignedEscapePodId = assignedEscapePodId; PlayerGameObjectId = playerGameObjectId; @@ -135,6 +139,7 @@ public InitialPlayerSync( IsFirstPlayer = isFirstPlayer; BuildOperationIds = buildOperationIds; KeepInventoryOnDeath = keepInventoryOnDeath; + MarkDeathPointsWithBeacon = markDeathPointsWithBeacon; } } } diff --git a/NitroxModel/Serialization/SubnauticaServerConfig.cs b/NitroxModel/Serialization/SubnauticaServerConfig.cs index 0f58cf8f5e..8d742aac7b 100644 --- a/NitroxModel/Serialization/SubnauticaServerConfig.cs +++ b/NitroxModel/Serialization/SubnauticaServerConfig.cs @@ -30,6 +30,9 @@ public class SubnauticaServerConfig : NitroxConfig [PropertyDescription("Prevents players from losing items on death")] public bool KeepInventoryOnDeath { get; set; } = false; + [PropertyDescription("Places a beacon where players die")] + public bool MarkDeathPointsWithBeacon { get; set; } = false; + [PropertyDescription("Measured in milliseconds")] public int SaveInterval { diff --git a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs new file mode 100644 index 0000000000..ba732809ca --- /dev/null +++ b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs @@ -0,0 +1,39 @@ +using NitroxModel.Packets; +using System.IO; +using NitroxServer.ConsoleCommands.Abstract; +using NitroxServer.ConsoleCommands.Abstract.Type; +using NitroxServer.GameLogic; +using NitroxServer.Serialization; +using NitroxServer.Serialization.World; + +namespace NitroxServer.ConsoleCommands; +internal class SetDeathMarkersCommand : Command +{ + private readonly PlayerManager playerManager; + private readonly ServerConfig serverConfig; + + public SetDeathMarkersCommand(PlayerManager playerManager, ServerConfig serverConfig) : base("setdeathmarkers", NitroxModel.DataStructures.GameLogic.Perms.ADMIN, "Sets \"keep inventory\" setting to on/off. If \"on\", a beacon will appear at the location where a player dies.") + { + this.playerManager = playerManager; + this.serverConfig = serverConfig; + AddParameter(new TypeBoolean("state", true, "the on/off state to set death markers to")); + } + + protected override void Execute(CallArgs args) + { + bool newDeathMarkersState = args.Get(0); + using (serverConfig.Update(Path.Combine(WorldManager.SavesFolderDir, serverConfig.SaveName))) + { + if (serverConfig.MarkDeathPointsWithBeacon != newDeathMarkersState) + { + serverConfig.MarkDeathPointsWithBeacon = newDeathMarkersState; + playerManager.SendPacketToAllPlayers(new DeathMarkersChanged(newDeathMarkersState)); + SendMessageToAllPlayers($"MarkDeathPointsWithBeacon changed to \"{newDeathMarkersState}\" by {args.SenderName}"); + } + else + { + SendMessage(args.Sender, $"MarkDeathPointsWithBeacon already set to {newDeathMarkersState}"); + } + } + } +} From 9c528c47dd4eac7c3677d9d25a9dc92a3aac0cf3 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Wed, 8 Jan 2025 13:39:22 -0500 Subject: [PATCH 02/32] Create beacons on all clients --- .../Processors/SpawnDeathMarkerProcessor.cs | 19 ++++++++++++++++++ NitroxModel/Packets/SpawnDeathMarker.cs | 12 +++++++++++ .../Patches/Dynamic/Player_OnKill_Patch.cs | 20 +++++++++++++++++-- .../Processors/SpawnDeathMarkerProcessor.cs | 19 ++++++++++++++++++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 NitroxClient/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs create mode 100644 NitroxModel/Packets/SpawnDeathMarker.cs create mode 100644 NitroxServer/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs diff --git a/NitroxClient/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs b/NitroxClient/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs new file mode 100644 index 0000000000..99da5d1ffa --- /dev/null +++ b/NitroxClient/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs @@ -0,0 +1,19 @@ +using NitroxClient.Communication.Packets.Processors.Abstract; +using NitroxClient.GameLogic.Spawning.WorldEntities; +using NitroxModel.DataStructures; +using NitroxModel.Packets; +using NitroxModel_Subnautica.DataStructures; +using UnityEngine; + +namespace NitroxClient.Communication.Packets.Processors; +public class SpawnDeathMarkerProcessor : ClientPacketProcessor +{ + public override void Process(SpawnDeathMarker packet) + { + if (!DefaultWorldEntitySpawner.TryCreateGameObjectSync(TechType.Beacon, "7b019de0-db51-4017-8812-2531b808228d", new NitroxId(), out GameObject createdBeacon)) + { + Log.Error("!!! Error occured in spawning death beacon"); + } + createdBeacon.transform.position = packet.spawnPosition.ToUnity(); + } +} diff --git a/NitroxModel/Packets/SpawnDeathMarker.cs b/NitroxModel/Packets/SpawnDeathMarker.cs new file mode 100644 index 0000000000..0f83a83ecd --- /dev/null +++ b/NitroxModel/Packets/SpawnDeathMarker.cs @@ -0,0 +1,12 @@ +using NitroxModel.DataStructures.Unity; + +namespace NitroxModel.Packets; +public class SpawnDeathMarker : Packet +{ + public NitroxVector3 spawnPosition { get; } + + public SpawnDeathMarker(NitroxVector3 spawnPosition) + { + this.spawnPosition = spawnPosition; + } +} diff --git a/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs b/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs index 7b19648056..37dfd80658 100644 --- a/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs +++ b/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs @@ -1,10 +1,16 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Reflection.Emit; using HarmonyLib; +using NitroxClient.Communication.Abstract; +using NitroxClient.GameLogic; +using NitroxClient.GameLogic.Spawning.WorldEntities; +using NitroxModel.DataStructures; +using NitroxModel.DataStructures.Unity; using NitroxModel.Helper; - +using NitroxModel.Packets; +using UnityEngine; namespace NitroxPatcher.Patches.Dynamic; public sealed partial class Player_OnKill_Patch : NitroxPatch, IDynamicPatch @@ -12,6 +18,16 @@ public sealed partial class Player_OnKill_Patch : NitroxPatch, IDynamicPatch private static readonly MethodInfo TARGET_METHOD = Reflect.Method((Player t) => t.OnKill(default(DamageType))); private static readonly MethodInfo SKIP_METHOD = Reflect.Method(() => GameModeUtils.IsPermadeath()); + + public static bool Prefix(Player __instance) + { + if (Resolve().MarkDeathPointsWithBeacon) + { + Resolve().Send(new SpawnDeathMarker(new NitroxVector3(__instance.lastPosition.x, __instance.lastPosition.y, __instance.lastPosition.z))); + } + return true; + } + public static IEnumerable Transpiler(MethodBase original, IEnumerable instructions) { List instructionList = instructions.ToList(); diff --git a/NitroxServer/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs b/NitroxServer/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs new file mode 100644 index 0000000000..19b64f6635 --- /dev/null +++ b/NitroxServer/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs @@ -0,0 +1,19 @@ +using NitroxModel.Packets; +using NitroxServer.Communication.Packets.Processors.Abstract; +using NitroxServer.GameLogic; + +namespace NitroxServer.Communication.Packets.Processors; +public class SpawnDeathMarkerProcessor : AuthenticatedPacketProcessor +{ + private readonly PlayerManager playerManager; + + public SpawnDeathMarkerProcessor(PlayerManager playerManager) + { + this.playerManager = playerManager; + } + + public override void Process(SpawnDeathMarker packet, Player player) + { + playerManager.SendPacketToAllPlayers(packet); + } +} From aa32a3da79188c8fa8fe4d047214f9a61a339371 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Wed, 8 Jan 2025 16:07:34 -0500 Subject: [PATCH 03/32] Fix syntax error --- .../Processors/PlayerJoiningMultiplayerSessionProcessor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NitroxServer/Communication/Packets/Processors/PlayerJoiningMultiplayerSessionProcessor.cs b/NitroxServer/Communication/Packets/Processors/PlayerJoiningMultiplayerSessionProcessor.cs index 2f2bb2d892..8578e04547 100644 --- a/NitroxServer/Communication/Packets/Processors/PlayerJoiningMultiplayerSessionProcessor.cs +++ b/NitroxServer/Communication/Packets/Processors/PlayerJoiningMultiplayerSessionProcessor.cs @@ -87,7 +87,8 @@ public override void Process(PlayerJoiningMultiplayerSession packet, INitroxConn storyManager.GetTimeData(), isFirstPlayer, BuildingManager.GetEntitiesOperations(globalRootEntities), - serverConfig.KeepInventoryOnDeath + serverConfig.KeepInventoryOnDeath, + serverConfig.MarkDeathPointsWithBeacon ); player.SendPacket(initialPlayerSync); From bc433fef4053a3539c62ebfa7b3367377eabef0b Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Thu, 9 Jan 2025 22:01:37 -0500 Subject: [PATCH 04/32] Shift to using the existing PlayerDeathEvent packet to trigger the beacon spawns, beacon spawn code working --- .../Processors/PlayerDeathProcessor.cs | 52 +++++++++++++++++-- .../Processors/SpawnDeathMarkerProcessor.cs | 19 ------- NitroxClient/GameLogic/LocalPlayer.cs | 3 ++ NitroxModel/Packets/SpawnDeathMarker.cs | 12 ----- .../Patches/Dynamic/Player_OnKill_Patch.cs | 9 ---- .../Processors/SpawnDeathMarkerProcessor.cs | 19 ------- 6 files changed, 52 insertions(+), 62 deletions(-) delete mode 100644 NitroxClient/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs delete mode 100644 NitroxModel/Packets/SpawnDeathMarker.cs delete mode 100644 NitroxServer/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index 981ebe24bb..8393a0ff61 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -1,17 +1,27 @@ -using NitroxClient.Communication.Packets.Processors.Abstract; +using System.Collections; +using NitroxClient.Communication.Packets.Processors.Abstract; using NitroxClient.GameLogic; +using NitroxClient.GameLogic.Spawning.WorldEntities; +using NitroxModel.DataStructures; +using NitroxModel.DataStructures.Unity; using NitroxModel.Helper; using NitroxModel.Packets; +using NitroxModel_Subnautica.DataStructures; +using UnityEngine; +using UWE; +using static HandReticle; namespace NitroxClient.Communication.Packets.Processors; public class PlayerDeathProcessor : ClientPacketProcessor { private readonly PlayerManager playerManager; + private readonly LocalPlayer localPlayer; - public PlayerDeathProcessor(PlayerManager playerManager) + public PlayerDeathProcessor(PlayerManager playerManager, LocalPlayer localPlayer) { this.playerManager = playerManager; + this.localPlayer = localPlayer; } public override void Process(PlayerDeathEvent playerDeath) @@ -19,8 +29,44 @@ public override void Process(PlayerDeathEvent playerDeath) RemotePlayer player = Validate.IsPresent(playerManager.Find(playerDeath.PlayerId)); Log.Debug($"{player.PlayerName} died"); Log.InGame(Language.main.Get("Nitrox_PlayerDied").Replace("{PLAYER}", player.PlayerName)); + Log.InGame($"player died at {playerDeath.DeathPosition.X}, {playerDeath.DeathPosition.Y}, {playerDeath.DeathPosition.Z}"); player.PlayerDeathEvent.Trigger(player); - + if (localPlayer.MarkDeathPointsWithBeacon) + { + CoroutineHost.StartCoroutine(SpawnDeathBeacon(playerDeath.DeathPosition, player.PlayerName)); + } // TODO: Add any death related triggers (i.e. scoreboard updates, rewards, etc.) } + public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) + { + TaskResult result = new TaskResult(); + yield return CraftData.InstantiateFromPrefabAsync(TechType.Beacon, result, false); + GameObject beacon = result.Get(); + if(beacon != null) + { + CrafterLogic.NotifyCraftEnd(beacon, TechType.Beacon); + Pickupable item = beacon.GetComponent(); + if(item != null) + { + item.Drop(location.ToUnity(), new Vector3(0,0,0), false); + beacon.GetComponent().label = $"{playerName}'s death"; + CoroutineHost.StartCoroutine(TimedDestroyGameObject(beacon, 900)); + } + else + { + Log.Error("Something went wrong in using the pickupable!"); + } + } + else + { + Log.Error("!!! something went wrong during beacon initialization"); + } + yield break; + } + private static IEnumerator TimedDestroyGameObject(GameObject gameObj, float durationS) + { + yield return new WaitForSeconds(durationS); + GameObject.Destroy(gameObj); + yield break; + } } diff --git a/NitroxClient/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs b/NitroxClient/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs deleted file mode 100644 index 99da5d1ffa..0000000000 --- a/NitroxClient/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs +++ /dev/null @@ -1,19 +0,0 @@ -using NitroxClient.Communication.Packets.Processors.Abstract; -using NitroxClient.GameLogic.Spawning.WorldEntities; -using NitroxModel.DataStructures; -using NitroxModel.Packets; -using NitroxModel_Subnautica.DataStructures; -using UnityEngine; - -namespace NitroxClient.Communication.Packets.Processors; -public class SpawnDeathMarkerProcessor : ClientPacketProcessor -{ - public override void Process(SpawnDeathMarker packet) - { - if (!DefaultWorldEntitySpawner.TryCreateGameObjectSync(TechType.Beacon, "7b019de0-db51-4017-8812-2531b808228d", new NitroxId(), out GameObject createdBeacon)) - { - Log.Error("!!! Error occured in spawning death beacon"); - } - createdBeacon.transform.position = packet.spawnPosition.ToUnity(); - } -} diff --git a/NitroxClient/GameLogic/LocalPlayer.cs b/NitroxClient/GameLogic/LocalPlayer.cs index 59cac65a85..8cd3c77ff4 100644 --- a/NitroxClient/GameLogic/LocalPlayer.cs +++ b/NitroxClient/GameLogic/LocalPlayer.cs @@ -1,5 +1,6 @@ using System; using NitroxClient.Communication.Abstract; +using NitroxClient.Communication.Packets.Processors; using NitroxClient.GameLogic.PlayerLogic.PlayerModel; using NitroxClient.GameLogic.PlayerLogic.PlayerModel.Abstract; using NitroxClient.MonoBehaviours; @@ -12,6 +13,7 @@ using NitroxModel_Subnautica.DataStructures; using UnityEngine; using UnityEngine.Rendering; +using UWE; using Object = UnityEngine.Object; namespace NitroxClient.GameLogic; @@ -89,6 +91,7 @@ public void BroadcastDeath(Vector3 deathPosition) if (PlayerId.HasValue) { packetSender.Send(new PlayerDeathEvent(PlayerId.Value, deathPosition.ToDto())); + CoroutineHost.StartCoroutine(PlayerDeathProcessor.SpawnDeathBeacon(deathPosition.ToDto(), PlayerName)); } } diff --git a/NitroxModel/Packets/SpawnDeathMarker.cs b/NitroxModel/Packets/SpawnDeathMarker.cs deleted file mode 100644 index 0f83a83ecd..0000000000 --- a/NitroxModel/Packets/SpawnDeathMarker.cs +++ /dev/null @@ -1,12 +0,0 @@ -using NitroxModel.DataStructures.Unity; - -namespace NitroxModel.Packets; -public class SpawnDeathMarker : Packet -{ - public NitroxVector3 spawnPosition { get; } - - public SpawnDeathMarker(NitroxVector3 spawnPosition) - { - this.spawnPosition = spawnPosition; - } -} diff --git a/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs b/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs index 37dfd80658..d656f3e191 100644 --- a/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs +++ b/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs @@ -19,15 +19,6 @@ public sealed partial class Player_OnKill_Patch : NitroxPatch, IDynamicPatch private static readonly MethodInfo SKIP_METHOD = Reflect.Method(() => GameModeUtils.IsPermadeath()); - public static bool Prefix(Player __instance) - { - if (Resolve().MarkDeathPointsWithBeacon) - { - Resolve().Send(new SpawnDeathMarker(new NitroxVector3(__instance.lastPosition.x, __instance.lastPosition.y, __instance.lastPosition.z))); - } - return true; - } - public static IEnumerable Transpiler(MethodBase original, IEnumerable instructions) { List instructionList = instructions.ToList(); diff --git a/NitroxServer/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs b/NitroxServer/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs deleted file mode 100644 index 19b64f6635..0000000000 --- a/NitroxServer/Communication/Packets/Processors/SpawnDeathMarkerProcessor.cs +++ /dev/null @@ -1,19 +0,0 @@ -using NitroxModel.Packets; -using NitroxServer.Communication.Packets.Processors.Abstract; -using NitroxServer.GameLogic; - -namespace NitroxServer.Communication.Packets.Processors; -public class SpawnDeathMarkerProcessor : AuthenticatedPacketProcessor -{ - private readonly PlayerManager playerManager; - - public SpawnDeathMarkerProcessor(PlayerManager playerManager) - { - this.playerManager = playerManager; - } - - public override void Process(SpawnDeathMarker packet, Player player) - { - playerManager.SendPacketToAllPlayers(packet); - } -} From 46618e48e3d39763ca0519a292ab753455abb046 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Thu, 9 Jan 2025 22:10:34 -0500 Subject: [PATCH 05/32] Make death beacons player exclusive(only spawns for the player that triggers them) --- .../Communication/Packets/Processors/PlayerDeathProcessor.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index 8393a0ff61..34ce8e77da 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -31,10 +31,6 @@ public override void Process(PlayerDeathEvent playerDeath) Log.InGame(Language.main.Get("Nitrox_PlayerDied").Replace("{PLAYER}", player.PlayerName)); Log.InGame($"player died at {playerDeath.DeathPosition.X}, {playerDeath.DeathPosition.Y}, {playerDeath.DeathPosition.Z}"); player.PlayerDeathEvent.Trigger(player); - if (localPlayer.MarkDeathPointsWithBeacon) - { - CoroutineHost.StartCoroutine(SpawnDeathBeacon(playerDeath.DeathPosition, player.PlayerName)); - } // TODO: Add any death related triggers (i.e. scoreboard updates, rewards, etc.) } public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) From 887fc59225c952c478c05f167896d366252288ac Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Fri, 10 Jan 2025 11:36:27 -0500 Subject: [PATCH 06/32] Disconnecting also despawns all active death beacons --- .../ConnectionState/CommunicatingState.cs | 4 ++- .../Processors/PlayerDeathProcessor.cs | 33 ++++++++++++++----- NitroxClient/GameLogic/LocalPlayer.cs | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs b/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs index d07d22a42b..b3f304a358 100644 --- a/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs +++ b/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs @@ -1,5 +1,6 @@ -using System.Threading.Tasks; +using System.Threading.Tasks; using NitroxClient.Communication.Abstract; +using NitroxClient.Communication.Packets.Processors; namespace NitroxClient.Communication.MultiplayerSession.ConnectionState { @@ -12,6 +13,7 @@ public abstract class CommunicatingState : IMultiplayerSessionConnectionState public virtual void Disconnect(IMultiplayerSessionConnectionContext sessionConnectionContext) { + DeathBeacon.DespawnAllDeathBeacons(); sessionConnectionContext.ClearSessionState(); sessionConnectionContext.Client.Stop(); diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index 34ce8e77da..c3a0feea74 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; using NitroxClient.Communication.Packets.Processors.Abstract; using NitroxClient.GameLogic; using NitroxClient.GameLogic.Spawning.WorldEntities; @@ -33,20 +34,26 @@ public override void Process(PlayerDeathEvent playerDeath) player.PlayerDeathEvent.Trigger(player); // TODO: Add any death related triggers (i.e. scoreboard updates, rewards, etc.) } +} +public class DeathBeacon : MonoBehaviour +{ + private static List activeDeathBeacons = new(); + private static readonly float despawnDistance = 20f; public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) { TaskResult result = new TaskResult(); yield return CraftData.InstantiateFromPrefabAsync(TechType.Beacon, result, false); GameObject beacon = result.Get(); - if(beacon != null) + if (beacon != null) { CrafterLogic.NotifyCraftEnd(beacon, TechType.Beacon); Pickupable item = beacon.GetComponent(); - if(item != null) + if (item != null) { - item.Drop(location.ToUnity(), new Vector3(0,0,0), false); + item.Drop(location.ToUnity(), new Vector3(0, 0, 0), false); beacon.GetComponent().label = $"{playerName}'s death"; - CoroutineHost.StartCoroutine(TimedDestroyGameObject(beacon, 900)); + beacon.AddComponent(); + activeDeathBeacons.Add(beacon); } else { @@ -59,10 +66,20 @@ public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string player } yield break; } - private static IEnumerator TimedDestroyGameObject(GameObject gameObj, float durationS) + private void Update() { - yield return new WaitForSeconds(durationS); - GameObject.Destroy(gameObj); - yield break; + if(Vector3.Distance(Player.main.transform.position, transform.position) <= despawnDistance) + { + Destroy(gameObject); + activeDeathBeacons.Remove(gameObject); + } + } + public static void DespawnAllDeathBeacons() + { + foreach (GameObject beacon in activeDeathBeacons) + { + Destroy(beacon); + } + activeDeathBeacons.Clear(); } } diff --git a/NitroxClient/GameLogic/LocalPlayer.cs b/NitroxClient/GameLogic/LocalPlayer.cs index 8cd3c77ff4..ccf86de3c0 100644 --- a/NitroxClient/GameLogic/LocalPlayer.cs +++ b/NitroxClient/GameLogic/LocalPlayer.cs @@ -91,7 +91,7 @@ public void BroadcastDeath(Vector3 deathPosition) if (PlayerId.HasValue) { packetSender.Send(new PlayerDeathEvent(PlayerId.Value, deathPosition.ToDto())); - CoroutineHost.StartCoroutine(PlayerDeathProcessor.SpawnDeathBeacon(deathPosition.ToDto(), PlayerName)); + CoroutineHost.StartCoroutine(DeathBeacon.SpawnDeathBeacon(deathPosition.ToDto(), PlayerName)); } } From c309ada025b065c775d60c3a7c820bbdfe2c0425 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sat, 11 Jan 2025 21:25:48 -0500 Subject: [PATCH 07/32] Fix death beacons getting synced to other players and not disappearing on disconnect --- .../Processors/PlayerDeathProcessor.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index c3a0feea74..f6a0470724 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -3,14 +3,12 @@ using NitroxClient.Communication.Packets.Processors.Abstract; using NitroxClient.GameLogic; using NitroxClient.GameLogic.Spawning.WorldEntities; -using NitroxModel.DataStructures; +using NitroxClient.MonoBehaviours; using NitroxModel.DataStructures.Unity; using NitroxModel.Helper; using NitroxModel.Packets; using NitroxModel_Subnautica.DataStructures; using UnityEngine; -using UWE; -using static HandReticle; namespace NitroxClient.Communication.Packets.Processors; @@ -42,15 +40,18 @@ public class DeathBeacon : MonoBehaviour public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) { TaskResult result = new TaskResult(); - yield return CraftData.InstantiateFromPrefabAsync(TechType.Beacon, result, false); - GameObject beacon = result.Get(); - if (beacon != null) + yield return DefaultWorldEntitySpawner.RequestPrefab(TechType.Beacon, result); + GameObject beaconPrefab = result.Get(); + if(beaconPrefab != null) { - CrafterLogic.NotifyCraftEnd(beacon, TechType.Beacon); + GameObject beacon = Instantiate(beaconPrefab); Pickupable item = beacon.GetComponent(); if (item != null) { - item.Drop(location.ToUnity(), new Vector3(0, 0, 0), false); + using (PacketSuppressor.Suppress()) + { + item.Drop(location.ToUnity(), new Vector3(0, 0, 0), false); + } beacon.GetComponent().label = $"{playerName}'s death"; beacon.AddComponent(); activeDeathBeacons.Add(beacon); @@ -62,7 +63,7 @@ public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string player } else { - Log.Error("!!! something went wrong during beacon initialization"); + Log.Error("Something went wrong in getting the prefab"); } yield break; } From 68a31303fdf5a0c0eb72b62f0b5b32b2f9bed754 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sat, 11 Jan 2025 21:30:52 -0500 Subject: [PATCH 08/32] Remove unnecessary logging --- .../Packets/Processors/PlayerDeathProcessor.cs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index f6a0470724..2138363146 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -28,7 +28,6 @@ public override void Process(PlayerDeathEvent playerDeath) RemotePlayer player = Validate.IsPresent(playerManager.Find(playerDeath.PlayerId)); Log.Debug($"{player.PlayerName} died"); Log.InGame(Language.main.Get("Nitrox_PlayerDied").Replace("{PLAYER}", player.PlayerName)); - Log.InGame($"player died at {playerDeath.DeathPosition.X}, {playerDeath.DeathPosition.Y}, {playerDeath.DeathPosition.Z}"); player.PlayerDeathEvent.Trigger(player); // TODO: Add any death related triggers (i.e. scoreboard updates, rewards, etc.) } @@ -42,13 +41,13 @@ public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string player TaskResult result = new TaskResult(); yield return DefaultWorldEntitySpawner.RequestPrefab(TechType.Beacon, result); GameObject beaconPrefab = result.Get(); - if(beaconPrefab != null) + if (beaconPrefab != null) { GameObject beacon = Instantiate(beaconPrefab); Pickupable item = beacon.GetComponent(); if (item != null) { - using (PacketSuppressor.Suppress()) + using (PacketSuppressor.Suppress()) // Prevent the beacon from syncing to other players or the server so it will disappear on disconnect { item.Drop(location.ToUnity(), new Vector3(0, 0, 0), false); } @@ -56,14 +55,6 @@ public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string player beacon.AddComponent(); activeDeathBeacons.Add(beacon); } - else - { - Log.Error("Something went wrong in using the pickupable!"); - } - } - else - { - Log.Error("Something went wrong in getting the prefab"); } yield break; } From 90822ec6dd03681dfb445e6c61b5ec1dbdb4e80e Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sat, 11 Jan 2025 21:58:37 -0500 Subject: [PATCH 09/32] Remove unnecessary method, various semantic updates to prep for PR --- .../ConnectionState/CommunicatingState.cs | 1 - .../Processors/DeathMarkersChangedProcessor.cs | 1 + .../Packets/Processors/PlayerDeathProcessor.cs | 11 +++-------- NitroxModel/Packets/DeathMarkersChanged.cs | 1 + .../ConsoleCommands/SetDeathMarkersCommand.cs | 3 ++- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs b/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs index b3f304a358..c735df9051 100644 --- a/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs +++ b/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs @@ -13,7 +13,6 @@ public abstract class CommunicatingState : IMultiplayerSessionConnectionState public virtual void Disconnect(IMultiplayerSessionConnectionContext sessionConnectionContext) { - DeathBeacon.DespawnAllDeathBeacons(); sessionConnectionContext.ClearSessionState(); sessionConnectionContext.Client.Stop(); diff --git a/NitroxClient/Communication/Packets/Processors/DeathMarkersChangedProcessor.cs b/NitroxClient/Communication/Packets/Processors/DeathMarkersChangedProcessor.cs index c80a9954d4..e2645c9edb 100644 --- a/NitroxClient/Communication/Packets/Processors/DeathMarkersChangedProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/DeathMarkersChangedProcessor.cs @@ -3,6 +3,7 @@ using NitroxModel.Packets; namespace NitroxClient.Communication.Packets.Processors; + public class DeathMarkersChangedProcessor : ClientPacketProcessor { private readonly LocalPlayer localPlayer; diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index 2138363146..f5adc8df2b 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -32,10 +32,12 @@ public override void Process(PlayerDeathEvent playerDeath) // TODO: Add any death related triggers (i.e. scoreboard updates, rewards, etc.) } } + public class DeathBeacon : MonoBehaviour { private static List activeDeathBeacons = new(); private static readonly float despawnDistance = 20f; + public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) { TaskResult result = new TaskResult(); @@ -58,6 +60,7 @@ public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string player } yield break; } + private void Update() { if(Vector3.Distance(Player.main.transform.position, transform.position) <= despawnDistance) @@ -66,12 +69,4 @@ private void Update() activeDeathBeacons.Remove(gameObject); } } - public static void DespawnAllDeathBeacons() - { - foreach (GameObject beacon in activeDeathBeacons) - { - Destroy(beacon); - } - activeDeathBeacons.Clear(); - } } diff --git a/NitroxModel/Packets/DeathMarkersChanged.cs b/NitroxModel/Packets/DeathMarkersChanged.cs index 80aae04c2c..fe26c2a029 100644 --- a/NitroxModel/Packets/DeathMarkersChanged.cs +++ b/NitroxModel/Packets/DeathMarkersChanged.cs @@ -1,4 +1,5 @@ namespace NitroxModel.Packets; + public class DeathMarkersChanged : Packet { public bool MarkDeathPointsWithBeacon { get; } diff --git a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs index ba732809ca..dd964559b1 100644 --- a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs +++ b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs @@ -7,12 +7,13 @@ using NitroxServer.Serialization.World; namespace NitroxServer.ConsoleCommands; + internal class SetDeathMarkersCommand : Command { private readonly PlayerManager playerManager; private readonly ServerConfig serverConfig; - public SetDeathMarkersCommand(PlayerManager playerManager, ServerConfig serverConfig) : base("setdeathmarkers", NitroxModel.DataStructures.GameLogic.Perms.ADMIN, "Sets \"keep inventory\" setting to on/off. If \"on\", a beacon will appear at the location where a player dies.") + public SetDeathMarkersCommand(PlayerManager playerManager, ServerConfig serverConfig) : base("setdeathmarkers", NitroxModel.DataStructures.GameLogic.Perms.ADMIN, "Sets \"Death Markers\" setting to on/off. If \"on\", a beacon will appear at the location where a player dies.") { this.playerManager = playerManager; this.serverConfig = serverConfig; From b12d092322bb0467b6d62d904d2334eb07022b51 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sun, 12 Jan 2025 11:05:49 -0500 Subject: [PATCH 10/32] Fixed a random import that was accidentally added --- .../MultiplayerSession/ConnectionState/CommunicatingState.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs b/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs index c735df9051..2557c9e6d0 100644 --- a/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs +++ b/NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs @@ -1,6 +1,5 @@ using System.Threading.Tasks; using NitroxClient.Communication.Abstract; -using NitroxClient.Communication.Packets.Processors; namespace NitroxClient.Communication.MultiplayerSession.ConnectionState { From c6ad6ef976079c798faabf5e94c7090d2157c20f Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sun, 12 Jan 2025 11:02:27 -0500 Subject: [PATCH 11/32] Update NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs Co-authored-by: Coding-Hen <8798074+Coding-Hen@users.noreply.github.com> --- NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs index dd964559b1..7a222f7391 100644 --- a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs +++ b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs @@ -17,7 +17,7 @@ public SetDeathMarkersCommand(PlayerManager playerManager, ServerConfig serverCo { this.playerManager = playerManager; this.serverConfig = serverConfig; - AddParameter(new TypeBoolean("state", true, "the on/off state to set death markers to")); + AddParameter(new TypeBoolean("state", true, "the on/off state of if a death marker is spawned on death")); } protected override void Execute(CallArgs args) From 54596acc6d5571ba4527bddc5eaa83a52d17ef36 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sun, 12 Jan 2025 16:57:29 -0500 Subject: [PATCH 12/32] Fixed deathbeacons on land --- .../Packets/Processors/PlayerDeathProcessor.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index f5adc8df2b..2542b7da0d 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -35,7 +35,6 @@ public override void Process(PlayerDeathEvent playerDeath) public class DeathBeacon : MonoBehaviour { - private static List activeDeathBeacons = new(); private static readonly float despawnDistance = 20f; public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) @@ -54,9 +53,9 @@ public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string player item.Drop(location.ToUnity(), new Vector3(0, 0, 0), false); } beacon.GetComponent().label = $"{playerName}'s death"; - beacon.AddComponent(); - activeDeathBeacons.Add(beacon); - } + beacon.GetComponent().aboveWaterGravity = 0; + beacon.GetComponent().aboveWaterDrag = 10; // Object has a miniscule velocity in a random error from floating point error, need to add drag or object will drift + beacon.AddComponent(); } } yield break; } @@ -66,7 +65,6 @@ private void Update() if(Vector3.Distance(Player.main.transform.position, transform.position) <= despawnDistance) { Destroy(gameObject); - activeDeathBeacons.Remove(gameObject); } } } From 30ab97a7b955d6438321272a05f2afc752e1e286 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sun, 12 Jan 2025 17:14:40 -0500 Subject: [PATCH 13/32] Switch to using blank gameobjects instead of actual beacons --- .../Processors/PlayerDeathProcessor.cs | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index 2542b7da0d..aa153256a1 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -39,24 +39,15 @@ public class DeathBeacon : MonoBehaviour public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) { - TaskResult result = new TaskResult(); - yield return DefaultWorldEntitySpawner.RequestPrefab(TechType.Beacon, result); - GameObject beaconPrefab = result.Get(); - if (beaconPrefab != null) - { - GameObject beacon = Instantiate(beaconPrefab); - Pickupable item = beacon.GetComponent(); - if (item != null) - { - using (PacketSuppressor.Suppress()) // Prevent the beacon from syncing to other players or the server so it will disappear on disconnect - { - item.Drop(location.ToUnity(), new Vector3(0, 0, 0), false); - } - beacon.GetComponent().label = $"{playerName}'s death"; - beacon.GetComponent().aboveWaterGravity = 0; - beacon.GetComponent().aboveWaterDrag = 10; // Object has a miniscule velocity in a random error from floating point error, need to add drag or object will drift - beacon.AddComponent(); } - } + GameObject beacon = new(); + PingInstance signal = beacon.AddComponent(); + signal.pingType = PingType.Signal; + signal.displayPingInManager = true; + signal.origin = beacon.transform; + signal._label = $"{playerName}'s death"; + beacon.transform.position = location.ToUnity(); + beacon.AddComponent(); + signal.Initialize(); yield break; } From c20ea8c107188d0011799aa42d2549a53b20a104 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Wed, 15 Jan 2025 23:35:06 -0500 Subject: [PATCH 14/32] Added missing using --- NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs index 7a222f7391..9f72c31d51 100644 --- a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs +++ b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs @@ -1,5 +1,6 @@ -using NitroxModel.Packets; using System.IO; +using NitroxModel.DataStructures.GameLogic; +using NitroxModel.Packets; using NitroxServer.ConsoleCommands.Abstract; using NitroxServer.ConsoleCommands.Abstract.Type; using NitroxServer.GameLogic; @@ -13,7 +14,7 @@ internal class SetDeathMarkersCommand : Command private readonly PlayerManager playerManager; private readonly ServerConfig serverConfig; - public SetDeathMarkersCommand(PlayerManager playerManager, ServerConfig serverConfig) : base("setdeathmarkers", NitroxModel.DataStructures.GameLogic.Perms.ADMIN, "Sets \"Death Markers\" setting to on/off. If \"on\", a beacon will appear at the location where a player dies.") + public SetDeathMarkersCommand(PlayerManager playerManager, ServerConfig serverConfig) : base("setdeathmarkers", Perms.ADMIN, "Sets \"Death Markers\" setting to on/off. If \"on\", a beacon will appear at the location where a player dies.") { this.playerManager = playerManager; this.serverConfig = serverConfig; From e2310197d0f30708a52c0da9ea9ec21f94d01be6 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Wed, 15 Jan 2025 23:38:32 -0500 Subject: [PATCH 15/32] Removed unneeded changes --- NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs b/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs index d656f3e191..e8195e0bdf 100644 --- a/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs +++ b/NitroxPatcher/Patches/Dynamic/Player_OnKill_Patch.cs @@ -3,14 +3,8 @@ using System.Reflection; using System.Reflection.Emit; using HarmonyLib; -using NitroxClient.Communication.Abstract; -using NitroxClient.GameLogic; -using NitroxClient.GameLogic.Spawning.WorldEntities; -using NitroxModel.DataStructures; -using NitroxModel.DataStructures.Unity; using NitroxModel.Helper; -using NitroxModel.Packets; -using UnityEngine; + namespace NitroxPatcher.Patches.Dynamic; public sealed partial class Player_OnKill_Patch : NitroxPatch, IDynamicPatch From 481dc6a2ae17628d9313b1ae59766cb067c1c592 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Wed, 15 Jan 2025 23:43:06 -0500 Subject: [PATCH 16/32] Moved DeathBeacon class to its own file --- .../Processors/PlayerDeathProcessor.cs | 34 ------------------- NitroxClient/GameLogic/LocalPlayer.cs | 1 - .../MonoBehaviours/Gui/InGame/DeathBeacon.cs | 31 +++++++++++++++++ 3 files changed, 31 insertions(+), 35 deletions(-) create mode 100644 NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index aa153256a1..861a6a5e4d 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -1,14 +1,7 @@ -using System.Collections; -using System.Collections.Generic; using NitroxClient.Communication.Packets.Processors.Abstract; using NitroxClient.GameLogic; -using NitroxClient.GameLogic.Spawning.WorldEntities; -using NitroxClient.MonoBehaviours; -using NitroxModel.DataStructures.Unity; using NitroxModel.Helper; using NitroxModel.Packets; -using NitroxModel_Subnautica.DataStructures; -using UnityEngine; namespace NitroxClient.Communication.Packets.Processors; @@ -32,30 +25,3 @@ public override void Process(PlayerDeathEvent playerDeath) // TODO: Add any death related triggers (i.e. scoreboard updates, rewards, etc.) } } - -public class DeathBeacon : MonoBehaviour -{ - private static readonly float despawnDistance = 20f; - - public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) - { - GameObject beacon = new(); - PingInstance signal = beacon.AddComponent(); - signal.pingType = PingType.Signal; - signal.displayPingInManager = true; - signal.origin = beacon.transform; - signal._label = $"{playerName}'s death"; - beacon.transform.position = location.ToUnity(); - beacon.AddComponent(); - signal.Initialize(); - yield break; - } - - private void Update() - { - if(Vector3.Distance(Player.main.transform.position, transform.position) <= despawnDistance) - { - Destroy(gameObject); - } - } -} diff --git a/NitroxClient/GameLogic/LocalPlayer.cs b/NitroxClient/GameLogic/LocalPlayer.cs index ccf86de3c0..68a0520dd2 100644 --- a/NitroxClient/GameLogic/LocalPlayer.cs +++ b/NitroxClient/GameLogic/LocalPlayer.cs @@ -1,6 +1,5 @@ using System; using NitroxClient.Communication.Abstract; -using NitroxClient.Communication.Packets.Processors; using NitroxClient.GameLogic.PlayerLogic.PlayerModel; using NitroxClient.GameLogic.PlayerLogic.PlayerModel.Abstract; using NitroxClient.MonoBehaviours; diff --git a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs new file mode 100644 index 0000000000..af6146821a --- /dev/null +++ b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs @@ -0,0 +1,31 @@ +using System.Collections; +using NitroxModel.DataStructures.Unity; +using NitroxModel_Subnautica.DataStructures; +using UnityEngine; + +public class DeathBeacon : MonoBehaviour +{ + private static readonly float despawnDistance = 20f; + + public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) + { + GameObject beacon = new(); + PingInstance signal = beacon.AddComponent(); + signal.pingType = PingType.Signal; + signal.displayPingInManager = true; + signal.origin = beacon.transform; + signal._label = $"{playerName}'s death"; + beacon.transform.position = location.ToUnity(); + beacon.AddComponent(); + signal.Initialize(); + yield break; + } + + private void Update() + { + if (Vector3.Distance(Player.main.transform.position, transform.position) <= despawnDistance) + { + Destroy(gameObject); + } + } +} From d631a8246e3eda86cfedd29aac9c1548c5f0979e Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Wed, 15 Jan 2025 23:45:19 -0500 Subject: [PATCH 17/32] changed field to const and named deathbeacon GO --- NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs index af6146821a..7c34970163 100644 --- a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs +++ b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs @@ -5,11 +5,11 @@ public class DeathBeacon : MonoBehaviour { - private static readonly float despawnDistance = 20f; + private const float despawnDistance = 20f; public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) { - GameObject beacon = new(); + GameObject beacon = new($"{playerName}DeathBeacon"); PingInstance signal = beacon.AddComponent(); signal.pingType = PingType.Signal; signal.displayPingInManager = true; From 48e7a6d419ad1530ff99e5ea1dc4827cda2c8f4b Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Wed, 15 Jan 2025 23:52:47 -0500 Subject: [PATCH 18/32] Use InvokeRepeating and sqrMagnitude to check distances for better performance --- NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs index 7c34970163..430a9d5fa3 100644 --- a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs +++ b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs @@ -6,6 +6,8 @@ public class DeathBeacon : MonoBehaviour { private const float despawnDistance = 20f; + private const float despawnDistanceSquared = despawnDistance * despawnDistance; + private const float checkRate = 10f; // in seconds public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) { @@ -21,9 +23,13 @@ public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string player yield break; } - private void Update() + private void Start() { - if (Vector3.Distance(Player.main.transform.position, transform.position) <= despawnDistance) + InvokeRepeating("CheckPlayerDistance", 0, checkRate); + } + private void CheckPlayerDistance() + { + if ((Player.main.transform.position - transform.position).sqrMagnitude <= despawnDistanceSquared) { Destroy(gameObject); } From afaf90f03022cdedc7ed5e97274b1d306d41dc45 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Thu, 16 Jan 2025 00:00:05 -0500 Subject: [PATCH 19/32] Add translation string for death beacon label --- Nitrox.Assets.Subnautica/LanguageFiles/en.json | 1 + NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Nitrox.Assets.Subnautica/LanguageFiles/en.json b/Nitrox.Assets.Subnautica/LanguageFiles/en.json index 146565dbea..8b50d9afc9 100644 --- a/Nitrox.Assets.Subnautica/LanguageFiles/en.json +++ b/Nitrox.Assets.Subnautica/LanguageFiles/en.json @@ -58,6 +58,7 @@ "Nitrox_OK": "Ok", "Nitrox_OutOfDateClient": "Your Nitrox installation is out of date. Server: {serverVersion}, Yours: {localVersion}.", "Nitrox_OutOfDateServer": "The server runs an older version of Nitrox. Ask the server admin to upgrade the server or downgrade your Nitrox installation. Server: {serverVersion}, Yours: {localVersion}.", + "Nitrox_PlayerDeathBeaconLabel": "{PLAYER}'s death'", "Nitrox_PlayerDied": "{PLAYER} died", "Nitrox_PlayerDisconnected": "{PLAYER} disconnected", "Nitrox_PlayerJoined": "{PLAYER} joined the game.", diff --git a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs index 430a9d5fa3..f20287359f 100644 --- a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs +++ b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs @@ -16,7 +16,7 @@ public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string player signal.pingType = PingType.Signal; signal.displayPingInManager = true; signal.origin = beacon.transform; - signal._label = $"{playerName}'s death"; + signal._label = Language.main.Get("Nitrox_PlayerDeathBeaconLabel").Replace("{PLAYER}", playerName); beacon.transform.position = location.ToUnity(); beacon.AddComponent(); signal.Initialize(); From 4968b3e4008e3f3898506ea41f98ae6fa4d0a0f0 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Thu, 16 Jan 2025 17:32:33 -0500 Subject: [PATCH 20/32] implement various code review requsted changes --- Nitrox.Assets.Subnautica/LanguageFiles/en.json | 1 - .../Packets/Processors/PlayerDeathProcessor.cs | 4 +--- .../MonoBehaviours/Gui/InGame/DeathBeacon.cs | 17 ++++++++--------- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Nitrox.Assets.Subnautica/LanguageFiles/en.json b/Nitrox.Assets.Subnautica/LanguageFiles/en.json index 8b50d9afc9..146565dbea 100644 --- a/Nitrox.Assets.Subnautica/LanguageFiles/en.json +++ b/Nitrox.Assets.Subnautica/LanguageFiles/en.json @@ -58,7 +58,6 @@ "Nitrox_OK": "Ok", "Nitrox_OutOfDateClient": "Your Nitrox installation is out of date. Server: {serverVersion}, Yours: {localVersion}.", "Nitrox_OutOfDateServer": "The server runs an older version of Nitrox. Ask the server admin to upgrade the server or downgrade your Nitrox installation. Server: {serverVersion}, Yours: {localVersion}.", - "Nitrox_PlayerDeathBeaconLabel": "{PLAYER}'s death'", "Nitrox_PlayerDied": "{PLAYER} died", "Nitrox_PlayerDisconnected": "{PLAYER} disconnected", "Nitrox_PlayerJoined": "{PLAYER} joined the game.", diff --git a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs index 861a6a5e4d..7bfc5e2f8e 100644 --- a/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs +++ b/NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs @@ -8,12 +8,10 @@ namespace NitroxClient.Communication.Packets.Processors; public class PlayerDeathProcessor : ClientPacketProcessor { private readonly PlayerManager playerManager; - private readonly LocalPlayer localPlayer; - public PlayerDeathProcessor(PlayerManager playerManager, LocalPlayer localPlayer) + public PlayerDeathProcessor(PlayerManager playerManager) { this.playerManager = playerManager; - this.localPlayer = localPlayer; } public override void Process(PlayerDeathEvent playerDeath) diff --git a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs index f20287359f..088db505f7 100644 --- a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs +++ b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs @@ -5,31 +5,30 @@ public class DeathBeacon : MonoBehaviour { - private const float despawnDistance = 20f; - private const float despawnDistanceSquared = despawnDistance * despawnDistance; - private const float checkRate = 10f; // in seconds + private const float DESPAWN_DISTANCE = 20f; + private const float DESPAWN_DISTANCE_SQUARED = DESPAWN_DISTANCE * DESPAWN_DISTANCE; + private const float CHECK_RATE = 1.5f; // in seconds - public static IEnumerator SpawnDeathBeacon(NitroxVector3 location, string playerName) + public static void SpawnDeathBeacon(NitroxVector3 location, string playerName) { GameObject beacon = new($"{playerName}DeathBeacon"); + beacon.transform.position = location.ToUnity(); PingInstance signal = beacon.AddComponent(); signal.pingType = PingType.Signal; - signal.displayPingInManager = true; signal.origin = beacon.transform; signal._label = Language.main.Get("Nitrox_PlayerDeathBeaconLabel").Replace("{PLAYER}", playerName); - beacon.transform.position = location.ToUnity(); beacon.AddComponent(); + signal.displayPingInManager = true; signal.Initialize(); - yield break; } private void Start() { - InvokeRepeating("CheckPlayerDistance", 0, checkRate); + InvokeRepeating(nameof(CheckPlayerDistance), 0, CHECK_RATE); } private void CheckPlayerDistance() { - if ((Player.main.transform.position - transform.position).sqrMagnitude <= despawnDistanceSquared) + if ((Player.main.transform.position - transform.position).sqrMagnitude <= DESPAWN_DISTANCE_SQUARED) { Destroy(gameObject); } From 0ccbe3f3237ec8328ba6cbb8f3afb1c60e346745 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Thu, 16 Jan 2025 17:52:58 -0500 Subject: [PATCH 21/32] Fix error in building --- NitroxClient/GameLogic/LocalPlayer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NitroxClient/GameLogic/LocalPlayer.cs b/NitroxClient/GameLogic/LocalPlayer.cs index 68a0520dd2..4bca937041 100644 --- a/NitroxClient/GameLogic/LocalPlayer.cs +++ b/NitroxClient/GameLogic/LocalPlayer.cs @@ -90,7 +90,7 @@ public void BroadcastDeath(Vector3 deathPosition) if (PlayerId.HasValue) { packetSender.Send(new PlayerDeathEvent(PlayerId.Value, deathPosition.ToDto())); - CoroutineHost.StartCoroutine(DeathBeacon.SpawnDeathBeacon(deathPosition.ToDto(), PlayerName)); + DeathBeacon.SpawnDeathBeacon(deathPosition.ToDto(), PlayerName); } } From f20e5e0fc74424371ec1607cb6d86706093831b5 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Thu, 16 Jan 2025 18:05:01 -0500 Subject: [PATCH 22/32] Add beacon fade out --- NitroxClient/GameLogic/LocalPlayer.cs | 5 ++++- NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/NitroxClient/GameLogic/LocalPlayer.cs b/NitroxClient/GameLogic/LocalPlayer.cs index 4bca937041..f5bac2697d 100644 --- a/NitroxClient/GameLogic/LocalPlayer.cs +++ b/NitroxClient/GameLogic/LocalPlayer.cs @@ -90,7 +90,10 @@ public void BroadcastDeath(Vector3 deathPosition) if (PlayerId.HasValue) { packetSender.Send(new PlayerDeathEvent(PlayerId.Value, deathPosition.ToDto())); - DeathBeacon.SpawnDeathBeacon(deathPosition.ToDto(), PlayerName); + if (MarkDeathPointsWithBeacon) + { + DeathBeacon.SpawnDeathBeacon(deathPosition.ToDto(), PlayerName); + } } } diff --git a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs index 088db505f7..92616224cb 100644 --- a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs +++ b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs @@ -16,6 +16,7 @@ public static void SpawnDeathBeacon(NitroxVector3 location, string playerName) PingInstance signal = beacon.AddComponent(); signal.pingType = PingType.Signal; signal.origin = beacon.transform; + signal.minDist = DESPAWN_DISTANCE + 15f; signal._label = Language.main.Get("Nitrox_PlayerDeathBeaconLabel").Replace("{PLAYER}", playerName); beacon.AddComponent(); signal.displayPingInManager = true; From 47c5829601bcef7a6a84244de220978561f60495 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Thu, 16 Jan 2025 19:56:28 -0500 Subject: [PATCH 23/32] Fixed add and sort usings, as well as added a whitespace --- NitroxClient/GameLogic/LocalPlayer.cs | 1 - NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/NitroxClient/GameLogic/LocalPlayer.cs b/NitroxClient/GameLogic/LocalPlayer.cs index f5bac2697d..ffbd096144 100644 --- a/NitroxClient/GameLogic/LocalPlayer.cs +++ b/NitroxClient/GameLogic/LocalPlayer.cs @@ -12,7 +12,6 @@ using NitroxModel_Subnautica.DataStructures; using UnityEngine; using UnityEngine.Rendering; -using UWE; using Object = UnityEngine.Object; namespace NitroxClient.GameLogic; diff --git a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs index 92616224cb..41a875a331 100644 --- a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs +++ b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs @@ -1,4 +1,3 @@ -using System.Collections; using NitroxModel.DataStructures.Unity; using NitroxModel_Subnautica.DataStructures; using UnityEngine; @@ -27,6 +26,7 @@ private void Start() { InvokeRepeating(nameof(CheckPlayerDistance), 0, CHECK_RATE); } + private void CheckPlayerDistance() { if ((Player.main.transform.position - transform.position).sqrMagnitude <= DESPAWN_DISTANCE_SQUARED) From 3b4f64846314c9ded3ab157cc735f7304419f387 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Fri, 17 Jan 2025 20:52:00 -0500 Subject: [PATCH 24/32] set DeathMarkers setting to true by default --- NitroxModel/Serialization/SubnauticaServerConfig.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NitroxModel/Serialization/SubnauticaServerConfig.cs b/NitroxModel/Serialization/SubnauticaServerConfig.cs index 8d742aac7b..16f719ec43 100644 --- a/NitroxModel/Serialization/SubnauticaServerConfig.cs +++ b/NitroxModel/Serialization/SubnauticaServerConfig.cs @@ -31,7 +31,7 @@ public class SubnauticaServerConfig : NitroxConfig public bool KeepInventoryOnDeath { get; set; } = false; [PropertyDescription("Places a beacon where players die")] - public bool MarkDeathPointsWithBeacon { get; set; } = false; + public bool MarkDeathPointsWithBeacon { get; set; } = true; [PropertyDescription("Measured in milliseconds")] public int SaveInterval From 4f9fa44e0dd694d8795c3923228a71172d1ee86b Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sat, 15 Feb 2025 00:15:27 -0500 Subject: [PATCH 25/32] Fix DeathMarkers for NitroxLauncher(tested in-game for this commit) --- .../ConsoleCommands/SetDeathMarkersCommand.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs index 9f72c31d51..4d46fe86ab 100644 --- a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs +++ b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs @@ -1,30 +1,31 @@ using System.IO; using NitroxModel.DataStructures.GameLogic; using NitroxModel.Packets; +using NitroxModel.Serialization; using NitroxServer.ConsoleCommands.Abstract; using NitroxServer.ConsoleCommands.Abstract.Type; using NitroxServer.GameLogic; -using NitroxServer.Serialization; -using NitroxServer.Serialization.World; namespace NitroxServer.ConsoleCommands; internal class SetDeathMarkersCommand : Command { private readonly PlayerManager playerManager; - private readonly ServerConfig serverConfig; + private readonly SubnauticaServerConfig serverConfig; + private readonly Server server; - public SetDeathMarkersCommand(PlayerManager playerManager, ServerConfig serverConfig) : base("setdeathmarkers", Perms.ADMIN, "Sets \"Death Markers\" setting to on/off. If \"on\", a beacon will appear at the location where a player dies.") + public SetDeathMarkersCommand(PlayerManager playerManager, SubnauticaServerConfig serverConfig, Server server) : base("setdeathmarkers", Perms.ADMIN, "Sets \"Death Markers\" setting to on/off. If \"on\", a beacon will appear at the location where a player dies.") { this.playerManager = playerManager; this.serverConfig = serverConfig; + this.server = server; AddParameter(new TypeBoolean("state", true, "the on/off state of if a death marker is spawned on death")); } protected override void Execute(CallArgs args) { bool newDeathMarkersState = args.Get(0); - using (serverConfig.Update(Path.Combine(WorldManager.SavesFolderDir, serverConfig.SaveName))) + using (serverConfig.Update(Path.Combine(KeyValueStore.Instance.GetSavesFolderDir(), server.Name))) { if (serverConfig.MarkDeathPointsWithBeacon != newDeathMarkersState) { From 74beffe7f8cd60fc0f09348e78ff1aaec67a2187 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Tue, 18 Feb 2025 22:43:06 -0500 Subject: [PATCH 26/32] Added missing namespace declaration --- NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs index 41a875a331..29d7baba92 100644 --- a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs +++ b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs @@ -2,6 +2,7 @@ using NitroxModel_Subnautica.DataStructures; using UnityEngine; +namespace NitroxClient.MonoBehaviours.Gui.InGame; public class DeathBeacon : MonoBehaviour { private const float DESPAWN_DISTANCE = 20f; From 99d9ce4a15a4f8f7e580880f0a71416f043dcbe4 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Tue, 18 Feb 2025 22:45:49 -0500 Subject: [PATCH 27/32] Moved spawning of death beacon to PlayerDeath in PlayerDeathBroadcaster --- NitroxClient/GameLogic/LocalPlayer.cs | 4 ---- NitroxClient/MonoBehaviours/PlayerDeathBroadcaster.cs | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/NitroxClient/GameLogic/LocalPlayer.cs b/NitroxClient/GameLogic/LocalPlayer.cs index ffbd096144..59cac65a85 100644 --- a/NitroxClient/GameLogic/LocalPlayer.cs +++ b/NitroxClient/GameLogic/LocalPlayer.cs @@ -89,10 +89,6 @@ public void BroadcastDeath(Vector3 deathPosition) if (PlayerId.HasValue) { packetSender.Send(new PlayerDeathEvent(PlayerId.Value, deathPosition.ToDto())); - if (MarkDeathPointsWithBeacon) - { - DeathBeacon.SpawnDeathBeacon(deathPosition.ToDto(), PlayerName); - } } } diff --git a/NitroxClient/MonoBehaviours/PlayerDeathBroadcaster.cs b/NitroxClient/MonoBehaviours/PlayerDeathBroadcaster.cs index 32ff578210..7a2cda4203 100644 --- a/NitroxClient/MonoBehaviours/PlayerDeathBroadcaster.cs +++ b/NitroxClient/MonoBehaviours/PlayerDeathBroadcaster.cs @@ -1,4 +1,6 @@ using NitroxClient.GameLogic; +using NitroxClient.MonoBehaviours.Gui.InGame; +using NitroxModel_Subnautica.DataStructures; using UnityEngine; namespace NitroxClient.MonoBehaviours; @@ -16,6 +18,10 @@ public void Awake() private void PlayerDeath(Player player) { + if (localPlayer.MarkDeathPointsWithBeacon) + { + DeathBeacon.SpawnDeathBeacon(player.transform.position.ToDto(), localPlayer.PlayerName); + } localPlayer.BroadcastDeath(player.transform.position); } From 870f6a6310e45908bed8fc491a58236d4faa7f6b Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sun, 23 Feb 2025 20:09:14 -0500 Subject: [PATCH 28/32] Update NitroxModel/Packets/DeathMarkersChanged.cs Co-authored-by: rootcan <24827220+tornac1234@users.noreply.github.com> --- NitroxModel/Packets/DeathMarkersChanged.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NitroxModel/Packets/DeathMarkersChanged.cs b/NitroxModel/Packets/DeathMarkersChanged.cs index fe26c2a029..11223f04bf 100644 --- a/NitroxModel/Packets/DeathMarkersChanged.cs +++ b/NitroxModel/Packets/DeathMarkersChanged.cs @@ -1,5 +1,6 @@ namespace NitroxModel.Packets; +[Serializable] public class DeathMarkersChanged : Packet { public bool MarkDeathPointsWithBeacon { get; } From a03e8839398094a1dea59cc2d173055ee70f2138 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sun, 23 Feb 2025 20:09:22 -0500 Subject: [PATCH 29/32] Update NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs Co-authored-by: rootcan <24827220+tornac1234@users.noreply.github.com> --- NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs index 4d46fe86ab..72e057ddc2 100644 --- a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs +++ b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs @@ -19,7 +19,7 @@ public SetDeathMarkersCommand(PlayerManager playerManager, SubnauticaServerConfi this.playerManager = playerManager; this.serverConfig = serverConfig; this.server = server; - AddParameter(new TypeBoolean("state", true, "the on/off state of if a death marker is spawned on death")); + AddParameter(new TypeBoolean("state", true, "on/off to enable/disable death markers")); } protected override void Execute(CallArgs args) From 120fa3550c4366dd114dae2d8c98e2086830284d Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sun, 23 Feb 2025 20:10:14 -0500 Subject: [PATCH 30/32] Add newline between namespace and class --- NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs index 29d7baba92..412b2394f2 100644 --- a/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs +++ b/NitroxClient/MonoBehaviours/Gui/InGame/DeathBeacon.cs @@ -3,6 +3,7 @@ using UnityEngine; namespace NitroxClient.MonoBehaviours.Gui.InGame; + public class DeathBeacon : MonoBehaviour { private const float DESPAWN_DISTANCE = 20f; From 5262c91dd4b22d1cd0f1d6a1471c219a7f4c9d10 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Sun, 23 Feb 2025 20:15:38 -0500 Subject: [PATCH 31/32] Fix missing import --- NitroxModel/Packets/DeathMarkersChanged.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NitroxModel/Packets/DeathMarkersChanged.cs b/NitroxModel/Packets/DeathMarkersChanged.cs index 11223f04bf..5b598526d0 100644 --- a/NitroxModel/Packets/DeathMarkersChanged.cs +++ b/NitroxModel/Packets/DeathMarkersChanged.cs @@ -1,3 +1,5 @@ +using System; + namespace NitroxModel.Packets; [Serializable] From b63420f86418a483f817b8e54ef31592e8416e55 Mon Sep 17 00:00:00 2001 From: Adrien Bourdeaux Date: Wed, 26 Feb 2025 22:16:25 -0500 Subject: [PATCH 32/32] change setdeathmarkers to deathmarkers cmd name --- NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs index 72e057ddc2..72943efd64 100644 --- a/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs +++ b/NitroxServer/ConsoleCommands/SetDeathMarkersCommand.cs @@ -14,7 +14,7 @@ internal class SetDeathMarkersCommand : Command private readonly SubnauticaServerConfig serverConfig; private readonly Server server; - public SetDeathMarkersCommand(PlayerManager playerManager, SubnauticaServerConfig serverConfig, Server server) : base("setdeathmarkers", Perms.ADMIN, "Sets \"Death Markers\" setting to on/off. If \"on\", a beacon will appear at the location where a player dies.") + public SetDeathMarkersCommand(PlayerManager playerManager, SubnauticaServerConfig serverConfig, Server server) : base("deathmarkers", Perms.ADMIN, "Sets \"Death Markers\" setting to on/off. If \"on\", a beacon will appear at the location where a player dies.") { this.playerManager = playerManager; this.serverConfig = serverConfig;