Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VoterComponent.c
Go to the documentation of this file.
1[ComponentEditorProps(category: "GameScripted/Voting", description: "")]
5
6class 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 //~ Trying to start a vote but there is an active cooldown timer for the player
113 if (!manager.IsVoting(type, value) && manager.GetCurrentVoteCooldownForLocalPlayer(type) > 0)
114 return;
115
116 manager.PreVoteLocal(type, value);
117
118 Rpc(VoteServer, type, value);
119 manager.VoteLocal(type, value);
120 }
121
122 //------------------------------------------------------------------------------------------------
127 {
129 if (!manager)
130 return;
131
132 //~ Abstain vote (Local only)
133 AbstainVote(type, value);
134
135 Rpc(RemoveVoteServer, type, value);
136 manager.RemoveVoteLocal(type, value);
137 }
138
139 //------------------------------------------------------------------------------------------------
144 {
146 if (!manager)
147 return;
148
149 //~ Vote is active so remove it
150 if (manager.IsLocalVote(type, value))
151 {
152 Rpc(RemoveVoteServer, type, value);
153 manager.RemoveVoteLocal(type, value);
154 }
155
156 manager.AbstainVoteLocally(type, value);
157 }
158
159 //------------------------------------------------------------------------------------------------
165 {
167 if (manager)
168 return manager.IsLocalVote(type, value);
169 else
170 return false;
171 }
172
173 //------------------------------------------------------------------------------------------------
179 {
181 if (manager)
182 return manager.HasAbstainedLocally(type, value);
183 else
184 return false;
185 }
186
187 //------------------------------------------------------------------------------------------------
188 //--- Protected, server
189 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
190 protected void VoteServer(EVotingType type, int value)
191 {
193 if (manager)
194 manager.Vote(m_PlayerController.GetPlayerId(), type, value);
195 }
196
197 //------------------------------------------------------------------------------------------------
198 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
199 protected void RemoveVoteServer(EVotingType type, int value)
200 {
202 if (manager)
203 manager.RemoveVote(m_PlayerController.GetPlayerId(), type, value);
204 }
205
206 //------------------------------------------------------------------------------------------------
207 //--- Overrides
208 override void OnPostInit(IEntity owner)
209 {
210 m_PlayerController = PlayerController.Cast(owner);
212 {
213 Debug.Error2("SCR_VoterComponent", "SCR_VoterComponent must be attached to PlayerController!");
214 return;
215 }
216 }
217}
EVotingType
Definition EVotingType.c:2
ArmaReforgerScripted GetGame()
Definition game.c:1398
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
EDamageType type
SCR_FastTravelComponentClass m_PlayerController
void VoteServer(EVotingType type, int value)
void RemoveVote(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
bool DidVote(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
bool HasAbstained(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
void Vote(EVotingType type, int value)
void RemoveVoteServer(EVotingType type, int value)
void AbstainVote(EVotingType type, int value=SCR_VotingBase.DEFAULT_VALUE)
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition Debug.c:13
proto external GenericComponent FindComponent(typename typeName)
static const int DEFAULT_VALUE
proto external PlayerController GetPlayerController()
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14