Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_FactionCommanderVolunteerUserAction.c
Go to the documentation of this file.
1
class
SCR_FactionCommanderVolunteerUserAction
:
ScriptedUserAction
2
{
3
protected
bool
m_bInProgress
;
4
protected
bool
m_bIsCommanderRoleEnabled
;
5
6
protected
SCR_VotingManagerComponent
m_VotingManager
;
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
//------------------------------------------------------------------------------------------------
15
static
ScriptInvokerInt
GetOnCanBePerformed
()
16
{
17
if
(!
s_OnCanBePerformed
)
18
s_OnCanBePerformed
=
new
ScriptInvokerInt
();
19
20
return
s_OnCanBePerformed
;
21
}
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
38
m_bIsCommanderRoleEnabled
=
true
;
39
40
m_SignupComponent
= SCR_FactionCommanderSignupComponent.Cast(pOwnerEntity.
FindComponent
(SCR_FactionCommanderSignupComponent));
41
42
if
(!
m_SignupComponent
)
43
return
;
44
45
if
(!SCR_FactionCommanderHandlerComponent.GetInstance())
46
return
;
47
48
m_VotingManager
=
SCR_VotingManagerComponent
.GetInstance();
49
50
if
(
m_VotingManager
)
51
{
52
m_VotingManager
.GetOnVotingStart().Insert(
OnVotingStart
);
53
m_VotingManager
.GetOnVotingEnd().Insert(
OnVotingEnd
);
54
}
55
}
56
57
//------------------------------------------------------------------------------------------------
58
override
bool
CanBeShownScript
(
IEntity
user)
59
{
60
if
(
m_bInProgress
|| !
m_VotingManager
|| !
m_SignupComponent
|| !
m_bIsCommanderRoleEnabled
)
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
124
if
(
s_OnCanBePerformed
)
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)
148
ActionNameParams
[1] =
"0"
+
ActionNameParams
[1];
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
//------------------------------------------------------------------------------------------------
177
override
bool
HasLocalEffectOnlyScript
()
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
EVotingType
Definition
EVotingType.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
SCR_CharacterRankComponent
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition
SCR_CharacterRankComponent.c:306
type
EDamageType type
Definition
SCR_DestructibleTreeV2.c:32
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition
SCR_FactionManager.c:498
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition
SCR_GameModeCampaign.c:1812
ScriptInvokerInt
ScriptInvokerBase< ScriptInvokerIntMethod > ScriptInvokerInt
Definition
SCR_ScriptInvokerHelper.c:24
SCR_VotingManagerComponent
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition
SCR_VotingManagerComponent.c:1083
BaseUserAction::SetCannotPerformReason
void SetCannotPerformReason(string reason)
Definition
BaseUserAction.c:21
BaseUserAction::ActionNameParams
string ActionNameParams[9]
Can be filled in scripts to be used as params when name is being formatted when displayed in UI.
Definition
BaseUserAction.c:34
ChimeraWorld
Definition
ChimeraWorld.c:13
GenericComponent
Definition
GenericComponent.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
Math
Definition
Math.c:13
SCR_DateTimeHelper
Definition
SCR_DateTimeHelper.c:2
SCR_FactionCommanderVolunteerUserAction
Definition
SCR_FactionCommanderVolunteerUserAction.c:2
SCR_FactionCommanderVolunteerUserAction::PerformAction
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
Definition
SCR_FactionCommanderVolunteerUserAction.c:158
SCR_FactionCommanderVolunteerUserAction::m_SignupComponent
SCR_FactionCommanderSignupComponent m_SignupComponent
Definition
SCR_FactionCommanderVolunteerUserAction.c:7
SCR_FactionCommanderVolunteerUserAction::m_bIsCommanderRoleEnabled
bool m_bIsCommanderRoleEnabled
Definition
SCR_FactionCommanderVolunteerUserAction.c:4
SCR_FactionCommanderVolunteerUserAction::m_bInProgress
bool m_bInProgress
Definition
SCR_FactionCommanderVolunteerUserAction.c:3
SCR_FactionCommanderVolunteerUserAction::HasLocalEffectOnlyScript
override bool HasLocalEffectOnlyScript()
Definition
SCR_FactionCommanderVolunteerUserAction.c:177
SCR_FactionCommanderVolunteerUserAction::Init
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
Definition
SCR_FactionCommanderVolunteerUserAction.c:24
SCR_FactionCommanderVolunteerUserAction::IsCooldownActive
bool IsCooldownActive(WorldTimestamp deadline, string reasonKey)
Definition
SCR_FactionCommanderVolunteerUserAction.c:131
SCR_FactionCommanderVolunteerUserAction::GetOnCanBePerformed
static ScriptInvokerInt GetOnCanBePerformed()
Definition
SCR_FactionCommanderVolunteerUserAction.c:15
SCR_FactionCommanderVolunteerUserAction::NEXT_VOLUNTEERING_COOLDOWN_TEXT
static const string NEXT_VOLUNTEERING_COOLDOWN_TEXT
Definition
SCR_FactionCommanderVolunteerUserAction.c:11
SCR_FactionCommanderVolunteerUserAction::OnVotingStart
void OnVotingStart(EVotingType type, int value)
Definition
SCR_FactionCommanderVolunteerUserAction.c:183
SCR_FactionCommanderVolunteerUserAction::CanBeShownScript
override bool CanBeShownScript(IEntity user)
Definition
SCR_FactionCommanderVolunteerUserAction.c:58
SCR_FactionCommanderVolunteerUserAction::s_OnCanBePerformed
static ref ScriptInvokerInt s_OnCanBePerformed
Definition
SCR_FactionCommanderVolunteerUserAction.c:9
SCR_FactionCommanderVolunteerUserAction::CanBePerformedScript
override bool CanBePerformedScript(IEntity user)
Definition
SCR_FactionCommanderVolunteerUserAction.c:77
SCR_FactionCommanderVolunteerUserAction::REPLACE_COMMANDER_COOLDOWN_TEXT
static const string REPLACE_COMMANDER_COOLDOWN_TEXT
Definition
SCR_FactionCommanderVolunteerUserAction.c:12
SCR_FactionCommanderVolunteerUserAction::m_VotingManager
SCR_VotingManagerComponent m_VotingManager
Definition
SCR_FactionCommanderVolunteerUserAction.c:6
SCR_FactionCommanderVolunteerUserAction::OnVotingEnd
void OnVotingEnd(EVotingType type, int value, int winner)
Definition
SCR_FactionCommanderVolunteerUserAction.c:190
SCR_Faction
Definition
SCR_Faction.c:6
SCR_Faction::GetRanks
SCR_RankContainer GetRanks()
Definition
SCR_Faction.c:199
SCR_Faction::GetCommanderId
int GetCommanderId()
Definition
SCR_Faction.c:899
SCR_Faction::IsCommanderAvailable
bool IsCommanderAvailable()
Definition
SCR_Faction.c:347
SCR_RankContainer::GetRankName
string GetRankName(SCR_ECharacterRank rankID)
Definition
SCR_RankContainer.c:213
ScriptedUserAction
Definition
ScriptedUserAction.c:13
System
Definition
System.c:13
WorldTimestamp
Definition
WorldTimestamp.c:26
GetPlayerController
proto external PlayerController GetPlayerController()
Definition
SCR_PlayerDeployMenuHandlerComponent.c:307
GetPlayerId
proto external int GetPlayerId()
Definition
SCR_SpawnRequestComponent.c:39
scripts
Game
FactionCommander
UserActions
SCR_FactionCommanderVolunteerUserAction.c
Generated by
1.17.0