Skip to content

Commit f00aafd

Browse files
authored
Death markers setting (#2253)
1 parent 55afb6d commit f00aafd

20 files changed

Lines changed: 167 additions & 19 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using Nitrox.Model.Packets;
3+
4+
namespace NitroxModel.Packets;
5+
6+
[Serializable]
7+
public class DeathMarkersChanged : Packet
8+
{
9+
public bool MarkDeathPointsWithBeacon { get; }
10+
11+
public DeathMarkersChanged(bool markDeathPointsWithBeacon)
12+
{
13+
MarkDeathPointsWithBeacon = markDeathPointsWithBeacon;
14+
}
15+
}

Nitrox.Model.Subnautica/Packets/InitialPlayerSync.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class InitialPlayerSync : Packet
4242
public SessionSettings SessionSettings { get; }
4343
public bool InPrecursor { get; }
4444
public bool DisplaySurfaceWater { get; }
45+
public bool MarkDeathPointsWithBeacon { get; }
4546

4647
public InitialPlayerSync(NitroxId playerGameObjectId,
4748
bool firstTimeConnecting,
@@ -68,7 +69,8 @@ public InitialPlayerSync(NitroxId playerGameObjectId,
6869
bool keepInventoryOnDeath,
6970
SessionSettings sessionSettings,
7071
bool inPrecursor,
71-
bool displaySurfaceWater)
72+
bool displaySurfaceWater,
73+
bool markDeathPointsWithBeacon)
7274
{
7375
AssignedEscapePodId = assignedEscapePodId;
7476
PlayerGameObjectId = playerGameObjectId;
@@ -96,6 +98,7 @@ public InitialPlayerSync(NitroxId playerGameObjectId,
9698
SessionSettings = sessionSettings;
9799
InPrecursor = inPrecursor;
98100
DisplaySurfaceWater = displaySurfaceWater;
101+
MarkDeathPointsWithBeacon = markDeathPointsWithBeacon;
99102
}
100103

101104
/// <remarks>Used for deserialization</remarks>
@@ -125,7 +128,8 @@ public InitialPlayerSync(
125128
bool keepInventoryOnDeath,
126129
SessionSettings sessionSettings,
127130
bool inPrecursor,
128-
bool displaySurfaceWater)
131+
bool displaySurfaceWater,
132+
bool markDeathPointsWithBeacon)
129133
{
130134
AssignedEscapePodId = assignedEscapePodId;
131135
PlayerGameObjectId = playerGameObjectId;
@@ -153,6 +157,7 @@ public InitialPlayerSync(
153157
SessionSettings = sessionSettings;
154158
InPrecursor = inPrecursor;
155159
DisplaySurfaceWater = displaySurfaceWater;
160+
MarkDeathPointsWithBeacon = markDeathPointsWithBeacon;
156161
}
157162
}
158163
}

Nitrox.Model/Configuration/SubnauticaServerOptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public sealed partial class SubnauticaServerOptions
7070
public bool DisableConsole { get; set; }
7171
public string? AdminPassword { get; set; } = "";
7272
public bool KeepInventoryOnDeath { get; set; }
73+
74+
[PropertyDescription("Places a beacon where players die")]
75+
public bool MarkDeathPointsWithBeacon { get; set; }
7376
public bool PvpEnabled { get; set; } = true;
7477
public bool AutoSave { get; set; } = true;
7578

Nitrox.Server.Subnautica/Models/Commands/Core/HostToServerCommandContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ public async ValueTask SendAsync<T>(SessionId sessionId, T data)
8282
break;
8383
}
8484
}
85+
86+
public override string ToString() => $"'{OriginName}' #{OriginId}";
8587
}

Nitrox.Server.Subnautica/Models/Commands/Core/PlayerToServerCommandContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,6 @@ public async ValueTask SendToOthersAsync<T>(T data)
7777
break;
7878
}
7979
}
80+
81+
public override string ToString() => $"'{OriginName}' #{OriginId}";
8082
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.ComponentModel;
2+
using Nitrox.Model.DataStructures.GameLogic;
3+
using Nitrox.Server.Subnautica.Models.Commands.Core;
4+
using NitroxModel.Packets;
5+
6+
namespace Nitrox.Server.Subnautica.Models.Commands;
7+
8+
[RequiresPermission(Perms.ADMIN)]
9+
internal sealed class DeathMarkerCommand(IOptions<SubnauticaServerOptions> options) : ICommandHandler<bool>
10+
{
11+
private readonly IOptions<SubnauticaServerOptions> options = options;
12+
13+
[Description("Sets \"death markers\" setting to on/off. If \"on\", a beacon will be placed when a player dies at the location of the death.")]
14+
public async Task Execute(ICommandContext context, [Description("The true/false state to set the death markers setting to")] bool newState)
15+
{
16+
if (options.Value.MarkDeathPointsWithBeacon == newState)
17+
{
18+
await context.ReplyAsync($"{nameof(options.Value.MarkDeathPointsWithBeacon)} already set to {newState}");
19+
return;
20+
}
21+
options.Value.MarkDeathPointsWithBeacon = newState;
22+
await context.SendToAllAsync(new DeathMarkersChanged(newState));
23+
await context.SendToAllAsync($"{nameof(options.Value.MarkDeathPointsWithBeacon)} changed to \"{newState}\" by {context}");
24+
}
25+
}

Nitrox.Server.Subnautica/Models/GameLogic/JoiningManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,8 @@ private async Task SendInitialSyncAsync(SessionId sessionId, string reservationK
206206
options.Value.KeepInventoryOnDeath,
207207
sessionSettings,
208208
player.InPrecursor,
209-
player.DisplaySurfaceWater
209+
player.DisplaySurfaceWater,
210+
options.Value.MarkDeathPointsWithBeacon
210211
);
211212

212213
await packetSender.SendPacketAsync(initialPlayerSync, player.SessionId);

NitroxClient/Communication/MultiplayerSession/ConnectionState/CommunicatingState.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Threading.Tasks;
1+
using System.Threading.Tasks;
22
using NitroxClient.Communication.Abstract;
33

44
namespace NitroxClient.Communication.MultiplayerSession.ConnectionState
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using NitroxClient.Communication.Packets.Processors.Core;
2+
using NitroxClient.GameLogic;
3+
using NitroxModel.Packets;
4+
5+
namespace NitroxClient.Communication.Packets.Processors;
6+
7+
internal sealed class DeathMarkersChangedProcessor(LocalPlayer localPlayer) : IClientPacketProcessor<DeathMarkersChanged>
8+
{
9+
private readonly LocalPlayer localPlayer = localPlayer;
10+
11+
public Task Process(ClientProcessorContext context, DeathMarkersChanged packet)
12+
{
13+
localPlayer.MarkDeathPointsWithBeacon = packet.MarkDeathPointsWithBeacon;
14+
return Task.CompletedTask;
15+
}
16+
}

NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Nitrox.Model.Helper;
1+
using Nitrox.Model.Helper;
22
using Nitrox.Model.Subnautica.Packets;
33
using NitroxClient.Communication.Packets.Processors.Core;
44
using NitroxClient.GameLogic;

0 commit comments

Comments
 (0)