Skip to content

Commit

Permalink
Synchronise configurable PlayerData values
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed Nov 12, 2023
1 parent 13213a8 commit 88ad3e1
Show file tree
Hide file tree
Showing 11 changed files with 1,717 additions and 50 deletions.
4 changes: 3 additions & 1 deletion HKMP/Game/Client/ClientManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Hkmp.Eventing;
using Hkmp.Fsm;
using Hkmp.Game.Client.Entity;
using Hkmp.Game.Client.Save;
using Hkmp.Game.Command.Client;
using Hkmp.Game.Server;
using Hkmp.Game.Settings;
Expand Down Expand Up @@ -179,7 +180,8 @@ ModSettings modSettings
_mapManager = new MapManager(netClient, serverSettings);

_entityManager = new EntityManager(netClient);


new SaveManager(netClient, packetManager, _entityManager).Initialize();
new PauseManager(netClient).RegisterHooks();
new FsmPatcher().RegisterHooks();

Expand Down
36 changes: 18 additions & 18 deletions HKMP/Game/Client/Entity/EntityManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ internal class EntityManager {
/// <summary>
/// Whether the scene host is determined for this scene locally.
/// </summary>
private bool _isSceneHostDetermined;
public bool IsSceneHostDetermined { get; private set; }

/// <summary>
/// Whether the client user is the scene host.
/// </summary>
private bool _isSceneHost;
public bool IsSceneHost { get; private set; }

/// <summary>
/// Queue of entity updates that have not been applied yet because of a missing entity.
Expand Down Expand Up @@ -64,13 +64,13 @@ public EntityManager(NetClient netClient) {
public void InitializeSceneHost() {
Logger.Info("We are scene host, releasing control of all registered entities");

_isSceneHost = true;
IsSceneHost = true;

foreach (var entity in _entities.Values) {
entity.InitializeHost();
}

_isSceneHostDetermined = true;
IsSceneHostDetermined = true;

CheckReceivedUpdates();
}
Expand All @@ -81,9 +81,9 @@ public void InitializeSceneHost() {
public void InitializeSceneClient() {
Logger.Info("We are scene client, taking control of all registered entities");

_isSceneHost = false;
IsSceneHost = false;

_isSceneHostDetermined = true;
IsSceneHostDetermined = true;

CheckReceivedUpdates();
}
Expand All @@ -94,7 +94,7 @@ public void InitializeSceneClient() {
public void BecomeSceneHost() {
Logger.Info("Becoming scene host");

_isSceneHost = true;
IsSceneHost = true;

foreach (var entity in _entities.Values) {
entity.MakeHost();
Expand Down Expand Up @@ -136,7 +136,7 @@ public void SpawnEntity(ushort id, EntityType spawningType, EntityType spawnedTy

var processor = new EntityProcessor {
GameObject = spawnedObject,
IsSceneHost = _isSceneHost,
IsSceneHost = IsSceneHost,
LateLoad = true,
SpawnedId = id
}.Process();
Expand All @@ -152,12 +152,12 @@ public void SpawnEntity(ushort id, EntityType spawningType, EntityType spawnedTy
/// <param name="entityUpdate">The entity update to handle.</param>
/// <param name="alreadyInSceneUpdate">Whether this is the update from the already in scene packet.</param>
public bool HandleEntityUpdate(EntityUpdate entityUpdate, bool alreadyInSceneUpdate = false) {
if (_isSceneHost) {
if (IsSceneHost) {
return true;
}

if (!_entities.TryGetValue(entityUpdate.Id, out var entity) || !_isSceneHostDetermined) {
if (_isSceneHostDetermined) {
if (!_entities.TryGetValue(entityUpdate.Id, out var entity) || !IsSceneHostDetermined) {
if (IsSceneHostDetermined) {
Logger.Debug($"Could not find entity ({entityUpdate.Id}) to apply update for; storing update for now");
} else {
Logger.Debug("Scene host is not determined yet to apply update; storing update for now");
Expand Down Expand Up @@ -193,12 +193,12 @@ public bool HandleEntityUpdate(EntityUpdate entityUpdate, bool alreadyInSceneUpd
/// <param name="entityUpdate">The reliable entity update to handle.</param>
/// <param name="alreadyInSceneUpdate">Whether this is the update from the already in scene packet.</param>
public bool HandleReliableEntityUpdate(ReliableEntityUpdate entityUpdate, bool alreadyInSceneUpdate = false) {
if (_isSceneHost) {
if (IsSceneHost) {
return true;
}

if (!_entities.TryGetValue(entityUpdate.Id, out var entity) || !_isSceneHostDetermined) {
if (_isSceneHostDetermined) {
if (!_entities.TryGetValue(entityUpdate.Id, out var entity) || !IsSceneHostDetermined) {
if (IsSceneHostDetermined) {
Logger.Debug($"Could not find entity ({entityUpdate.Id}) to apply update for; storing update for now");
} else {
Logger.Debug("Scene host is not determined yet to apply update; storing update for now");
Expand Down Expand Up @@ -237,15 +237,15 @@ private bool OnGameObjectSpawned(EntitySpawnDetails details) {

var processor = new EntityProcessor {
GameObject = details.GameObject,
IsSceneHost = _isSceneHost,
IsSceneHost = IsSceneHost,
LateLoad = true
}.Process();

if (!processor.Success) {
return false;
}

if (!_isSceneHost) {
if (!IsSceneHost) {
Logger.Warn("Game object was spawned while not scene host, this shouldn't happen");
return false;
}
Expand Down Expand Up @@ -335,7 +335,7 @@ private void OnSceneChanged(Scene oldScene, Scene newScene) {
// those entities
CheckReceivedUpdates();

_isSceneHostDetermined = false;
IsSceneHostDetermined = false;
}

/// <summary>
Expand Down Expand Up @@ -443,7 +443,7 @@ private void FindEntitiesInScene(Scene scene, bool lateLoad) {
foreach (var obj in objectsToCheck) {
new EntityProcessor {
GameObject = obj,
IsSceneHost = _isSceneHost,
IsSceneHost = IsSceneHost,
LateLoad = lateLoad
}.Process();
}
Expand Down
Loading

0 comments on commit 88ad3e1

Please sign in to comment.