Skip to content

Commit d18c74d

Browse files
Merge pull request #3 from OhmV-IR/DeathMarkers
Death markers
2 parents a070121 + 99d9ce4 commit d18c74d

File tree

13 files changed

+141
-8
lines changed

13 files changed

+141
-8
lines changed

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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using NitroxClient.Communication.Packets.Processors.Abstract;
2+
using NitroxClient.GameLogic;
3+
using NitroxModel.Packets;
4+
5+
namespace NitroxClient.Communication.Packets.Processors;
6+
7+
public class DeathMarkersChangedProcessor : ClientPacketProcessor<DeathMarkersChanged>
8+
{
9+
private readonly LocalPlayer localPlayer;
10+
11+
public DeathMarkersChangedProcessor(LocalPlayer localPlayer)
12+
{
13+
this.localPlayer = localPlayer;
14+
}
15+
16+
public override void Process(DeathMarkersChanged packet)
17+
{
18+
localPlayer.MarkDeathPointsWithBeacon = packet.MarkDeathPointsWithBeacon;
19+
}
20+
}

NitroxClient/Communication/Packets/Processors/PlayerDeathProcessor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using NitroxClient.Communication.Packets.Processors.Abstract;
1+
using NitroxClient.Communication.Packets.Processors.Abstract;
22
using NitroxClient.GameLogic;
33
using NitroxModel.Helper;
44
using NitroxModel.Packets;
@@ -20,7 +20,6 @@ public override void Process(PlayerDeathEvent playerDeath)
2020
Log.Debug($"{player.PlayerName} died");
2121
Log.InGame(Language.main.Get("Nitrox_PlayerDied").Replace("{PLAYER}", player.PlayerName));
2222
player.PlayerDeathEvent.Trigger(player);
23-
2423
// TODO: Add any death related triggers (i.e. scoreboard updates, rewards, etc.)
2524
}
2625
}

NitroxClient/GameLogic/InitialSync/PlayerInitialSyncProcessor.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public PlayerInitialSyncProcessor(Items item, ItemContainers itemContainers, Loc
3535
AddStep(sync => SetPlayerStats(sync.PlayerStatsData));
3636
AddStep(sync => SetPlayerGameMode(sync.GameMode));
3737
AddStep(sync => SetPlayerKeepInventoryOnDeath(sync.KeepInventoryOnDeath));
38+
AddStep(sync => SetPlayerMarkDeathPointsWithBeacon(sync.MarkDeathPointsWithBeacon));
3839
}
3940

4041
private void SetPlayerPermissions(Perms permissions)
@@ -141,4 +142,9 @@ private void SetPlayerKeepInventoryOnDeath(bool keepInventoryOnDeath)
141142
{
142143
localPlayer.KeepInventoryOnDeath = keepInventoryOnDeath;
143144
}
145+
146+
private void SetPlayerMarkDeathPointsWithBeacon(bool markDeathPointsWithBeacon)
147+
{
148+
localPlayer.MarkDeathPointsWithBeacon = markDeathPointsWithBeacon;
149+
}
144150
}

NitroxClient/GameLogic/LocalPlayer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public class LocalPlayer : ILocalNitroxPlayer
3737
/// </summary>
3838
public ushort? PlayerId => multiplayerSession?.Reservation?.PlayerId;
3939
public PlayerSettings PlayerSettings => multiplayerSession.PlayerSettings;
40-
4140
public Perms Permissions { get; set; }
4241
public IntroCinematicMode IntroCinematicMode { get; set; }
4342
public bool KeepInventoryOnDeath { get; set; }
43+
public bool MarkDeathPointsWithBeacon { get; set; }
4444

4545
public LocalPlayer(IMultiplayerSession multiplayerSession, IPacketSender packetSender, ThrottledPacketSender throttledPacketSender)
4646
{
@@ -53,6 +53,7 @@ public LocalPlayer(IMultiplayerSession multiplayerSession, IPacketSender packetS
5353
Permissions = Perms.PLAYER;
5454
IntroCinematicMode = IntroCinematicMode.NONE;
5555
KeepInventoryOnDeath = false;
56+
MarkDeathPointsWithBeacon = false;
5657
}
5758

5859
public void BroadcastLocation(Vector3 location, Vector3 velocity, Quaternion bodyRotation, Quaternion aimingRotation)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using NitroxModel.DataStructures.Unity;
2+
using NitroxModel_Subnautica.DataStructures;
3+
using UnityEngine;
4+
5+
namespace NitroxClient.MonoBehaviours.Gui.InGame;
6+
public class DeathBeacon : MonoBehaviour
7+
{
8+
private const float DESPAWN_DISTANCE = 20f;
9+
private const float DESPAWN_DISTANCE_SQUARED = DESPAWN_DISTANCE * DESPAWN_DISTANCE;
10+
private const float CHECK_RATE = 1.5f; // in seconds
11+
12+
public static void SpawnDeathBeacon(NitroxVector3 location, string playerName)
13+
{
14+
GameObject beacon = new($"{playerName}DeathBeacon");
15+
beacon.transform.position = location.ToUnity();
16+
PingInstance signal = beacon.AddComponent<PingInstance>();
17+
signal.pingType = PingType.Signal;
18+
signal.origin = beacon.transform;
19+
signal.minDist = DESPAWN_DISTANCE + 15f;
20+
signal._label = Language.main.Get("Nitrox_PlayerDeathBeaconLabel").Replace("{PLAYER}", playerName);
21+
beacon.AddComponent<DeathBeacon>();
22+
signal.displayPingInManager = true;
23+
signal.Initialize();
24+
}
25+
26+
private void Start()
27+
{
28+
InvokeRepeating(nameof(CheckPlayerDistance), 0, CHECK_RATE);
29+
}
30+
31+
private void CheckPlayerDistance()
32+
{
33+
if ((Player.main.transform.position - transform.position).sqrMagnitude <= DESPAWN_DISTANCE_SQUARED)
34+
{
35+
Destroy(gameObject);
36+
}
37+
}
38+
}

NitroxClient/MonoBehaviours/PlayerDeathBroadcaster.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using NitroxClient.GameLogic;
2+
using NitroxClient.MonoBehaviours.Gui.InGame;
3+
using NitroxModel_Subnautica.DataStructures;
24
using UnityEngine;
35

46
namespace NitroxClient.MonoBehaviours;
@@ -16,6 +18,10 @@ public void Awake()
1618

1719
private void PlayerDeath(Player player)
1820
{
21+
if (localPlayer.MarkDeathPointsWithBeacon)
22+
{
23+
DeathBeacon.SpawnDeathBeacon(player.transform.position.ToDto(), localPlayer.PlayerName);
24+
}
1925
localPlayer.BroadcastDeath(player.transform.position);
2026
}
2127

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

NitroxModel/Packets/InitialPlayerSync.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class InitialPlayerSync : Packet
3636
public bool IsFirstPlayer { get; }
3737
public Dictionary<NitroxId, int> BuildOperationIds { get; }
3838
public bool KeepInventoryOnDeath { get; }
39+
public bool MarkDeathPointsWithBeacon { get; }
3940

4041
public InitialPlayerSync(NitroxId playerGameObjectId,
4142
bool firstTimeConnecting,
@@ -59,7 +60,8 @@ public InitialPlayerSync(NitroxId playerGameObjectId,
5960
TimeData timeData,
6061
bool isFirstPlayer,
6162
Dictionary<NitroxId, int> buildOperationIds,
62-
bool keepInventoryOnDeath)
63+
bool keepInventoryOnDeath,
64+
bool markDeathPointsWithBeacon)
6365
{
6466
AssignedEscapePodId = assignedEscapePodId;
6567
PlayerGameObjectId = playerGameObjectId;
@@ -84,6 +86,7 @@ public InitialPlayerSync(NitroxId playerGameObjectId,
8486
IsFirstPlayer = isFirstPlayer;
8587
BuildOperationIds = buildOperationIds;
8688
KeepInventoryOnDeath = keepInventoryOnDeath;
89+
MarkDeathPointsWithBeacon = markDeathPointsWithBeacon;
8790
}
8891

8992
/// <remarks>Used for deserialization</remarks>
@@ -110,7 +113,8 @@ public InitialPlayerSync(
110113
TimeData timeData,
111114
bool isFirstPlayer,
112115
Dictionary<NitroxId, int> buildOperationIds,
113-
bool keepInventoryOnDeath)
116+
bool keepInventoryOnDeath,
117+
bool markDeathPointsWithBeacon)
114118
{
115119
AssignedEscapePodId = assignedEscapePodId;
116120
PlayerGameObjectId = playerGameObjectId;
@@ -135,6 +139,7 @@ public InitialPlayerSync(
135139
IsFirstPlayer = isFirstPlayer;
136140
BuildOperationIds = buildOperationIds;
137141
KeepInventoryOnDeath = keepInventoryOnDeath;
142+
MarkDeathPointsWithBeacon = markDeathPointsWithBeacon;
138143
}
139144
}
140145
}

NitroxModel/Serialization/SubnauticaServerConfig.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public class SubnauticaServerConfig : NitroxConfig<SubnauticaServerConfig>
3030
[PropertyDescription("Prevents players from losing items on death")]
3131
public bool KeepInventoryOnDeath { get; set; } = false;
3232

33+
[PropertyDescription("Places a beacon where players die")]
34+
public bool MarkDeathPointsWithBeacon { get; set; } = true;
35+
3336
[PropertyDescription("Measured in milliseconds")]
3437
public int SaveInterval
3538
{

0 commit comments

Comments
 (0)