Fix Hns Task Event not registering properly

This commit is contained in:
Atony committed 2025-11-23 12:50:52 -06:00
1 parent 62c01b2f72
commit 3afe437101
2 files changed
+7 -33

No files matched your search

@@ -1,9 +1,9 @@
namespace MiraAPI.Events.Vanilla.Player;
/// <summary>
/// The event that is invoked when a player completes a task within Hide and Seek. Task cannot be cancelled, but timer changes can.
/// The event that is invoked when a player completes a task within Hide and Seek. Non-cancelable.
/// </summary>
public class CompleteHnsTaskEvent : MiraCancelableEvent
public class CompleteHnsTaskEvent : MiraEvent
{
/// <summary>
/// Gets the instance of the <see cref="PlayerControl"/>.
+5 -31
View File
@@ -1,5 +1,4 @@
using HarmonyLib;
using HarmonyLib;
using MiraAPI.Events;
using MiraAPI.Events.Vanilla.Player;
@@ -8,36 +7,11 @@ namespace MiraAPI.Patches.Events;
[HarmonyPatch(typeof(HideAndSeekManager))]
public static class HnsFinishTaskPatch
{
[HarmonyPrefix]
[HarmonyPostfix]
[HarmonyPatch(nameof(HideAndSeekManager.FinishTask))]
public static bool FinishTask(HideAndSeekManager __instance, PlayerTask task)
public static void FinishTaskPostfix(HideAndSeekManager __instance, PlayerTask task)
{
NormalPlayerTask normalPlayerTask = task as NormalPlayerTask;
if (normalPlayerTask != null)
{
var completeTaskEvent = new CompleteHnsTaskEvent(__instance, task.Owner, task);
MiraEventManager.InvokeEvent(completeTaskEvent);
if (completeTaskEvent.IsCancelled)
{
return false;
}
switch (normalPlayerTask.Length)
{
case NormalPlayerTask.TaskLength.None:
case NormalPlayerTask.TaskLength.Common:
__instance.LogicFlowHnS.OnTaskComplete(__instance.LogicOptionsHnS.GetCommonTaskTimeValue());
break;
case NormalPlayerTask.TaskLength.Short:
__instance.LogicFlowHnS.OnTaskComplete(__instance.LogicOptionsHnS.GetShortTaskTimeValue());
break;
case NormalPlayerTask.TaskLength.Long:
__instance.LogicFlowHnS.OnTaskComplete(__instance.LogicOptionsHnS.GetLongTaskTimeValue());
break;
}
SoundManager.Instance.PlaySoundImmediate(__instance.TaskFinishedSound, false, 1f, 1f, null);
}
return false;
var completeTaskEvent = new CompleteHnsTaskEvent(__instance, task.Owner, task);
MiraEventManager.InvokeEvent(completeTaskEvent);
}
}