Skip to content

Commit

Permalink
Fix certain Godhome fights not ending on scene clients
Browse files Browse the repository at this point in the history
  • Loading branch information
Extremelyd1 committed Jun 30, 2024
1 parent b1e203a commit 9de4dac
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion HKMP/Game/Client/Entity/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Hkmp.Networking.Packet.Data;
using Hkmp.Util;
using HutongGames.PlayMaker;
using Modding;
using UnityEngine;
using Logger = Hkmp.Logging.Logger;
using Vector2 = Hkmp.Math.Vector2;
Expand Down Expand Up @@ -220,7 +221,9 @@ params EntityComponentType[] types

Object.Host.SetActive(false);
Object.Client.SetActive(false);


CheckGodhome();

// // Debug code that logs each action's OnEnter method call
// foreach (var fsm in _fsms.Host) {
// foreach (var state in fsm.FsmStates) {
Expand Down Expand Up @@ -465,6 +468,44 @@ private void HandleEnemyDeathEffects() {
UnityEngine.Object.Destroy(corpse);
}

/// <summary>
/// Checks whether this is an enemy in a godhome fight. If that's the case, the health manager of the client
/// object will have their death be registered as a trigger for the boss scene controller. This ensures that
/// fights will end on scene clients if the client objects die.
/// </summary>
private void CheckGodhome() {
var bossSceneController = UnityEngine.Object.FindObjectOfType<BossSceneController>();
if (bossSceneController == null) {
return;
}

var hostHealthManager = Object.Host.GetComponent<HealthManager>();
if (hostHealthManager == null) {
return;
}

var clientHealthManager = Object.Client.GetComponent<HealthManager>();
if (clientHealthManager == null) {
Logger.Debug($"Entity ({Id}, {Type}) has HealthManager on host but not on client");
return;
}

if (!bossSceneController.bosses.Contains(hostHealthManager)) {
return;
}

Logger.Debug($"Entity ({Id}, {Type}) is contained in the boss scene controller, registering on death");

clientHealthManager.OnDeath += () => {
Logger.Debug("OnDeath triggered for health manager in boss scene controller");

var bossesLeft = ReflectionHelper.GetField<BossSceneController, int>(bossSceneController, "bossesLeft");
ReflectionHelper.SetField(bossSceneController, "bossesLeft", bossesLeft - 1);

ReflectionHelper.CallMethod(bossSceneController, "CheckBossesDead");
};
}

/// <summary>
/// Callback method for entering a hooked FSM action.
/// </summary>
Expand Down

0 comments on commit 9de4dac

Please sign in to comment.