Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VotingManagerComponent.c
Go to the documentation of this file.
3 typedef ScriptInvokerBase<ScriptInvoker_VotingManagerStartMethod> ScriptInvoker_VotingManagerStart;
4 
5 void ScriptInvoker_VotingManagerEndMethod(EVotingType type, int value, int winner);
7 typedef ScriptInvokerBase<ScriptInvoker_VotingManagerEndMethod> ScriptInvoker_VotingManagerEnd;
8 
9 void ScriptInvoker_VotingManagerPlayerMethod(EVotingType type, int value, int playerID);
11 typedef ScriptInvokerBase<ScriptInvoker_VotingManagerPlayerMethod> ScriptInvoker_VotingManagerPlayer;
12 
15 typedef ScriptInvokerBase<ScriptInvoker_VotingManagerVoteCountChangedMethod> ScriptInvoker_VotingManagerVoteCountChanged;
16 
17 [ComponentEditorProps(category: "GameScripted/Voting", description: "")]
19 {
20 }
21 
23 {
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;
26 
27  [Attribute("1")]
28  protected float m_fUpdateStep;
29 
30  protected int m_iHostPlayerID = -1;
31  protected float m_fUpdateLength;
32  protected ref array<ref SCR_VotingBase> m_aVotingInstances = {};
33  protected ref set<SCR_VotingBase> m_aAbstainedVotingInstances = new set<SCR_VotingBase>(); //~ Player locally abstained from voting
34  protected ref array<ref Tuple2<int, int>> m_LocalVoteRecords = {};
35 
44 
46  //--- Public, static, anywhere
47 
48  //------------------------------------------------------------------------------------------------
52  {
53  if (GetGame().GetGameMode())
55  else
56  return null;
57  }
58 
60  //--- Public, server
61 
62  //------------------------------------------------------------------------------------------------
69  void Vote(int playerID, EVotingType type, int value)
70  {
71  //--- Prevent voting fraud, non-existent players cannot vote!
72  if (!GetGame().GetPlayerManager().IsPlayerConnected(playerID))
73  {
74  Print(string.Format("Non-existent player %1 is attempting to vote in %2 for %3", playerID, typename.EnumToString(EVotingType, type), value), LogLevel.WARNING);
75  return;
76  }
77 
78  //--- Find the voting, or create it if it doesn't exist yet
79  SCR_VotingBase voting = FindVoting(type, value);
80  if (!voting)
81  {
82  if (!StartVoting(type, value))
83  return;
84 
85  voting = FindVoting(type, value);
86  }
87 
88  //--- Voting for the same value, ignore
89  if (voting.GetPlayerVote(playerID) == value)
90  return;
91 
92  //--- Set the vote
93  voting.SetVote(playerID, value);
94 
95  //~ If vote was successfully added send RPC to update vote count for players
96  if (voting.AddPlayerVotedServer(playerID))
97  Rpc(RPC_PlayerVoteCountChanged, type, value, voting.GetCurrentVoteCount());
98 
99  m_OnVote.Invoke(type, value, playerID);
100 
101  //--- Check if the vote completed the voting
102  EVotingOutcome outcome = EVotingOutcome.EVALUATE;
103  if (voting.Evaluate(outcome))
104  EndVoting(voting, outcome);
105  }
106 
107  //------------------------------------------------------------------------------------------------
113  void RemoveVote(int playerID, EVotingType type, int value)
114  {
115  SCR_VotingBase voting = FindVoting(type, value);
116  if (voting)
117  {
118  //--- Cancel the vote when no votes are left (i.e., last player canceled theirs) or when player who is target of the vote cancels their vote
119  if (voting.RemoveVote(playerID) || (voting.IsValuePlayerID() && playerID == value))
120  EndVoting(type, value, EVotingOutcome.FORCE_FAIL);
121 
122  //~ If vote was successfully removed send RPC to update vote count for players
123  if (voting.RemovePlayerVotedServer(playerID))
124  Rpc(RPC_PlayerVoteCountChanged, type, value, voting.GetCurrentVoteCount());
125  }
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
130  protected void RPC_PlayerVoteCountChanged(EVotingType type, int value, int voteCount)
131  {
132  SCR_VotingBase voting = FindVoting(type, value);
133  if (voting)
134  {
135  voting.SetCurrentVoteCount(voteCount);
136  m_PlayerVoteCountChanged.Invoke(type, value, voteCount);
137  }
138  }
139 
140  //------------------------------------------------------------------------------------------------
145  bool StartVoting(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
146  {
147  if (FindVoting(type, value))
148  return false;
149 
150  StartVotingBroadcast(type, value);
151  Rpc(StartVotingBroadcast, type, value);
152 
153  //-- Find the voting; cannot use returned value, StartVotingBroadcast is replicated and such functions cannot return anything
154  SCR_VotingBase voting = FindVoting(type, value);
155  return voting != null;
156  }
157 
158  //------------------------------------------------------------------------------------------------
164  void EndVoting(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE, EVotingOutcome outcome = EVotingOutcome.EVALUATE)
165  {
166  SCR_VotingBase voting = FindVoting(type, value);
167  if (voting)
168  EndVoting(voting, outcome);
169  }
170 
171  //------------------------------------------------------------------------------------------------
177  int GetPlayerVote(int playerID, EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
178  {
179  SCR_VotingBase voting = FindVoting(type, value);
180  if (voting)
181  return voting.GetPlayerVote(playerID);
182  else
183  return SCR_VotingBase.DEFAULT_VALUE;
184  }
185 
186  //------------------------------------------------------------------------------------------------
194  bool GetVoteCounts(EVotingType type, int value, out int currentVotes, out int votesRequired)
195  {
196  SCR_VotingBase voting = FindVoting(type, value);
197  if (!voting)
198  return false;
199 
200  currentVotes = voting.GetCurrentVoteCount();
201  votesRequired = voting.GetVoteCountRequired();
202 
203  return votesRequired > 0;
204  }
205 
206  //------------------------------------------------------------------------------------------------
210  {
211  return m_OnVotingStart;
212  }
213 
214  //------------------------------------------------------------------------------------------------
218  {
220  }
221 
222  //------------------------------------------------------------------------------------------------
226  {
227  return m_OnVotingEnd;
228  }
229 
230  //------------------------------------------------------------------------------------------------
234  {
235  return m_OnVote;
236  }
237 
238  //------------------------------------------------------------------------------------------------
242  {
243  return m_OnRemoveVote;
244  }
245 
246  //------------------------------------------------------------------------------------------------
250  {
251  return m_OnVoteLocal;
252  }
253 
254  //------------------------------------------------------------------------------------------------
258  {
259  return m_OnRemoveVoteLocal;
260  }
261 
262  //------------------------------------------------------------------------------------------------
266  {
267  return m_OnAbstainVoteLocal;
268  }
269 
271  //--- Public, anywhere
272 
273  //------------------------------------------------------------------------------------------------
277  {
278  if (m_iHostPlayerID == -1)
279  m_iHostPlayerID = SCR_PlayerController.GetLocalPlayerId();
280 
281  return m_iHostPlayerID;
282  }
283 
284  //------------------------------------------------------------------------------------------------
289  bool IsVotingAvailable(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
290  {
291  SCR_VotingBase template = FindTemplate(type);
292  return template && (template.IsAvailable(value, IsVoting(type, value)) || DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_VOTING_ENABLE_ALL));
293  }
294 
295  //------------------------------------------------------------------------------------------------
300  bool IsVoting(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
301  {
302  return FindVoting(type, value) != null;
303  }
304 
305  //------------------------------------------------------------------------------------------------
312  {
313  SCR_VotingBase voting = FindVoting(type, playerID);
314  if (voting)
315  return voting.IsValuePlayerID();
316  else
317  return SCR_VotingBase.DEFAULT_VALUE;
318  }
319 
320  //------------------------------------------------------------------------------------------------
324  void AbstainVoteLocally(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
325  {
326  SCR_VotingBase vote = FindVoting(type, value);
327  if (!vote || m_aAbstainedVotingInstances.Contains(vote))
328  return;
329 
330  m_aAbstainedVotingInstances.Insert(vote);
331 
332  //~ Script invoker
333  m_OnAbstainVoteLocal.Invoke(type, value);
334  }
335 
336  //------------------------------------------------------------------------------------------------
341  bool HasAbstainedLocally(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
342  {
343  if (IsLocalVote(type, value))
344  return false;
345 
346  SCR_VotingBase vote = FindVoting(type, value);
347  if (vote && m_aAbstainedVotingInstances.Contains(vote))
348  return true;
349 
350  return false;
351  }
352 
353  //------------------------------------------------------------------------------------------------
357  float GetRemainingDurationOfVote(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
358  {
359  SCR_VotingBase vote = FindVoting(type, value);
360  if (vote)
361  return vote.GetRemainingDuration();
362 
363  return -1;
364  }
365 
366  //------------------------------------------------------------------------------------------------
375  int GetVotingsAboutPlayer(int playerID, out notnull array<EVotingType> outVotingTypes, bool onlyTemplates = false, bool onlyAvailable = false)
376  {
377  array<ref SCR_VotingBase> votings;
378  if (onlyTemplates)
379  votings = m_aVotingTemplates;
380  else
381  votings = m_aVotingInstances;
382 
383  outVotingTypes.Clear();
384  foreach (SCR_VotingBase voting: votings)
385  {
386  //if (template.IsAvailable(playerID, IsVoting(template.GetType(), playerID)) || DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_VOTING_ENABLE_ALL))
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());
391  }
392  return outVotingTypes.Count();
393  }
394 
395  //------------------------------------------------------------------------------------------------
403  int GetAllVotingsAboutPlayer(bool aboutPlayer, out notnull array<EVotingType> outVotingTypes, bool onlyTemplates = false, bool onlyAvailable = false)
404  {
405  array<ref SCR_VotingBase> votings;
406  if (onlyTemplates)
407  votings = m_aVotingTemplates;
408  else
409  votings = m_aVotingInstances;
410 
411  outVotingTypes.Clear();
412  foreach (SCR_VotingBase voting: votings)
413  {
414  if (aboutPlayer == voting.IsValuePlayerID() && (!onlyAvailable || voting.IsAvailable(voting.GetValue(), true)))
415  outVotingTypes.Insert(voting.GetType());
416  }
417  return outVotingTypes.Count();
418  }
419 
420  //------------------------------------------------------------------------------------------------
428  int GetAllVotingsWithValue(out notnull array<EVotingType> outVotingTypes, array<EVotingType> outValues, bool onlyTemplates = false, bool onlyAvailable = false)
429  {
430  array<ref SCR_VotingBase> votings;
431  if (onlyTemplates)
432  votings = m_aVotingTemplates;
433  else
434  votings = m_aVotingInstances;
435 
436  outVotingTypes.Clear();
437  foreach (SCR_VotingBase voting: votings)
438  {
439  if (voting.GetValue() != SCR_VotingBase.DEFAULT_VALUE && (!onlyAvailable || voting.IsAvailable(voting.GetValue(), true)))
440  {
441  outVotingTypes.Insert(voting.GetType());
442  outValues.Insert(voting.GetValue());
443  }
444  }
445  return outVotingTypes.Count();
446  }
447 
448  //------------------------------------------------------------------------------------------------
455  int GetAllVotingValues(EVotingType type, out notnull array<int> outValues, bool onlyTemplates = false, bool onlyAvailable = false)
456  {
457  array<ref SCR_VotingBase> votings;
458  if (onlyTemplates)
459  votings = m_aVotingTemplates;
460  else
461  votings = m_aVotingInstances;
462 
463  outValues.Clear();
464  foreach (SCR_VotingBase voting: votings)
465  {
466  if (voting.GetType() == type && (!onlyAvailable || voting.IsAvailable(voting.GetValue(), true)))
467  outValues.Insert(voting.GetValue());
468  }
469  return outValues.Count();
470  }
471 
472  //------------------------------------------------------------------------------------------------
477  {
478  SCR_VotingBase template = FindTemplate(type);
479  if (template)
480  return template.GetInfo();
481  else
482  return null;
483  }
484 
485  //------------------------------------------------------------------------------------------------
490  string GetValueName(EVotingType type, int value)
491  {
492  SCR_VotingBase template = FindTemplate(type);
493  if (template)
494  return template.GetValueName(value);
495  else
496  return value.ToString();
497  }
498 
499  //------------------------------------------------------------------------------------------------
505  void VoteLocal(EVotingType type, int value)
506  {
507  SCR_VotingBase voting = FindVoting(type, value);
508  if (voting)
509  {
510  voting.SetVoteLocal(value);
511  m_OnVoteLocal.Invoke(type, value);
512 
513  //~ Vote Cast Notification
514  SCR_VotingBase template = FindTemplate(type);
515  if (template && template.CanSendNotification(value))
516  {
517  SCR_VotingUIInfo uiInfo = template.GetInfo();
518 
519  if (uiInfo && uiInfo.GetLocalVoteCastNotification() != ENotification.UNKNOWN)
520  SCR_NotificationsComponent.SendLocal(uiInfo.GetLocalVoteCastNotification(), value);
521  }
522  }
523  else
524  {
525  //--- Voting doesn't exist yet - cache it, it will be restored by StartVotingBroadcast
526  m_LocalVoteRecords.Insert(new Tuple2<int, int>(type, value));
527  }
528  }
529 
530  //------------------------------------------------------------------------------------------------
537  {
538  SCR_VotingBase voting = FindVoting(type, value);
539  if (voting)
540  {
541  m_aAbstainedVotingInstances.Insert(voting);
542 
543  voting.RemoveVoteLocal();
544  m_OnRemoveVoteLocal.Invoke(type, value);
545 
546  //~ Vote Abstained Notification
547  SCR_VotingBase template = FindTemplate(type);
548  if (template && template.CanSendNotification(value))
549  {
550  SCR_VotingUIInfo uiInfo = template.GetInfo();
551 
552  if (uiInfo && uiInfo.GetLocalVoteAbstainedNotification() != ENotification.UNKNOWN)
553  SCR_NotificationsComponent.SendLocal(uiInfo.GetLocalVoteAbstainedNotification(), value);
554  }
555  }
556  }
557 
558  //------------------------------------------------------------------------------------------------
564  int GetLocalVote(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
565  {
566  SCR_VotingBase voting = FindVoting(type, value);
567  if (voting)
568  return voting.GetLocalVote();
569  else
570  return SCR_VotingBase.DEFAULT_VALUE;
571  }
572 
573  //------------------------------------------------------------------------------------------------
579  bool IsLocalVote(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
580  {
581  return GetLocalVote(type, value) != SCR_VotingBase.DEFAULT_VALUE;
582  }
583 
584  //------------------------------------------------------------------------------------------------
586  void Log()
587  {
588  Print("---------------------------------------------");
589  PrintFormat("Ongoing votings: %1", m_aVotingInstances.Count());
590  foreach (SCR_VotingBase voting: m_aVotingInstances)
591  {
592  voting.Log();
593  }
594  Print("---------------------------------------------");
595  }
596 
598  //--- Protected, server
599 
600  //------------------------------------------------------------------------------------------------
601  protected void EndVoting(SCR_VotingBase voting, EVotingOutcome outcome = EVotingOutcome.EVALUATE)
602  {
603  EVotingType type = voting.GetType();
604  int value = voting.GetValue();
605  int winner = SCR_VotingBase.DEFAULT_VALUE;
606 
607  switch (outcome)
608  {
609  case EVotingOutcome.EVALUATE:
610  winner = voting.GetWinner();
611  break;
612  case EVotingOutcome.FORCE_WIN:
613  winner = value;
614  break;
615  }
616 
617  voting.OnVotingEnd(value, winner);
618 
619  EndVotingBroadcast(type, value, winner);
620  Rpc(EndVotingBroadcast, type, value, winner);
621  }
622 
623  //------------------------------------------------------------------------------------------------
625  {
626  for (int i, count = m_aVotingInstances.Count(); i < count; i++)
627  {
628  if (m_aVotingInstances[i].IsMatching(type, value))
629  return m_aVotingInstances[i];
630  }
631  return null;
632  }
633 
634  //------------------------------------------------------------------------------------------------
636  {
637  for (int i, count = m_aVotingTemplates.Count(); i < count; i++)
638  {
639  if (m_aVotingTemplates[i].GetType() == type)
640  return m_aVotingTemplates[i];
641  }
642  return null;
643  }
644 
646  //--- Protected, anywhere
647 
648  //------------------------------------------------------------------------------------------------
649  protected SCR_VotingBase CreateVotingInstance(EVotingType type, int value, float remainingDuration = -1, int currentVoteCount = -1)
650  {
651  if (FindVoting(type, value))
652  return null;
653 
654  //--- Find voting template
655  SCR_VotingBase template = FindTemplate(type);
656  if (!template)
657  {
658  Debug.Error2("SCR_VotingManagerComponent", string.Format("Cannot initiate voting of type %1, it does not have a template!", typename.EnumToString(EVotingType, type)));
659  return null;
660  }
661 
662  //--- Voting about player who is not connected, ignore
663  if (Replication.IsServer() && template.IsValuePlayerID() && value != SCR_VotingBase.DEFAULT_VALUE && !GetGame().GetPlayerManager().IsPlayerConnected(value))
664  {
665  Print(string.Format("Cannot create voting %1 about %2, player with given ID does not exist!", typename.EnumToString(EVotingType, type), value), LogLevel.WARNING);
666  return null;
667  }
668 
669  //--- Start new voting
670  SCR_VotingBase voting = SCR_VotingBase.Cast(template.Type().Spawn());
671  voting.InitFromTemplate(template, value, remainingDuration);
672 
673  if (currentVoteCount > 0)
674  voting.SetCurrentVoteCount(currentVoteCount);
675 
676  m_aVotingInstances.Insert(voting);
677 
678  m_OnVotingStart.Invoke(type, value);
679  Print(string.Format("Voting %1 started with value %2.", typename.EnumToString(EVotingType, type), voting.GetValueName(value)), LogLevel.VERBOSE);
680 
681  //~ Vote start Notification
682  if (template.CanSendNotification(value))
683  {
684  if (template.GetInfo() && template.GetInfo().GetVotingStartNotification() != ENotification.UNKNOWN)
685  {
686  SCR_NotificationsComponent.SendLocal(template.GetInfo().GetVotingStartNotification(), value);
687  }
688  }
689 
690  //--- First voting, start updating countdown
691  if (m_aVotingInstances.Count() == 1)
692  SetEventMask(GetOwner(), EntityEvent.FRAME);
693 
694  return voting;
695  }
696 
697  //------------------------------------------------------------------------------------------------
698  protected void DeleteVotingInstance(EVotingType type, int value, int winner)
699  {
700  SCR_VotingBase voting = FindVoting(type, value);
701  if (!voting)
702  return;
703 
704  if (m_aAbstainedVotingInstances.Contains(voting))
705  m_aAbstainedVotingInstances.RemoveItem(voting);
706 
707  m_aVotingInstances.RemoveItem(voting);
708 
709  m_OnVotingEnd.Invoke(type, value, winner);
710  Print(string.Format("Voting %1 ended, the winner is %2.", typename.EnumToString(EVotingType, type), voting.GetValueName(winner)), LogLevel.VERBOSE);
711 
712  SCR_VotingBase template = FindTemplate(type);
713 
714  //~ Vote End Notification
715  if (template && template.CanSendNotification(value))
716  {
717  if (template.GetInfo())
718  {
719  //~ Vote succeeded notification
720  if (winner != SCR_VotingBase.DEFAULT_VALUE && template.GetInfo().GetVotingSucceedNotification() != ENotification.UNKNOWN)
721  SCR_NotificationsComponent.SendLocal(template.GetInfo().GetVotingSucceedNotification(), value);
722  //~ Vote failed notification
723  else if (winner == SCR_VotingBase.DEFAULT_VALUE && template.GetInfo().GetVotingFailNotification() != ENotification.UNKNOWN)
724  SCR_NotificationsComponent.SendLocal(template.GetInfo().GetVotingFailNotification(), value);
725  }
726  }
727 
728  if (m_aVotingInstances.IsEmpty())
729  ClearEventMask(GetOwner(), EntityEvent.FRAME);
730  }
731 
732  //------------------------------------------------------------------------------------------------
733  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
734  protected void StartVotingBroadcast(EVotingType type, int value)
735  {
736  SCR_VotingBase voting = CreateVotingInstance(type, value);
737 
738  //--- Restore local vote from cache
739  foreach (int index, Tuple2<int, int> record: m_LocalVoteRecords)
740  {
741  if (type == record.param1 && value == record.param2)
742  {
743  if (voting)
744  VoteLocal(record.param1, record.param2);
745 
746  m_LocalVoteRecords.Remove(index);
747  }
748  }
749  }
750 
751  //------------------------------------------------------------------------------------------------
752  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
753  protected void EndVotingBroadcast(EVotingType type, int value, int winner)
754  {
755  DeleteVotingInstance(type, value, winner);
756  }
757 
759  //--- Overrides
760 
761  //------------------------------------------------------------------------------------------------
762  override void OnPlayerConnected(int playerId)
763  {
764  //--- Force instant refresh in EOnFrame
766  }
767 
768  //------------------------------------------------------------------------------------------------
769  override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
770  {
771  for (int i = m_aVotingInstances.Count() - 1; i >= 0; i--)
772  {
773  //--- Remove player's vote
774  m_aVotingInstances[i].RemoveVote(playerId);
775 
776  //--- If the player was a target of a vote, update the vote
777  if (m_aVotingInstances[i].RemoveValue(playerId))
778  {
780  }
781  }
782 
783  //--- Force instant refresh in EOnFrame
785  }
786 
787  //------------------------------------------------------------------------------------------------
788  override bool RplSave(ScriptBitWriter writer)
789  {
790  int votingTypeMin, votingTypeMax;
791  SCR_Enum.GetRange(EVotingType, votingTypeMin, votingTypeMax);
792 
793  writer.WriteInt(GetHostPlayerID());
794 
795  int count = m_aVotingInstances.Count();
796  writer.WriteInt(count);
797 
798  for (int i; i < count; i++)
799  {
800  writer.WriteIntRange(m_aVotingInstances[i].GetType(), votingTypeMin, votingTypeMax);
801  writer.WriteInt(m_aVotingInstances[i].GetValue());
802  writer.WriteFloat(m_aVotingInstances[i].GetRemainingDuration());
803  writer.WriteFloat(m_aVotingInstances[i].GetCurrentVoteCount());
804  }
805 
806  return true;
807  }
808 
809  //------------------------------------------------------------------------------------------------
810  override bool RplLoad(ScriptBitReader reader)
811  {
812  int votingTypeMin, votingTypeMax;
813  SCR_Enum.GetRange(EVotingType, votingTypeMin, votingTypeMax);
814 
815  reader.ReadInt(m_iHostPlayerID);
816 
817  int count;
818  reader.ReadInt(count);
819 
821  int value, currentVoteCount;
822  float remainingDuration;
823  for (int i; i < count; i++)
824  {
825  reader.ReadIntRange(type, votingTypeMin, votingTypeMax);
826  reader.ReadInt(value);
827  reader.ReadFloat(remainingDuration);
828  reader.ReadInt(currentVoteCount);
829  CreateVotingInstance(type, value, remainingDuration, currentVoteCount);
830  }
831 
832  return true;
833  }
834 
835  //------------------------------------------------------------------------------------------------
836  override protected void EOnFrame(IEntity owner, float timeSlice)
837  {
838  m_fUpdateLength += timeSlice;
840  {
841  if (Replication.IsServer())
842  {
843  //--- Server, manager all votings
844  if (GetGame().GetPlayerManager().GetPlayerCount() > 0)
845  {
846  //--- Update countdowns (only if some players are present; otherwise votings are paused)
847  for (int i = m_aVotingInstances.Count() - 1; i >= 0; i--)
848  {
850 
851  //--- End voting when time expired
852  EVotingOutcome outcome = EVotingOutcome.EVALUATE;
853  if (m_aVotingInstances[i].Evaluate(outcome))
854  {
855  EndVoting(m_aVotingInstances[i], outcome);
856  }
857  }
858  }
859  }
860  else
861  {
862  //--- Client, merely update countdowns
863  for (int i = m_aVotingInstances.Count() - 1; i >= 0; i--)
864  {
866  }
867  }
868 
869  m_fUpdateLength = 0; //--- Must be after the code above, as it's passed inside Update() as a parameter
870  }
871  }
872 
873  //------------------------------------------------------------------------------------------------
874  // constructor
878  void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
879  {
880  DiagMenu.RegisterMenu(SCR_DebugMenuID.DEBUGUI_VOTING, "Voting", "Game");
881  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_VOTING_ENABLE_ALL, "", "Enable All Vote Types", "Voting");
882  }
883 }
GetPlayerVote
int GetPlayerVote(int playerID, EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VotingManagerComponent.c:177
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
m_aVotingInstances
protected ref array< ref SCR_VotingBase > m_aVotingInstances
Definition: SCR_VotingManagerComponent.c:32
HasAbstainedLocally
bool HasAbstainedLocally(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VotingManagerComponent.c:341
FindVoting
protected SCR_VotingBase FindVoting(EVotingType type, int value)
Definition: SCR_VotingManagerComponent.c:624
GetVotingsAboutPlayer
int GetVotingsAboutPlayer(int playerID, out notnull array< EVotingType > outVotingTypes, bool onlyTemplates=false, bool onlyAvailable=false)
Definition: SCR_VotingManagerComponent.c:375
SCR_VotingBase
Definition: SCR_VotingBase.c:5
RemoveVoteLocal
void RemoveVoteLocal(EVotingType type, int value)
Definition: SCR_VotingManagerComponent.c:536
FindTemplate
protected SCR_VotingBase FindTemplate(EVotingType type)
Definition: SCR_VotingManagerComponent.c:635
SCR_PlayerController
Definition: SCR_PlayerController.c:31
AbstainVoteLocally
void AbstainVoteLocally(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VotingManagerComponent.c:324
SCR_Enum
Definition: SCR_Enum.c:1
ScriptInvoker_VotingManagerEndMethod
func ScriptInvoker_VotingManagerEndMethod
Definition: SCR_VotingManagerComponent.c:6
GetType
override EGadgetType GetType()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:52
IsVotingAvailable
bool IsVotingAvailable(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VotingManagerComponent.c:289
m_PlayerVoteCountChanged
protected ref ScriptInvoker_VotingManagerVoteCountChanged m_PlayerVoteCountChanged
Definition: SCR_VotingManagerComponent.c:43
IsVoting
bool IsVoting(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VotingManagerComponent.c:300
GetOnRemoveVoteLocal
ScriptInvoker_VotingManagerStart GetOnRemoveVoteLocal()
Definition: SCR_VotingManagerComponent.c:257
m_OnRemoveVote
protected ref ScriptInvoker_VotingManagerPlayer m_OnRemoveVote
Definition: SCR_VotingManagerComponent.c:39
EOnFrame
override protected void EOnFrame(IEntity owner, float timeSlice)
Definition: SCR_VotingManagerComponent.c:836
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
CreateVotingInstance
protected SCR_VotingBase CreateVotingInstance(EVotingType type, int value, float remainingDuration=-1, int currentVoteCount=-1)
Definition: SCR_VotingManagerComponent.c:649
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
VoteLocal
void VoteLocal(EVotingType type, int value)
Definition: SCR_VotingManagerComponent.c:505
GetVotingInfo
SCR_VotingUIInfo GetVotingInfo(EVotingType type)
Definition: SCR_VotingManagerComponent.c:476
OnPlayerConnected
override void OnPlayerConnected(int playerId)
Definition: SCR_VotingManagerComponent.c:762
GetInfo
override SCR_UIInfo GetInfo(IEntity owner=null)
Definition: SCR_EditablePlayerDelegateComponent.c:140
GetOnVote
ScriptInvoker_VotingManagerPlayer GetOnVote()
Definition: SCR_VotingManagerComponent.c:233
GetOnVoteCountChanged
ScriptInvoker_VotingManagerVoteCountChanged GetOnVoteCountChanged()
Definition: SCR_VotingManagerComponent.c:217
GetRemainingDurationOfVote
float GetRemainingDurationOfVote(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VotingManagerComponent.c:357
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
func
func
Definition: SCR_AIThreatSystem.c:5
KickCauseCode
KickCauseCode
Definition: KickCauseCode.c:19
m_fUpdateStep
protected float m_fUpdateStep
Definition: SCR_VotingManagerComponent.c:28
SCR_VotingManagerComponentClass
Definition: SCR_VotingManagerComponent.c:18
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
GetHostPlayerID
int GetHostPlayerID()
Definition: SCR_VotingManagerComponent.c:276
GetAllVotingsAboutPlayer
int GetAllVotingsAboutPlayer(bool aboutPlayer, out notnull array< EVotingType > outVotingTypes, bool onlyTemplates=false, bool onlyAvailable=false)
Definition: SCR_VotingManagerComponent.c:403
RemoveVote
void RemoveVote(int playerID, EVotingType type, int value)
Definition: SCR_VotingManagerComponent.c:113
RemoveValue
override bool RemoveValue(int value)
Definition: SCR_VotingBase.c:33
ENotification
ENotification
Definition: ENotification.c:4
Spawn
override IEntity Spawn(IEntity owner, Physics parentPhysics, SCR_HitInfo hitInfo, bool snapToTerrain=false)
Definition: SCR_DestructionBaseComponent.c:815
EndVotingBroadcast
protected void EndVotingBroadcast(EVotingType type, int value, int winner)
Definition: SCR_VotingManagerComponent.c:753
GetOnAbstainVoteLocal
ScriptInvoker_VotingManagerStart GetOnAbstainVoteLocal()
Definition: SCR_VotingManagerComponent.c:265
RPC_PlayerVoteCountChanged
protected void RPC_PlayerVoteCountChanged(EVotingType type, int value, int voteCount)
Definition: SCR_VotingManagerComponent.c:130
m_OnVotingEnd
protected ref ScriptInvoker_VotingManagerEnd m_OnVotingEnd
Definition: SCR_VotingManagerComponent.c:37
Evaluate
override bool Evaluate(out EVotingOutcome outcome)
Definition: SCR_VotingBase.c:45
GetAllVotingValues
int GetAllVotingValues(EVotingType type, out notnull array< int > outValues, bool onlyTemplates=false, bool onlyAvailable=false)
Definition: SCR_VotingManagerComponent.c:455
DeleteVotingInstance
protected void DeleteVotingInstance(EVotingType type, int value, int winner)
Definition: SCR_VotingManagerComponent.c:698
IsMatching
override bool IsMatching(EVotingType type, int value=DEFAULT_VALUE)
Definition: SCR_VotingBase.c:39
IsLocalVote
bool IsLocalVote(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VotingManagerComponent.c:579
ScriptInvoker_VotingManagerStartMethod
func ScriptInvoker_VotingManagerStartMethod
Definition: SCR_VotingManagerComponent.c:2
RplSave
override bool RplSave(ScriptBitWriter writer)
Definition: SCR_VotingManagerComponent.c:788
ScriptInvoker_VotingManagerVoteCountChanged
ScriptInvokerBase< ScriptInvoker_VotingManagerVoteCountChangedMethod > ScriptInvoker_VotingManagerVoteCountChanged
Definition: SCR_VotingManagerComponent.c:15
CanSendNotification
override bool CanSendNotification(int value)
Definition: SCR_VotingEditor.c:51
GetAllVotingsWithValue
int GetAllVotingsWithValue(out notnull array< EVotingType > outVotingTypes, array< EVotingType > outValues, bool onlyTemplates=false, bool onlyAvailable=false)
Definition: SCR_VotingManagerComponent.c:428
m_OnAbstainVoteLocal
protected ref ScriptInvoker_VotingManagerStart m_OnAbstainVoteLocal
Definition: SCR_VotingManagerComponent.c:42
EndVoting
void EndVoting(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE, EVotingOutcome outcome=EVotingOutcome.EVALUATE)
Definition: SCR_VotingManagerComponent.c:164
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
Vote
void Vote(int playerID, EVotingType type, int value)
Definition: SCR_VotingManagerComponent.c:69
GetValue
override int GetValue()
Definition: SCR_VotingBase.c:69
m_LocalVoteRecords
protected ref array< ref Tuple2< int, int > > m_LocalVoteRecords
Definition: SCR_VotingManagerComponent.c:34
IsVotingAboutPlayer
bool IsVotingAboutPlayer(int playerID, EVotingType type)
Definition: SCR_VotingManagerComponent.c:311
GetOnVoteLocal
ScriptInvoker_VotingManagerStart GetOnVoteLocal()
Definition: SCR_VotingManagerComponent.c:249
StartVoting
bool StartVoting(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VotingManagerComponent.c:145
GetVoteCounts
bool GetVoteCounts(EVotingType type, int value, out int currentVotes, out int votesRequired)
Definition: SCR_VotingManagerComponent.c:194
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
EVotingType
EVotingType
Definition: EVotingType.c:1
SCR_VotingUIInfo
Definition: SCR_VotingUIInfo.c:2
GetLocalVote
int GetLocalVote(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VotingManagerComponent.c:564
ScriptInvoker_VotingManagerPlayer
ScriptInvokerBase< ScriptInvoker_VotingManagerPlayerMethod > ScriptInvoker_VotingManagerPlayer
Definition: SCR_VotingManagerComponent.c:11
m_aAbstainedVotingInstances
protected ref set< SCR_VotingBase > m_aAbstainedVotingInstances
Definition: SCR_VotingManagerComponent.c:33
m_iHostPlayerID
protected int m_iHostPlayerID
Definition: SCR_VotingManagerComponent.c:30
Log
void Log()
Print out information about all ongoing voting instances.
Definition: SCR_VotingManagerComponent.c:586
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
Attribute
SCR_VotingManagerComponentClass SCR_BaseGameModeComponentClass Attribute(desc:"Voting Templates, please use configs and the VotingManagerComponent prefab for default gamemode voting templates")] protected ref array< ref SCR_VotingBase > m_aVotingTemplates
SCR_VotingManagerComponent
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VotingManagerComponent.c:878
ScriptInvoker_VotingManagerVoteCountChangedMethod
func ScriptInvoker_VotingManagerVoteCountChangedMethod
Definition: SCR_VotingManagerComponent.c:14
GetOnRemoveVote
ScriptInvoker_VotingManagerPlayer GetOnRemoveVote()
Definition: SCR_VotingManagerComponent.c:241
ScriptInvoker_VotingManagerStart
ScriptInvokerBase< ScriptInvoker_VotingManagerStartMethod > ScriptInvoker_VotingManagerStart
Definition: SCR_VotingManagerComponent.c:3
m_OnVotingStart
protected ref ScriptInvoker_VotingManagerStart m_OnVotingStart
Definition: SCR_VotingManagerComponent.c:36
ScriptInvoker_VotingManagerPlayerMethod
func ScriptInvoker_VotingManagerPlayerMethod
Definition: SCR_VotingManagerComponent.c:10
m_fUpdateLength
protected float m_fUpdateLength
Definition: SCR_VotingManagerComponent.c:31
m_OnRemoveVoteLocal
protected ref ScriptInvoker_VotingManagerStart m_OnRemoveVoteLocal
Definition: SCR_VotingManagerComponent.c:41
GetPlayerCount
int GetPlayerCount()
Definition: SCR_Faction.c:365
m_OnVoteLocal
protected ref ScriptInvoker_VotingManagerStart m_OnVoteLocal
Definition: SCR_VotingManagerComponent.c:40
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
GetOnVotingStart
ScriptInvoker_VotingManagerStart GetOnVotingStart()
Definition: SCR_VotingManagerComponent.c:209
OnPlayerDisconnected
override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
Definition: SCR_VotingManagerComponent.c:769
SCR_BaseGameModeComponentClass
Definition: SCR_BaseGameModeComponent.c:2
StartVotingBroadcast
protected void StartVotingBroadcast(EVotingType type, int value)
Definition: SCR_VotingManagerComponent.c:734
ScriptInvoker_VotingManagerEnd
ScriptInvokerBase< ScriptInvoker_VotingManagerEndMethod > ScriptInvoker_VotingManagerEnd
Definition: SCR_VotingManagerComponent.c:7
EVotingOutcome
EVotingOutcome
Definition: EVotingOutcome.c:1
m_OnVote
protected ref ScriptInvoker_VotingManagerPlayer m_OnVote
Definition: SCR_VotingManagerComponent.c:38
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_VotingManagerComponent.c:810
GetValueName
string GetValueName(EVotingType type, int value)
Definition: SCR_VotingManagerComponent.c:490
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BaseGameModeComponent.c:199
GetOnVotingEnd
ScriptInvoker_VotingManagerEnd GetOnVotingEnd()
Definition: SCR_VotingManagerComponent.c:225