Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_TaskSystem.c
Go to the documentation of this file.
3typedef ScriptInvokerBase<TaskInvokerDelegate> SCR_TaskInvoker;
4
6{
7 protected RplComponent m_Rpl;
8
9 protected static ref SCR_TaskInvoker s_OnTaskAdded;
10 protected static ref SCR_TaskInvoker s_OnTaskRemoved;
11 protected static ref SCR_TaskInvoker s_OnTaskCreated;
12
13 protected static ref array<SCR_Task> s_aTasks = {};
14
15 protected const ResourceName BASE_TASK_RESOURCE = "{1D0F815858EE24AD}Prefabs/Tasks/BaseTask.et";
16 protected const ResourceName EXTENDED_TASK_RESOURCE = "{CF6A2A13DF7B1018}Prefabs/Tasks/ExtendedTask.et";
17
18 // Diag
19 private bool diag_taskListMenu;
20 private int diag_taskListMenuSelection;
21 private string diag_taskListMenuExecutorName;
22 private ref SCR_TaskExecutor diag_selectedExecutor;
23
24 private const int DIAG_MAX_NAME_LENGTH = 30;
25 private const int DIAG_MAX_NAME_LENGTH_LIST = 20;
26 private const int DIAG_MAX_DESCRIPTION_LENGTH = 23;
27
28 //------------------------------------------------------------------------------------------------
29 override static void InitInfo(WorldSystemInfo outInfo)
30 {
31 super.InitInfo(outInfo);
32 outInfo
33 .SetAbstract(false)
34 .SetLocation(ESystemLocation.Both)
35 .AddPoint(ESystemPoint.Frame);
36
37#ifdef ENABLE_DIAG
38 DiagMenu.RegisterMenu(SCR_DebugMenuID.DEBUGUI_TASKS, "Task System", "Systems");
39 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_TASKS_LIST, "", "Task List", "Task System");
40 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_TASKS_CREATE, "", "Create Task", "Task System");
41#endif
42 }
43
44 //------------------------------------------------------------------------------------------------
47 static SCR_TaskSystem GetInstance()
48 {
49 World world = GetGame().GetWorld();
50 if (!world)
51 return null;
52
53 return SCR_TaskSystem.Cast(world.FindSystem(SCR_TaskSystem));
54 }
55
56 //------------------------------------------------------------------------------------------------
59 static SCR_TaskInvoker GetOnTaskAdded()
60 {
61 if (!s_OnTaskAdded)
63
64 return s_OnTaskAdded;
65 }
66
67 //------------------------------------------------------------------------------------------------
70 static SCR_TaskInvoker GetOnTaskRemoved()
71 {
72 if (!s_OnTaskRemoved)
74
75 return s_OnTaskRemoved;
76 }
77
78 //------------------------------------------------------------------------------------------------
81 static SCR_TaskInvoker GetOnTaskCreated()
82 {
83 if (!s_OnTaskCreated)
85
86 return s_OnTaskCreated;
87 }
88
89 //------------------------------------------------------------------------------------------------
93 void GetAssigneesForTask(notnull SCR_Task task, out array<ref SCR_TaskExecutor> assignees)
94 {
95 assignees = task.GetTaskAssignees();
96 }
97
98 //------------------------------------------------------------------------------------------------
102 bool IsTaskVisibleInTaskList(notnull SCR_Task task)
103 {
104 return task.GetTaskUIVisibility() == SCR_ETaskUIVisibility.ALL || task.GetTaskUIVisibility() == SCR_ETaskUIVisibility.LIST_ONLY;
105 }
106
107 //------------------------------------------------------------------------------------------------
111 bool IsTaskVisibleOnMap(notnull SCR_Task task)
112 {
113 return task.GetTaskUIVisibility() == SCR_ETaskUIVisibility.ALL || task.GetTaskUIVisibility() == SCR_ETaskUIVisibility.MAP_ONLY;
114 }
115
116 //------------------------------------------------------------------------------------------------
121 bool IsTaskVisibleFor(notnull SCR_Task task, notnull SCR_TaskExecutor executor)
122 {
123 SCR_ETaskVisibility visibility = task.GetTaskVisibility();
124
125 if (visibility == SCR_ETaskVisibility.NONE)
126 {
127 return false;
128 }
129 else if (visibility == SCR_ETaskVisibility.EXECUTOR)
130 {
131 array<ref SCR_TaskExecutor> executors = task.GetOwnerExecutors();
132 if (!executors)
133 return false;
134
135 SCR_TaskExecutor match = SCR_TaskExecutor.FindMatchingTaskExecutor(executors, executor, true);
136 if (!match)
137 return false;
138 }
139 else if (visibility == SCR_ETaskVisibility.ASSIGNEES)
140 {
141 array<ref SCR_TaskExecutor> assignees = task.GetTaskAssignees();
142 if (!assignees)
143 return false;
144
145 SCR_TaskExecutor match = SCR_TaskExecutor.FindMatchingTaskExecutor(assignees, executor, true);
146 if (!match)
147 return false;
148 }
149 else if (visibility == SCR_ETaskVisibility.GROUP)
150 {
151 int groupID = executor.GetGroupID();
152 if (groupID <= -1)
153 return false;
154
155 array<int> groupIDs = task.GetOwnerGroupIDs();
156 if (!groupIDs)
157 return false;
158
159 if (!groupIDs.Contains(groupID))
160 return false;
161 }
162 else if (visibility == SCR_ETaskVisibility.FACTION)
163 {
164 FactionKey factionKey = executor.GetFactionKey();
165 if (factionKey == FactionKey.Empty)
166 return false;
167
168 array<string> factionKeys = task.GetOwnerFactionKeys();
169 if (!factionKeys)
170 return false;
171
172 if (!factionKeys.Contains(factionKey))
173 return false;
174 }
175
176 return true;
177 }
178
179 //------------------------------------------------------------------------------------------------
184 bool CanTaskBeAssignedTo(notnull SCR_Task task, notnull SCR_TaskExecutor executor)
185 {
186 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
187 if (extendedTask && !extendedTask.CanBeAssigned())
188 return false;
189
190 SCR_ETaskState state = task.GetTaskState();
191 if (state == SCR_ETaskState.COMPLETED || state == SCR_ETaskState.FAILED || state == SCR_ETaskState.CANCELLED)
192 return false;
193
194 SCR_ETaskOwnership ownership = task.GetTaskOwnership();
195
196 if (ownership == SCR_ETaskOwnership.NONE)
197 {
198 return false;
199 }
200 else if (ownership == SCR_ETaskOwnership.EXECUTOR)
201 {
202 array<ref SCR_TaskExecutor> executors = task.GetOwnerExecutors();
203 if (!executors)
204 return false;
205
206 SCR_TaskExecutor match = SCR_TaskExecutor.FindMatchingTaskExecutor(executors, executor);
207 if (!match)
208 {
209 array<int> groupIDs = {};
210 foreach (SCR_TaskExecutor e : executors)
211 {
212 SCR_TaskExecutorGroup eGroup = SCR_TaskExecutorGroup.Cast(e);
213 if (eGroup)
214 groupIDs.Insert(eGroup.GetGroupID());
215 }
216
217 SCR_TaskExecutorPlayer executorPlayer = SCR_TaskExecutorPlayer.Cast(executor);
218 if (!executorPlayer)
219 return false;
220
221 if (!IsGroupLeader(groupIDs, executorPlayer.GetPlayerID()))
222 return false;
223 }
224 }
225 else if (ownership == SCR_ETaskOwnership.GROUP)
226 {
227 int groupID = executor.GetGroupID();
228 if (groupID <= -1)
229 return false;
230
231 array<int> groupIDs = task.GetOwnerGroupIDs();
232 if (!groupIDs)
233 return false;
234
235 if (!groupIDs.Contains(groupID))
236 return false;
237 }
238 else if (ownership == SCR_ETaskOwnership.FACTION)
239 {
240 FactionKey factionKey = executor.GetFactionKey();
241 if (factionKey == FactionKey.Empty)
242 return false;
243
244 array<string> factionKeys = task.GetOwnerFactionKeys();
245 if (!factionKeys)
246 return false;
247
248 if (!factionKeys.Contains(factionKey))
249 return false;
250 }
251
252 return true;
253 }
254
255 //------------------------------------------------------------------------------------------------
259 bool IsGroupLeader(notnull array<int> groupIDs, int playerID)
260 {
261 SCR_GroupsManagerComponent groupsManagerComponent = SCR_GroupsManagerComponent.GetInstance();
262 if (!groupsManagerComponent)
263 return false;
264
265 if (!groupIDs || groupIDs.IsEmpty())
266 return false;
267
268 SCR_AIGroup group;
269 foreach (int groupID : groupIDs)
270 {
271 group = groupsManagerComponent.FindGroup(groupID);
272 if (!group)
273 continue;
274
275 int groupLeaderID = group.GetLeaderID();
276 if (groupLeaderID == playerID)
277 return true;
278 }
279
280 return false;
281 }
282
283 //------------------------------------------------------------------------------------------------
288 int FindGroupByLeader(notnull array<int> groupIDs, int leaderID)
289 {
290 SCR_GroupsManagerComponent groupsManagerComponent = SCR_GroupsManagerComponent.GetInstance();
291 if (!groupsManagerComponent)
292 return -1;
293
294 if (!groupIDs || groupIDs.IsEmpty())
295 return -1;
296
297 foreach (int groupID : groupIDs)
298 {
299 SCR_AIGroup group = groupsManagerComponent.FindGroup(groupID);
300 if (!group)
301 continue;
302
303 if (group.IsPlayerLeader(leaderID))
304 return groupID;
305 }
306
307 return -1;
308 }
309
310 //------------------------------------------------------------------------------------------------
314 int GetTasks(out notnull array<SCR_Task> outTasks)
315 {
316 outTasks.Copy(s_aTasks);
317 return outTasks.Count();
318 }
319
320 //------------------------------------------------------------------------------------------------
324 SCR_Task GetTaskAssignedTo(notnull SCR_TaskExecutor executor)
325 {
326 foreach (SCR_Task task : s_aTasks)
327 {
328 if (!task)
329 continue;
330
331 if (task.IsTaskAssignedTo(executor))
332 return task;
333 }
334
335 return null;
336 }
337
338 //------------------------------------------------------------------------------------------------
344 void GetTasksByState(out notnull array<SCR_Task> outTasks, SCR_ETaskState state, FactionKey filterFaction = FactionKey.Empty, int filterGroup = -1)
345 {
346 outTasks = {};
347
348 array<string> factionKeys;
349 array<int> groupIDs;
350
351 foreach (SCR_Task task : s_aTasks)
352 {
353 if (!task)
354 continue;
355
356 if ((state & task.GetTaskState()) == 0)
357 continue;
358
359 if (filterFaction != FactionKey.Empty)
360 {
361 factionKeys = task.GetOwnerFactionKeys();
362 if (!factionKeys || factionKeys.IsEmpty())
363 continue;
364
365 if (!factionKeys.Contains(filterFaction))
366 continue;
367 }
368
369 if (filterGroup > -1)
370 {
371 groupIDs = task.GetOwnerGroupIDs();
372 if (!groupIDs || groupIDs.IsEmpty())
373 continue;
374
375 if (!groupIDs.Contains(filterGroup))
376 continue;
377 }
378
379 outTasks.Insert(task);
380 }
381 }
382
383 //------------------------------------------------------------------------------------------------
391 int GetTasksByStateFiltered(out notnull array<SCR_Task> outTasks, SCR_ETaskState state, FactionKey filterFaction = FactionKey.Empty, int filterGroup = -1, typename filterClass = typename.Empty, bool allowInherited = false)
392 {
393 SCR_TaskSystem.GetInstance().GetTasksByState(outTasks, state, filterFaction, filterGroup);
394
395 if (filterClass == filterClass.Empty)
396 return outTasks.Count();
397
398 for (int i = outTasks.Count() - 1; i >= 0; i--)
399 {
400 if (allowInherited)
401 {
402 if (!outTasks[i].IsInherited(filterClass))
403 outTasks.Remove(i);
404 }
405 else
406 {
407 if (outTasks[i].Type() != filterClass)
408 outTasks.Remove(i);
409 }
410 }
411
412 return outTasks.Count();
413 }
414
415 //------------------------------------------------------------------------------------------------
420 int GetTasksVisibleFor(out notnull array<SCR_Task> outTasks, notnull SCR_TaskExecutor executor)
421 {
422 outTasks = {};
423
424 array<SCR_Task> tasks = {};
425 GetTasks(tasks);
426 foreach (SCR_Task task : tasks)
427 {
428 if (!task)
429 continue;
430
431 if (!IsTaskVisibleFor(task, executor))
432 continue;
433
434 outTasks.Insert(task);
435 }
436
437 return outTasks.Count();
438 }
439
440 //------------------------------------------------------------------------------------------------
443 void RegisterTask(notnull SCR_Task task)
444 {
445 s_aTasks.Insert(task);
446
447 if (s_OnTaskAdded)
448 s_OnTaskAdded.Invoke(task);
449 }
450
451 //------------------------------------------------------------------------------------------------
454 void UnregisterTask(notnull SCR_Task task)
455 {
456 s_aTasks.RemoveItem(task);
457
458 if (s_OnTaskRemoved)
459 s_OnTaskRemoved.Invoke(task);
460 }
461
462 //------------------------------------------------------------------------------------------------
469 void AssignTask(notnull SCR_Task task, notnull SCR_TaskExecutor executor, bool force = false, int requesterID = 0)
470 {
471 if (Replication.IsClient())
472 {
473 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
474 return;
475 }
476
477 if (task.IsTaskAssignedTo(executor))
478 return; // Already assigned
479
480 SCR_TaskExecutor assignee;
481 if (executor)
482 assignee = executor;
483
484 if (task.GetTaskOwnership() == SCR_ETaskOwnership.EXECUTOR)
485 {
486 array<ref SCR_TaskExecutor> ownerExecutors = task.GetOwnerExecutors();
487 if (ownerExecutors && !ownerExecutors.IsEmpty())
488 {
489 array<int> groupIDs = {};
490 foreach (SCR_TaskExecutor ownerExecutor : ownerExecutors)
491 {
492 SCR_TaskExecutorGroup ownerExecutorGroup = SCR_TaskExecutorGroup.Cast(ownerExecutor);
493 if (ownerExecutorGroup)
494 groupIDs.Insert(ownerExecutorGroup.GetGroupID());
495 }
496
497 SCR_TaskExecutorPlayer assigneePlayer = SCR_TaskExecutorPlayer.Cast(assignee);
498 if (assigneePlayer)
499 {
500 int groupID = FindGroupByLeader(groupIDs, assigneePlayer.GetPlayerID());
501 if (groupID > -1)
502 assignee = TaskExecutorFromGroup(groupID);
503 }
504 }
505 }
506
507 string name, suffix;
508 if (assignee)
509 {
510 SCR_TaskExecutorPlayer assigneePlayer = SCR_TaskExecutorPlayer.Cast(assignee);
511 if (assigneePlayer)
512 {
513 PlayerManager playerManager = GetGame().GetPlayerManager();
514 if (!playerManager)
515 return;
516
517 int playerID = assigneePlayer.GetPlayerID();
518 name = playerManager.GetPlayerName(playerID);
519 suffix = playerID.ToString();
520 }
521
522 SCR_TaskExecutorEntity assigneeEntity = SCR_TaskExecutorEntity.Cast(assignee);
523 if (assigneeEntity)
524 {
525 IEntity entity = assigneeEntity.GetEntity();
526 if (!entity)
527 return;
528
529 name = entity.GetName();
530 suffix = entity.Type().ToString();
531 }
532
533 SCR_TaskExecutorGroup assigneeGroup = SCR_TaskExecutorGroup.Cast(assignee);
534 if (assigneeGroup)
535 {
536 SCR_GroupsManagerComponent groupsManagerComponent = SCR_GroupsManagerComponent.GetInstance();
537 if (!groupsManagerComponent)
538 return;
539
540 SCR_AIGroup group = groupsManagerComponent.FindGroup(assigneeGroup.GetGroupID());
541 if (!group)
542 return;
543
544 name = "Group";
545 suffix = group.GetGroupID().ToString();
546 }
547 }
548
549 if (!CanTaskBeAssignedTo(task, assignee))
550 {
551 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " cannot be assigned to " + name + "(" + suffix + ")", LogLevel.WARNING);
552 return;
553 }
554
555 foreach (SCR_Task t : s_aTasks)
556 {
557 if (!t)
558 continue;
559
560 if (t.IsTaskAssignedTo(assignee))
561 {
562 if (t == task)
563 {
564 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " is already assigned to " + name + "(" + suffix + ")", LogLevel.WARNING);
565 return;
566 }
567
568 if (!force)
569 {
570 Print("SCR_TaskSystem: " + name + "(" + suffix + ") can only have 1 task assigned to it at a time!", LogLevel.WARNING);
571 return;
572 }
573
574 t.RemoveTaskAssignee(assignee, true, requesterID);
575 }
576 }
577
578 if (!task.AddTaskAssignee(assignee, true, requesterID))
579 {
580 Print("SCR_TaskSystem: Could not assign " + name + "(" + suffix + ") to task with ID: " + task.GetTaskID(), LogLevel.ERROR);
581 return;
582 }
583
584 if (task.GetTaskState() != SCR_ETaskState.COMPLETED && task.GetTaskState() != SCR_ETaskState.FAILED && task.GetTaskState() != SCR_ETaskState.CANCELLED && task.GetTaskAssignees().Count() == 1)
585 task.SetTaskState(SCR_ETaskState.ASSIGNED);
586
587 if (force)
588 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " force-assigned to " + name + "(" + suffix + ")", LogLevel.DEBUG);
589 else
590 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " assigned to " + name + "(" + suffix + ")", LogLevel.DEBUG);
591 }
592
593 //------------------------------------------------------------------------------------------------
598 void UnassignTask(notnull SCR_Task task, notnull SCR_TaskExecutor executor, int requesterID = 0)
599 {
600 if (Replication.IsClient())
601 {
602 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
603 return;
604 }
605
606 SCR_TaskExecutor assignee;
607 if (executor)
608 assignee = executor;
609
610 if (task.GetTaskOwnership() == SCR_ETaskOwnership.EXECUTOR)
611 {
612 array<ref SCR_TaskExecutor> ownerExecutors = task.GetOwnerExecutors();
613 if (ownerExecutors && !ownerExecutors.IsEmpty())
614 {
615 array<int> groupIDs = {};
616 foreach (SCR_TaskExecutor ownerExecutor : ownerExecutors)
617 {
618 SCR_TaskExecutorGroup ownerExecutorGroup = SCR_TaskExecutorGroup.Cast(ownerExecutor);
619 if (ownerExecutorGroup)
620 groupIDs.Insert(ownerExecutorGroup.GetGroupID());
621 }
622
623 SCR_TaskExecutorPlayer assigneePlayer = SCR_TaskExecutorPlayer.Cast(assignee);
624 if (assigneePlayer)
625 {
626 int groupID = FindGroupByLeader(groupIDs, assigneePlayer.GetPlayerID());
627 if (groupID > -1)
628 assignee = TaskExecutorFromGroup(groupID);
629 }
630 }
631 }
632
633 string name, suffix;
634 if (assignee)
635 {
636 SCR_TaskExecutorPlayer assigneePlayer = SCR_TaskExecutorPlayer.Cast(assignee);
637 if (assigneePlayer)
638 {
639 PlayerManager playerManager = GetGame().GetPlayerManager();
640 if (!playerManager)
641 return;
642
643 int playerID = assigneePlayer.GetPlayerID();
644 name = playerManager.GetPlayerName(playerID);
645 suffix = playerID.ToString();
646 }
647
648 SCR_TaskExecutorEntity assigneeEntity = SCR_TaskExecutorEntity.Cast(assignee);
649 if (assigneeEntity)
650 {
651 IEntity entity = assigneeEntity.GetEntity();
652 if (!entity)
653 return;
654
655 name = entity.GetName();
656 suffix = entity.Type().ToString();
657 }
658
659 SCR_TaskExecutorGroup assigneeGroup = SCR_TaskExecutorGroup.Cast(assignee);
660 if (assigneeGroup)
661 {
662 SCR_GroupsManagerComponent groupsManagerComponent = SCR_GroupsManagerComponent.GetInstance();
663 if (!groupsManagerComponent)
664 return;
665
666 SCR_AIGroup group = groupsManagerComponent.FindGroup(assigneeGroup.GetGroupID());
667 if (!group)
668 return;
669
670 name = "Group";
671 suffix = group.GetGroupID().ToString();
672 }
673 }
674
675 if (!task.RemoveTaskAssignee(assignee, true, requesterID))
676 {
677 Print("SCR_TaskSystem: Could not unassign " + name + "(" + suffix + ") from task with ID: " + task.GetTaskID(), LogLevel.ERROR);
678 return;
679 }
680
681 if (task.GetTaskState() != SCR_ETaskState.COMPLETED && task.GetTaskState() != SCR_ETaskState.FAILED && task.GetTaskAssignees().IsEmpty())
682 task.SetTaskState(SCR_ETaskState.CREATED);
683
684 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " unassigned from " + name + "(" + suffix + ")", LogLevel.DEBUG);
685 }
686
687 //------------------------------------------------------------------------------------------------
691 bool CanProgressBeShownForTask(notnull SCR_Task task)
692 {
693 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
694 if (!extendedTask)
695 return false;
696
697 return extendedTask.CanTaskProgressBeShown();
698 }
699
700 //------------------------------------------------------------------------------------------------
705 void ShowProgressForTask(notnull SCR_Task task, bool enable)
706 {
707 if (Replication.IsClient())
708 {
709 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
710 return;
711 }
712
713 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
714 if (!extendedTask)
715 {
716 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " is not an extended task!", LogLevel.WARNING);
717 return;
718 }
719
720 extendedTask.ShowTaskProgress(enable);
721
722 if (enable)
723 Print("SCR_TaskSystem: Enabled progress bar for task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
724 else
725 Print("SCR_TaskSystem: Disabled progress bar for task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
726 }
727
728 //------------------------------------------------------------------------------------------------
732 float GetTaskProgress(notnull SCR_Task task)
733 {
734 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
735 if (!extendedTask)
736 return -1;
737
738 return extendedTask.GetTaskProgress();
739 }
740
741 //------------------------------------------------------------------------------------------------
746 void SetTaskProgress(notnull SCR_Task task, float percentage)
747 {
748 if (Replication.IsClient())
749 {
750 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
751 return;
752 }
753
754 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
755 if (!extendedTask)
756 {
757 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " is not an extended task!", LogLevel.WARNING);
758 return;
759 }
760
761 extendedTask.SetTaskProgress(percentage);
762 Print("SCR_TaskSystem: Changed progress of task with ID: " + task.GetTaskID() + " to " + percentage + "%", LogLevel.DEBUG);
763 }
764
765 //------------------------------------------------------------------------------------------------
770 void AddTaskProgress(notnull SCR_Task task, float percentage)
771 {
772 if (Replication.IsClient())
773 {
774 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
775 return;
776 }
777
778 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
779 if (!extendedTask)
780 {
781 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " is not an extended task!", LogLevel.WARNING);
782 return;
783 }
784
785 extendedTask.AddTaskProgress(percentage);
786 Print("SCR_TaskSystem: Added " + percentage + "% progress to task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
787 }
788
789 //------------------------------------------------------------------------------------------------
794 void RemoveTaskProgress(notnull SCR_Task task, float percentage)
795 {
796 if (Replication.IsClient())
797 {
798 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
799 return;
800 }
801
802 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
803 if (!extendedTask)
804 {
805 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " is not an extended task!", LogLevel.WARNING);
806 return;
807 }
808
809 extendedTask.RemoveTaskProgress(percentage);
810 Print("SCR_TaskSystem: Removed " + percentage + "% progress from task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
811 }
812
813 //------------------------------------------------------------------------------------------------
818 {
819 if (!task)
820 return -1;
821
822 return task.GetTaskState();
823 }
824
825 //------------------------------------------------------------------------------------------------
829 void SetTaskState(notnull SCR_Task task, SCR_ETaskState state)
830 {
831 if (Replication.IsClient())
832 {
833 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
834 return;
835 }
836
837 task.SetTaskState(state);
838 Print("SCR_TaskSystem: Changed state for task with ID: " + task.GetTaskID() + " to " + SCR_Enum.GetEnumName(SCR_ETaskState, state), LogLevel.DEBUG);
839 }
840
841 //------------------------------------------------------------------------------------------------
845 SCR_ETaskOwnership GetTaskOwnership(notnull SCR_Task task)
846 {
847 if (!task)
848 return -1;
849
850 return task.GetTaskOwnership();
851 }
852
853 //------------------------------------------------------------------------------------------------
857 void SetTaskOwnership(notnull SCR_Task task, SCR_ETaskOwnership ownership)
858 {
859 if (Replication.IsClient())
860 {
861 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
862 return;
863 }
864
865 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
866 if (extendedTask && extendedTask.IsChildTask())
867 {
868 SCR_Task parentTask = extendedTask.GetParentTask();
869 if (!parentTask)
870 return;
871
872 if (ownership > parentTask.GetTaskOwnership())
873 {
874 Print("SCR_TaskSystem: Cannot change ownership for task with ID: " + task.GetTaskID() + " as ownership level cannot be higher than parent!", LogLevel.WARNING);
875 return;
876 }
877 }
878
879 task.SetTaskOwnership(ownership);
880
881 array<ref SCR_TaskExecutor> assignees = task.GetTaskAssignees();
882 if (assignees && !assignees.IsEmpty())
883 {
884 foreach (SCR_TaskExecutor assignee : assignees)
885 {
886 if (!CanTaskBeAssignedTo(task, assignee))
887 task.RemoveTaskAssignee(assignee);
888 }
889 }
890
891 Print("SCR_TaskSystem: Changed ownership for task with ID: " + task.GetTaskID() + " to " + SCR_Enum.GetEnumName(SCR_ETaskOwnership, ownership), LogLevel.DEBUG);
892 }
893
894 //------------------------------------------------------------------------------------------------
899 {
900 if (!task)
901 return -1;
902
903 return task.GetTaskVisibility();
904 }
905
906 //------------------------------------------------------------------------------------------------
910 void SetTaskVisibility(notnull SCR_Task task, SCR_ETaskVisibility visibility)
911 {
912 if (Replication.IsClient())
913 {
914 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
915 return;
916 }
917
918 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
919 if (extendedTask && extendedTask.IsChildTask())
920 {
921 SCR_Task parentTask = extendedTask.GetParentTask();
922 if (!parentTask)
923 return;
924
925 if (visibility > parentTask.GetTaskVisibility())
926 {
927 Print("SCR_TaskSystem: Cannot change visibility for task with ID: " + task.GetTaskID() + " as visibility level cannot be higher than parent!", LogLevel.WARNING);
928 return;
929 }
930 }
931
932 task.SetTaskVisibility(visibility);
933 Print("SCR_TaskSystem: Changed visibility for task with ID: " + task.GetTaskID() + " to " + SCR_Enum.GetEnumName(SCR_ETaskVisibility, visibility), LogLevel.DEBUG);
934 }
935
936 //------------------------------------------------------------------------------------------------
940 SCR_ETaskUIVisibility GetTaskUIVisibility(notnull SCR_Task task)
941 {
942 if (!task)
943 return -1;
944
945 return task.GetTaskUIVisibility();
946 }
947
948 //------------------------------------------------------------------------------------------------
952 void SetTaskUIVisibility(notnull SCR_Task task, SCR_ETaskUIVisibility visibility)
953 {
954 if (Replication.IsClient())
955 {
956 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
957 return;
958 }
959
960 task.SetTaskUIVisibility(visibility);
961 Print("SCR_TaskSystem: Changed UI visibility for task with ID: " + task.GetTaskID() + " to " + SCR_Enum.GetEnumName(SCR_ETaskUIVisibility, visibility), LogLevel.DEBUG);
962 }
963
964 //------------------------------------------------------------------------------------------------
968 array<string> GetTaskFactions(notnull SCR_Task task)
969 {
970 if (!task)
971 return null;
972
973 return task.GetOwnerFactionKeys();
974 }
975
976 //------------------------------------------------------------------------------------------------
980 void AddTaskFaction(notnull SCR_Task task, FactionKey factionKey)
981 {
982 if (Replication.IsClient())
983 {
984 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
985 return;
986 }
987
988 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
989 if (extendedTask && extendedTask.IsChildTask())
990 {
991 SCR_Task parentTask = extendedTask.GetParentTask();
992 if (!parentTask)
993 return;
994
995 if (parentTask.GetTaskOwnership() <= SCR_ETaskOwnership.FACTION || parentTask.GetTaskVisibility() <= SCR_ETaskVisibility.FACTION)
996 {
997 Print("SCR_TaskSystem: Cannot add faction to task with ID: " + task.GetTaskID() + " as parent task does not allow it!", LogLevel.WARNING);
998 return;
999 }
1000 }
1001
1002 FactionManager factionManager = GetGame().GetFactionManager();
1003 if (!factionManager)
1004 return;
1005
1006 if (!factionManager.GetFactionByKey(factionKey))
1007 {
1008 Print("SCR_TaskSystem: Faction with key: " + factionKey + " does not exist!", LogLevel.WARNING);
1009 return;
1010 }
1011
1012 task.AddOwnerFactionKey(factionKey);
1013 Print("SCR_TaskSystem: Added faction with key: " + factionKey + " to task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
1014 }
1015
1016 //------------------------------------------------------------------------------------------------
1020 void RemoveTaskFaction(notnull SCR_Task task, FactionKey factionKey)
1021 {
1022 if (Replication.IsClient())
1023 {
1024 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1025 return;
1026 }
1027
1028 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1029 if (extendedTask && extendedTask.IsChildTask())
1030 {
1031 SCR_Task parentTask = extendedTask.GetParentTask();
1032 if (!parentTask)
1033 return;
1034
1035 if (parentTask.GetTaskOwnership() <= SCR_ETaskOwnership.FACTION || parentTask.GetTaskVisibility() <= SCR_ETaskVisibility.FACTION)
1036 {
1037 Print("SCR_TaskSystem: Cannot remove faction from task with ID: " + task.GetTaskID() + " as parent task does not allow it!", LogLevel.WARNING);
1038 return;
1039 }
1040 }
1041
1042 FactionManager factionManager = GetGame().GetFactionManager();
1043 if (!factionManager)
1044 return;
1045
1046 if (!factionManager.GetFactionByKey(factionKey))
1047 {
1048 Print("SCR_TaskSystem: Faction with key: " + factionKey + " does not exist!", LogLevel.WARNING);
1049 return;
1050 }
1051
1052 task.RemoveOwnerFactionKey(factionKey);
1053
1054 array<ref SCR_TaskExecutor> assignees = task.GetTaskAssignees();
1055 if (assignees && !assignees.IsEmpty())
1056 {
1057 foreach (SCR_TaskExecutor assignee : assignees)
1058 {
1059 if (!CanTaskBeAssignedTo(task, assignee))
1060 task.RemoveTaskAssignee(assignee);
1061 }
1062 }
1063
1064 Print("SCR_TaskSystem: Removed faction with key: " + factionKey + " from task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
1065 }
1066
1067 //------------------------------------------------------------------------------------------------
1071 array<int> GetTaskGroups(notnull SCR_Task task)
1072 {
1073 if (!task)
1074 return null;
1075
1076 return task.GetOwnerGroupIDs();
1077 }
1078
1079 //------------------------------------------------------------------------------------------------
1083 void AddTaskGroup(notnull SCR_Task task, int groupID)
1084 {
1085 if (Replication.IsClient())
1086 {
1087 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1088 return;
1089 }
1090
1091 SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
1092 if (!groupsManager)
1093 return;
1094
1095 SCR_AIGroup group = groupsManager.FindGroup(groupID);
1096 if (!group)
1097 {
1098 Print("SCR_TaskSystem: Group with ID: " + groupID + " does not exist!", LogLevel.WARNING);
1099 return;
1100 }
1101
1102 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1103 if (extendedTask && extendedTask.IsChildTask())
1104 {
1105 SCR_Task parentTask = extendedTask.GetParentTask();
1106 if (!parentTask)
1107 return;
1108
1109 if (parentTask.GetTaskOwnership() <= SCR_ETaskOwnership.GROUP || parentTask.GetTaskVisibility() <= SCR_ETaskVisibility.GROUP)
1110 {
1111 Print("SCR_TaskSystem: Cannot add group with ID: " + groupID + " to task with ID: " + task.GetTaskID() + " as parent task does not allow it!", LogLevel.WARNING);
1112 return;
1113 }
1114
1115 array<string> parentTaskFactions = parentTask.GetOwnerFactionKeys();
1116 if ((!parentTaskFactions || !parentTaskFactions.Contains(group.GetFactionName())) && parentTask.GetTaskOwnership() == SCR_ETaskOwnership.FACTION)
1117 {
1118 Print("SCR_TaskSystem: Cannot add group with ID: " + groupID + " to task with ID: " + task.GetTaskID() + " as group is from another faction!", LogLevel.WARNING);
1119 return;
1120 }
1121 }
1122
1123 task.AddOwnerGroupID(groupID);
1124 Print("SCR_TaskSystem: Added group with ID: " + groupID + " to task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
1125 }
1126
1127 //------------------------------------------------------------------------------------------------
1131 void RemoveTaskGroup(notnull SCR_Task task, int groupID)
1132 {
1133 if (Replication.IsClient())
1134 {
1135 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1136 return;
1137 }
1138
1139 SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
1140 if (!groupsManager)
1141 return;
1142
1143 SCR_AIGroup group = groupsManager.FindGroup(groupID);
1144 if (!group)
1145 {
1146 Print("SCR_TaskSystem: Group with ID: " + groupID + " does not exist!", LogLevel.WARNING);
1147 return;
1148 }
1149
1150 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1151 if (extendedTask && extendedTask.IsChildTask())
1152 {
1153 SCR_Task parentTask = extendedTask.GetParentTask();
1154 if (!parentTask)
1155 return;
1156
1157 if (parentTask.GetTaskOwnership() <= SCR_ETaskOwnership.GROUP || parentTask.GetTaskVisibility() <= SCR_ETaskVisibility.GROUP)
1158 {
1159 Print("SCR_TaskSystem: Cannot remove group with ID: " + groupID + " from task with ID: " + task.GetTaskID() + " as parent task does not allow it!", LogLevel.WARNING);
1160 return;
1161 }
1162 }
1163
1164 task.RemoveOwnerGroupID(groupID);
1165
1166 array<ref SCR_TaskExecutor> assignees = task.GetTaskAssignees();
1167 if (assignees && !assignees.IsEmpty())
1168 {
1169 foreach (SCR_TaskExecutor assignee : assignees)
1170 {
1171 if (!CanTaskBeAssignedTo(task, assignee))
1172 task.RemoveTaskAssignee(assignee);
1173 }
1174 }
1175
1176 Print("SCR_TaskSystem: Removed group with ID: " + groupID + " from task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
1177 }
1178
1179 //------------------------------------------------------------------------------------------------
1183 array<ref SCR_TaskExecutor> GetTaskExecutors(notnull SCR_Task task)
1184 {
1185 if (!task)
1186 return null;
1187
1188 return task.GetOwnerExecutors();
1189 }
1190
1191 //------------------------------------------------------------------------------------------------
1195 void AddTaskExecutor(notnull SCR_Task task, notnull SCR_TaskExecutor executor)
1196 {
1197 if (Replication.IsClient())
1198 {
1199 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1200 return;
1201 }
1202
1203 string name, suffix;
1204 if (executor)
1205 {
1206 SCR_TaskExecutorPlayer executorPlayer = SCR_TaskExecutorPlayer.Cast(executor);
1207 if (executorPlayer)
1208 {
1209 PlayerManager playerManager = GetGame().GetPlayerManager();
1210 if (!playerManager)
1211 return;
1212
1213 int playerID = executorPlayer.GetPlayerID();
1214 name = playerManager.GetPlayerName(playerID);
1215 suffix = playerID.ToString();
1216 }
1217
1218 SCR_TaskExecutorEntity executorEntity = SCR_TaskExecutorEntity.Cast(executor);
1219 if (executorEntity)
1220 {
1221 IEntity entity = executorEntity.GetEntity();
1222 if (!entity)
1223 return;
1224
1225 name = entity.GetName();
1226 suffix = entity.Type().ToString();
1227 }
1228
1229 SCR_TaskExecutorGroup executorGroup = SCR_TaskExecutorGroup.Cast(executor);
1230 if (executorGroup)
1231 {
1232 SCR_GroupsManagerComponent groupsManagerComponent = SCR_GroupsManagerComponent.GetInstance();
1233 if (!groupsManagerComponent)
1234 return;
1235
1236 SCR_AIGroup group = groupsManagerComponent.FindGroup(executorGroup.GetGroupID());
1237 if (!group)
1238 return;
1239
1240 name = "Group";
1241 suffix = group.GetGroupID().ToString();
1242 }
1243 }
1244
1245 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1246 if (extendedTask && extendedTask.IsChildTask())
1247 {
1248 SCR_Task parentTask = extendedTask.GetParentTask();
1249 if (!parentTask)
1250 return;
1251
1252 if (parentTask.GetTaskOwnership() <= SCR_ETaskOwnership.EXECUTOR || parentTask.GetTaskVisibility() <= SCR_ETaskVisibility.EXECUTOR)
1253 {
1254 Print("SCR_TaskSystem: Cannot add " + name + "(" + suffix + ") to task with ID: " + task.GetTaskID() + " as parent task does not allow it!", LogLevel.WARNING);
1255 return;
1256 }
1257
1258 if (parentTask.GetTaskOwnership() == SCR_ETaskOwnership.FACTION || parentTask.GetTaskVisibility() == SCR_ETaskVisibility.FACTION)
1259 {
1260 string factionKey = executor.GetFactionKey();
1261
1262 array<string> parentTaskFactions = parentTask.GetOwnerFactionKeys();
1263 if (!parentTaskFactions || !parentTaskFactions.Contains(factionKey))
1264 {
1265 Print("SCR_TaskSystem: Cannot add " + name + "(" + suffix + ") to task with ID: " + task.GetTaskID() + " as entity is from another faction!", LogLevel.WARNING);
1266 return;
1267 }
1268 }
1269
1270 if (parentTask.GetTaskOwnership() == SCR_ETaskOwnership.GROUP || parentTask.GetTaskVisibility() == SCR_ETaskVisibility.GROUP)
1271 {
1272 int groupID = executor.GetGroupID();
1273
1274 array<int> parentTaskGroupIDs = parentTask.GetOwnerGroupIDs();
1275 if (!parentTaskGroupIDs)
1276 return;
1277
1278 if (!parentTaskGroupIDs.Contains(groupID))
1279 {
1280 Print("SCR_TaskSystem: Cannot add " + name + "(" + suffix + ") to task with ID: " + task.GetTaskID() + " as entity is from another group!", LogLevel.WARNING);
1281 return;
1282 }
1283 }
1284 }
1285
1286 if (!task.AddOwnerExecutor(executor))
1287 {
1288 Print("SCR_TaskSystem: Could not add " + name + "(" + suffix + ") to task with ID: " + task.GetTaskID(), LogLevel.ERROR);
1289 return;
1290 }
1291
1292 Print("SCR_TaskSystem: Added " + name + "(" + suffix + ") to task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
1293 }
1294
1295 //------------------------------------------------------------------------------------------------
1299 void RemoveTaskExecutor(notnull SCR_Task task, notnull SCR_TaskExecutor executor)
1300 {
1301 if (Replication.IsClient())
1302 {
1303 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1304 return;
1305 }
1306
1307 string name, suffix;
1308 if (executor)
1309 {
1310 SCR_TaskExecutorPlayer executorPlayer = SCR_TaskExecutorPlayer.Cast(executor);
1311 if (executorPlayer)
1312 {
1313 PlayerManager playerManager = GetGame().GetPlayerManager();
1314 if (!playerManager)
1315 return;
1316
1317 int playerID = executorPlayer.GetPlayerID();
1318 name = playerManager.GetPlayerName(playerID);
1319 suffix = playerID.ToString();
1320 }
1321
1322 SCR_TaskExecutorEntity executorEntity = SCR_TaskExecutorEntity.Cast(executor);
1323 if (executorEntity)
1324 {
1325 IEntity entity = executorEntity.GetEntity();
1326 if (!entity)
1327 return;
1328
1329 name = entity.GetName();
1330 suffix = entity.Type().ToString();
1331 }
1332
1333 SCR_TaskExecutorGroup executorGroup = SCR_TaskExecutorGroup.Cast(executor);
1334 if (executorGroup)
1335 {
1336 SCR_GroupsManagerComponent groupsManagerComponent = SCR_GroupsManagerComponent.GetInstance();
1337 if (!groupsManagerComponent)
1338 return;
1339
1340 SCR_AIGroup group = groupsManagerComponent.FindGroup(executorGroup.GetGroupID());
1341 if (!group)
1342 return;
1343
1344 name = "Group";
1345 suffix = group.GetGroupID().ToString();
1346 }
1347 }
1348
1349 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1350 if (extendedTask && extendedTask.IsChildTask())
1351 {
1352 SCR_Task parentTask = extendedTask.GetParentTask();
1353 if (!parentTask)
1354 return;
1355
1356 if (parentTask.GetTaskOwnership() <= SCR_ETaskOwnership.EXECUTOR || parentTask.GetTaskVisibility() <= SCR_ETaskVisibility.EXECUTOR)
1357 {
1358 Print("SCR_TaskSystem: Cannot remove " + name + "(" + suffix + ") from task with ID: " + task.GetTaskID() + " as parent task does not allow it!", LogLevel.WARNING);
1359 return;
1360 }
1361 }
1362
1363 if (!task.RemoveOwnerExecutor(executor))
1364 {
1365 Print("SCR_TaskSystem: Could not remove " + name + "(" + suffix + ") from task with ID: " + task.GetTaskID(), LogLevel.ERROR);
1366 return;
1367 }
1368
1369 array<ref SCR_TaskExecutor> assignees = task.GetTaskAssignees();
1370 if (assignees && !assignees.IsEmpty())
1371 {
1372 foreach (SCR_TaskExecutor assignee : assignees)
1373 {
1374 if (!CanTaskBeAssignedTo(task, assignee))
1375 task.RemoveTaskAssignee(assignee);
1376 }
1377 }
1378
1379 Print("SCR_TaskSystem: Removed " + name + "(" + suffix + ") from task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
1380 }
1381
1382 //------------------------------------------------------------------------------------------------
1386 vector GetTaskLocation(notnull SCR_Task task)
1387 {
1388 if (!task)
1389 return vector.Zero;
1390
1391 return task.GetTaskPosition();
1392 }
1393
1394 //------------------------------------------------------------------------------------------------
1398 void MoveTask(notnull SCR_Task task, vector destination)
1399 {
1400 if (Replication.IsClient())
1401 {
1402 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1403 return;
1404 }
1405
1406 task.SetTaskPosition(destination);
1407 Print("SCR_TaskSystem: Task with ID: " + task.GetTaskID() + " moved to " + destination, LogLevel.DEBUG);
1408 }
1409
1410 //------------------------------------------------------------------------------------------------
1414 void GetParentTasksFor(notnull SCR_Task task, out SCR_Task parentTask)
1415 {
1416 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1417 if (!extendedTask)
1418 return;
1419
1420 parentTask = extendedTask.GetParentTask();
1421 }
1422
1423 //------------------------------------------------------------------------------------------------
1427 void GetChildTasksFor(notnull SCR_Task task, out array<SCR_Task> childTasks)
1428 {
1429 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1430 if (!extendedTask)
1431 return;
1432
1433 childTasks = extendedTask.GetChildTasks();
1434 }
1435
1436 //------------------------------------------------------------------------------------------------
1440 void AddChildTaskTo(notnull SCR_Task task, notnull SCR_Task childTask)
1441 {
1442 if (Replication.IsClient())
1443 {
1444 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1445 return;
1446 }
1447
1448 SCR_ExtendedTask extendedParentTask = SCR_ExtendedTask.Cast(task);
1449 SCR_ExtendedTask extendedChildTask = SCR_ExtendedTask.Cast(childTask);
1450 if (!extendedParentTask || !extendedChildTask)
1451 {
1452 Print("SCR_TaskSystem: Both parent and child tasks need to be extended tasks!", LogLevel.WARNING);
1453 return;
1454 }
1455
1456 if (extendedParentTask.GetNodeDepth() > 0)
1457 {
1458 Print("SCR_TaskSystem: Tasks cannot be nested beyond depth 1!", LogLevel.WARNING);
1459 return;
1460 }
1461
1462 if (!extendedParentTask.AddChildTask(childTask))
1463 {
1464 Print("SCR_TaskSystem: Could not parent task with ID: " + childTask.GetTaskID() + " to task with ID: " + task.GetTaskID(), LogLevel.ERROR);
1465 return;
1466 }
1467
1468 Print("SCR_TaskSystem: Task with ID: " + childTask.GetTaskID() + " parented to task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
1469 }
1470
1471 //------------------------------------------------------------------------------------------------
1475 void RemoveChildTaskFrom(notnull SCR_Task task, notnull SCR_Task childTask)
1476 {
1477 if (Replication.IsClient())
1478 {
1479 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1480 return;
1481 }
1482
1483 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1484 if (!extendedTask)
1485 {
1486 Print("SCR_TaskSystem: Parent task needs to be an extended task!", LogLevel.ERROR);
1487 return;
1488 }
1489
1490 if (!extendedTask.RemoveChildTask(childTask))
1491 {
1492 Print("SCR_TaskSystem: Could not unparent task with ID: " + childTask.GetTaskID() + " from task with ID: " + task.GetTaskID(), LogLevel.ERROR);
1493 return;
1494 }
1495
1496 Print("SCR_TaskSystem: Task with ID: " + childTask.GetTaskID() + " unparented from task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
1497 }
1498
1499 //------------------------------------------------------------------------------------------------
1507 SCR_Task CreateTask(ResourceName taskResourceName, string taskID, string name, string desc, vector position = vector.Zero, int playerId = -1)
1508 {
1509 if (Replication.IsClient())
1510 {
1511 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1512 return null;
1513 }
1514
1515 if (GetTaskFromTaskID(taskID, false))
1516 {
1517 Print("SCR_TaskSystem: Task with ID: " + taskID + " already exists!", LogLevel.WARNING);
1518 return null;
1519 }
1520
1521 if (!taskResourceName || taskResourceName.IsEmpty())
1522 {
1523 Print("SCR_TaskSystem: Task resource name is empty! Using default task resource", LogLevel.WARNING);
1524 taskResourceName = BASE_TASK_RESOURCE;
1525 }
1526
1527 Resource taskResource = Resource.Load(taskResourceName);
1528 if (!taskResource || !taskResource.IsValid())
1529 {
1530 Print("SCR_TaskSystem: Task resource is invalid!", LogLevel.WARNING);
1531 return null;
1532 }
1533
1534 IEntitySource entitySource = taskResource.GetResource().ToEntitySource();
1535 if (!entitySource)
1536 return null;
1537
1538 typename taskType = entitySource.GetClassName().ToType();
1539 if (!taskType.IsInherited(SCR_Task))
1540 return null;
1541
1542 vector transform[4];
1543 Math3D.MatrixIdentity3(transform);
1544 transform[3] = position;
1545
1546 EntitySpawnParams spawnParams = new EntitySpawnParams();
1547 spawnParams.TransformMode = ETransformMode.WORLD;
1548 spawnParams.Transform = transform;
1549
1550 SCR_Task task = SCR_Task.Cast(GetGame().SpawnEntityPrefab(taskResource, GetGame().GetWorld(), spawnParams));
1551 if (!task || !task.FindComponent(RplComponent))
1552 {
1553 Print("SCR_TaskSystem: Failed to create task with ID: " + taskID, LogLevel.WARNING);
1554 return null;
1555 }
1556
1557 task.SetTaskID(taskID);
1558
1559 if (playerId > -1) // author is a player
1560 {
1561 UUID playerIdentity = SCR_PlayerIdentityUtils.GetPlayerIdentityId(playerId);
1562 PlayerManager playerManager = GetGame().GetPlayerManager();
1563 PlatformKind platform = playerManager.GetPlatformKind(playerId);
1564 task.SetAuthorCredentials(playerId,playerIdentity,platform);
1565 }
1566
1567 if (!SCR_StringHelper.IsEmptyOrWhiteSpace(name))
1568 task.SetTaskName(name);
1569
1570 if (!SCR_StringHelper.IsEmptyOrWhiteSpace(desc))
1571 task.SetTaskDescription(desc);
1572
1574 if (s_OnTaskCreated)
1575 s_OnTaskCreated.Invoke(task);
1576
1577 Print("SCR_TaskSystem: Created task with ID: " + taskID, LogLevel.DEBUG);
1578 return task;
1579 }
1580
1581 //------------------------------------------------------------------------------------------------
1584 void DeleteTask(notnull SCR_Task task)
1585 {
1586 if (Replication.IsClient())
1587 {
1588 Print("SCR_TaskSystem: Trying to invoke server-only function on client", LogLevel.ERROR);
1589 return;
1590 }
1591
1592 RplComponent taskRpl = RplComponent.Cast(task.FindComponent(RplComponent));
1593 if (!taskRpl)
1594 {
1595 Print("SCR_TaskSystem: Missing Rpl Component; Cannot delete task with ID: " + task.GetTaskID(), LogLevel.WARNING);
1596 return;
1597 }
1598
1599 Print("SCR_TaskSystem: Deleted task with ID: " + task.GetTaskID(), LogLevel.DEBUG);
1600 taskRpl.DeleteRplEntity(task, false);
1601 }
1602
1603 //------------------------------------------------------------------------------------------------
1608 static SCR_Task GetTaskFromTaskID(string taskID, bool notify = true)
1609 {
1610 foreach (SCR_Task task : s_aTasks)
1611 {
1612 if (!task)
1613 continue;
1614
1615 string ID = task.GetTaskID();
1616 if (!ID || ID.IsEmpty())
1617 continue;
1618
1619 if (taskID == ID)
1620 return task;
1621 }
1622
1623 if (notify)
1624 Print("SCR_TaskSystem: Task with ID: " + taskID + " does not exist!", LogLevel.WARNING);
1625
1626 return null;
1627 }
1628
1629 //------------------------------------------------------------------------------------------------
1633 static SCR_TaskExecutor TaskExecutorFromPlayerID(int playerID)
1634 {
1635 return SCR_TaskExecutor.FromPlayerID(playerID);
1636 }
1637
1638 //------------------------------------------------------------------------------------------------
1642 static SCR_TaskExecutor TaskExecutorFromEntity(IEntity ent)
1643 {
1644 return SCR_TaskExecutor.FromEntity(ent);
1645 }
1646
1647 //------------------------------------------------------------------------------------------------
1651 static SCR_TaskExecutor TaskExecutorFromGroup(int groupID)
1652 {
1653 return SCR_TaskExecutor.FromGroup(groupID);
1654 }
1655
1656 //------------------------------------------------------------------------------------------------
1657 override protected void OnUpdatePoint(WorldUpdatePointArgs args)
1658 {
1659 // Debug task system
1660#ifdef ENABLE_DIAG
1661 if (args.GetPoint() != WorldSystemPoint.Frame)
1662 return;
1663
1664 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_TASKS_CREATE))
1666
1667 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_TASKS_LIST))
1668 Diag_TaskList();
1669#endif
1670 }
1671
1672 //------------------------------------------------------------------------------------------------
1674 {
1675 DbgUI.Begin("Create Task");
1676
1677 string taskID;
1678 DbgUI.InputText("ID: ", taskID);
1679
1680 string taskName;
1681 DbgUI.InputText("Name: ", taskName);
1682
1683 string taskDesc;
1684 DbgUI.InputText("Description: ", taskDesc);
1685
1686 if (DbgUI.Button("Create Base Task") &&
1689 CreateTask(BASE_TASK_RESOURCE, taskID, taskName, taskDesc);
1690
1691 if (DbgUI.Button("Create Extended Task") &&
1694 CreateTask(EXTENDED_TASK_RESOURCE, taskID, taskName, taskDesc);
1695
1696 DbgUI.End();
1697 }
1698
1699 //------------------------------------------------------------------------------------------------
1701 {
1702 array<SCR_Task> tasks = {};
1703 int taskCount;
1704 string header;
1705
1706 if (diag_taskListMenu && diag_selectedExecutor)
1707 {
1708 taskCount = GetTasksVisibleFor(tasks, diag_selectedExecutor);
1709
1710 string executorName;
1711
1712 SCR_TaskExecutorPlayer playerExecutor = SCR_TaskExecutorPlayer.Cast(diag_selectedExecutor);
1713 if (playerExecutor)
1714 executorName = GetGame().GetPlayerManager().GetPlayerName(playerExecutor.GetPlayerID());
1715
1716 SCR_TaskExecutorEntity entityExecutor = SCR_TaskExecutorEntity.Cast(diag_selectedExecutor);
1717 if (entityExecutor)
1718 executorName = entityExecutor.GetEntity().GetName();
1719
1720 SCR_TaskExecutorGroup groupExecutor = SCR_TaskExecutorGroup.Cast(diag_selectedExecutor);
1721 if (groupExecutor)
1722 executorName = groupExecutor.GetGroupID().ToString();
1723
1724 header = string.Format("Task List for %1 (%2)", executorName, taskCount);
1725 }
1726 else
1727 {
1728 taskCount = GetTasks(tasks);
1729 header = string.Format("Task List (%1)", taskCount);
1730 }
1731
1732 DbgUI.Begin(header);
1733
1734 bool checked = diag_taskListMenu;
1735 DbgUI.Check("Show Task List for: ", checked);
1736 diag_taskListMenu = checked;
1737
1738 if (diag_taskListMenu)
1740
1741 DbgUI.Text("________________________________________________");
1742
1743 int currentTask;
1744 foreach (SCR_Task task : tasks)
1745 {
1746 if (!task)
1747 continue;
1748
1749 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1750 if (extendedTask && extendedTask.IsChildTask())
1751 continue;
1752
1753 Diag_Task(task, currentTask);
1754 currentTask++;
1755 }
1756
1757 DbgUI.End();
1758 }
1759
1760 //------------------------------------------------------------------------------------------------
1761 void Diag_Task(notnull SCR_Task task, int index, int subIndex = -1)
1762 {
1763 SCR_TaskData data = task.GetTaskData();
1764 if (!data)
1765 return;
1766
1767 string taskName = task.GetTaskName();
1768 if (taskName.Length() > DIAG_MAX_NAME_LENGTH_LIST)
1769 taskName = taskName.Substring(0, DIAG_MAX_NAME_LENGTH_LIST) + "...";
1770
1771 string taskText;
1772 if (subIndex > -1)
1773 taskText = string.Format("%1.%2 - id:%3 | name:%4", index, subIndex, task.GetTaskID(), taskName);
1774 else
1775 taskText = string.Format("%1 - id:%2 | name:%3", index, task.GetTaskID(), taskName);
1776
1777 bool checked = data.diag_isChecked;
1778 DbgUI.Check(taskText + " " , checked);
1779 data.diag_isChecked = checked;
1780
1781 if (data.diag_isChecked)
1783
1784 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1785 if (!extendedTask || !extendedTask.HasChildTasks())
1786 return;
1787
1788 array<SCR_Task> childTasks = extendedTask.GetChildTasks();
1789 if (!childTasks || childTasks.IsEmpty())
1790 return;
1791
1792 int currentChildTask;
1793 foreach (SCR_Task childTask : childTasks)
1794 {
1795 if (!childTask)
1796 continue;
1797
1798 Diag_Task(childTask, index, currentChildTask);
1799 currentChildTask++;
1800 }
1801 }
1802
1803 //------------------------------------------------------------------------------------------------
1805 {
1806 DbgUI.Begin("Show task list for individual executor");
1807
1808 array<string> executorTypes = {"PLAYER", "ENTITY", "GROUP"};
1809 DbgUI.Combo("Executor Type: ", diag_taskListMenuSelection, executorTypes);
1810
1811 DbgUI.InputText("Executor Name/ID: ", diag_taskListMenuExecutorName);
1812
1813 DbgUI.End();
1814
1815 if (!SCR_StringHelper.IsEmptyOrWhiteSpace(diag_taskListMenuExecutorName))
1816 {
1817 switch (diag_taskListMenuSelection)
1818 {
1819 // Player Executor
1820 case 0:
1821 int playerID = diag_taskListMenuExecutorName.ToInt();
1822 if (playerID > -1)
1823 diag_selectedExecutor = SCR_TaskExecutor.FromPlayerID(playerID);
1824
1825 break;
1826 // Entity Executor
1827 case 1:
1828 IEntity entity = GetGame().FindEntity(diag_taskListMenuExecutorName);
1829 if (entity)
1830 diag_selectedExecutor = SCR_TaskExecutor.FromEntity(entity);
1831
1832 break;
1833 // Group Executor
1834 case 2:
1835 int groupID = diag_taskListMenuExecutorName.ToInt();
1836 if (groupID > -1)
1837 diag_selectedExecutor = SCR_TaskExecutor.FromGroup(groupID);
1838
1839 break;
1840 }
1841 }
1842 }
1843
1844 //------------------------------------------------------------------------------------------------
1846 {
1847 DbgUI.Begin(string.Format("Task: %1 (%2)", task.GetTaskID(), task.Type()));
1848
1849 bool checked;
1850
1851 // Name
1852 string taskName = task.GetTaskName();
1853 if (taskName.Length() > DIAG_MAX_NAME_LENGTH)
1854 taskName = taskName.Substring(0, DIAG_MAX_NAME_LENGTH) + "...";
1855
1856 checked = data.diag_checkedSettings[0];
1857 DbgUI.Check(string.Format("Name: %1", taskName), checked);
1858 data.diag_checkedSettings[0] = checked;
1859
1860 if (data.diag_checkedSettings[0])
1861 Diag_EditStringContextMenu(task, "Name", 0);
1862
1863 // Description
1864 string taskDesc = task.GetTaskDescription();
1865 if (taskDesc.Length() > DIAG_MAX_DESCRIPTION_LENGTH)
1866 taskDesc = taskDesc.Substring(0, DIAG_MAX_DESCRIPTION_LENGTH) + "...";
1867
1868 checked = data.diag_checkedSettings[1];
1869 DbgUI.Check(string.Format("Description: %1", taskDesc), checked);
1870 data.diag_checkedSettings[1] = checked;
1871
1872 if (data.diag_checkedSettings[1])
1873 Diag_EditStringContextMenu(task, "Description", 1);
1874
1875 // State
1876 checked = data.diag_checkedSettings[2];
1877 DbgUI.Check(string.Format("State: %1", SCR_Enum.GetEnumName(SCR_ETaskState, task.GetTaskState())), checked);
1878 data.diag_checkedSettings[2] = checked;
1879
1880 if (data.diag_checkedSettings[2])
1882
1883 // Ownership
1884 checked = data.diag_checkedSettings[3];
1885 DbgUI.Check(string.Format("Ownership: %1", SCR_Enum.GetEnumName(SCR_ETaskOwnership, task.GetTaskOwnership())), checked);
1886 data.diag_checkedSettings[3] = checked;
1887
1888 if (data.diag_checkedSettings[3])
1889 Diag_EditEnumContextMenu(task, SCR_ETaskOwnership, 3);
1890
1891 // Visibility
1892 checked = data.diag_checkedSettings[4];
1893 DbgUI.Check(string.Format("Visibility: %1", SCR_Enum.GetEnumName(SCR_ETaskVisibility, task.GetTaskVisibility())), checked);
1894 data.diag_checkedSettings[4] = checked;
1895
1896 if (data.diag_checkedSettings[4])
1898
1899 // UI Visibility
1900 checked = data.diag_checkedSettings[5];
1901 DbgUI.Check(string.Format("UI Visibility: %1", SCR_Enum.GetEnumName(SCR_ETaskUIVisibility, task.GetTaskUIVisibility())), checked);
1902 data.diag_checkedSettings[5] = checked;
1903
1904 if (data.diag_checkedSettings[5])
1905 Diag_EditEnumContextMenu(task, SCR_ETaskUIVisibility, 5);
1906
1907 // Assignees
1908 checked = data.diag_checkedSettings[6];
1909 DbgUI.Check(string.Format("Assignees: %1", task.GetTaskAssigneeCount()), checked);
1910 data.diag_checkedSettings[6] = checked;
1911
1912 if (data.diag_checkedSettings[6])
1913 Diag_EditExecutorContextMenu(task, "Assignee", 6);
1914
1915 // Owner Executors
1916 checked = data.diag_checkedSettings[7];
1917 DbgUI.Check(string.Format("Executors: %1", task.GetOwnerExecutorCount()), checked);
1918 data.diag_checkedSettings[7] = checked;
1919
1920 if (data.diag_checkedSettings[7])
1921 Diag_EditExecutorContextMenu(task, "Executor", 7);
1922
1923 // Owner Factions
1924 checked = data.diag_checkedSettings[8];
1925 DbgUI.Check(string.Format("Factions: %1", task.GetOwnerFactionCount()), checked);
1926 data.diag_checkedSettings[8] = checked;
1927
1928 if (data.diag_checkedSettings[8])
1930
1931 // Owner Groups
1932 checked = data.diag_checkedSettings[9];
1933 DbgUI.Check(string.Format("Groups: %1", task.GetOwnerGroupCount()), checked);
1934 data.diag_checkedSettings[9] = checked;
1935
1936 if (data.diag_checkedSettings[9])
1938
1939 // Position
1940 checked = data.diag_checkedSettings[10];
1941 DbgUI.Check(string.Format("Position: %1", task.GetTaskPosition()), checked);
1942 data.diag_checkedSettings[10] = checked;
1943
1944 if (data.diag_checkedSettings[10])
1946
1947 // Extended Task Settings
1948 SCR_ExtendedTask extendedTask = SCR_ExtendedTask.Cast(task);
1949 SCR_ExtendedTaskData extendedData = SCR_ExtendedTaskData.Cast(data);
1950 if (extendedTask && extendedData)
1951 {
1952 // Child Tasks
1953 checked = extendedData.diag_checkedExtendedSettings[0];
1954 DbgUI.Check(string.Format("Child Tasks: %1", extendedTask.GetChildTaskCount()), checked);
1955 extendedData.diag_checkedExtendedSettings[0] = checked;
1956
1957 if (extendedData.diag_checkedExtendedSettings[0])
1958 Diag_EditChildTasksContextMenu(extendedTask, 0);
1959
1960 // Progress
1961 checked = extendedData.diag_checkedExtendedSettings[1];
1962 DbgUI.Check(string.Format("Progress: %1%2", extendedTask.GetTaskProgress(), "%"), checked);
1963 extendedData.diag_checkedExtendedSettings[1] = checked;
1964
1965 if (extendedData.diag_checkedExtendedSettings[1])
1966 Diag_EditProgressContextMenu(extendedTask, 1);
1967 }
1968
1969 // Shortcuts
1970 DbgUI.Text("_________________________________________");
1971 DbgUI.Text("Shortcuts:");
1972
1973 PlayerController localPlayerController;
1974 int localPlayerID;
1975 SCR_TaskExecutor localPlayerExecutor;
1976 SCR_TaskSystemNetworkComponent networkComponent;
1977
1978 if (DbgUI.Button("Assign Self"))
1979 {
1980 localPlayerController = GetGame().GetPlayerController();
1981 localPlayerID = localPlayerController.GetPlayerId();
1982 localPlayerExecutor = SCR_TaskExecutor.FromPlayerID(localPlayerID);
1983
1984 networkComponent = SCR_TaskSystemNetworkComponent.Cast(localPlayerController.FindComponent(SCR_TaskSystemNetworkComponent));
1985 if (networkComponent)
1986 networkComponent.AssignTask(task, localPlayerExecutor, true);
1987 }
1988
1989 if (DbgUI.Button("Unassign Self"))
1990 {
1991 localPlayerController = GetGame().GetPlayerController();
1992 localPlayerID = localPlayerController.GetPlayerId();
1993 localPlayerExecutor = SCR_TaskExecutor.FromPlayerID(localPlayerID);
1994
1995 networkComponent = SCR_TaskSystemNetworkComponent.Cast(localPlayerController.FindComponent(SCR_TaskSystemNetworkComponent));
1996 if (networkComponent)
1997 networkComponent.UnassignTask(task, localPlayerExecutor);
1998 }
1999
2000 if (DbgUI.Button("Complete Task"))
2001 SetTaskState(task, SCR_ETaskState.COMPLETED);
2002
2003 if (DbgUI.Button("Fail Task"))
2004 SetTaskState(task, SCR_ETaskState.FAILED);
2005
2006 // Delete
2007 if (DbgUI.Button("Delete Task"))
2009
2010 DbgUI.End();
2011 }
2012
2013 //------------------------------------------------------------------------------------------------
2014 void Diag_EditStringContextMenu(notnull SCR_Task task, string name, int settingIndex)
2015 {
2016 string input;
2017 switch (name)
2018 {
2019 case "Name":
2020 input = task.GetTaskName();
2021 break;
2022 case "Description":
2023 input = task.GetTaskDescription();
2024 break;
2025 }
2026
2027 DbgUI.Begin(string.Format("Edit %1 for task: %2", name, task.GetTaskID()));
2028
2029 DbgUI.InputText(string.Format("%1:", name), input);
2030
2031 if (DbgUI.Button(string.Format("Set %1", name)) && !SCR_StringHelper.IsEmptyOrWhiteSpace(input))
2032 {
2033 switch (name)
2034 {
2035 case "Name":
2036 task.SetTaskName(input);
2037 break;
2038 case "Description":
2039 task.SetTaskDescription(input);
2040 break;
2041 }
2042
2043 task.GetTaskData().diag_checkedSettings[settingIndex] = false;
2044 }
2045
2046 DbgUI.End();
2047 }
2048
2049 //------------------------------------------------------------------------------------------------
2050 void Diag_EditEnumContextMenu(notnull SCR_Task task, typename enumType, int settingIndex)
2051 {
2052 string enumName;
2053 int selection;
2054 switch (enumType)
2055 {
2056 case SCR_ETaskState:
2057 enumName = "State";
2058 selection = Math.Log2(task.GetTaskState());
2059 break;
2060 case SCR_ETaskOwnership:
2061 enumName = "Ownership";
2062 selection = task.GetTaskOwnership();
2063 break;
2065 enumName = "Visibility";
2066 selection = task.GetTaskVisibility();
2067 break;
2068 case SCR_ETaskUIVisibility:
2069 enumName = "UI Visibility";
2070 selection = task.GetTaskUIVisibility();
2071 break;
2072 }
2073
2074 DbgUI.Begin(string.Format("Edit %1 for task: %2", enumName, task.GetTaskID()));
2075
2076 array<string> enumNames = {};
2077 SCR_Enum.GetEnumNames(enumType, enumNames);
2078
2079 DbgUI.Combo(enumName, selection, enumNames);
2080
2081 if (DbgUI.Button(string.Format("Set %1", enumName)))
2082 {
2083 switch (enumType)
2084 {
2085 case SCR_ETaskState:
2086 SetTaskState(task, 1 << selection);
2087 break;
2088 case SCR_ETaskOwnership:
2089 SetTaskOwnership(task, selection);
2090 break;
2092 SetTaskVisibility(task, selection);
2093 break;
2094 case SCR_ETaskUIVisibility:
2095 SetTaskUIVisibility(task, selection);
2096 break;
2097 }
2098
2099 task.GetTaskData().diag_checkedSettings[settingIndex] = false;
2100 }
2101
2102 DbgUI.End();
2103 }
2104
2105 //------------------------------------------------------------------------------------------------
2106 void Diag_EditExecutorContextMenu(notnull SCR_Task task, string name, int settingIndex)
2107 {
2108 DbgUI.Begin(string.Format("Add/Remove %1 for task: %2", name, task.GetTaskID()));
2109
2110 array<ref SCR_TaskExecutor> executors;
2111 switch (name)
2112 {
2113 case "Assignee":
2114 executors = task.GetTaskAssignees();
2115 break;
2116 case "Executor":
2117 executors = task.GetOwnerExecutors();
2118 break;
2119 }
2120
2121 int currentExecutor;
2122 if (executors && !executors.IsEmpty())
2123 {
2124 foreach (SCR_TaskExecutor executor : executors)
2125 {
2126 string executorName, executorType;
2127
2128 SCR_TaskExecutorPlayer playerExecutor = SCR_TaskExecutorPlayer.Cast(executor);
2129 if (playerExecutor)
2130 {
2131 executorName = GetGame().GetPlayerManager().GetPlayerName(playerExecutor.GetPlayerID());
2132 executorType = "PLAYER";
2133 }
2134
2135 SCR_TaskExecutorEntity entityExecutor = SCR_TaskExecutorEntity.Cast(executor);
2136 if (entityExecutor)
2137 {
2138 executorName = entityExecutor.GetEntity().GetName();
2139 executorType = "ENTITY";
2140 }
2141
2142 SCR_TaskExecutorGroup groupExecutor = SCR_TaskExecutorGroup.Cast(executor);
2143 if (groupExecutor)
2144 {
2145 executorName = groupExecutor.GetGroupID().ToString();
2146 executorType = "GROUP";
2147 }
2148
2149 DbgUI.Text(string.Format("%1 - name/id:%2 | type:%3", currentExecutor, executorName, executorType));
2150 ++currentExecutor;
2151 }
2152 }
2153
2154 if (currentExecutor > 0)
2155 DbgUI.Text("________________________________________________");
2156
2157 array<string> executorTypes = {"PLAYER", "ENTITY", "GROUP"};
2158 int selection;
2159 DbgUI.Combo("Executor Type: ", selection, executorTypes);
2160
2161 string input;
2162 DbgUI.InputText("Executor Name/ID: ", input);
2163
2164 SCR_TaskExecutor executor;
2166 {
2167 switch (selection)
2168 {
2169 // Player Executor
2170 case 0:
2171 int playerID = input.ToInt();
2172 if (playerID > -1)
2173 executor = SCR_TaskExecutor.FromPlayerID(playerID);
2174
2175 break;
2176 // Entity Executor
2177 case 1:
2178 IEntity entity = GetGame().FindEntity(input);
2179 if (entity)
2180 executor = SCR_TaskExecutor.FromEntity(entity);
2181
2182 break;
2183 // Group Executor
2184 case 2:
2185 int groupID = input.ToInt();
2186 if (groupID > -1)
2187 executor = SCR_TaskExecutor.FromGroup(groupID);
2188
2189 break;
2190 }
2191 }
2192
2193 PlayerController localPlayerController;
2194 SCR_TaskSystemNetworkComponent networkComponent;
2195
2196 if (DbgUI.Button(string.Format("Add %1", name)) && executor)
2197 {
2198 localPlayerController = GetGame().GetPlayerController();
2199 networkComponent = SCR_TaskSystemNetworkComponent.Cast(localPlayerController.FindComponent(SCR_TaskSystemNetworkComponent));
2200
2201 switch (name)
2202 {
2203 case "Assignee":
2204 networkComponent.AssignTask(task, executor, true);
2205 break;
2206 case "Executor":
2207 AddTaskExecutor(task, executor);
2208 break;
2209 }
2210
2211 task.GetTaskData().diag_checkedSettings[settingIndex] = false;
2212 }
2213
2214 if (DbgUI.Button(string.Format("Remove %1", name)) && executor)
2215 {
2216 localPlayerController = GetGame().GetPlayerController();
2217 networkComponent = SCR_TaskSystemNetworkComponent.Cast(localPlayerController.FindComponent(SCR_TaskSystemNetworkComponent));
2218
2219 switch (name)
2220 {
2221 case "Assignee":
2222 networkComponent.UnassignTask(task, executor);
2223 break;
2224 case "Executor":
2225 RemoveTaskExecutor(task, executor);
2226 break;
2227 }
2228
2229 task.GetTaskData().diag_checkedSettings[settingIndex] = false;
2230 }
2231
2232 DbgUI.End();
2233 }
2234
2235 //------------------------------------------------------------------------------------------------
2236 void Diag_EditFactionContextMenu(notnull SCR_Task task, int settingIndex)
2237 {
2238 DbgUI.Begin(string.Format("Add/Remove Faction for task: %1", task.GetTaskID()));
2239
2240 array<string> factionKeys = task.GetOwnerFactionKeys();
2241
2242 int currentFaction = 0;
2243 if (factionKeys && !factionKeys.IsEmpty())
2244 {
2245 foreach (string factionKey : factionKeys)
2246 {
2247 DbgUI.Text(string.Format("%1 - key:%2", currentFaction, factionKey));
2248 ++currentFaction;
2249 }
2250 }
2251
2252 if (currentFaction > 0)
2253 DbgUI.Text("________________________________________________");
2254
2255 string input;
2256 DbgUI.InputText("Faction Key: ", input);
2257
2258 if (DbgUI.Button("Add Faction"))
2259 {
2260 AddTaskFaction(task, input);
2261 task.GetTaskData().diag_checkedSettings[settingIndex] = false;
2262 }
2263
2264 if (DbgUI.Button("Remove Faction"))
2265 {
2266 RemoveTaskFaction(task, input);
2267 task.GetTaskData().diag_checkedSettings[settingIndex] = false;
2268 }
2269
2270 DbgUI.End();
2271 }
2272
2273 //------------------------------------------------------------------------------------------------
2274 void Diag_EditGroupContextMenu(notnull SCR_Task task, int settingIndex)
2275 {
2276 DbgUI.Begin(string.Format("Add/Remove Group for task: %1", task.GetTaskID()));
2277
2278 array<int> groupIDs = task.GetOwnerGroupIDs();
2279
2280 int currentGroup = 0;
2281 if (groupIDs && !groupIDs.IsEmpty())
2282 {
2283 foreach (int groupID : groupIDs)
2284 {
2285 DbgUI.Text(string.Format("%1 - id:%2", currentGroup, groupID.ToString()));
2286 ++currentGroup;
2287 }
2288 }
2289
2290 if (currentGroup > 0)
2291 DbgUI.Text("________________________________________________");
2292
2293 string input;
2294 DbgUI.InputText("Group ID: ", input);
2295
2296 if (DbgUI.Button("Add Group"))
2297 {
2298 AddTaskGroup(task, input.ToInt());
2299 task.GetTaskData().diag_checkedSettings[settingIndex] = false;
2300 }
2301
2302 if (DbgUI.Button("Remove Group"))
2303 {
2304 RemoveTaskGroup(task, input.ToInt());
2305 task.GetTaskData().diag_checkedSettings[settingIndex] = false;
2306 }
2307
2308 DbgUI.End();
2309 }
2310
2311 //------------------------------------------------------------------------------------------------
2312 void Diag_MoveTaskContextMenu(notnull SCR_Task task, int settingIndex)
2313 {
2314 DbgUI.Begin(string.Format("Move task: %1", task.GetTaskID()));
2315
2316 vector position = task.GetTaskPosition();
2317 float x = position[0];
2318 float y = position[1];
2319 float z = position[2];
2320 DbgUI.InputFloat("X: ", x);
2321 DbgUI.InputFloat("Y: ", y);
2322 DbgUI.InputFloat("Z: ", z);
2323
2324 if (DbgUI.Button("Move Task"))
2325 {
2326 MoveTask(task, {x, y, z});
2327 task.GetTaskData().diag_checkedSettings[settingIndex] = false;
2328 }
2329
2330 DbgUI.End();
2331 }
2332
2333 //------------------------------------------------------------------------------------------------
2334 void Diag_EditChildTasksContextMenu(notnull SCR_ExtendedTask extendedTask, int settingIndex)
2335 {
2336 DbgUI.Begin(string.Format("Add/Remove Child Task for task: %1", extendedTask.GetTaskID()));
2337
2338 array<SCR_Task> childTasks = extendedTask.GetChildTasks();
2339
2340 string taskName;
2341 int currentChildTask = 0;
2342 if (childTasks && !childTasks.IsEmpty())
2343 {
2344 foreach (SCR_Task childTask : childTasks)
2345 {
2346 taskName = childTask.GetTaskName();
2347 if (taskName.Length() > DIAG_MAX_NAME_LENGTH_LIST)
2348 taskName = taskName.Substring(0, DIAG_MAX_NAME_LENGTH_LIST) + "...";
2349
2350 DbgUI.Text(string.Format("%1 - id:%2 | name:%3", currentChildTask, childTask.GetTaskID(), taskName));
2351 ++currentChildTask;
2352 }
2353 }
2354
2355 if (currentChildTask > 0)
2356 DbgUI.Text("________________________________________________");
2357
2358 string input;
2359 DbgUI.InputText("Task ID: ", input);
2360
2361 if (DbgUI.Button("Parent Task"))
2362 {
2363 SCR_Task task = GetTaskFromTaskID(input);
2364 if (task)
2365 AddChildTaskTo(extendedTask, task);
2366
2367 SCR_ExtendedTaskData.Cast(extendedTask.GetTaskData()).diag_checkedExtendedSettings[settingIndex] = false;
2368 }
2369
2370 if (DbgUI.Button("Unparent Task"))
2371 {
2372 SCR_Task task = GetTaskFromTaskID(input);
2373 if (task)
2374 RemoveChildTaskFrom(extendedTask, task);
2375
2376 SCR_ExtendedTaskData.Cast(extendedTask.GetTaskData()).diag_checkedExtendedSettings[settingIndex] = false;
2377 }
2378
2379 DbgUI.End();
2380 }
2381
2382 //------------------------------------------------------------------------------------------------
2383 void Diag_EditProgressContextMenu(notnull SCR_ExtendedTask extendedTask, int settingIndex)
2384 {
2385 DbgUI.Begin(string.Format("Edit Progress for task: %1", extendedTask.GetTaskID()));
2386
2387 float input = extendedTask.GetTaskProgress();
2388 DbgUI.InputFloat("Progress: ", input);
2389
2390 if (DbgUI.Button("Set Progress"))
2391 {
2392 SetTaskProgress(extendedTask, input);
2393 SCR_ExtendedTaskData.Cast(extendedTask.GetTaskData()).diag_checkedExtendedSettings[settingIndex] = false;
2394 }
2395
2396 if (DbgUI.Button("Add Progress"))
2397 {
2398 AddTaskProgress(extendedTask, input);
2399 SCR_ExtendedTaskData.Cast(extendedTask.GetTaskData()).diag_checkedExtendedSettings[settingIndex] = false;
2400 }
2401
2402 if (DbgUI.Button("Remove Progress"))
2403 {
2404 RemoveTaskProgress(extendedTask, input);
2405 SCR_ExtendedTaskData.Cast(extendedTask.GetTaskData()).diag_checkedExtendedSettings[settingIndex] = false;
2406 }
2407
2408 DbgUI.End();
2409 }
2410}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
string FactionKey
Faction unique identifier type.
Definition FactionKey.c:2
ArmaReforgerScripted GetGame()
Definition game.c:1398
PlatformKind
Definition PlatformKind.c:8
void SCR_AIGroup(IEntitySource src, IEntity parent)
void DeleteTask()
vector position
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Get all prefabs that have the spawner data
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ETaskState GetTaskState()
SCR_ETaskVisibility GetTaskVisibility()
Definition SCR_Task.c:874
SCR_ETaskVisibility
Definition SCR_Task.c:24
SCR_ETaskOwnership GetTaskOwnership()
Definition SCR_Task.c:841
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
SCR_ETaskUIVisibility GetTaskUIVisibility()
Definition SCR_Task.c:907
SCR_ETaskState
Definition SCR_Task.c:3
ScriptInvokerBase< TaskInvokerDelegate > SCR_TaskInvoker
func TaskInvokerDelegate
int Type
proto native external bool IsInherited(typename type)
enum EVehicleType IEntity
Definition DbgUI.c:66
Diagnostic and developer menu system.
Definition DiagMenu.c:18
proto external string GetName()
Definition Math.c:13
bool IsPlayerLeader(int playerID)
int GetGroupID()
int GetLeaderID()
string GetFactionName()
void SetTaskProgress(float percentage, bool changeState=true)
void ShowTaskProgress(bool enable)
void RemoveTaskProgress(float percentage, bool changeState=true)
array< SCR_Task > GetChildTasks()
bool RemoveChildTask(SCR_Task task)
bool AddChildTask(SCR_Task task)
void AddTaskProgress(float percentage, bool changeState=true)
static bool IsEmptyOrWhiteSpace(string input)
const ResourceName BASE_TASK_RESOURCE
static ref SCR_TaskInvoker s_OnTaskCreated
void Diag_EditFactionContextMenu(notnull SCR_Task task, int settingIndex)
const ResourceName EXTENDED_TASK_RESOURCE
void Diag_EditProgressContextMenu(notnull SCR_ExtendedTask extendedTask, int settingIndex)
void OnUpdatePoint(WorldUpdatePointArgs args)
void Diag_EditGroupContextMenu(notnull SCR_Task task, int settingIndex)
void Diag_Task(notnull SCR_Task task, int index, int subIndex=-1)
void Diag_TaskWindow(notnull SCR_Task task, notnull SCR_TaskData data)
void Diag_MoveTaskContextMenu(notnull SCR_Task task, int settingIndex)
static ref SCR_TaskInvoker s_OnTaskRemoved
void Diag_EditEnumContextMenu(notnull SCR_Task task, typename enumType, int settingIndex)
static ref SCR_TaskInvoker s_OnTaskAdded
static ref array< SCR_Task > s_aTasks
void Diag_ShowTaskListFor()
void Diag_EditChildTasksContextMenu(notnull SCR_ExtendedTask extendedTask, int settingIndex)
void Diag_EditStringContextMenu(notnull SCR_Task task, string name, int settingIndex)
RplComponent m_Rpl
void Diag_EditExecutorContextMenu(notnull SCR_Task task, string name, int settingIndex)
Definition World.c:16
Structure holding world system meta-information required by the engine.
Structure holding extra data of WorldSystem update point.
WorldSystemPoint ESystemPoint
Definition gameLib.c:7
void EntitySpawnParams()
Definition gameLib.c:130
WorldSystemLocation ESystemLocation
Definition gameLib.c:10
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
WorldSystemPoint
@ ID
Ordered by Group application ID.