Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_VoterComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Voting", description: "")]
2 class SCR_VoterComponentClass : ScriptComponentClass
3 {
4 }
5 
6 class SCR_VoterComponent : ScriptComponent
7 {
8  protected PlayerController m_PlayerController;
9 
10  //------------------------------------------------------------------------------------------------
11  //--- Public, anywhere
14  static SCR_VoterComponent GetInstance()
15  {
17  return SCR_VoterComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_VoterComponent));
18  else
19  return null;
20  }
21 
22  //------------------------------------------------------------------------------------------------
25  static void InstantVote()
26  {
28  if (!manager)
29  return;
30 
31  SCR_VoterComponent voterComponent = GetInstance();
32  if (!voterComponent)
33  return;
34 
35  array<EVotingType> votingTypes = {};
36  array<int> votingValues = {};
37 
38  int count = manager.GetAllVotingsWithValue(votingTypes, votingValues, false, true);
39 
40  for (int i = count - 1; i >= 0; i--)
41  {
42  if (manager.HasAbstainedLocally(votingTypes[i], votingValues[i]))
43  {
44  votingTypes.Remove(i);
45  votingValues.Remove(i);
46  continue;
47  }
48 
49  if (manager.IsLocalVote(votingTypes[i], votingValues[i]))
50  {
51  votingTypes.Remove(i);
52  votingValues.Remove(i);
53  continue;
54  }
55  }
56 
57  if (votingTypes.Count() == 1)
58  voterComponent.Vote(votingTypes[0], votingValues[0]);
59 
60  }
61 
62  //------------------------------------------------------------------------------------------------
65  static void InstantRemoveAndAbstainVote()
66  {
68  if (!manager)
69  return;
70 
71  SCR_VoterComponent voterComponent = GetInstance();
72  if (!voterComponent)
73  return;
74 
75  array<EVotingType> votingTypes = {};
76  array<int> votingValues = {};
77 
78  int count = manager.GetAllVotingsWithValue(votingTypes, votingValues, false, true);
79 
80  for (int i = count - 1; i >= 0; i--)
81  {
82  if (manager.HasAbstainedLocally(votingTypes[i], votingValues[i]))
83  {
84  votingTypes.Remove(i);
85  votingValues.Remove(i);
86  continue;
87  }
88 
89  if (manager.IsLocalVote(votingTypes[i], votingValues[i]))
90  {
91  votingTypes.Remove(i);
92  votingValues.Remove(i);
93  continue;
94  }
95  }
96 
97  if (votingTypes.Count() == 1)
98  voterComponent.RemoveVote(votingTypes[0], votingValues[0]);
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  //--- Public, owner
106  void Vote(EVotingType type, int value)
107  {
109  if (!manager)
110  return;
111 
112  Rpc(VoteServer, type, value);
113  manager.VoteLocal(type, value);
114  }
115 
116  //------------------------------------------------------------------------------------------------
120  void RemoveVote(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
121  {
123  if (!manager)
124  return;
125 
126  //~ Abstain vote (Local only)
127  AbstainVote(type, value);
128 
129  Rpc(RemoveVoteServer, type, value);
130  manager.RemoveVoteLocal(type, value);
131  }
132 
133  //------------------------------------------------------------------------------------------------
137  void AbstainVote(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
138  {
140  if (!manager)
141  return;
142 
143  //~ Vote is active so remove it
144  if (manager.IsLocalVote(type, value))
145  {
146  Rpc(RemoveVoteServer, type, value);
147  manager.RemoveVoteLocal(type, value);
148  }
149 
150  manager.AbstainVoteLocally(type, value);
151  }
152 
153  //------------------------------------------------------------------------------------------------
158  bool DidVote(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
159  {
161  if (manager)
162  return manager.IsLocalVote(type, value);
163  else
164  return false;
165  }
166 
167  //------------------------------------------------------------------------------------------------
172  bool HasAbstained(EVotingType type, int value = SCR_VotingBase.DEFAULT_VALUE)
173  {
175  if (manager)
176  return manager.HasAbstainedLocally(type, value);
177  else
178  return false;
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  //--- Protected, server
183  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
184  protected void VoteServer(EVotingType type, int value)
185  {
187  if (manager)
188  manager.Vote(m_PlayerController.GetPlayerId(), type, value);
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
193  protected void RemoveVoteServer(EVotingType type, int value)
194  {
196  if (manager)
197  manager.RemoveVote(m_PlayerController.GetPlayerId(), type, value);
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  //--- Overrides
202  override void OnPostInit(IEntity owner)
203  {
204  m_PlayerController = PlayerController.Cast(owner);
205  if (!m_PlayerController)
206  {
207  Debug.Error2("SCR_VoterComponent", "SCR_VoterComponent must be attached to PlayerController!");
208  return;
209  }
210  }
211 }
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
SCR_VotingBase
Definition: SCR_VotingBase.c:5
VoteServer
protected void VoteServer(EVotingType type, int value)
Definition: SCR_VoterComponent.c:184
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
Vote
void Vote(EVotingType type, int value)
Definition: SCR_VoterComponent.c:106
GetInstance
SCR_TextsTaskManagerComponentClass ScriptComponentClass GetInstance()
Definition: SCR_TextsTaskManagerComponent.c:50
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
RemoveVoteServer
protected void RemoveVoteServer(EVotingType type, int value)
Definition: SCR_VoterComponent.c:193
m_PlayerController
SCR_VoterComponentClass m_PlayerController
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_VoterComponent.c:202
RemoveVote
void RemoveVote(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VoterComponent.c:120
EVotingType
EVotingType
Definition: EVotingType.c:1
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_VotingManagerComponent
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VotingManagerComponent.c:878
SCR_VoterComponentClass
Definition: SCR_VoterComponent.c:2
AbstainVote
void AbstainVote(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VoterComponent.c:137
DidVote
bool DidVote(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VoterComponent.c:158
HasAbstained
bool HasAbstained(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
Definition: SCR_VoterComponent.c:172
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180