From fb40664bd0a868df043d01cf78c1ea98dac9504a Mon Sep 17 00:00:00 2001
From: XtraCube <72575280+XtraCube@users.noreply.github.com>
Date: Wed, 12 Mar 2025 22:56:41 -0400
Subject: [PATCH] add CheckForEndVotingEvent.cs
---
.../Meeting/Voting/CheckForEndVotingEvent.cs | 26 +++++++++++++++++++
MiraAPI/Patches/Voting/MeetingHudPatches.cs | 8 +++++-
2 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 MiraAPI/Events/Vanilla/Meeting/Voting/CheckForEndVotingEvent.cs
diff --git a/MiraAPI/Events/Vanilla/Meeting/Voting/CheckForEndVotingEvent.cs b/MiraAPI/Events/Vanilla/Meeting/Voting/CheckForEndVotingEvent.cs
new file mode 100644
index 0000000..b0bdae5
--- /dev/null
+++ b/MiraAPI/Events/Vanilla/Meeting/Voting/CheckForEndVotingEvent.cs
@@ -0,0 +1,26 @@
+namespace MiraAPI.Events.Vanilla.Meeting.Voting;
+
+///
+/// Checks if voting is complete. If canceled, the default end voting logic will be skipped.
+///
+public class CheckForEndVotingEvent : MiraCancelableEvent
+{
+ ///
+ /// Gets a value indicating whether default voting logic determines that voting is complete.
+ ///
+ public bool IsVotingComplete { get; }
+
+ ///
+ /// Gets or sets a value indicating whether the voting should be forced to end, regardless of the default logic.
+ ///
+ public bool ForceEndVoting { get; set; }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// >True if voting is complete, false otherwise.
+ public CheckForEndVotingEvent(bool isVotingComplete)
+ {
+ IsVotingComplete = isVotingComplete;
+ }
+}
diff --git a/MiraAPI/Patches/Voting/MeetingHudPatches.cs b/MiraAPI/Patches/Voting/MeetingHudPatches.cs
index c7babda..25bb2f0 100644
--- a/MiraAPI/Patches/Voting/MeetingHudPatches.cs
+++ b/MiraAPI/Patches/Voting/MeetingHudPatches.cs
@@ -173,7 +173,13 @@ internal static class MeetingHudPatches
[HarmonyPatch(nameof(MeetingHud.CheckForEndVoting))]
public static bool EndCheck(MeetingHud __instance)
{
- if (Helpers.GetAlivePlayers().Exists(plr => plr.GetVoteData().VotesRemaining > 0))
+ var shouldEnd = Helpers.GetAlivePlayers().Exists(plr => plr.GetVoteData().VotesRemaining > 0);
+
+ var checkEndEvent = new CheckForEndVotingEvent(shouldEnd);
+ MiraEventManager.InvokeEvent(checkEndEvent);
+ shouldEnd = checkEndEvent.ForceEndVoting || checkEndEvent is { IsCancelled: false, IsVotingComplete: true };
+
+ if (!shouldEnd)
{
return false;
}