mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
improve MeetingSelectEvent
This commit is contained in:
1 parent
db327604c5
commit
25eafe664b
2 files changed
+14
-12
No files matched your search
@@ -3,9 +3,9 @@
|
||||
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when the player tries to select another player to vote. If you cancel this, the player will not be selectable.
|
||||
/// The event that is invoked when the player tries to select another player to vote.
|
||||
/// </summary>
|
||||
public class MeetingSelectEvent : MiraCancelableEvent
|
||||
public class MeetingSelectEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the voter's vote data.
|
||||
@@ -22,15 +22,22 @@ public class MeetingSelectEvent : MiraCancelableEvent
|
||||
/// </summary>
|
||||
public NetworkedPlayerInfo TargetPlayerInfo { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the player is allowed to vote for the target.
|
||||
/// </summary>
|
||||
public bool AllowVote { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MeetingSelectEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="playerVoteData">The voter's data.</param>
|
||||
/// <param name="targetId">The target's playerId.</param>
|
||||
public MeetingSelectEvent(PlayerVoteData playerVoteData, int targetId)
|
||||
/// <param name="allowVote">>Whether the player is allowed to vote for the target.</param>
|
||||
public MeetingSelectEvent(PlayerVoteData playerVoteData, int targetId, bool allowVote)
|
||||
{
|
||||
VoteData = playerVoteData;
|
||||
TargetId = targetId;
|
||||
TargetPlayerInfo = GameData.Instance.GetPlayerById((byte)targetId);
|
||||
AllowVote = allowVote;
|
||||
}
|
||||
}
|
||||
@@ -37,18 +37,13 @@ internal static class MeetingHudPatches
|
||||
{
|
||||
var voteData = PlayerControl.LocalPlayer.GetVoteData();
|
||||
|
||||
var @event = new MeetingSelectEvent(voteData, suspectStateIdx);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (@event.IsCancelled)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var hasVotes = voteData.VotesRemaining > 0;
|
||||
var hasVotedFor = voteData.VotedFor((byte)suspectStateIdx);
|
||||
|
||||
return hasVotes && !hasVotedFor;
|
||||
var @event = new MeetingSelectEvent(voteData, suspectStateIdx, hasVotes && !hasVotedFor);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
return @event.AllowVote;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
|
||||
Reference in new issue
Block a user