1 [
EntityEditorProps(
category:
"GameScripted/Groups", description:
"This component should be attached to player controller and is used by groups to send requests to server.")]
26 static SCR_PlayerControllerGroupComponent GetPlayerControllerComponent(
int playerID)
28 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerID);
29 if (!playerController)
32 return SCR_PlayerControllerGroupComponent.Cast(playerController.FindComponent(SCR_PlayerControllerGroupComponent));
37 static SCR_PlayerControllerGroupComponent GetLocalPlayerControllerGroupComponent()
40 if (!playerController)
43 return SCR_PlayerControllerGroupComponent.Cast(playerController.FindComponent(SCR_PlayerControllerGroupComponent));
107 PlayerController playerController = PlayerController.Cast(
GetOwner());
108 if (!playerController)
111 return playerController.GetPlayerId();
132 Faction groupFaction = group.GetFaction();
135 #ifdef DEPLOY_MENU_DEBUG
136 Print(
string.Format(
"SCR_PlayerControllerGroupComponent.CanPlayerJoinGroup(%1, %2) - No group faction", playerID, group), LogLevel.ERROR);
141 PlayerController pc =
GetGame().GetPlayerManager().GetPlayerController(playerID);
144 #ifdef DEPLOY_MENU_DEBUG
145 Print(
string.Format(
"SCR_PlayerControllerGroupComponent.CanPlayerJoinGroup(%1, %2) - No player controller", playerID, group), LogLevel.ERROR);
152 if (!playerAffiliation)
155 #ifdef DEPLOY_MENU_DEBUG
156 Print(
string.Format(
"SCR_PlayerControllerGroupComponent.CanPlayerJoinGroup(%1, %2) - No SCR_PlayerFactionAffiliationComponent", playerID, group), LogLevel.ERROR);
161 Faction playerFaction = playerAffiliation.GetAffiliatedFaction();
162 if (playerFaction != groupFaction)
164 #ifdef DEPLOY_MENU_DEBUG
165 Print(
string.Format(
"SCR_PlayerControllerGroupComponent.CanPlayerJoinGroup(%1, %2) - Faction mis-match! See, below:", playerID, group), LogLevel.ERROR);
166 Print(playerFaction, LogLevel.NORMAL);
168 Print(playerFaction.GetFactionKey(), LogLevel.NORMAL);
170 Print(groupFaction, LogLevel.NORMAL);
172 Print(groupFaction.GetFactionKey(), LogLevel.NORMAL);
213 #ifdef DEPLOY_MENU_DEBUG
214 Print(
string.Format(
"SCR_PlayerControllerGroupComponent.CanPlayerJoinGroup(%1, %2) - No SCR_GroupsManagerComponent!", playerID, group), LogLevel.ERROR);
224 if (groupsManager.GetPlayerGroup(playerID) == group)
226 #ifdef DEPLOY_MENU_DEBUG
227 Print(
string.Format(
"SCR_PlayerControllerGroupComponent.CanPlayerJoinGroup(%1, %2) - Already in group!", playerID, group), LogLevel.ERROR);
242 return playerID == group.GetLeaderID();
259 int playerID = controller.GetPlayerId();
260 SCR_AIGroup playerGroup = groupManager.GetPlayerGroup(playerID);
425 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
432 group.AddRequester(playerID);
433 SCR_NotificationsComponent.SendToPlayer(group.GetLeaderID(),
ENotification.GROUPS_REQUEST_JOIN_PRIVATE_GROUP, playerID);
440 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
451 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerID);
452 if (!playerController)
455 SCR_PlayerControllerGroupComponent playerComponent = SCR_PlayerControllerGroupComponent.Cast(playerController.FindComponent(SCR_PlayerControllerGroupComponent));
457 playerComponent.RequestJoinGroup(group.GetGroupID());
459 group.RemoveRequester(playerID);
461 SCR_NotificationsComponent.SendToPlayer(playerID,
ENotification.GROUPS_REQUEST_ACCEPTED);
468 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
479 group.RemoveRequester(playerID);
480 group.AddDeniedRequester(playerID);
482 SCR_NotificationsComponent.SendToPlayer(playerID,
ENotification.GROUPS_REQUEST_DENIED);
489 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
507 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
510 PlayerController invitedPlayer =
GetGame().GetPlayerManager().GetPlayerController(playerID);
514 SCR_PlayerControllerGroupComponent invitedPlayerGroupComponent = SCR_PlayerControllerGroupComponent.Cast(invitedPlayer.FindComponent(SCR_PlayerControllerGroupComponent));
515 if (!invitedPlayerGroupComponent)
523 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
543 if (groupsManager.TryFindEmptyGroup(faction))
547 if(scrFaction.GetCanCreateOnlyPredefinedGroups())
551 SCR_AIGroup newGroup = groupsManager.CreateNewPlayableGroup(faction);
565 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
569 SCR_PlayerControllerGroupComponent playerGroupController;
578 SCR_AIGroup newGroup = groupsManager.GetFirstNotFullForFaction(group.GetFaction(), group,
true);
580 newGroup = groupsManager.CreateNewPlayableGroup(group.GetFaction());
584 playerGroupController.RequestJoinGroup(newGroup.GetGroupID());
590 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
594 SCR_PlayerControllerGroupComponent playerGroupController;
602 groupsManager.SetGroupLeader(group.GetGroupID(), playerID);
609 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
613 SCR_PlayerControllerGroupComponent playerGroupController;
618 groupsManager.SetPrivateGroup(group.GetGroupID(), isPrivate);
632 [
RplRpc(RplChannel.Reliable, RplRcver.Owner)]
656 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
671 groupIDAfter = groupsManager.AddPlayerToGroup(groupID,
GetPlayerID());
693 playerGroupController = SCR_PlayerControllerGroupComponent.GetPlayerControllerComponent(playerID);
694 if (!playerGroupController)
697 group = groupsManager.GetPlayerGroup(playerID);
789 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
796 SCR_AIGroup group = groupsManager.FindGroup(groupID);
800 group.SetCustomDescription(
desc, authorID);
813 SCR_AIGroup group = groupsManager.FindGroup(groupID);
817 if (group.GetMaxMembers() == maxMembers || maxMembers < 0)
827 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
834 SCR_AIGroup group = groupsManager.FindGroup(groupID);
838 if (group.GetMaxMembers() == maxMembers || maxMembers < 0)
841 group.SetMaxMembers(maxMembers);
856 SCR_AIGroup group = groupsManager.FindGroup(groupID);
860 if (frequency < 0 || group.GetRadioFrequency() == frequency)
872 if (!groupsManager || isAllowed == groupsManager.GetNewGroupsAllowed())
884 if (!groupsManager || isAllowed == groupsManager.GetNewGroupsAllowed())
904 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
911 SCR_AIGroup group = groupsManager.FindGroup(groupID);
915 group.SetCustomName(name, authorID);
921 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
925 if (!groupsManager || isAllowed == groupsManager.GetNewGroupsAllowed())
928 groupsManager.SetNewGroupsAllowed(isAllowed);
934 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
938 if (!groupsManager || isAllowed == groupsManager.GetNewGroupsAllowed())
941 groupsManager.SetCanPlayersChangeAttributes(isAllowed);
948 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
955 SCR_AIGroup group = groupsManager.FindGroup(groupID);
959 if (frequency < 0 || group.GetRadioFrequency() == frequency)
966 int formerFrequency = group.GetRadioFrequency();
967 int foundGroupsWithFrequency = 0;
970 array<SCR_AIGroup> existingGroups = groupsManager.GetPlayableGroupsByFaction(groupFaction);
974 if (checkedGroup.GetRadioFrequency() == formerFrequency)
975 foundGroupsWithFrequency++;
979 if (foundGroupsWithFrequency <= 1)
980 groupsManager.ReleaseFrequency(formerFrequency, groupFaction);
983 if (!groupsManager.IsFrequencyClaimed(frequency, groupFaction))
984 groupsManager.ClaimFrequency(frequency, groupFaction);
986 group.SetRadioFrequency(frequency);
1004 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
1011 SCR_AIGroup group = groupsManager.FindGroup(groupID);
1015 group.SetGroupFlag(flagIndex, isFromImageset);
1021 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
1032 group.ClearRequesters();
1033 group.ClearDeniedRequester();
1047 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
1055 if (!commandingManager)
1058 IEntity groupEntity =
GetGame().SpawnEntityPrefab(Resource.Load(commandingManager.GetGroupPrefab()));
1066 RplComponent slaveRplComp = RplComponent.Cast(group.FindComponent(RplComponent));
1070 groupManager.RequestSetGroupSlave(rplCompID, slaveRplComp.Id());
1086 array<SCR_AIGroup> groups = groupManager.GetPlayableGroupsByFaction(faction);
1090 if (group.IsAIControlledCharacterMember(character))
1103 RplComponent rplComp = RplComponent.Cast(character.FindComponent(RplComponent));
1114 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
1118 SCR_PlayerControllerGroupComponent playerGroupController;
1123 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(characterID));
1127 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(rplComp.GetEntity());
1131 if (!group.IsPlayerLeader(playerID))
1151 if (!slaveGroup.IsAIActivated())
1152 slaveGroup.ActivateAI();
1154 slaveGroup.AddAgentFromControlledEntity(controlledEntity);
1156 RplId groupCompID, characterCompID;
1157 RplComponent rplComp = RplComponent.Cast(slaveGroup.FindComponent(RplComponent));
1161 groupCompID = rplComp.Id();
1162 rplComp = RplComponent.Cast(controlledEntity.FindComponent(RplComponent));
1163 characterCompID = rplComp.Id();
1165 groupManager.AskAddAiMemberToGroup(groupCompID, characterCompID);
1172 [
RplRpc(RplChannel.Reliable, RplRcver.Server)]
1176 SCR_PlayerControllerGroupComponent playerGroupController;
1181 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(characterID));
1185 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(rplComp.GetEntity());
1189 if (!group.IsPlayerLeader(playerID))
1210 if (slaveGroup.GetAgentsCount() == 1)
1211 slaveGroup.Deactivate();
1213 slaveGroup.RemoveAgentFromControlledEntity(controlledEntity);
1215 RplId groupCompID, characterCompID;
1216 RplComponent rplComp = RplComponent.Cast(slaveGroup.FindComponent(RplComponent));
1217 groupCompID = rplComp.Id();
1218 rplComp = RplComponent.Cast(controlledEntity.FindComponent(RplComponent));
1222 characterCompID = rplComp.Id();
1224 groupManager.AskRemoveAiMemberFromGroup(groupCompID, characterCompID);
1233 RplComponent rplComp = RplComponent.Cast(character.FindComponent(RplComponent));
1243 super.OnPostInit(owner);
1250 DiagMenu.RegisterMenu(
SCR_DebugMenuID.DEBUGUI_GROUPS,
"Groups",
"GameCode");
1251 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_GROUPS_ENABLE_DIAG,
"",
"Enable groups diag",
"Groups");
1252 ConnectToDiagSystem(owner);
1254 groupsManager.GetOnPlayableGroupRemoved().Insert(
OnGroupDeleted);
1261 DisconnectFromDiagSystem(owner);
1264 super.OnDelete(owner);
1290 return group.GetRadioFrequency();
1294 override void EOnDiag(IEntity owner,
float timeSlice)
1299 DbgUI.Begin(
"Groups");
1305 faction = factionManager.GetPlayerFaction(playerID);
1309 DbgUI.Text(
"Groups do not support factionless players now!!");
1316 DbgUI.Text(
"Your Faction:" + faction.GetFactionKey());
1319 DbgUI.Text(
"Playable groups of your faction:");
1323 DbgUI.Text(
"Your group:");
1324 SCR_AIGroup group = groupsManager.GetPlayerGroup(playerID);
1327 DbgUI.Text(
"." + group.ToString());
1328 Print(group.ToString(), LogLevel.NORMAL);
1332 if (DbgUI.Button(
"Create and join group for my faction"))
1345 array<SCR_AIGroup> groups = groupsManager.GetPlayableGroupsByFaction(faction);
1348 DbgUI.Text(
"No groups for your faction!!");
1354 DbgUI.Text(group.ToString());
1363 SCR_PlayerControllerGroupComponent playerGroupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
1364 if (!playerGroupController)
1368 if (!groupsManager || !groupsManager.IsPlayerInAnyGroup(
SCR_PlayerController.GetLocalPlayerId()))
1371 SCR_AIGroup group = groupsManager.GetFirstNotFullForFaction(faction,
null,
true);
1373 playerGroupController.RequestJoinGroup(group.GetGroupID());
1375 playerGroupController.RequestCreateGroup();