Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Last minute additions #2217

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using NitroxClient.GameLogic.Spawning.Metadata.Extractor.Abstract;
using NitroxClient.Unity.Helper;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;

namespace NitroxClient.GameLogic.Spawning.Metadata.Extractor;

public class KeypadMetadataExtractor : EntityMetadataExtractor<KeypadDoorConsole, KeypadMetadata>
{
public override KeypadMetadata Extract(KeypadDoorConsole keypadDoorConsole)
{
string pathToRoot = string.Empty;

if (keypadDoorConsole.root)
{
pathToRoot = keypadDoorConsole.gameObject.GetHierarchyPath(keypadDoorConsole.root);
}

return new(keypadDoorConsole.unlocked, pathToRoot);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,32 @@ public class KeypadMetadataProcessor : EntityMetadataProcessor<KeypadMetadata>
{
public override void ProcessMetadata(GameObject gameObject, KeypadMetadata metadata)
{
Log.Debug($"Received keypad metadata change for {gameObject.name} with data of {metadata}");
GameObject keypadObject = gameObject;

KeypadDoorConsole keypad = gameObject.GetComponent<KeypadDoorConsole>();
keypad.unlocked = metadata.Unlocked;

if (metadata.Unlocked)
if (metadata.PathFromRoot.Length > 0)
{
if (keypad.root)
{
keypad.root.BroadcastMessage("UnlockDoor");
}
else
Transform child = gameObject.transform.Find(metadata.PathFromRoot);
if (!child)
{
keypad.BroadcastMessage("UnlockDoor");
Log.Error($"Could not find child at path \"{child}\" from {gameObject}");
return;
}
keypadObject = child.gameObject;
}

keypad.UnlockDoor();
if (!keypadObject.TryGetComponent(out KeypadDoorConsole keypadDoorConsole))
{
Log.Error($"Could not find {nameof(KeypadDoorConsole)} on {gameObject}");
return;
}

keypadDoorConsole.unlocked = metadata.Unlocked;

if (metadata.Unlocked)
{
keypadDoorConsole.keypadUI.SetActive(false);
keypadDoorConsole.unlockIcon.SetActive(true);
keypadDoorConsole.AcceptNumberField();
}
}
}
21 changes: 19 additions & 2 deletions NitroxClient/GameLogic/Terrain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
using System.Collections.Generic;
using NitroxClient.Communication.Abstract;
using NitroxClient.Map;
using NitroxClient.Unity.Helper;
using NitroxModel.Core;
using NitroxModel.DataStructures.GameLogic;
using NitroxModel.Packets;
using NitroxModel_Subnautica.DataStructures;
using UnityEngine;
using UWE;
using WorldStreaming;

namespace NitroxClient.GameLogic;
Expand Down Expand Up @@ -77,11 +80,23 @@ public void UpdateVisibility()

}

public static void WaitForEntities()
{
// In case the player is spawned in the air, we need to hold them up while all the entities load around them
if (Player.main && !Player.main.IsUnderwater() && !Player.main.groundMotor.grounded)
{
Player.main.cinematicModeActive = true;
CoroutineHost.StartCoroutine(WaitForWorldLoad(Yielders.WaitFor2Seconds));
}
}

/// <summary>
/// Forces world streamer's to load the terrain around the MainCamera and waits until it's done to unfreeze the player.
/// </summary>
public static IEnumerator WaitForWorldLoad()
public static IEnumerator WaitForWorldLoad(WaitForSeconds initialWait = null)
{
Entities entities = NitroxServiceLocator.LocateService<Entities>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be using dependency injection, this will generate a warning from our analyzers

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't work in this static context

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terrain is already being required inside Mutiplayer mb, so static can be removed


// In WorldStreamer.CreateStreamers() three coroutines are created to constantly call UpdateCenter() on the streamers
// We force these updates so that the world streamer gets busy instantly
WorldStreamer streamerV2 = LargeWorldStreamer.main.streamerV2;
Expand All @@ -90,7 +105,9 @@ public static IEnumerator WaitForWorldLoad()
streamerV2.lowDetailOctreesStreamer.UpdateCenter(streamerV2.streamingCenter);
streamerV2.clipmapStreamer.UpdateCenter(streamerV2.streamingCenter);

yield return new WaitUntil(() => LargeWorldStreamer.main.IsWorldSettled());
yield return initialWait;

yield return new WaitUntil(() => LargeWorldStreamer.main.IsWorldSettled() && entities.EntitiesToSpawn.Count == 0);
Player.main.cinematicModeActive = false;
}
}
2 changes: 2 additions & 0 deletions NitroxClient/MonoBehaviours/Multiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ private static void SetLoadingComplete()
LoadingScreenVersionText.DisableWarningText();
DiscordClient.InitializeRPInGame(Main.multiplayerSession.AuthenticationContext.Username, remotePlayerManager.GetTotalPlayerCount(), Main.multiplayerSession.SessionPolicy.MaxConnections);
CoroutineHost.StartCoroutine(NitroxServiceLocator.LocateService<PlayerChatManager>().LoadChatKeyHint());

GameLogic.Terrain.WaitForEntities();
}

private IEnumerator InitializeLocalPlayerState()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
using System;
using System;
using System.Runtime.Serialization;
using BinaryPack.Attributes;

namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata
namespace NitroxModel.DataStructures.GameLogic.Entities.Metadata;

[Serializable]
[DataContract]
public class KeypadMetadata : EntityMetadata
{
[Serializable]
[DataContract]
public class KeypadMetadata : EntityMetadata
{
[DataMember(Order = 1)]
public bool Unlocked { get; }
[DataMember(Order = 1)]
public bool Unlocked { get; }

[IgnoreConstructor]
protected KeypadMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}
[DataMember(Order = 2)]
public string PathFromRoot { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really a metadata ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This metadata is applied to an object which doesn't necessarily hold the KeypadDoorConsole component. Thus we need a way to find the component, which varies from one prefab to another

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not do this by extracting it from the object it's on rather than using the path?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetComponentInChildren is quite costy and might pick the wrong door is there are two available in the children


[IgnoreConstructor]
protected KeypadMetadata()
{
// Constructor for serialization. Has to be "protected" for json serialization.
}

public KeypadMetadata(bool unlocked)
{
Unlocked = unlocked;
}
public KeypadMetadata(bool unlocked, string pathFromRoot)
{
Unlocked = unlocked;
PathFromRoot = pathFromRoot;
}

public override string ToString()
{
return $"[KeypadMetadata isOpen: {Unlocked}]";
}
public override string ToString()
{
return $"[{nameof(KeypadMetadata)} Unlocked: {Unlocked}, PathFromRoot: {PathFromRoot}]";
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Reflection;
using System.Reflection;
using NitroxClient.GameLogic;
using NitroxClient.GameLogic.Spawning.Metadata.Extractor;
using NitroxModel.DataStructures;
using NitroxModel.DataStructures.GameLogic.Entities.Metadata;
using NitroxModel.Helper;
Expand All @@ -12,10 +13,21 @@ public sealed partial class KeypadDoorConsole_AcceptNumberField_Patch : NitroxPa

public static void Postfix(KeypadDoorConsole __instance)
{
if (__instance.TryGetIdOrWarn(out NitroxId id))
KeypadMetadata keypadMetadata = Resolve<KeypadMetadataExtractor>().Extract(__instance);

NitroxId entityId;
if (keypadMetadata.PathFromRoot.Length > 0)
{
if (!__instance.root.TryGetIdOrWarn(out entityId))
{
return;
}
}
else if (!__instance.TryGetIdOrWarn(out entityId))
{
KeypadMetadata keypadMetadata = new(__instance.unlocked);
Resolve<Entities>().BroadcastMetadataUpdate(id, keypadMetadata);
return;
}

Resolve<Entities>().BroadcastMetadataUpdate(entityId, keypadMetadata);
}
}