mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +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;
|
namespace MiraAPI.Events.Vanilla.Meeting.Voting;
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public class MeetingSelectEvent : MiraCancelableEvent
|
public class MeetingSelectEvent : MiraEvent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the instance of the voter's vote data.
|
/// Gets the instance of the voter's vote data.
|
||||||
@@ -22,15 +22,22 @@ public class MeetingSelectEvent : MiraCancelableEvent
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public NetworkedPlayerInfo TargetPlayerInfo { get; }
|
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>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="MeetingSelectEvent"/> class.
|
/// Initializes a new instance of the <see cref="MeetingSelectEvent"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="playerVoteData">The voter's data.</param>
|
/// <param name="playerVoteData">The voter's data.</param>
|
||||||
/// <param name="targetId">The target's playerId.</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;
|
VoteData = playerVoteData;
|
||||||
TargetId = targetId;
|
TargetId = targetId;
|
||||||
TargetPlayerInfo = GameData.Instance.GetPlayerById((byte)targetId);
|
TargetPlayerInfo = GameData.Instance.GetPlayerById((byte)targetId);
|
||||||
|
AllowVote = allowVote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,18 +37,13 @@ internal static class MeetingHudPatches
|
|||||||
{
|
{
|
||||||
var voteData = PlayerControl.LocalPlayer.GetVoteData();
|
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 hasVotes = voteData.VotesRemaining > 0;
|
||||||
var hasVotedFor = voteData.VotedFor((byte)suspectStateIdx);
|
var hasVotedFor = voteData.VotedFor((byte)suspectStateIdx);
|
||||||
|
|
||||||
return hasVotes && !hasVotedFor;
|
var @event = new MeetingSelectEvent(voteData, suspectStateIdx, hasVotes && !hasVotedFor);
|
||||||
|
MiraEventManager.InvokeEvent(@event);
|
||||||
|
|
||||||
|
return @event.AllowVote;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPrefix]
|
[HarmonyPrefix]
|
||||||
|
|||||||
Reference in new issue
Block a user