Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_VotingFactionCommander.c
Go to the documentation of this file.
3{
4 //------------------------------------------------------------------------------------------------
5 override bool IsAvailable(int value, bool isOngoing)
6 {
8 if (!campaignGameMode || !campaignGameMode.GetCommanderRoleEnabled())
9 return false;
10
11 SCR_FactionManager fManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
12
13 if (!fManager)
14 return false;
15
16 Faction playerFaction = fManager.GetPlayerFaction(value);
17
18 if (!playerFaction)
19 return false;
20
21 SCR_Faction playerFactionLocal = SCR_Faction.Cast(fManager.GetLocalPlayerFaction());
22
23 if (!playerFactionLocal || !playerFactionLocal.IsCommanderAvailable())
24 return false;
25
26 if (isOngoing)
27 return (playerFaction == playerFactionLocal);
28
29 PlayerController playerController = GetGame().GetPlayerController();
30
31 if (!playerController)
32 return false;
33
34 if (value != playerController.GetPlayerId())
35 return false;
36
37 if (value == playerFactionLocal.GetCommanderId())
38 return false;
39
40 SCR_FactionCommanderHandlerComponent handlerComponent = SCR_FactionCommanderHandlerComponent.GetInstance();
41
42 if (!handlerComponent)
43 return false;
44
45 if (handlerComponent.CheckRank())
46 {
47 IEntity player = playerController.GetControlledEntity();
48
49 if (!player)
50 return false;
51
52 if (SCR_CharacterRankComponent.GetCharacterRank(player) < handlerComponent.GetMinimumRank())
53 return false;
54 }
55
56 SCR_FactionCommanderPlayerComponent comp = SCR_FactionCommanderPlayerComponent.Cast(playerController.FindComponent(SCR_FactionCommanderPlayerComponent));
57
58 if (!comp)
59 return false;
60
61 ChimeraWorld world = GetGame().GetWorld();
62
63 if (!world)
64 return false;
65
66 WorldTimestamp currentTimestamp = world.GetServerTimestamp();
67 WorldTimestamp ReplaceCommanderCooldown = comp.GetReplaceCommanderCooldownTimestamp();
68 if (ReplaceCommanderCooldown.Greater(currentTimestamp))
69 return false;
70
71 return world.GetServerTimestamp().GreaterEqual(comp.GetNextVolunteeringTimestamp());
72 }
73
74 //------------------------------------------------------------------------------------------------
75 override int GetPlayerCount()
76 {
77 int playerCount;
78 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
79
80 Faction targetFaction;
81
82 if (factionManager)
83 targetFaction = factionManager.GetPlayerFaction(m_iValue);
84
85 //--- Count only players on the same faction as target of the vote
86 //--- e.g., with 50% vote limit, only half of BLUFOR players will have to vote, not half of all players
87
88 Faction playerFaction;
89 array<int> players = {};
90
91 for (int i = 0, count = GetGame().GetPlayerManager().GetPlayers(players); i < count; i++)
92 {
93 playerFaction = factionManager.GetPlayerFaction(players[i]);
94
95 if (targetFaction == playerFaction)
96 playerCount++;
97 }
98
99 //--- Limit to prevent instant completion in a session with less than limited participants
100 return Math.Max(playerCount, m_iMinVotes);
101 }
102
103 //------------------------------------------------------------------------------------------------
104 override bool CanSendNotification(int value)
105 {
106 SCR_FactionManager fManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
107
108 if (!fManager)
109 return false;
110
111 return (fManager.GetPlayerFaction(value) == fManager.GetLocalPlayerFaction());
112 }
113
114 //------------------------------------------------------------------------------------------------
115 override void OnVotingEnd(int value = DEFAULT_VALUE, int winner = DEFAULT_VALUE)
116 {
117 if (winner == DEFAULT_VALUE)
118 return;
119
120 if (Replication.IsClient())
121 return;
122
123 SCR_FactionCommanderHandlerComponent component = SCR_FactionCommanderHandlerComponent.GetInstance();
124
125 if (!component)
126 return;
127
128 component.SetFactionCommander(SCR_Faction.Cast(SCR_FactionManager.SGetPlayerFaction(winner)), winner);
129 }
130
131 //------------------------------------------------------------------------------------------------
132 override int GetWinner()
133 {
134 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
135 if (!factionManager)
136 return 0;
137
138 SCR_Faction targetFaction = SCR_Faction.Cast(factionManager.GetPlayerFaction(m_iValue));
139 if (!targetFaction)
140 return 0;
141
142 // Current Commander is AI, appoint first volunteer as Commander
143 if (targetFaction.GetCommanderId() <= 0)
144 return m_iValue;
145
146 return super.GetWinner();
147 }
148}
EVotingType
Definition EVotingType.c:2
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_BaseGameMode GetGameMode()
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
int GetPlayers(out notnull array< int > outPlayers)
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition Math.c:13
Main replication API.
Definition Replication.c:14
int GetCommanderId()
bool IsCommanderAvailable()
static const int DEFAULT_VALUE
override int GetWinner()