Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FactionCommanderPlayerComponent.c
Go to the documentation of this file.
1
2[ComponentEditorProps(category: "GameScripted/Commander", description: "Handles interactions for the faction Commander role. Should be attached to player controller.")]
4{
5 [Attribute("squad", desc: "Default icon for a group order.", category: "Defaults")]
6 protected string m_sGroupOrderIcon;
7
8 [Attribute("VON_radio", desc: "Default icon for a request order.", category: "Defaults")]
9 protected string m_sRequestOrderIcon;
10
11 [Attribute("addCircle", desc: "Default icon for a create objective order.", category: "Defaults")]
13
14 [Attribute("#AR-Tasks_TitleRequest", desc: "'Request' default text.", category: "Defaults")]
15 protected string m_sStringRequest;
16
17 [Attribute("#AR-FactionCommander_TaskObjective", desc: "'Create objective' default text.", category: "Defaults")]
18 protected string m_sStringCreateObjective;
19
20 //------------------------------------------------------------------------------------------------
22 {
23 return m_sGroupOrderIcon;
24 }
25
26 //------------------------------------------------------------------------------------------------
28 {
30 }
31
32 //------------------------------------------------------------------------------------------------
37
38 //------------------------------------------------------------------------------------------------
40 {
41 return m_sStringRequest;
42 }
43
44 //------------------------------------------------------------------------------------------------
49}
50
51class SCR_FactionCommanderPlayerComponent : ScriptComponent
52{
53 protected bool m_bMenuVisible;
54
56
58
60
62
67
73
74 [RplProp(condition: RplCondition.OwnerOnly)]
76
77 protected SCR_MapCursorModule m_MapCursorModule;
79
82
83 protected static int s_iLastGeneratedTaskId;
84
85 static const string TASK_ID = "%1_Task_%2";
86 static const string REQUESTED_TASK_ID = "%1_RequestedTask_%2";
87
88 //------------------------------------------------------------------------------------------------
89 SCR_FactionCommanderMenuEntry GetConfigForEntry(notnull SCR_SelectionMenuEntry entry)
90 {
92 return null;
93
94 SCR_FactionCommanderMenuEntry configEntry = m_mTaskRootMenuEntries.Get(entry);
95 if (configEntry)
96 return configEntry;
97
98 if (m_mEntryNames)
99 {
101 if (m_mEntryNames && m_mTaskRootMenuEntries && m_mEntryNames.Find(entry.GetId(), key))
102 return m_mTaskRootMenuEntries.Get(key);
103 }
104
105 return null;
106 }
107
108 //------------------------------------------------------------------------------------------------
113
114 //------------------------------------------------------------------------------------------------
119
120 //------------------------------------------------------------------------------------------------
121 static int GenerateTaskID()
122 {
123 return s_iLastGeneratedTaskId++;
124 }
125
126 //------------------------------------------------------------------------------------------------
127 static bool IsLocalPlayerCommander()
128 {
129 PlayerController pc = GetGame().GetPlayerController();
130
131 if (!pc)
132 return false;
133
134 SCR_Faction faction = SCR_Faction.Cast(SCR_FactionManager.SGetPlayerFaction(pc.GetPlayerId()));
135
136 if (!faction)
137 return false;
138
139 return (pc.GetPlayerId() == faction.GetCommanderId());
140 }
141
142 //------------------------------------------------------------------------------------------------
144
145 //------------------------------------------------------------------------------------------------
147
148 //------------------------------------------------------------------------------------------------
150 {
152 Replication.BumpMe();
153 }
154
155 //------------------------------------------------------------------------------------------------
160
161 //------------------------------------------------------------------------------------------------
164 {
165 return m_mEntryNames.Get(name);
166 }
167
168 //------------------------------------------------------------------------------------------------
171 {
172 return m_mEntryGroups.Get(entry);
173 }
174
175 //------------------------------------------------------------------------------------------------
177 {
178 string name;
179 if (category)
180 name = category.GetId();
181
183 entry.SetId(name);
184 string disabledText;
185
187 entry.Enable(requestHandler.CanRequestEntryBeSelected(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity, disabledText));
188 m_mEntryParents.Set(entry, category);
189 m_mEntryHandlers.Set(entry, handler);
190 m_mTaskRootMenuEntries.Set(entry, handler.GetMenuEntry());
191 requestHandler.SetMenuEntry(handler.GetMenuEntry());
192
193 if (!disabledText.IsEmpty())
194 entry.SetName(disabledText);
195
196 ResourceName imagesetName;
197 string iconName;
198 GetRequestOrderEntryIconData(imagesetName, iconName);
199
200 if (!iconName.IsEmpty())
201 {
202 if (imagesetName.IsEmpty())
203 entry.SetIconFromDeafaultImageSet(iconName);
204 else
205 entry.SetIcon(imagesetName, iconName);
206 }
207 }
208
209 //------------------------------------------------------------------------------------------------
211 {
212 string name;
213 if (category)
214 name = category.GetId();
215
217 entry.SetId(name);
218 string disabledText;
219
221 entry.Enable(conflictBaseMenuhandler.CanCreateObjectiveEntryBeSelected(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity, disabledText));
222 m_mEntryParents.Set(entry, category);
223 m_mEntryHandlers.Set(entry, handler);
224 m_mTaskRootMenuEntries.Set(entry, handler.GetMenuEntry());
225
226 if (!disabledText.IsEmpty())
227 entry.SetName(disabledText);
228
229 ResourceName imagesetName;
230 string iconName;
231 GetCreateObjectiveOrderEntryIconData(imagesetName, iconName);
232
233 if (!iconName.IsEmpty())
234 {
235 if (imagesetName.IsEmpty())
236 entry.SetIconFromDeafaultImageSet(iconName);
237 else
238 entry.SetIcon(imagesetName, iconName);
239 }
240 }
241
242 //------------------------------------------------------------------------------------------------
245 {
246 SCR_Faction faction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
247
248 if (!faction)
249 return;
250
252
253 if (!groupsManager)
254 return;
255
256 string name;
257 if (category)
258 name = category.GetId();
259
260 array<SCR_AIGroup> playableGroups = groupsManager.GetPlayableGroupsByFaction(faction);
262
263 foreach (SCR_AIGroup group : playableGroups)
264 {
265 if (!group || !handler.CanGroupEntryBeShown(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity, group))
266 continue;
267
268 string disabledText;
269 entry = m_MapContextualMenu.AddRadialEntry(GetGroupEntryDisplayName(group), category);
270 entry.SetId(name);
271 entry.Enable(handler.CanGroupEntryBeSelected(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity, group, disabledText));
272 m_mEntryParents.Set(entry, category);
273 m_mEntryHandlers.Set(entry, handler);
274 m_mTaskRootMenuEntries.Set(entry, handler.GetMenuEntry());
275
276 if (!disabledText.IsEmpty())
277 entry.SetName(disabledText);
278
279 ResourceName imagesetName;
280 string iconName;
281 GetGroupEntryIconData(group, imagesetName, iconName);
282
283 if (!iconName.IsEmpty())
284 {
285 if (imagesetName.IsEmpty())
286 entry.SetIconFromDeafaultImageSet(iconName);
287 else
288 entry.SetIcon(imagesetName, iconName);
289 }
290
291 m_mEntryGroups.Set(entry, group);
292 }
293 }
294
295 //------------------------------------------------------------------------------------------------
297 protected string GetGroupEntryDisplayName(SCR_AIGroup group)
298 {
299 // This function can only be used in UI menu, where to change the language you need to close and open the shown menu, so it will be renewed.
301 }
302
303 //------------------------------------------------------------------------------------------------
305 protected void GetGroupEntryIconData(SCR_AIGroup group, out ResourceName imagesetName, out string iconName)
306 {
307 iconName = GetDefaultGroupOrderIcon();
308 }
309
310 //------------------------------------------------------------------------------------------------
311 protected string GetDefaultGroupOrderIcon()
312 {
313 IEntity owner = GetOwner();
314
315 if (!owner)
316 return string.Empty;
317
319
320 if (!componentData)
321 return string.Empty;
322
323 return componentData.GetGroupOrderIcon();
324 }
325
326 //------------------------------------------------------------------------------------------------
329 {
330 IEntity owner = GetOwner();
331
332 if (!owner)
333 return string.Empty;
334
336
337 if (!componentData)
338 return string.Empty;
339
340 return componentData.GetStringRequest();
341 }
342
343 //------------------------------------------------------------------------------------------------
345 protected void GetRequestOrderEntryIconData(out ResourceName imagesetName, out string iconName)
346 {
347 iconName = GetDefaultRequestOrderIcon();
348 }
349
350 //------------------------------------------------------------------------------------------------
351 protected string GetDefaultRequestOrderIcon()
352 {
353 IEntity owner = GetOwner();
354
355 if (!owner)
356 return string.Empty;
357
359
360 if (!componentData)
361 return string.Empty;
362
363 return componentData.GetRequestOrderIcon();
364 }
365
366 //------------------------------------------------------------------------------------------------
369 {
370 IEntity owner = GetOwner();
371
372 if (!owner)
373 return string.Empty;
374
376
377 if (!componentData)
378 return string.Empty;
379
380 return componentData.GetStringCreateObjective();
381 }
382
383 //------------------------------------------------------------------------------------------------
385 protected void GetCreateObjectiveOrderEntryIconData(out ResourceName imagesetName, out string iconName)
386 {
388 }
389
390 //------------------------------------------------------------------------------------------------
392 {
393 IEntity owner = GetOwner();
394
395 if (!owner)
396 return string.Empty;
397
399
400 if (!componentData)
401 return string.Empty;
402
403 return componentData.GetCreateObjectiveOrderIcon();
404 }
405
406 //------------------------------------------------------------------------------------------------
407 protected void OnMapOpen(MapConfiguration config)
408 {
409 m_MapCursorModule = SCR_MapCursorModule.Cast(SCR_MapEntity.GetMapInstance().GetMapModule(SCR_MapCursorModule));
410
411 m_HoveredEntity = null;
412
415
417
420
422 {
423 m_MapContextualMenu.GetOnMenuInitInvoker().Insert(OnContextualMenuInit);
424 m_MapContextualMenu.GetOnEntryPerformedInvoker().Insert(OnCommandPerformed);
425 m_MapContextualMenu.GetOnEntrySelectedInvoker().Insert(OnEntryHovered);
426 }
427 }
428
429 //------------------------------------------------------------------------------------------------
430 protected void OnMapClose(MapConfiguration config)
431 {
432 m_bMenuVisible = false;
433 m_HoveredEntity = null;
434
437
439
442
444 {
445 m_MapContextualMenu.GetOnMenuInitInvoker().Remove(OnContextualMenuInit);
446 m_MapContextualMenu.GetOnEntryPerformedInvoker().Remove(OnCommandPerformed);
447 m_MapContextualMenu.GetOnEntrySelectedInvoker().Remove(OnEntryHovered);
448 }
449
450 if (!m_RadialMenu)
451 return;
452
453 m_RadialMenu.GetOnOpen().Remove(OnRadialMenuOpen);
454 m_RadialMenu.GetOnBeforeOpen().Remove(OnRadialMenuBeforeOpen);
455 m_RadialMenu.GetOnClose().Remove(OnRadialMenuClose);
456 }
457
458 //------------------------------------------------------------------------------------------------
460 protected void OnContextualMenuInit()
461 {
463 return;
464
465 m_RadialMenu = m_MapContextualMenu.GetRadialController().GetRadialMenu();
466
467 if (!m_RadialMenu)
468 return;
469
470 m_RadialMenu.GetOnOpen().Insert(OnRadialMenuOpen);
471 m_RadialMenu.GetOnBeforeOpen().Insert(OnRadialMenuBeforeOpen);
472 m_RadialMenu.GetOnClose().Insert(OnRadialMenuClose);
473 }
474
475 //------------------------------------------------------------------------------------------------
477 protected void CreateConfigEntries()
478 {
479 m_mEntryNames.Clear();
480 m_mEntryGroups.Clear();
481 m_mEntryParents.Clear();
482 m_mEntryHandlers.Clear();
484
485 SCR_Faction faction = SCR_Faction.Cast(SCR_FactionManager.SGetLocalPlayerFaction());
486
487 if (!faction)
488 return;
489
490 Resource container;
491
492 // set proper commander menu config by faction, this config can by overrided by another one from SCR_MapFactionCommanderRadialMenu
494 if (mapFactionCommanderRadialMenu && !mapFactionCommanderRadialMenu.GetCommanderMenuConfig(faction).IsEmpty())
495 container = BaseContainerTools.LoadContainer(mapFactionCommanderRadialMenu.GetCommanderMenuConfig(faction));
496 else
497 container = BaseContainerTools.LoadContainer(faction.GetCommanderMenuConfig());
498
499 if (!container)
500 return;
501
502 SCR_FactionCommanderMenuHierarchy menuHierarchy = SCR_FactionCommanderMenuHierarchy.Cast(BaseContainerTools.CreateInstanceFromContainer(container.GetResource().ToBaseContainer()));
503
504 if (!menuHierarchy)
505 return;
506
507 array<ref SCR_FactionCommanderMenuEntry> entries = {};
508 menuHierarchy.GetEntries(entries);
509
510 foreach (int index, SCR_FactionCommanderMenuEntry entry : entries)
511 {
512 if (entry.IsEnabled())
513 CreateConfigEntry(entry, null, null);
514 }
515
516 // remove mainCommandMenuHandler icon from the radial menu if no commands were added.
517 if (m_mEntryHandlers.Count() != 1)
518 return;
519
522 if (!mainCommandMenuHandler || !entry)
523 return;
524
525 m_MapContextualMenu.RemoveRadialEntry(entry);
526 }
527
528 //------------------------------------------------------------------------------------------------
529 protected bool ShouldCategoryBeHidden(SCR_FactionCommanderMenuEntry configEntry, array<ref SCR_FactionCommanderMenuEntry> childEntries)
530 {
531 //Checking if tasks are disabled for the player's faction
532 PlayerController pc = GetGame().GetPlayerController();
533 if (!pc)
534 return false;
535
536 SCR_Faction faction = SCR_Faction.Cast(SCR_FactionManager.SGetPlayerFaction(pc.GetPlayerId()));
537 if (!faction || faction.IsTasksEnabled())
538 return false;
539
540 //Checking whether the category or the entries within this category are task related. If they all are while tasks for this faction are disabled: Hide the category.
541 if (configEntry.IsGroupOrder() || configEntry.IsSupportRequest())
542 return true;
543
544 foreach (int index, SCR_FactionCommanderMenuEntry entry : childEntries)
545 {
546 if (!entry.IsGroupOrder() && !entry.IsSupportRequest())
547 return false;
548 }
549
550 return true;
551 }
552
553 //------------------------------------------------------------------------------------------------
555 protected void CreateConfigEntry(notnull SCR_FactionCommanderMenuEntry configEntry, SCR_SelectionMenuCategoryEntry parentCategory, SCR_FactionCommanderMenuEntry rootConfigEntry)
556 {
557 SCR_FactionCommanderBaseMenuHandler handler = configEntry.GetMenuHandler();
558
559 if (!handler)
560 {
561 PrintFormat("Faction Commander menu entry config '%1' is missing its handler class. Skipping...", configEntry.GetName(), level: LogLevel.WARNING);
562 return;
563 }
564
565 if (!rootConfigEntry && SCR_FactionCommanderTaskRootMenuEntry.Cast(configEntry))
566 {
567 rootConfigEntry = configEntry;
568 }
569
570 handler.SetMenuEntry(rootConfigEntry);
571
572 if (!handler.CanEntryBeShown(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity))
573 return;
574
575 string name = configEntry.GetName();
576
577 array<ref SCR_FactionCommanderMenuEntry> childEntries = {};
578 configEntry.GetEntries(childEntries);
579
580 if (!childEntries.IsEmpty() || configEntry.IsCategory() || configEntry.IsGroupOrder())
581 {
582 // This entry's values indicate it should be in fact a category
583 if (!childEntries.IsEmpty() || !configEntry.IsSupportRequest() || SCR_FactionCommanderPlayerComponent.IsLocalPlayerCommander())
584 {
585 if (ShouldCategoryBeHidden(configEntry, childEntries))
586 return;
587
588 CreateConfigCategory(configEntry, parentCategory, childEntries, rootConfigEntry);
589 return;
590 }
591 }
592
593 SCR_SelectionMenuEntry entry = m_MapContextualMenu.AddRadialEntry(configEntry.GetDisplayName(), parentCategory);
594
595 m_mEntryParents.Set(entry, parentCategory);
596 m_mEntryNames.Set(name, entry);
597 m_mEntryHandlers.Set(entry, handler);
598 m_mTaskRootMenuEntries.Set(entry, rootConfigEntry);
599
600 entry.SetId(name);
601 string disabledText;
602 entry.Enable(handler.CanEntryBeSelected(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity, disabledText));
603
604 if (!disabledText.IsEmpty())
605 entry.SetName(disabledText);
606
607 string iconName = configEntry.GetIconName();
608
609 if (!iconName.IsEmpty())
610 entry.SetIcon(configEntry.GetIconImageset(), iconName);
611 }
612
613 //------------------------------------------------------------------------------------------------
615 protected void CreateConfigCategory(notnull SCR_FactionCommanderMenuEntry configEntry, SCR_SelectionMenuCategoryEntry parentCategory, notnull array<ref SCR_FactionCommanderMenuEntry> childEntries, SCR_FactionCommanderMenuEntry rootConfigEntry)
616 {
617 SCR_FactionCommanderBaseMenuHandler handler = configEntry.GetMenuHandler();
618
619 if (!handler)
620 return;
621
622 handler.SetMenuEntry(rootConfigEntry);
623
624 // if hovered entity is a task, shows quick menu
625 bool isQuickMenu = m_HoveredEntity && SCR_Task.Cast(m_HoveredEntity);
626
627 // quick menu shows entries on the first level
628 if (isQuickMenu)
629 parentCategory = null;
630
631 string name = configEntry.GetName();
633
634 if (!isQuickMenu)
635 category = m_MapContextualMenu.AddRadialCategory(configEntry.GetDisplayName(), parentCategory);
636
637 m_mEntryNames.Set(name, category);
638 m_mEntryParents.Set(category, parentCategory);
639 m_mEntryHandlers.Set(category, handler);
640 m_mTaskRootMenuEntries.Set(category, rootConfigEntry);
641
642 if (category)
643 {
644 category.SetId(name);
645 string disabledText;
646 category.Enable(handler.CanEntryBeSelected(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity, disabledText));
647
648 if (!disabledText.IsEmpty())
649 category.SetName(disabledText);
650
651 string iconName = configEntry.GetIconName();
652
653 if (!iconName.IsEmpty())
654 category.SetIcon(configEntry.GetIconImageset(), iconName);
655 }
656
657 // skip other task categories
658 if (isQuickMenu && !handler.CanQuickEntryBeShown(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity))
659 return;
660
661 if (configEntry.IsSupportRequest())
662 {
664 if (requestHandler && requestHandler.CanRequestEntryBeShown(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity))
665 AddRequestOrder(category, handler);
666 }
667 else
668 {
670 if (!isQuickMenu && requestHandler && requestHandler.CanCreateObjectiveEntryBeShown(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity))
672 }
673
674 if (configEntry.IsGroupOrder())
676
677 foreach (SCR_FactionCommanderMenuEntry childEntry : childEntries)
678 {
679 if (childEntry.IsEnabled())
680 CreateConfigEntry(childEntry, category, rootConfigEntry);
681 }
682 }
683
684 //------------------------------------------------------------------------------------------------
691
692 //------------------------------------------------------------------------------------------------
694 protected void OnRadialMenuOpen()
695 {
696 m_bMenuVisible = true;
697
699 }
700
701 //------------------------------------------------------------------------------------------------
703 protected void OnRadialMenuClose()
704 {
705 // Remove entries the next frame so callbacks still work properly
706 GetGame().GetCallqueue().CallLater(ClearRadialMenu);
707 }
708
709 //------------------------------------------------------------------------------------------------
710 protected void ClearRadialMenu()
711 {
713
715 {
716 if (!entry)
717 continue;
718
719 if (category)
720 category.RemoveEntry(entry);
721 else
722 m_RadialMenu.RemoveEntry(entry);
723 }
724
725 m_bMenuVisible = false;
726
728 {
729 m_HoveredTask = null;
730 m_HoveredEntity = null;
731 }
732
734 }
735
736 //------------------------------------------------------------------------------------------------
738 protected void OnCommandPerformed(SCR_SelectionMenuEntry element, float[] worldPos)
739 {
740 if (!element)
741 return;
742
744 position[0] = worldPos[0];
745 position[1] = GetGame().GetWorld().GetSurfaceY(worldPos[0], worldPos[1]);
746 position[2] = worldPos[1];
747
748 SCR_FactionCommanderBaseMenuHandler menuHandler = m_mEntryHandlers.Get(element);
749 if (menuHandler)
750 {
751 menuHandler.SetMenuEntry(m_mTaskRootMenuEntries.Get(element));
752 menuHandler.OnCommandIssued(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity, GetAssignedGroup(element));
753 }
754 }
755
756 //------------------------------------------------------------------------------------------------
764 void CreateRequestedTask(string taskPrefab, vector position, int requesterGroupId, SCR_AIGroup group, int playerId, SCR_FactionCommanderBaseMenuHandler handler = null)
765 {
766 int groupId = -1;
767
768 if (group)
769 groupId = group.GetGroupID();
770
771 if (requesterGroupId == -1)
772 return;
773
774 Rpc(RpcAsk_CreateRequestedTask, taskPrefab, position, requesterGroupId, groupId, playerId);
775 }
776
777 //------------------------------------------------------------------------------------------------
778 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
779 protected void RpcAsk_CreateRequestedTask(string taskPrefab, vector destination, int requesterGroupId, int assigneeId, int playerId)
780 {
781 SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
782 if (!groupsManager)
783 return;
784
785 SCR_AIGroup requesterGroup = groupsManager.FindGroup(requesterGroupId);
786 if (!requesterGroup)
787 return;
788
789 Faction faction = requesterGroup.GetFaction();
790 if (!faction)
791 return;
792
793 if (!m_GroupTaskManager.CanCreateNewTaskWithResourceName(taskPrefab, faction))
794 return;
795
796 SCR_TaskSystem taskSystem = SCR_TaskSystem.GetInstance();
797 if (!taskSystem)
798 return;
799
800 string taskID = string.Format(REQUESTED_TASK_ID, faction.GetFactionKey(), GenerateTaskID());
801
802 SCR_BaseRequestedTaskEntity task = SCR_BaseRequestedTaskEntity.Cast(taskSystem.CreateTask(taskPrefab, taskID, "", "", destination, playerId));
803 if (!task)
804 {
805 Print("Task was not created", LogLevel.ERROR);
806 return;
807 }
808
809 taskSystem.SetTaskOwnership(task, SCR_ETaskOwnership.EXECUTOR);
810 taskSystem.SetTaskVisibility(task, SCR_ETaskVisibility.GROUP);
811 task.SetTaskRequesterId(requesterGroupId);
812 taskSystem.AddTaskFaction(task, faction.GetFactionKey());
813
814 SCR_TaskUIInfo taskUIInfo = task.GetTaskUIInfo();
815 if (!taskUIInfo)
816 return;
817
818 task.SetTaskName(taskUIInfo.GetName(), {SCR_MapEntity.GetGridLabel(destination)});
819
820 // set task description
821 string company, platoon, squad, character, format;
822 requesterGroup.GetCallsigns(company, platoon, squad, character, format);
823 task.SetTaskDescription(taskUIInfo.GetDescription(), {string.Format(format, company, platoon, squad)});
824
825 m_GroupTaskManager.SetRequestedGroupTask(task, playerId, requesterGroupId);
826
827 if (assigneeId > -1)
828 taskSystem.AssignTask(task, SCR_TaskExecutorGroup.FromGroup(assigneeId), true, playerId); // force assign
829 }
830
831 //------------------------------------------------------------------------------------------------
838 void CreateTask(ResourceName taskPrefab, vector position, SCR_AIGroup group, int playerId)
839 {
840 int groupId = -1;
841
842 if (group)
843 groupId = group.GetGroupID();
844
845 Rpc(RpcAsk_CreateTask, taskPrefab, groupId, playerId, position, GetGame().GetFactionManager().GetFactionIndex(SCR_FactionManager.SGetLocalPlayerFaction()));
846 }
847
848 //------------------------------------------------------------------------------------------------
849 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
850 protected void RpcAsk_CreateTask(string taskPrefab, int assigneeId, int playerId, vector destination, int factionIndex)
851 {
852 Faction faction = GetGame().GetFactionManager().GetFactionByIndex(factionIndex);
853 if (!faction)
854 return;
855
856 if (!m_GroupTaskManager || !m_GroupTaskManager.CanCreateNewTaskWithResourceName(taskPrefab, faction))
857 return;
858
859 SCR_TaskSystem taskSystem = SCR_TaskSystem.GetInstance();
860 if (!taskSystem)
861 return;
862
863 string taskID = string.Format(TASK_ID, faction.GetFactionKey(), GenerateTaskID());
864
865 SCR_Task task = taskSystem.CreateTask(taskPrefab, taskID, "", "", destination, playerId);
866 if (!task)
867 {
868 Print("Task was not created", LogLevel.ERROR);
869 return;
870 }
871
872 taskSystem.SetTaskOwnership(task, SCR_ETaskOwnership.EXECUTOR);
873 taskSystem.SetTaskVisibility(task, SCR_ETaskVisibility.GROUP);
874 taskSystem.AddTaskFaction(task, faction.GetFactionKey());
875
876 SCR_TaskUIInfo taskUIInfo = task.GetTaskUIInfo();
877 if (!taskUIInfo)
878 return;
879
880 task.SetTaskName(taskUIInfo.GetName(), {SCR_MapEntity.GetGridLabel(destination)});
881
882 m_GroupTaskManager.SetGroupTask(task, playerId);
883
884 if (assigneeId > -1)
885 taskSystem.AssignTask(task, SCR_TaskExecutorGroup.FromGroup(assigneeId), true, playerId); // force assign
886 }
887
888 //------------------------------------------------------------------------------------------------
889 void AssignGroupToTask(int groupId, string taskId)
890 {
891 Rpc(RpcAsk_AssignGroupToTask, groupId, taskId);
892 }
893
894 //------------------------------------------------------------------------------------------------
895 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
896 protected void RpcAsk_AssignGroupToTask(int groupId, string taskId)
897 {
898 SCR_Task task = SCR_TaskSystem.GetInstance().GetTaskFromTaskID(taskId);
899 if (!task)
900 return;
901
902 PlayerController sender = PlayerController.Cast(GetOwner());
903 if (!sender)
904 return;
905
906 SCR_Faction faction = SCR_Faction.Cast(SCR_Faction.GetEntityFaction(sender));
907 if (!faction)
908 return;
909
910 array<string> taskOwnerFactionKeys = task.GetOwnerFactionKeys();
911 if (!taskOwnerFactionKeys || !taskOwnerFactionKeys.Contains(faction.GetFactionKey()))
912 return;
913
914 int senderPlayerId = sender.GetPlayerId();
915 if (!faction.IsPlayerCommander(senderPlayerId))
916 return;
917
918 SCR_TaskSystem.GetInstance().AssignTask(task, SCR_TaskExecutorGroup.FromGroup(groupId), true, senderPlayerId); // force assign
919 }
920
921 //------------------------------------------------------------------------------------------------
924 void CancelTask(string taskId)
925 {
926 Rpc(RpcAsk_CancelTask, taskId);
927 }
928
929 //------------------------------------------------------------------------------------------------
930 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
931 protected void RpcAsk_CancelTask(string taskId)
932 {
933 SCR_TaskSystem taskSystem = SCR_TaskSystem.GetInstance();
934 if (!taskSystem)
935 return;
936
937 SCR_Task task = taskSystem.GetTaskFromTaskID(taskId);
938 if (!task)
939 return;
940
941 PlayerController sender = PlayerController.Cast(GetOwner());
942 if (!sender)
943 return;
944
945 SCR_Faction faction = SCR_Faction.Cast(SCR_Faction.GetEntityFaction(sender));
946 if (!faction)
947 return;
948
949 array<string> taskOwnerFactionKeys = task.GetOwnerFactionKeys();
950 if (!taskOwnerFactionKeys || !taskOwnerFactionKeys.Contains(faction.GetFactionKey()))
951 return;
952
953 int senderPlayerId = sender.GetPlayerId();
954 if (!faction.IsPlayerCommander(senderPlayerId))
955 {
956 SCR_BaseRequestedTaskEntity requestedTask = SCR_BaseRequestedTaskEntity.Cast(task);
957 if (!requestedTask || !requestedTask.IsPlayerFromRequesterGroup(senderPlayerId))
958 return;
959
960 SCR_PlayerControllerGroupComponent playerControllerGroupComponent = SCR_PlayerControllerGroupComponent.GetPlayerControllerComponent(senderPlayerId);
961 if (!playerControllerGroupComponent || !playerControllerGroupComponent.IsPlayerLeaderOwnGroup())
962 return;
963 }
964
965 taskSystem.SetTaskState(task, SCR_ETaskState.CANCELLED);
966 taskSystem.DeleteTask(task);
967 }
968
969 //------------------------------------------------------------------------------------------------
972 void FinishTask(string taskId)
973 {
974 Rpc(RpcAsk_FinishTask, taskId);
975 }
976
977 //------------------------------------------------------------------------------------------------
978 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
979 protected void RpcAsk_FinishTask(string taskId)
980 {
981 SCR_TaskSystem taskSystem = SCR_TaskSystem.GetInstance();
982 if (!taskSystem)
983 return;
984
985 SCR_Task task = taskSystem.GetTaskFromTaskID(taskId);
986 if (!task)
987 return;
988
989 PlayerController sender = PlayerController.Cast(GetOwner());
990 if (!sender)
991 return;
992
993 SCR_Faction faction = SCR_Faction.Cast(SCR_Faction.GetEntityFaction(sender));
994 if (!faction)
995 return;
996
997 array<string> taskOwnerFactionKeys = task.GetOwnerFactionKeys();
998 if (!taskOwnerFactionKeys || !taskOwnerFactionKeys.Contains(faction.GetFactionKey()))
999 return;
1000
1001 if (!faction.IsPlayerCommander(sender.GetPlayerId()))
1002 return;
1003
1004 taskSystem.SetTaskState(task, SCR_ETaskState.COMPLETED);
1005 taskSystem.DeleteTask(task);
1006 }
1007
1008 //------------------------------------------------------------------------------------------------
1009 protected void OnEntryHovered(SCR_SelectionMenuEntry entry, int id)
1010 {
1011 m_mEntryHandlers.Get(entry).OnEntryHovered(SCR_FactionManager.SGetLocalPlayerFaction(), m_PlayerController.GetPlayerId(), m_MapContextualMenu.GetMenuWorldPosition(), m_HoveredEntity);
1012 }
1013
1014 //------------------------------------------------------------------------------------------------
1016 {
1018
1019 if (IsTaskValid(task))
1020 {
1023 }
1024 else
1025 {
1026 m_CurrentHoveredTask = null;
1028 }
1029 }
1030
1031 //------------------------------------------------------------------------------------------------
1032 protected bool IsTaskValid(SCR_Task task)
1033 {
1034 if (!task)
1035 return false;
1036
1037 // the tasks still exist, even after they are finished, we don't need this
1038 if (task.GetTaskState() == SCR_ETaskState.COMPLETED)
1039 return false;
1040
1041 Faction faction = SCR_FactionManager.SGetLocalPlayerFaction();
1042 if (!faction)
1043 return false;
1044
1045 if (!task.GetOwnerFactionKeys() || !task.GetOwnerFactionKeys().Contains(faction.GetFactionKey()))
1046 return false;
1047
1048 return true;
1049 }
1050
1051 //------------------------------------------------------------------------------------------------
1052 void OnOwnershipChanged(bool changing, bool becameOwner)
1053 {
1054 if (changing)
1055 return;
1056
1057 ProcessEvents(becameOwner);
1058 }
1059
1060 //------------------------------------------------------------------------------------------------
1061 protected void ProcessEvents(bool activate)
1062 {
1063 if (RplSession.Mode() == RplMode.Dedicated)
1064 return;
1065
1066 if (activate)
1068 else
1070 }
1071
1072 //------------------------------------------------------------------------------------------------
1073 override void EOnInit(IEntity owner)
1074 {
1075 super.EOnInit(owner);
1076
1078
1080
1081 m_PlayerController.GetOnOwnershipChangedInvoker().Insert(OnOwnershipChanged);
1082
1083 RplComponent rpl = RplComponent.Cast(m_PlayerController.FindComponent(RplComponent));
1084
1086
1087 if (rpl && rpl.IsOwner())
1088 ProcessEvents(true);
1089 }
1090
1091 //------------------------------------------------------------------------------------------------
1092 override void OnPostInit(IEntity owner)
1093 {
1094 super.OnPostInit(owner);
1095
1096 if (!GetGame().InPlayMode())
1097 return;
1098
1099 SetEventMask(owner, EntityEvent.INIT);
1100 }
1101}
ArmaReforgerScripted GetGame()
Definition game.c:1398
RplMode
Mode of replication.
Definition RplMode.c:9
int GetFactionIndex()
enum EAIGroupCombatMode ComponentEditorProps(category:"GameScripted/AI", description:"Component for utility AI system for groups")
SCR_EditableEntityComponent m_HoveredEntity
SCR_BaseGameMode GetGameMode()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
override void OnEntryHovered(SCR_SelectionMenuEntry entry, int id)
Triggered when a radial menu entry is hovered on.
void OnRadialMenuBeforeOpen()
Called each time the radial menu is before open in the map.
void OnMapClose(MapConfiguration config)
void OnMapOpen(MapConfiguration config)
void ProcessEvents(bool activate)
SCR_CharacterSoundComponentClass GetComponentData()
vector position
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void SetNextVolunteeringTimestamp(int playerId, WorldTimestamp timestamp)
string GetRequestOrderEntryDisplayName()
Returns the display name to be shown in radial menu for the Request order category.
SCR_Task m_CurrentHoveredTask
void FinishTask(string taskId)
bool IsTaskValid(SCR_Task task)
WorldTimestamp m_ReplaceCommanderCooldown
void OnCommandPerformed(SCR_SelectionMenuEntry element, float[] worldPos)
Called when a radial menu action is triggered.
void AddCreateObjectiveOrder(SCR_SelectionMenuCategoryEntry category, notnull SCR_FactionCommanderBaseMenuHandler handler)
void CreateTask(ResourceName taskPrefab, vector position, SCR_AIGroup group, int playerId)
WorldTimestamp GetNextVolunteeringTimestamp()
ref map< SCR_SelectionMenuEntry, ref SCR_FactionCommanderBaseMenuHandler > m_mEntryHandlers
void GetRequestOrderEntryIconData(out ResourceName imagesetName, out string iconName)
Returns the imageset and icon name to be shown in radial menu for the Faction order category.
void OnContextualMenuInit()
Called when opening the radial menu for the first time after opening the map.
void OnTaskHovered(SCR_Task task)
string GetGroupEntryDisplayName(SCR_AIGroup group)
Returns the display name to be shown in radial menu for the given group.
void CreateRequestedTask(string taskPrefab, vector position, int requesterGroupId, SCR_AIGroup group, int playerId, SCR_FactionCommanderBaseMenuHandler handler=null)
void CreateConfigCategory(notnull SCR_FactionCommanderMenuEntry configEntry, SCR_SelectionMenuCategoryEntry parentCategory, notnull array< ref SCR_FactionCommanderMenuEntry > childEntries, SCR_FactionCommanderMenuEntry rootConfigEntry)
Creates a radial menu category from config data (SCR_FactionCommanderMenuEntry).
SCR_GroupTaskManagerComponent m_GroupTaskManager
void GetGroupEntryIconData(SCR_AIGroup group, out ResourceName imagesetName, out string iconName)
Returns the imageset and icon name to be shown in radial menu for the given group and category.
void CancelTask(string taskId)
string GetCreateObjectiveOrderEntryDisplayName()
Returns the display name to be shown in radial menu for the create objective order.
WorldTimestamp m_fNextVolunteeringAvailableAt
void OnCommanderRightsLost()
void GetCreateObjectiveOrderEntryIconData(out ResourceName imagesetName, out string iconName)
Returns the imageset and icon name to be shown in radial menu for the create objective order.
void CreateConfigEntry(notnull SCR_FactionCommanderMenuEntry configEntry, SCR_SelectionMenuCategoryEntry parentCategory, SCR_FactionCommanderMenuEntry rootConfigEntry)
Creates a radial menu entry from config data SCR_FactionCommanderMenuEntry.
bool ShouldCategoryBeHidden(SCR_FactionCommanderMenuEntry configEntry, array< ref SCR_FactionCommanderMenuEntry > childEntries)
WorldTimestamp GetReplaceCommanderCooldownTimestamp()
ref map< SCR_SelectionMenuEntry, SCR_AIGroup > m_mEntryGroups
SCR_SelectionMenuEntry GetEntryByName(string name)
ref map< SCR_SelectionMenuEntry, SCR_SelectionMenuCategoryEntry > m_mEntryParents
ref map< SCR_SelectionMenuEntry, ref SCR_FactionCommanderMenuEntry > m_mTaskRootMenuEntries
void RpcAsk_CancelTask(string taskId)
void AddRequestOrder(SCR_SelectionMenuCategoryEntry category, notnull SCR_FactionCommanderBaseMenuHandler handler)
void RpcAsk_FinishTask(string taskId)
void OnRadialMenuClose()
Called each time the radial menu is closed in the map.
SCR_FactionCommanderPlayerComponentClass m_bMenuVisible
string GetDefaultRequestOrderIcon()
void OnCommanderRightsGained()
SCR_AIGroup GetAssignedGroup(SCR_SelectionMenuEntry entry)
Returns a group associated with given entry.
void RpcAsk_CreateTask(string taskPrefab, int assigneeId, int playerId, vector destination, int factionIndex)
ref map< string, SCR_SelectionMenuEntry > m_mEntryNames
void RpcAsk_AssignGroupToTask(int groupId, string taskId)
SCR_MapCursorModule m_MapCursorModule
void AssignGroupToTask(int groupId, string taskId)
void CreateConfigEntries()
Adds entries as defined in the hierarchy config (stored in SCR_Faction).
void RpcAsk_CreateRequestedTask(string taskPrefab, vector destination, int requesterGroupId, int assigneeId, int playerId)
void SetReplaceCommanderCooldownTimestamp(WorldTimestamp timeStamp)
void FillMenuWithGroups(SCR_SelectionMenuCategoryEntry category, notnull SCR_FactionCommanderBaseMenuHandler handler)
Adds all groups of Commander's faction under a given category as menu entries.
string GetDefaultCreateObjectiveOrderIcon()
SCR_FactionCommanderMenuEntry GetConfigForEntry(notnull SCR_SelectionMenuEntry entry)
string GetDefaultGroupOrderIcon()
void SCR_FactionManager(IEntitySource src, IEntity parent)
SCR_FastTravelComponentClass m_PlayerController
void SCR_GroupTaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
SCR_MapEntity m_MapEntity
SCR_MapRadialUI m_MapContextualMenu
SCR_RadialMenu m_RadialMenu
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ETaskVisibility
Definition SCR_Task.c:24
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
SCR_ETaskState
Definition SCR_Task.c:3
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external GenericComponent FindComponent(typename typeName)
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
Main replication API.
Definition Replication.c:14
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void GetCallsigns(out string company, out string platoon, out string squad, out string character, out string format)
int GetGroupID()
Faction GetFaction()
void SetMenuEntry(SCR_FactionCommanderMenuEntry menuEntry)
bool CanEntryBeSelected(notnull Faction commanderFaction, int playerId, vector position, IEntity hoveredEntity, out string disabledText="")
void OnCommandIssued(notnull Faction commanderFaction, int playerId, vector position, IEntity hoveredEntity, SCR_AIGroup group)
bool CanQuickEntryBeShown(notnull Faction commanderFaction, int playerId, vector position, IEntity hoveredEntity)
bool CanEntryBeShown(notnull Faction commanderFaction, int playerId, vector position, IEntity hoveredEntity)
bool CanRequestEntryBeSelected(notnull Faction commanderFaction, int playerId, vector position, IEntity hoveredEntity, out string disabledText="")
bool CanRequestEntryBeShown(notnull Faction commanderFaction, int playerId, vector position, IEntity hoveredEntity)
bool CanCreateObjectiveEntryBeShown(notnull Faction commanderFaction, int playerId, vector position, IEntity hoveredEntity)
bool CanCreateObjectiveEntryBeSelected(notnull Faction commanderFaction, int playerId, vector position, IEntity hoveredEntity, out string disabledText="")
void GetEntries(out notnull array< ref SCR_FactionCommanderMenuEntry > entries)
Handles interactions for the faction Commander role. Should be attached to player controller.
bool IsTasksEnabled()
static Faction GetEntityFaction(notnull IEntity entity)
int GetCommanderId()
bool IsPlayerCommander(int playerId)
ResourceName GetCommanderMenuConfig()
static string GetTranslatedGroupNameAndRoleName(notnull SCR_AIGroup group)
SCR_MapModuleBase GetMapModule(typename moduleType)
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapClose()
Get on map close invoker.
SCR_MapUIBaseComponent GetMapUIComponent(typename componentType)
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapOpen()
Get on map open invoker.
static SCR_MapEntity GetMapInstance()
Get map entity instance.
Class for overriding commands on the map.
ResourceName GetCommanderMenuConfig(notnull Faction faction)
2D map radial menu UI
static SCR_MapRadialUI GetInstance()
void SetIcon(ResourceName iconPath, string imageSetName="")
Set icon and invoke change.
void SetId(string id)
void SetName(string name)
void Enable(bool enable)
void SetIconFromDeafaultImageSet(string imageSetName="")
static SCR_TaskManagerUIComponent GetInstance()
SCR_TaskHoveredInvoker GetOnTaskHovered()
proto external GenericEntity GetOwner()
Get owner entity.
void EOnInit(IEntity owner)
Definition Types.c:486
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
void OnOwnershipChanged(bool changing, bool becameOwner)
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplCondition
Conditional replication rule. Fine grained selection of receivers.
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14