Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FactionCommanderVolunteerUserAction.c
Go to the documentation of this file.
2{
3 protected bool m_bInProgress;
5
7 protected SCR_FactionCommanderSignupComponent m_SignupComponent;
8
9 protected static ref ScriptInvokerInt s_OnCanBePerformed;
10
11 protected static const string NEXT_VOLUNTEERING_COOLDOWN_TEXT = "#AR-FactionCommander_NextVolunteeringCooldown";
12 protected static const string REPLACE_COMMANDER_COOLDOWN_TEXT = "#AR-FactionCommander_ReplaceCommanderCooldown";
13
14 //------------------------------------------------------------------------------------------------
22
23 //------------------------------------------------------------------------------------------------
24 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
25 {
26 if (System.IsConsoleApp())
27 return;
28
29 BaseGameMode gameMode = GetGame().GetGameMode();
30
31 if (!gameMode)
32 return;
33
34 SCR_GameModeCampaign campaignGameMode = SCR_GameModeCampaign.Cast(gameMode);
35 if (campaignGameMode)
36 m_bIsCommanderRoleEnabled = campaignGameMode.GetCommanderRoleEnabled();
37 else
39
40 m_SignupComponent = SCR_FactionCommanderSignupComponent.Cast(pOwnerEntity.FindComponent(SCR_FactionCommanderSignupComponent));
41
43 return;
44
45 if (!SCR_FactionCommanderHandlerComponent.GetInstance())
46 return;
47
49
51 {
52 m_VotingManager.GetOnVotingStart().Insert(OnVotingStart);
53 m_VotingManager.GetOnVotingEnd().Insert(OnVotingEnd);
54 }
55 }
56
57 //------------------------------------------------------------------------------------------------
58 override bool CanBeShownScript(IEntity user)
59 {
61 return false;
62
63 SCR_Faction playerFaction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
64
65 if (!playerFaction || !playerFaction.IsCommanderAvailable())
66 return false;
67
68 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(user);
69
70 if (playerFaction.GetCommanderId() == playerId)
71 return false;
72
73 return m_SignupComponent.IsControlledByFaction(playerFaction);
74 }
75
76 //------------------------------------------------------------------------------------------------
77 override bool CanBePerformedScript(IEntity user)
78 {
79 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(user);
80 PlayerController pc = GetGame().GetPlayerManager().GetPlayerController(playerId);
81
82 if (!pc)
83 return false;
84
85 BaseGameMode gameMode = GetGame().GetGameMode();
86
87 if (!gameMode)
88 return false;
89
90 SCR_FactionCommanderHandlerComponent handlerComponent = SCR_FactionCommanderHandlerComponent.GetInstance();
91
92 if (!handlerComponent)
93 return false;
94
95 if (handlerComponent.CheckRank() && SCR_CharacterRankComponent.GetCharacterRank(user) < handlerComponent.GetMinimumRank())
96 {
97 SCR_Faction playerFaction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
98
99 if (playerFaction)
100 SetCannotPerformReason(playerFaction.GetRanks().GetRankName(handlerComponent.GetMinimumRank()));
101
102 return false;
103 }
104
105 SCR_FactionCommanderPlayerComponent comp = SCR_FactionCommanderPlayerComponent.Cast(pc.FindComponent(SCR_FactionCommanderPlayerComponent));
106
107 if (!comp)
108 return false;
109
110 ChimeraWorld world = GetGame().GetWorld();
111
112 if (!world)
113 return false;
114
115 WorldTimestamp nextVolunteeringAvailableAt = comp.GetNextVolunteeringTimestamp();
116 WorldTimestamp canVolunteeringAgain = comp.GetReplaceCommanderCooldownTimestamp();
117
118 if (IsCooldownActive(nextVolunteeringAvailableAt, NEXT_VOLUNTEERING_COOLDOWN_TEXT))
119 return false;
120
121 if (IsCooldownActive(canVolunteeringAgain, REPLACE_COMMANDER_COOLDOWN_TEXT))
122 return false;
123
125 s_OnCanBePerformed.Invoke(playerId);
126
127 return true;
128 }
129
130 //------------------------------------------------------------------------------------------------
131 protected bool IsCooldownActive(WorldTimestamp deadline, string reasonKey)
132 {
133 ChimeraWorld world = GetGame().GetWorld();
134 if (!world)
135 return false;
136
137 WorldTimestamp currentTimestamp = world.GetServerTimestamp();
138 if (deadline.Greater(currentTimestamp))
139 {
140 float timeLeft = deadline.DiffMilliseconds(currentTimestamp);
141 int hours, minutes, seconds;
142
143 SCR_DateTimeHelper.GetHourMinuteSecondFromSeconds(Math.Ceil(timeLeft * 0.001), hours, minutes, seconds);
144 ActionNameParams[0] = minutes.ToString();
145 ActionNameParams[1] = seconds.ToString();
146
147 if (seconds < 10)
149
150 SetCannotPerformReason(reasonKey);
151 return true;
152 }
153
154 return false;
155 }
156
157 //------------------------------------------------------------------------------------------------
158 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
159 {
160 if (!m_VotingManager)
161 return;
162
163 PlayerController pc = GetGame().GetPlayerController();
164
165 if (!pc)
166 return;
167
168 SCR_VoterComponent comp = SCR_VoterComponent.Cast(pc.FindComponent(SCR_VoterComponent));
169
170 if (!comp)
171 return;
172
173 comp.Vote(EVotingType.COMMANDER, pc.GetPlayerId());
174 }
175
176 //------------------------------------------------------------------------------------------------
178 {
179 return true;
180 }
181
182 //------------------------------------------------------------------------------------------------
183 protected void OnVotingStart(EVotingType type, int value)
184 {
185 if (type == EVotingType.COMMANDER && value == GetGame().GetPlayerController().GetPlayerId())
186 m_bInProgress = true;
187 }
188
189 //------------------------------------------------------------------------------------------------
190 protected void OnVotingEnd(EVotingType type, int value, int winner)
191 {
192 if (type != EVotingType.COMMANDER)
193 return;
194
195 int playerID = GetGame().GetPlayerController().GetPlayerId();
196 if (winner == playerID || value == playerID)
197 m_bInProgress = false;
198 }
199}
EVotingType
Definition EVotingType.c:2
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
EDamageType type
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
ScriptInvokerBase< ScriptInvokerIntMethod > ScriptInvokerInt
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SetCannotPerformReason(string reason)
string ActionNameParams[9]
Can be filled in scripts to be used as params when name is being formatted when displayed in UI.
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
bool IsCooldownActive(WorldTimestamp deadline, string reasonKey)
void OnVotingEnd(EVotingType type, int value, int winner)
SCR_RankContainer GetRanks()
int GetCommanderId()
bool IsCommanderAvailable()
string GetRankName(SCR_ECharacterRank rankID)
proto external PlayerController GetPlayerController()
proto external int GetPlayerId()