Skip to content

Commit

Permalink
Fix errors with boss scene entity mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed Sep 12, 2024
1 parent ed2048b commit 8efd694
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
9 changes: 7 additions & 2 deletions HKMP/Game/Client/Entity/Component/ColliderComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ public override void Update(EntityNetworkData data, bool alreadyInSceneUpdate) {
}

var enabled = data.Packet.ReadBool();
_collider.Host.enabled = enabled;
_collider.Client.enabled = enabled;
if (_collider.Host != null) {
_collider.Host.enabled = enabled;
}

if (_collider.Client != null) {
_collider.Client.enabled = enabled;
}

Logger.Info($" Enabled: {enabled}");
}
Expand Down
13 changes: 9 additions & 4 deletions HKMP/Game/Client/Entity/Component/HealthManagerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,15 @@ public override void Update(EntityNetworkData data, bool alreadyInSceneUpdate) {
var newInvincible = data.Packet.ReadBool();
var newInvincibleFromDir = data.Packet.ReadByte();

_healthManager.Host.IsInvincible = newInvincible;
_healthManager.Host.InvincibleFromDirection = newInvincibleFromDir;
_healthManager.Client.IsInvincible = newInvincible;
_healthManager.Client.InvincibleFromDirection = newInvincibleFromDir;
if (_healthManager.Host != null) {
_healthManager.Host.IsInvincible = newInvincible;
_healthManager.Host.InvincibleFromDirection = newInvincibleFromDir;
}

if (_healthManager.Client != null) {
_healthManager.Client.IsInvincible = newInvincible;
_healthManager.Client.InvincibleFromDirection = newInvincibleFromDir;
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions HKMP/Game/Client/Entity/Component/MeshRendererComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@ public override void InitializeHost() {
/// <inheritdoc />
public override void Update(EntityNetworkData data, bool alreadyInSceneUpdate) {
var enabled = data.Packet.ReadBool();
_meshRenderer.Host.enabled = enabled;
_meshRenderer.Client.enabled = enabled;

if (_meshRenderer.Host != null) {
_meshRenderer.Host.enabled = enabled;
}

if (_meshRenderer.Client != null) {
_meshRenderer.Client.enabled = enabled;
}
}

/// <inheritdoc />
Expand Down
14 changes: 10 additions & 4 deletions HKMP/Game/Client/Entity/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,16 +1110,17 @@ public void MakeHost() {
/// </summary>
/// <param name="position">The new position.</param>
public void UpdatePosition(Vector2 position) {
if (Object.Client == null || Object.Host == null) {
Logger.Warn($"Cannot update position for entity ({Id}, {Type}), client or host object is null");
return;
}

var unityPos = new Vector3(
position.X,
position.Y,
_hasParent ? Object.Host.transform.localPosition.z : Object.Host.transform.position.z
);

if (Object.Client == null) {
return;
}

var positionInterpolation = Object.Client.GetComponent<PositionInterpolation>();
if (positionInterpolation == null) {
return;
Expand All @@ -1133,6 +1134,11 @@ public void UpdatePosition(Vector2 position) {
/// </summary>
/// <param name="scale">The new scale data.</param>
public void UpdateScale(EntityUpdate.ScaleData scale) {
if (Object.Client == null) {
Logger.Warn($"Cannot update scale for entity ({Id}, {Type}), client object is null");
return;
}

var transform = Object.Client.transform;
var localScale = transform.localScale;

Expand Down

0 comments on commit 8efd694

Please sign in to comment.