6[
ComponentEditorProps(
category:
"GameScripted/Commander", description:
"Handles voting and AI decisions for the faction Commander role. Should be attached to gamemode entity.")]
13 [
Attribute(
"600",
desc:
"How often can a player volunteer for the Commander role (seconds).",
params:
"0 inf 1")]
14 protected int m_iVolunteerCooldown;
16 [
Attribute(
"300",
desc:
"When the commander can be replaced after being elected (seconds).",
params:
"0 inf 1")]
17 protected int m_iReplaceCommanderCooldown;
19 [
Attribute(
"1",
desc:
"When enabled, players need to gain a specific rank to be able to voluteer for the Commander role.")]
20 protected bool m_bCheckRank;
22 [
Attribute(SCR_ECharacterRank.PRIVATE.ToString(), uiwidget:
UIWidgets.ComboBox,
desc:
"If enabled, only players with this rank or higher can voluteer for the Commander role.", enumType:SCR_ECharacterRank)]
23 protected SCR_ECharacterRank m_eMinimumCommanderRank;
26 protected ref array<ref SCR_BaseAIFactionCommander> m_aAIFactionCommanders;
32 [
RplProp(onRplName:
"OnFactionCommanderChanged")]
33 protected ref array<int> m_aFactionCommanders = {};
40 static SCR_FactionCommanderHandlerComponent GetInstance()
42 BaseGameMode gameMode =
GetGame().GetGameMode();
47 return SCR_FactionCommanderHandlerComponent.Cast(gameMode.FindComponent(SCR_FactionCommanderHandlerComponent));
53 if (!m_OnFactionCommanderChanged)
56 return m_OnFactionCommanderChanged;
62 return m_iVolunteerCooldown;
80 return m_eMinimumCommanderRank;
88 if (oldCommanderId <= 0)
95 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(oldCommanderId);
96 if (!playerController)
103 SCR_PlayerControllerGroupComponent playerControllerGroupComponent = SCR_PlayerControllerGroupComponent.Cast(playerController.FindComponent(SCR_PlayerControllerGroupComponent));
104 if (!playerControllerGroupComponent)
108 int previousGroupID = playerControllerGroupComponent.GetPreviousGroupID();
109 if (previousGroupID >= 0)
111 SCR_AIGroup previousGroup = groupsManager.FindGroup(previousGroupID);
112 if (previousGroup && !previousGroup.
IsFull())
114 playerControllerGroupComponent.RequestJoinGroup(previousGroupID);
119 SCR_AIGroup group = groupsManager.GetFirstNotFullForFaction(faction, null,
true);
122 playerControllerGroupComponent.RequestJoinGroup(group.
GetGroupID());
126 playerControllerGroupComponent.RequestCreateGroupWithData(
SCR_EGroupRole.ASSAULT,
false,
"",
"");
128 group = groupsManager.GetFirstNotFullForFaction(faction, null,
true);
131 playerControllerGroupComponent.RequestJoinGroup(group.
GetGroupID());
144 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(newCommanderId);
145 if (!playerController)
152 array<SCR_AIGroup> playableGroups = groupsManager.GetPlayableGroupsByFaction(faction);
159 if (aiGroup && aiGroup.GetGroupRole() ==
SCR_EGroupRole.COMMANDER)
161 commanderGroup = aiGroup;
169 SCR_PlayerControllerGroupComponent playerControllerGroupComponent = SCR_PlayerControllerGroupComponent.Cast(playerController.FindComponent(SCR_PlayerControllerGroupComponent));
170 if (!playerControllerGroupComponent)
173 playerControllerGroupComponent.RequestJoinGroup(commanderGroup.
GetGroupID());
179 if (faction.GetCommanderId() == commanderPlayerId)
182 FactionManager fManager =
GetGame().GetFactionManager();
190 foreach (
int index,
int element : m_aFactionCommanders)
195 if (element != factionIndex)
198 if (m_aFactionCommanders.IsIndexValid(
index + 1))
199 m_aFactionCommanders.Set(
index + 1, commanderPlayerId);
201 m_aFactionCommanders.Insert(commanderPlayerId);
208 m_aFactionCommanders.Insert(factionIndex);
209 m_aFactionCommanders.Insert(commanderPlayerId);
216 if (commanderPlayerId > 0)
218 WorldTimestamp timeStamp = world.GetServerTimestamp().PlusSeconds(m_iReplaceCommanderCooldown);
244 int myFactionIdx = factionManager.GetFactionIndex(myFaction);
245 if (myFactionIdx != factionIdx)
248 PlayerController playerController =
GetGame().GetPlayerController();
249 if (!playerController)
252 SCR_FactionCommanderPlayerComponent comp = SCR_FactionCommanderPlayerComponent.Cast(playerController.FindComponent(SCR_FactionCommanderPlayerComponent));
256 comp.SetReplaceCommanderCooldownTimestamp(timeStamp);
262 FactionManager fManager =
GetGame().GetFactionManager();
267 foreach (
int index,
int element : m_aFactionCommanders)
272 if (!m_aFactionCommanders.IsIndexValid(
index + 1))
280 int commanderId = m_aFactionCommanders[
index + 1];
283 if (commanderIdOld == commanderId)
292 PlayerController pc =
GetGame().GetPlayerController();
296 int playerId = pc.GetPlayerId();
298 if (commanderIdOld == playerId || commanderId == playerId)
300 SCR_FactionCommanderPlayerComponent component = SCR_FactionCommanderPlayerComponent.Cast(pc.FindComponent(SCR_FactionCommanderPlayerComponent));
304 if (commanderIdOld == playerId)
305 component.OnCommanderRightsLost();
307 component.OnCommanderRightsGained();
312 if (m_OnFactionCommanderChanged)
313 m_OnFactionCommanderChanged.Invoke(faction, commanderId);
328 FactionManager fManager =
GetGame().GetFactionManager();
333 int factionIndex = -1;
335 foreach (
int index,
int element : m_aFactionCommanders)
340 if (element != playerId)
343 factionIndex = m_aFactionCommanders[
index - 1];
347 if (factionIndex == -1)
352 if (!commandedFaction || commandedFaction == faction)
356 SCR_NotificationsComponent.SendToFaction(commandedFaction,
false,
ENotification.VOTING_COMMANDER_WITHDRAW, playerId);
370 WorldTimestamp timestamp = world.GetServerTimestamp().PlusSeconds(m_iVolunteerCooldown);
371 m_mVotingTimestamps.Set(value, timestamp);
381 PlayerController controller =
GetGame().GetPlayerManager().GetPlayerController(winner);
388 if (!playerXPHandlerComponent)
397 PlayerController pc =
GetGame().GetPlayerManager().GetPlayerController(playerId);
402 SCR_FactionCommanderPlayerComponent comp = SCR_FactionCommanderPlayerComponent.Cast(pc.FindComponent(SCR_FactionCommanderPlayerComponent));
407 comp.SetNextVolunteeringTimestamp(timestamp);
413 WorldTimestamp cooldownTimestamp = m_mVotingTimestamps.Get(playerId);
414 if (!cooldownTimestamp)
417 string groupId, reasonId;
422 GetGame().GetFullKickReason(cause, groupInt, reasonInt, groupId, reasonId);
431 if (cooldownTimestamp.Greater(now))
433 m_mVotingTimestamps.Set(playerId, now);
442 super.OnPlayerRegistered(playerId);
444 if (m_mVotingTimestamps.Get(playerId))
452 super.OnPlayerDisconnected(playerId, cause, timeout);
459 FactionManager fManager =
GetGame().GetFactionManager();
464 int factionIndex = -1;
466 foreach (
int index,
int element : m_aFactionCommanders)
471 if (element != playerId)
474 factionIndex = m_aFactionCommanders[
index - 1];
478 if (factionIndex == -1)
490 SCR_NotificationsComponent.SendToFaction(faction,
false,
ENotification.VOTING_COMMANDER_WITHDRAW, playerId);
492 int factionIdx = fManager.GetFactionIndex(faction);
505 commander.Init(
this);
524 super.EOnInit(owner);
540 votingManager.GetOnVotingEnd().Insert(
OnVotingEnd);
548 super.OnPostInit(owner);
ArmaReforgerScripted GetGame()
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
override void OnGameEnd()
Called on all machines when the world ends.
SCR_BaseGameMode GetGameMode()
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
override void OnGameModeStart()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
RplComponent m_RplComponent
void OnServerCommanderChanged(int newCommanderId, int oldCommanderId)
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_EGroupRole
Group roles.
void SetGroupForNewCommander(int newCommanderId)
WorldTimestamp GetFactionCooldown(int factionIndex)
ScriptInvokerBase< OnFactionCommanderChangedDelegate > OnFactionCommanderChangedInvoker
OnFactionCommanderChangedInvoker GetOnFactionCommanderChanged()
void SetFactionCommander(notnull SCR_Faction faction, int commanderPlayerId)
SCR_ECharacterRank GetMinimumRank()
int GetVolunteerCooldown()
void OnVotingStart(EVotingType type, int value)
ref map< int, WorldTimestamp > m_mReplaceCommanderCooldowns
void RpcDo_FactionCooldown(int factionIdx, WorldTimestamp timeStamp)
void SetNextVolunteeringTimestamp(int playerId, WorldTimestamp timestamp)
void OnFactionCommanderChanged()
void SetGroupForOldCommander(int oldCommanderId)
func OnFactionCommanderChangedDelegate
void DisableVolunteerCooldown(int playerId, KickCauseCode cause)
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void OnPlayerFactionChanged(SCR_PlayerFactionAffiliationComponent component, Faction previous, Faction current)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
override void OnVotingEnd(int value=DEFAULT_VALUE, int winner=DEFAULT_VALUE)
void SCR_VotingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external Managed FindComponent(typename typeName)
int GetPlayerCount(bool checkMasterAndSlaves=false)
Handles voting and AI decisions for the faction Commander role. Should be attached to gamemode entity...
void SetCommanderId(int playerId)
void UpdatePlayerRank(bool notify=true)
override void EOnInit(IEntity owner)
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
override void OnPlayerRegistered(int playerId)
override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
KickCauseGroup2
Extends KickCauseGroup by adding game-specific groups.
RplRole
Role of replicated node (and all items in it) within the replication system.
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.