24 [
Attribute(
desc:
"Voting Templates, please use configs and the VotingManagerComponent prefab for default gamemode voting templates")]
25 protected ref array<ref SCR_VotingBase> m_aVotingTemplates;
72 if (!
GetGame().GetPlayerManager().IsPlayerConnected(playerID))
74 Print(
string.Format(
"Non-existent player %1 is attempting to vote in %2 for %3", playerID,
typename.EnumToString(
EVotingType,
type), value), LogLevel.WARNING);
89 if (voting.GetPlayerVote(playerID) == value)
93 voting.SetVote(playerID, value);
96 if (voting.AddPlayerVotedServer(playerID))
103 if (voting.Evaluate(outcome))
119 if (voting.RemoveVote(playerID) || (voting.IsValuePlayerID() && playerID == value))
123 if (voting.RemovePlayerVotedServer(playerID))
129 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
135 voting.SetCurrentVoteCount(voteCount);
155 return voting !=
null;
181 return voting.GetPlayerVote(playerID);
200 currentVotes = voting.GetCurrentVoteCount();
201 votesRequired = voting.GetVoteCountRequired();
203 return votesRequired > 0;
292 return template && (
template.IsAvailable(value,
IsVoting(
type, value)) || DiagMenu.GetValue(
SCR_DebugMenuID.DEBUGUI_VOTING_ENABLE_ALL));
315 return voting.IsValuePlayerID();
361 return vote.GetRemainingDuration();
375 int GetVotingsAboutPlayer(
int playerID, out notnull array<EVotingType> outVotingTypes,
bool onlyTemplates =
false,
bool onlyAvailable =
false)
377 array<ref SCR_VotingBase> votings;
379 votings = m_aVotingTemplates;
383 outVotingTypes.Clear();
387 bool isMatchingValue = onlyTemplates || voting.GetValue() == playerID;
388 bool isAvailable = !onlyAvailable || voting.IsAvailable(playerID,
IsVoting(voting.GetType(), playerID)) || (onlyTemplates && DiagMenu.GetValue(
SCR_DebugMenuID.DEBUGUI_VOTING_ENABLE_ALL));
389 if (voting.IsValuePlayerID() && isMatchingValue && isAvailable)
390 outVotingTypes.Insert(voting.GetType());
392 return outVotingTypes.Count();
403 int GetAllVotingsAboutPlayer(
bool aboutPlayer, out notnull array<EVotingType> outVotingTypes,
bool onlyTemplates =
false,
bool onlyAvailable =
false)
405 array<ref SCR_VotingBase> votings;
407 votings = m_aVotingTemplates;
411 outVotingTypes.Clear();
414 if (aboutPlayer == voting.IsValuePlayerID() && (!onlyAvailable || voting.IsAvailable(voting.GetValue(),
true)))
415 outVotingTypes.Insert(voting.GetType());
417 return outVotingTypes.Count();
428 int GetAllVotingsWithValue(out notnull array<EVotingType> outVotingTypes, array<EVotingType> outValues,
bool onlyTemplates =
false,
bool onlyAvailable =
false)
430 array<ref SCR_VotingBase> votings;
432 votings = m_aVotingTemplates;
436 outVotingTypes.Clear();
439 if (voting.GetValue() !=
SCR_VotingBase.DEFAULT_VALUE && (!onlyAvailable || voting.IsAvailable(voting.GetValue(),
true)))
441 outVotingTypes.Insert(voting.GetType());
442 outValues.Insert(voting.GetValue());
445 return outVotingTypes.Count();
457 array<ref SCR_VotingBase> votings;
459 votings = m_aVotingTemplates;
466 if (voting.GetType() ==
type && (!onlyAvailable || voting.IsAvailable(voting.GetValue(),
true)))
467 outValues.Insert(voting.GetValue());
469 return outValues.Count();
480 return template.GetInfo();
494 return template.GetValueName(value);
496 return value.ToString();
510 voting.SetVoteLocal(value);
519 if (uiInfo && uiInfo.GetLocalVoteCastNotification() !=
ENotification.UNKNOWN)
520 SCR_NotificationsComponent.SendLocal(uiInfo.GetLocalVoteCastNotification(), value);
543 voting.RemoveVoteLocal();
552 if (uiInfo && uiInfo.GetLocalVoteAbstainedNotification() !=
ENotification.UNKNOWN)
553 SCR_NotificationsComponent.SendLocal(uiInfo.GetLocalVoteAbstainedNotification(), value);
568 return voting.GetLocalVote();
588 Print(
"---------------------------------------------");
594 Print(
"---------------------------------------------");
604 int value = voting.GetValue();
610 winner = voting.GetWinner();
617 voting.OnVotingEnd(value, winner);
637 for (
int i, count = m_aVotingTemplates.Count(); i < count; i++)
640 return m_aVotingTemplates[i];
658 Debug.Error2(
"SCR_VotingManagerComponent",
string.Format(
"Cannot initiate voting of type %1, it does not have a template!",
typename.EnumToString(
EVotingType,
type)));
663 if (Replication.IsServer() &&
template.IsValuePlayerID() && value !=
SCR_VotingBase.DEFAULT_VALUE && !
GetGame().GetPlayerManager().IsPlayerConnected(value))
665 Print(
string.Format(
"Cannot create voting %1 about %2, player with given ID does not exist!",
typename.EnumToString(
EVotingType,
type), value), LogLevel.WARNING);
671 voting.InitFromTemplate(
template, value, remainingDuration);
673 if (currentVoteCount > 0)
674 voting.SetCurrentVoteCount(currentVoteCount);
679 Print(
string.Format(
"Voting %1 started with value %2.",
typename.EnumToString(
EVotingType,
type), voting.GetValueName(value)), LogLevel.VERBOSE);
686 SCR_NotificationsComponent.SendLocal(
template.
GetInfo().GetVotingStartNotification(), value);
692 SetEventMask(
GetOwner(), EntityEvent.FRAME);
710 Print(
string.Format(
"Voting %1 ended, the winner is %2.",
typename.EnumToString(
EVotingType,
type), voting.GetValueName(winner)), LogLevel.VERBOSE);
721 SCR_NotificationsComponent.SendLocal(
template.
GetInfo().GetVotingSucceedNotification(), value);
724 SCR_NotificationsComponent.SendLocal(
template.
GetInfo().GetVotingFailNotification(), value);
729 ClearEventMask(
GetOwner(), EntityEvent.FRAME);
733 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
741 if (
type == record.param1 && value == record.param2)
752 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
790 int votingTypeMin, votingTypeMax;
796 writer.WriteInt(count);
798 for (
int i; i < count; i++)
812 int votingTypeMin, votingTypeMax;
818 reader.ReadInt(count);
821 int value, currentVoteCount;
822 float remainingDuration;
823 for (
int i; i < count; i++)
825 reader.ReadIntRange(
type, votingTypeMin, votingTypeMax);
826 reader.ReadInt(value);
827 reader.ReadFloat(remainingDuration);
828 reader.ReadInt(currentVoteCount);
836 override protected void EOnFrame(IEntity owner,
float timeSlice)
841 if (Replication.IsServer())
880 DiagMenu.RegisterMenu(
SCR_DebugMenuID.DEBUGUI_VOTING,
"Voting",
"Game");
881 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_VOTING_ENABLE_ALL,
"",
"Enable All Vote Types",
"Voting");