Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseTask.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
2//class SCR_BaseTaskClass: GenericEntityClass
3//{
4//};
5//
6//------------------------------------------------------------------------------------------------
8//class SCR_BaseTask : GenericEntity
9//{
10//
11// //****************//
12// //STATIC VARIABLES//
13// //****************//
14//
15// static const string TASK_AMOUNT_COMPLETED_TEXT = "#AR-Tasks_AmountCompleted";
16// static const string TASK_PROGRESS_TEXT = "#AR-Tasks_StatusProgress-UC";
17// static const string TASK_FINISHED_TEXT = "#AR-Tasks_StatusFinished-UC";
18// static const string TASK_AVAILABLE_TEXT = "#AR-Tasks_StatusNew-UC";
19// static const string TASK_HINT_TEXT = "#AR-Tasks_Hint";
20// static const string TASK_CANCELLED_TEXT = "#AR-Tasks_StatusCancelled-UC";
21// static const string TASK_COMPLETED_TEXT = "#AR-Tasks_StatusCompleted-UC";
22// static const string TASK_FAILED_TEXT = "#AR-Tasks_StatusFailed-UC";
23// static const float DEFAULT_ASSIGNEE_TIME_LIMIT = 1800;
24// static const float DEFAULT_ASSIGNEE_TIMEOUT_TIME = 60;
25// static const int INVALID_TIMESTAMP = -1;
26// static const int INVALID_TASK_ID = -1;
27// protected static const float PLATFORM_ICON_SIZE = 2;
28//
29// static int s_iCurrentTaskID = 0;
30//
31// //*****************//
32// //MEMBER ATTRIBUTES//
33// //*****************//
34//
35// [Attribute(defvalue: "Task name.", desc: "The task name visible to the player.")]
36// protected string m_sName;
37//
38// [Attribute(defvalue: "Task description.", desc: "The task description visible to the player.")]
39// protected string m_sDescription;
40//
41// [Attribute("1", desc: "Can this task be assigned?")]
42// protected bool m_bAssignable;
43//
44// [Attribute(desc: "Is this task supposed to be completed just by an individual?")]
45// protected bool m_bIndividualTask;
46//
47// [Attribute("Task_Seize")]
48// protected string m_sMapIconName;
49//
50// [Attribute("Icon_")]
51// protected string m_sTaskListIconNamePrefix;
52//
53// [Attribute("Seize")]
54// protected string m_sTaskListIconName;
55//
56// [Attribute("M_")]
57// protected string m_sMajorModifier;
58//
59// [Attribute("{EAB5D9841F081D07}UI/layouts/Campaign/TaskElementNew.layout")]
60// protected ResourceName m_sMapUIElementResourceName;
61//
62// [Attribute("{10C0A9A305E8B3A4}UI/Imagesets/Tasks/Task_Icons.imageset", category: "Task icon")]
63// protected ResourceName m_sIconImageset;
64//
65// [Attribute(SCR_ERadioMsg.CONFIRM.ToString(), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_ERadioMsg))]
66// protected SCR_ERadioMsg m_eAssignMessage;
67//
68// [Attribute("0")]
69// protected bool m_bNotifyAssignment;
70//
71// [Attribute(SCR_ERadioMsg.TASK_UNASSIGN_EVAC.ToString(), UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_ERadioMsg))]
72// protected SCR_ERadioMsg m_eUnassignMessage;
73//
74// [Attribute("0")]
75// protected bool m_bNotifyUnassign;
76//
77// [Attribute("{6FE28246710CA6B1}UI/layouts/Tasks/TaskHUDIcon.layout")]
78// protected ResourceName m_sHUDIcon;
79//
80// //**************************//
81// //PROTECTED MEMBER VARIABLES//
82// //**************************//
83//
84// protected Faction m_TargetFaction = null;
85// protected int m_iTaskID = INVALID_TASK_ID;
86// protected float m_fAssigneeTimeLimit = DEFAULT_ASSIGNEE_TIME_LIMIT;
87// protected float m_fLastAssigneeAddedTimestamp = INVALID_TIMESTAMP;
88// protected ref array<SCR_BaseTaskExecutor> m_aAssignees = new array<SCR_BaseTaskExecutor>();
89// protected SCR_TaskState m_eState;
90// protected SCR_BaseTaskExecutor m_TimedOutAssignee = null;
91// protected float m_fAssigneeTimeoutTimestamp = INVALID_TIMESTAMP;
92// protected SCR_MapDescriptorComponent m_MapDescriptor;
93// protected ImageWidget m_wHUDIcon;
94// protected Widget m_wMapTaskIcon;
95// protected Widget m_wTaskListDescription;
96// protected bool m_bIsPriority;
97// protected SCR_PlayerFactionAffiliationComponent m_sPlyFactionAffilComp;
98// protected float m_fMajorSize = 80;
99//
100// const string TASK_BG_M = "Icon_M_Task_BG";
101// const string TASK_O_M = "Icon_M_Task_Outline";
102// const string TASK_BG = "Icon_Task_BG";
103// const string TASK_O = "Icon_Task_Outline";
104// const string TASK_H = "Icon_M_Task_Hover";
105// const string Task_S = "TaskIconSymbol";
106//
107// //***************************//
108// //PUBLIC MEMBER EVENT METHODS//
109// //***************************//
110//
111// //------------------------------------------------------------------------------------------------
112// void OnDelete()
113// {
114// }
115//
116// //*********************//
117// //PUBLIC MEMBER METHODS//
118// //*********************//
119//
120// //------------------------------------------------------------------------------------------------
121// bool NotifyAssignment()
122// {
123// return m_bNotifyAssignment;
124// }
125//
126// //------------------------------------------------------------------------------------------------
127// bool NotifyUnassign()
128// {
129// return m_bNotifyUnassign;
130// }
131//
132// //------------------------------------------------------------------------------------------------
133// void DoNotifyAssignment(int assigneeID)
134// {
135// SCR_CampaignNetworkComponent assigneeNetworkComponent = SCR_CampaignNetworkComponent.GetCampaignNetworkComponent(assigneeID);
136// if (!assigneeNetworkComponent)
137// return;
138//
139// assigneeNetworkComponent.SendPlayerMessage(GetAssignMessage());
140// }
141//
142// //------------------------------------------------------------------------------------------------
143// void DoNotifyUnassign(int assigneeID)
144// {
145// SCR_CampaignNetworkComponent assigneeNetworkComponent = SCR_CampaignNetworkComponent.GetCampaignNetworkComponent(assigneeID);
146// if (!assigneeNetworkComponent)
147// return;
148//
149// assigneeNetworkComponent.SendPlayerMessage(GetUnassignMessage());
150// }
151//
152// //------------------------------------------------------------------------------------------------
153// SCR_ERadioMsg GetAssignMessage()
154// {
155// return m_eAssignMessage;
156// }
157//
158// //------------------------------------------------------------------------------------------------
159// SCR_ERadioMsg GetUnassignMessage()
160// {
161// return m_eUnassignMessage;
162// }
163//
164// //------------------------------------------------------------------------------------------------
165// ResourceName GetMapUIElementResourceName()
166// {
167// return m_sMapUIElementResourceName;
168// }
169//
170// //------------------------------------------------------------------------------------------------
171// string GetMapDescriptorText()
172// {
173// return GetTaskListTaskText();
174// }
175//
176// //------------------------------------------------------------------------------------------------
177// void OnMapOpen(MapConfiguration config)
178// {
179// }
180//
181// //------------------------------------------------------------------------------------------------
182// void OnHoverItem(MapItem item)
183// {
184// }
185//
186// //------------------------------------------------------------------------------------------------
187// string GetFullTaskIconName()
188// {
189// return string.Format(GetTaskListIconNamePrefix() + GetTaskListIconName() + GetIconSuffix());
190// }
191//
192// //------------------------------------------------------------------------------------------------
193// string GetTaskMapIconName()
194// {
195// return m_sMapIconName;
196// }
197//
198// //------------------------------------------------------------------------------------------------
199// string GetTaskListIconNamePrefix()
200// {
201// return m_sTaskListIconNamePrefix;
202// }
203//
204// //------------------------------------------------------------------------------------------------
205// string GetTaskListIconName()
206// {
207// return m_sTaskListIconName;
208// }
209//
210// //------------------------------------------------------------------------------------------------
211// string GetTaskListTaskTitle()
212// {
213// return GetTitle();
214// }
215//
216// //------------------------------------------------------------------------------------------------
217// string GetMajorModifier()
218// {
219// return m_sMajorModifier;
220// }
221//
222// //------------------------------------------------------------------------------------------------
223// //Description
224// string GetTaskListTaskText()
225// {
226// return GetDescription();
227// }
228//
229// //------------------------------------------------------------------------------------------------
230// Widget GetParentWidget(notnull Widget rootWidget)
231// {
232// return rootWidget.FindAnyWidget("Tasks");
233// }
234//
235// ResourceName GetIconImageset()
236// {
237// return m_sIconImageset;
238// }
239//
240// //------------------------------------------------------------------------------------------------
241// void SetHUDIcon()
242// {
243// SetWidgetIcon(m_wHUDIcon);
244// }
245//
246// //------------------------------------------------------------------------------------------------
247// void SetWidgetIcon(ImageWidget image)
248// {
249// if (!image || !m_wMapTaskIcon)
250// return;
251// //Setting the regular task icon
252// image.LoadImageFromSet(0, m_sIconImageset, string.Format(GetTaskListIconNamePrefix() + GetTaskListIconName() + GetIconSuffix()));
253// UpdateMapTaskIcon();
254// //Setting the priority task icon
255// image.LoadImageFromSet(0, m_sIconImageset, string.Format(GetTaskListIconNamePrefix() + GetMajorModifier() + GetTaskListIconName() + GetIconSuffix()));
256// UpdatePriorityMapTaskIcon();
257// }
258//
259// //------------------------------------------------------------------------------------------------
260// //! Remove icon assigned to this task.
261// void ClearWidgetIcon()
262// {
263// if (m_wMapTaskIcon && m_wMapTaskIcon.GetParent())
264// m_wMapTaskIcon.GetParent().RemoveFromHierarchy();
265// }
266//
267// //------------------------------------------------------------------------------------------------
268// void UpdateMapTaskIcon()
269// {
270// if(m_bIsPriority)
271// return;
272// // Set color for default unnasigned task
273// if(!m_wMapTaskIcon)
274// return;
275//
276// m_wMapTaskIcon.SetColor(Color.FromInt(Color.WHITE));
277//
278// if (m_TargetFaction && (IsAssignedToLocalPlayer() || SCR_EditorManagerEntity.IsOpenedInstance(false)) && !m_bIsPriority)
279// m_wMapTaskIcon.SetColor(m_TargetFaction.GetFactionColor());
280// }
281// //------------------------------------------------------------------------------------------------
282// void UpdatePriorityMapTaskIcon()
283// {
284// if(!m_bIsPriority)
285// return;
286//
287// GetTaskIconkWidget();
288// //Casting widgets, layouts and variables for Icon handling
289//
290// if (!m_wMapTaskIcon)
291// return;
292//
293// ImageWidget outline = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget("TaskIconOutline"));
294// ImageWidget background = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget("TaskIconBackground"));
295// ImageWidget hover = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget("TaskIconHover"));
296// ImageWidget symbol = ImageWidget.Cast(m_wMapTaskIcon.GetParent().FindAnyWidget("TaskIconSymbol"));
297//
298// PlayerController playerController = GetGame().GetPlayerController();
299// if (!playerController)
300// return;
301//
302// m_sPlyFactionAffilComp = SCR_PlayerFactionAffiliationComponent.Cast(playerController.FindComponent(SCR_PlayerFactionAffiliationComponent));
303// if (!m_sPlyFactionAffilComp)
304// return;
305//
306// SCR_Faction m_sfactionCol = SCR_Faction.Cast(m_sPlyFactionAffilComp.GetAffiliatedFaction());
307// if (!m_sfactionCol)
308// return;
309//
310// background.LoadImageFromSet(0, m_sIconImageset,"Icon_M_Task_BG");
311// outline.LoadImageFromSet(0, m_sIconImageset,"Icon_M_Task_Outline");
312// hover.LoadImageFromSet(0,m_sIconImageset,TASK_H);
313//
314// background.SetSize(m_fMajorSize,m_fMajorSize);
315// outline.SetSize(m_fMajorSize,m_fMajorSize);
316// symbol.SetSize(m_fMajorSize,m_fMajorSize);
317// hover.SetSize(m_fMajorSize,m_fMajorSize);
318//
319// // Set color for assigned tasks
320// if (IsAssignedToLocalPlayer())
321// {
322// if (!outline || !background || !hover || !symbol)
323// return;
324//
325// background.SetColor(UIColors.CONTRAST_COLOR);
326// outline.SetColor(m_sfactionCol.GetOutlineFactionColor());
327// symbol.SetColor(m_sfactionCol.GetOutlineFactionColor());
328// return;
329// }
330// //Set color for unassigned priority task
331// if (!IsAssignedToLocalPlayer())
332// {
333// background.SetColor(m_sfactionCol.GetOutlineFactionColor());
334// outline.SetColor(m_sfactionCol.GetFactionColor());
335// symbol.SetColor(m_sfactionCol.GetFactionColor());
336// }
337//
338// }
339// //------------------------------------------------------------------------------------------------
340// bool AssignTaskToAI(AIAgent agent)
341// {
342// // Find entities in hierarchy - AIWaypoint type
343// // On agent add all waypoints
344// // Order matters! Check if it's deterministic
345// // Return false if no agent, no waypoint
346// // Return true at the end
347// }
348//
349// //------------------------------------------------------------------------------------------------
350// string GetIconName()
351// {
352// return GetTaskMapIconName() + GetIconSuffix();
353// }
354//
355// //------------------------------------------------------------------------------------------------
356// ResourceName GetImageSetName()
357// {
358// return GetMapUIElementResourceName();
359// }
360//
361// //------------------------------------------------------------------------------------------------
362// string GetIconSuffix()
363// {
364// return "";
365// }
366//
367// //------------------------------------------------------------------------------------------------
368// string GetTitleIconString()
369// {
370// return string.Format("<image set='%1' name='%2' />", GetMapUIElementResourceName(), GetIconName() + GetIconSuffix());
371// }
372//
373// //------------------------------------------------------------------------------------------------
374// void SetTitleWidgetText(notnull TextWidget textWidget, string taskText)
375// {
376// textWidget.SetTextFormat(taskText);
377// }
378//
379// //------------------------------------------------------------------------------------------------
380// string GetTitleText()
381// {
382// return m_sName; // todo(koudelkaluk): merge with GetTitle()
383// }
384//
385// //------------------------------------------------------------------------------------------------
386// void SetDescriptionWidgetText(notnull TextWidget textWidget, string taskText)
387// {
388// textWidget.SetTextFormat(taskText);
389// }
390//
391// //------------------------------------------------------------------------------------------------
392// Widget GenerateTaskDescriptionUI(notnull Widget rootWidget, array<Widget> widgets)
393// {
394// Widget parentWidget = GetParentWidget(rootWidget);
395// if (!parentWidget)
396// return null;
397//
398// WorkspaceWidget workspaceWidget = rootWidget.GetWorkspace();
399// if (!workspaceWidget)
400// return null;
401//
402// SCR_BaseTaskSupportEntity supportClass = GetTaskManager().FindSupportEntity(SCR_BaseTaskSupportEntity);
403// if (!supportClass)
404// return null;
405//
406// ResourceName taskDescriptionWidgetResourceName = supportClass.GetTaskDescriptionWidgetResource();
407// if (taskDescriptionWidgetResourceName == string.Empty)
408// return null;
409//
410// Widget taskDescriptionWidget = workspaceWidget.CreateWidgets(taskDescriptionWidgetResourceName, parentWidget);
411// widgets.Insert(taskDescriptionWidget);
412// VerticalLayoutSlot.SetPadding(taskDescriptionWidget, 4, 4, 4, 4);
413//
414// m_wTaskListDescription = taskDescriptionWidget;
415//
416// SCR_TaskListEntryHandler handler = SCR_TaskListEntryHandler.Cast(taskDescriptionWidget.FindHandler(SCR_TaskListEntryHandler));
417// if (handler)
418// {
419// //handler.SetTask(this);
420// //handler.UpdateTask(this);
421// }
422//
423// Widget doneLayout = taskDescriptionWidget.FindAnyWidget("DoneLayout");
424// if (doneLayout)
425// {
426// if (m_eState == SCR_TaskState.FINISHED)
427// doneLayout.SetOpacity(1);
428// else
429// doneLayout.SetOpacity(0);
430// }
431//
432// RichTextWidget textWidgetRich = RichTextWidget.Cast(taskDescriptionWidget.FindAnyWidget("TaskDescription"));
433// if (!textWidgetRich)
434// return taskDescriptionWidget;
435//
436// string taskText = GetTaskListTaskText();
437//
438// textWidgetRich.SetText(taskText);
439//
440// TextWidget textWidget = TextWidget.Cast(taskDescriptionWidget.FindAnyWidget("TaskTitle"));
441// if (!textWidget)
442// return taskDescriptionWidget;
443//
444// string taskTextTitle = GetTaskListTaskTitle();
445//
446// SetTitleWidgetText(textWidget, taskTextTitle);
447// SetWidgetIcon(ImageWidget.Cast(taskDescriptionWidget.FindAnyWidget("TaskIcon")));
448//
449// UpdateTaskListAssignee();
450//
451// return taskDescriptionWidget;
452// }
453//
454// //------------------------------------------------------------------------------------------------
455// void UpdateTaskListAssignee()
456// {
457// if (!m_wTaskListDescription)
458// return;
459//
460// TextWidget textWidget = TextWidget.Cast(m_wTaskListDescription.FindAnyWidget("TaskAssignee"));
461// if (!textWidget)
462// return;
463//
464// const string assigneeNames;
465//
466// //Names of assignees are disabled temporarily to be fixed later
467// /*if (IsAssigned())
468// {
469// textWidget.SetTextFormat("%1", GetAllAssigneeNamesString());
470// }
471// else
472// {
473// textWidget.SetTextFormat(assigneeNames);
474// }*/
475//
476// textWidget.SetTextFormat(assigneeNames);
477// }
478//
479// //------------------------------------------------------------------------------------------------
480// void OnAssigneeKilled()
481// {
482//
483// }
484//
485// //------------------------------------------------------------------------------------------------
486// void CreateMapUIIcon()
487// {
488//
489// }
490//
491// //------------------------------------------------------------------------------------------------
492// //! Returns the faction that should complete this task.
493// Faction GetTargetFaction()
494// {
495// return m_TargetFaction;
496// }
497//
498// //------------------------------------------------------------------------------------------------
499// //! Sets the faction that should complete this task.
500// void SetTargetFaction(Faction targetFaction)
501// {
502// m_TargetFaction = targetFaction;
503// SCR_BaseTaskManager.s_OnTaskFactionAssigned.Invoke(this);
504//
505// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_PROPERTY_CHANGED);
506//
507// SetHUDIcon();
508// }
509//
510// //------------------------------------------------------------------------------------------------
511// //! Returns a text informing about the task being finished
512// string GetFinishText()
513// {
514// return TASK_FINISHED_TEXT;
515// }
516//
517// //------------------------------------------------------------------------------------------------
518// //! Returns whether the task is assigned to someone or not
519// bool IsAssigned()
520// {
521// if (!m_aAssignees || m_aAssignees.Count() <= 0)
522// return false;
523//
524// return true;
525// }
526//
527// //------------------------------------------------------------------------------------------------
528// //! Returns a string with all the assignees on this task in following format: "PlayerA, PlayerB, ..., PlayerN"
529// string GetAllAssigneeNamesString()
530// {
531// string names = "";
532// if (!IsAssigned())
533// return names;
534//
535// string playerName;
536// for (int i = 0, count = m_aAssignees.Count(); i < count; i++)
537// {
538// playerName = m_aAssignees[i].GetPlayerName();
539// //if (GetGame().GetPlatformService().GetLocalPlatformKind() == PlatformKind.PSN)
540// if (true)
541// {
542// if (GetGame().GetPlayerManager().GetPlatformKind(m_aAssignees[i].GetExecutorID()) == PlatformKind.PSN)
543// playerName = string.Format("<color rgba=%1><image set='%2' name='%3' scale='%4'/></color>", UIColors.FormatColor(GUIColors.ENABLED), UIConstants.ICONS_IMAGE_SET, UIConstants.PLATFROM_PLAYSTATION_ICON_NAME, PLATFORM_ICON_SIZE) + playerName;
544// else
545// playerName = string.Format("<color rgba=%1><image set='%2' name='%3' scale='%4'/></color>", UIColors.FormatColor(GUIColors.ENABLED), UIConstants.ICONS_IMAGE_SET, UIConstants.PLATFROM_GENERIC_ICON_NAME, PLATFORM_ICON_SIZE) + playerName;
546// }
547//
548// names += playerName;
549// if (i < count - 1)
550// names += ", ";
551// }
552// Print(names);
553// return names;
554// }
555//
556// //------------------------------------------------------------------------------------------------
557// //! Checks all the assignees for timeout, if their time is up, they get unassigned
558// void CheckAssigneeTimeout()
559// {
560// if (!m_bIndividualTask || !m_aAssignees || !IsAssigned() || !GetTaskManager())
561// return;
562//
563// SCR_BaseTaskSupportEntity supportEntity = GetTaskManager().FindSupportEntity(SCR_BaseTaskSupportEntity);
564// if (!supportEntity)
565// return;
566//
567// if (GetAssigneeTimeLeft() <= 0)
568// {
569// foreach (SCR_BaseTaskExecutor assignee : m_aAssignees)
570// {
571// if (!assignee)
572// continue;
573//
574// supportEntity.UnassignTask(this, assignee, SCR_EUnassignReason.ASSIGNEE_TIMEOUT);
575// }
576// }
577// }
578//
579// //------------------------------------------------------------------------------------------------
580// void SetLastAssigneeAddedTimestamp(float timestamp)
581// {
582// m_fLastAssigneeAddedTimestamp = timestamp;
583// }
584//
585// //------------------------------------------------------------------------------------------------
586// //! Set this task as task for an individual
587// void SetIndividual(bool individual)
588// {
589// m_bIndividualTask = individual;
590// }
591//
592// //------------------------------------------------------------------------------------------------
593// //! Returns whether this task is for an individual or not
594// bool IsIndividual()
595// {
596// return m_bIndividualTask;
597// }
598//
599// //------------------------------------------------------------------------------------------------
600// void SetIsPriority(bool isPrio)
601// {
602// m_bIsPriority = isPrio;
603// }
604//
605// //------------------------------------------------------------------------------------------------
606// bool IsPriority()
607// {
608// return m_bIsPriority;
609// }
610//
611// //------------------------------------------------------------------------------------------------
612// bool IsAssignable()
613// {
614// return m_bAssignable;
615// }
616//
617// //------------------------------------------------------------------------------------------------
618// //! Returns whether this task can be assigned to the player with the given player ID
619// //! If playerID == -1, the local player is used as the target
620// bool CanBeAssigned(out SCR_ECannotAssignReasons reason, int playerID = -1)
621// {
622// SCR_BaseTaskExecutor executor = null;
623// SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
624// if (!localExecutor)
625// return false;
626//
627// SCR_BaseTask localExecutorTask = localExecutor.GetAssignedTask();
628// if (localExecutorTask)
629// {
630// if (localExecutorTask != this)
631// reason = SCR_ECannotAssignReasons.LOCAL_EXECUTOR_IS_ASSIGNED;
632// else
633// reason = SCR_ECannotAssignReasons.TASK_IS_ASSIGNED_TO_LOCAL_EXECUTOR;
634//
635// return false;
636// }
637//
638// if (playerID == -1)
639// executor = localExecutor;
640// else
641// executor = SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID);
642//
643// if (m_bAssignable && !m_bIndividualTask)
644// return true;
645//
646// if (m_bIndividualTask)
647// {
648// if (IsAssigned())
649// {
650// reason = SCR_ECannotAssignReasons.TASK_IS_ASSIGNED;
651// return false;
652// }
653//
654// if (m_TimedOutAssignee == executor && m_fAssigneeTimeoutTimestamp > GetTaskManager().GetTimestamp())
655// {
656// reason = SCR_ECannotAssignReasons.ASSIGNEE_TIMEOUT;
657// return false;
658// }
659//
660// if (GetTaskManager().GetAssigneeAbandoned(executor))
661// {
662// reason = SCR_ECannotAssignReasons.TASK_ABANDONED;
663// return false;
664// }
665//
666// // Is individual task, that is not assigned yet, can be assigned
667// return true;
668// }
669// else
670// {
671// // Cannot be assigned
672// reason = SCR_ECannotAssignReasons.TASK_NOT_ASSIGNABLE;
673// return false;
674// }
675//
676// // Is not individual task, can be assigned
677// reason = SCR_ECannotAssignReasons.TASK_NOT_ASSIGNABLE;
678// return true;
679// }
680//
681// //------------------------------------------------------------------------------------------------
682// //! Returns the timestamp of last add assignee event
683// float GetLastAssigneeAddedTimestamp()
684// {
685// return m_fLastAssigneeAddedTimestamp;
686// }
687//
688// //------------------------------------------------------------------------------------------------
689// //! Returns time left the assignee of this task has to finish it, after that they get automatically unassigned
690// float GetAssigneeTimeLeft()
691// {
692// float currentTimestamp = GetTaskManager().GetTimestamp();
693// float timeLeft = m_fAssigneeTimeLimit - (currentTimestamp - m_fLastAssigneeAddedTimestamp);
694//
695// return timeLeft;
696// }
697//
698// //------------------------------------------------------------------------------------------------
699// //! Sets an ID of this task
700// void SetTaskID(int taskID)
701// {
702// m_iTaskID = taskID;
703// }
704//
705// //------------------------------------------------------------------------------------------------
706// //! Returns an ID of this task
707// int GetTaskID()
708// {
709// return m_iTaskID;
710// }
711//
712// //------------------------------------------------------------------------------------------------
713// //! Returns the state of this task
714// SCR_TaskState GetTaskState()
715// {
716// return m_eState;
717// }
718//
719// //------------------------------------------------------------------------------------------------
720// void SetTitle(string title)
721// {
722// m_sName = title;
723// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_PROPERTY_CHANGED);
724// }
725//
726// //------------------------------------------------------------------------------------------------
727// //! Return the title of this task.
728// string GetTitle()
729// {
730// return m_sName;
731// }
732//
733// //------------------------------------------------------------------------------------------------
734// void SetDescription(string description)
735// {
736// m_sDescription = description;
737// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_PROPERTY_CHANGED);
738// }
739//
740// //------------------------------------------------------------------------------------------------
741// //! Return the description of this task.
742// string GetDescription()
743// {
744// return m_sDescription;
745// }
746//
747// //------------------------------------------------------------------------------------------------
748// //! Returns the first assignee of this task.
749// SCR_BaseTaskExecutor GetAssignee()
750// {
751// if (!m_aAssignees || m_aAssignees.Count() <= 0)
752// return null;
753//
754// return m_aAssignees[0];
755// }
756//
757// //------------------------------------------------------------------------------------------------
758// //! Returns assignees of this task.
759// int GetAssignees(out array<SCR_BaseTaskExecutor> assignees)
760// {
761// return assignees.Copy(m_aAssignees);
762// }
763//
764// //------------------------------------------------------------------------------------------------
765// int GetAssigneeCount()
766// {
767// return m_aAssignees.Count();
768// }
769//
770// //------------------------------------------------------------------------------------------------
771// void Cancel(bool showMsg = true)
772// {
773// SetState(SCR_TaskState.CANCELLED);
774//
775// SCR_BaseTaskManager.s_OnTaskCancelled.Invoke(this);
776//
777// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_CANCELED);
778// }
779//
780// //------------------------------------------------------------------------------------------------
781// //! Marks the task as removed.
782// void Remove()
783// {
784// SetState(SCR_TaskState.REMOVED);
785//
786// if (m_aAssignees)
787// {
788// foreach (SCR_BaseTaskExecutor assignee: m_aAssignees)
789// assignee.OnAssignedTaskRemoved();
790// }
791//
792// SCR_BaseTaskManager.s_OnTaskRemoved.Invoke(this);
793//
794// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_REMOVED);
795// }
796//
797// //------------------------------------------------------------------------------------------------
798// //! When the task is created
799// void Create(bool showMsg = true)
800// {
801// }
802//
803// //------------------------------------------------------------------------------------------------
804// //! Marks the task as finished.
805// void Finish(bool showMsg = true)
806// {
807// SetState(SCR_TaskState.FINISHED);
808//
809// if (m_aAssignees)
810// {
811// foreach (SCR_BaseTaskExecutor assignee: m_aAssignees)
812// assignee.OnAssignedTaskFinished();
813// }
814//
815// SCR_BaseTaskManager.s_OnTaskFinished.Invoke(this);
816//
817// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_FINISHED);
818// }
819//
820// //------------------------------------------------------------------------------------------------
821// //! Fails the task.
822// void Fail(bool showMsg = true)
823// {
824// SetState(SCR_TaskState.CANCELLED);
825//
826// if (m_aAssignees)
827// {
828// foreach (SCR_BaseTaskExecutor assignee: m_aAssignees)
829// assignee.OnAssignedTaskFailed();
830// }
831//
832// SCR_BaseTaskManager.s_OnTaskFailed.Invoke(this);
833//
834// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_FAILED);
835// }
836//
837// //------------------------------------------------------------------------------------------------
838// //! Removes every assignee from this task.
839// void RemoveAllAssignees()
840// {
841// if (!IsAssigned())
842// return;
843//
844// SCR_BaseTaskExecutor removedAssignee = null;
845//
846// for (int i = m_aAssignees.Count() - 1; i >= 0; i --)
847// {
848// removedAssignee = m_aAssignees[i];
849// m_aAssignees[i].OnAssignedTaskRemoved();
850// m_aAssignees.Remove(i);
851// }
852//
853// if (m_bIndividualTask)
854// {
855// // We automatically set timeout for the assignee, since we don't want them to be immediately able to assign the task to themselves again
856// m_fAssigneeTimeoutTimestamp = GetTaskManager().GetTimestamp() + DEFAULT_ASSIGNEE_TIMEOUT_TIME;
857// m_TimedOutAssignee = removedAssignee;
858//
859// ShowAvailableTask();
860// }
861//
862// SCR_BaseTaskManager.s_OnTaskUnassigned.Invoke(this);
863//
864// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_ASSIGNEE_CHANGED);
865// }
866//
867// //------------------------------------------------------------------------------------------------
868// //! Removes an assignee, specified as a parameter, from this task.
869// void RemoveAssignee(SCR_BaseTaskExecutor assignee, SCR_EUnassignReason reason)
870// {
871// if (!m_aAssignees || !assignee)
872// return;
873//
874// int index = m_aAssignees.Find(assignee);
875//
876// if (index == -1)
877// return;
878//
879// m_aAssignees.Remove(index);
880// if (assignee == SCR_BaseTaskExecutor.GetLocalExecutor())
881// ShowPopUpNotification("#AR-Tasks_UnassignPopup");
882//
883// OnAssigneeRemoved(assignee);
884//
885// if (m_bIndividualTask)
886// {
887// switch (reason)
888// {
889// case SCR_EUnassignReason.ASSIGNEE_TIMEOUT:
890// // We set timeout for the assignee, since we don't want them to be immediately able to assign the task to themselves again
891// m_fAssigneeTimeoutTimestamp = GetTaskManager().GetTimestamp() + DEFAULT_ASSIGNEE_TIMEOUT_TIME;
892// m_TimedOutAssignee = assignee;
893// break;
894// case SCR_EUnassignReason.ASSIGNEE_DISCONNECT:
895// break;
896// case SCR_EUnassignReason.ASSIGNEE_ABANDON:
897// break;
898// case SCR_EUnassignReason.GM_REASSIGN:
899// break;
900// }
901//
902// ShowAvailableTask(true);
903// }
904//
905// SCR_BaseTaskManager.s_OnTaskUnassigned.Invoke(this);
906//
907// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_ASSIGNEE_CHANGED);
908// }
909//
910// //------------------------------------------------------------------------------------------------
911// //! Adds a new assignee, specified as a parameter, to this task.
912// void AddAssignee(SCR_BaseTaskExecutor assignee, float timestamp)
913// {
914// if (!m_aAssignees || !assignee)
915// return;
916//
917// IEntity assigneeEntity = assignee.GetControlledEntity();
918// if (assigneeEntity)
919// {
920// SCR_CharacterControllerComponent characterControllerComponent = SCR_CharacterControllerComponent.Cast(assigneeEntity.FindComponent(SCR_CharacterControllerComponent));
921// if (characterControllerComponent)
922// characterControllerComponent.GetOnPlayerDeath().Insert(OnAssigneeKilled);
923// }
924// else
925// {
926// SCR_BaseGameMode gameMode = SCR_BaseGameMode.Cast(GetGame().GetGameMode());
927// if (!gameMode)
928// return;
929// gameMode.GetOnPlayerSpawned().Insert(InitOnSpawn);
930// }
931//
932// // Is this task for an individual & we already have someone assigned?
933// if (m_bIndividualTask && m_aAssignees.Count() > 0)
934// return;
935//
936// int index = m_aAssignees.Find(assignee);
937//
938// if (index != -1)
939// return;
940//
941// SetLastAssigneeAddedTimestamp(timestamp);
942//
943// m_aAssignees.Insert(assignee);
944// if (assignee == SCR_BaseTaskExecutor.GetLocalExecutor())
945// ShowPopUpNotification("#AR-Tasks_AssignPopup");
946//
947// OnAssigneeAdded(assignee);
948//
949// SCR_BaseTaskManager.s_OnTaskAssigned.Invoke(this);
950//
951// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_ASSIGNEE_CHANGED);
952// }
953//
954// //------------------------------------------------------------------------------------------------
955// void InitOnSpawn(int pid, IEntity ent)
956// {
957// SCR_CharacterControllerComponent charCtrlComp = SCR_CharacterControllerComponent.Cast(ent.FindComponent(SCR_CharacterControllerComponent));
958// if (charCtrlComp)
959// charCtrlComp.GetOnPlayerDeath().Insert(OnAssigneeKilled);
960// SCR_BaseGameMode gameMode = SCR_BaseGameMode.Cast(GetGame().GetGameMode());
961// if (gameMode)
962// gameMode.GetOnPlayerSpawned().Remove(InitOnSpawn);
963// }
964//
965// //------------------------------------------------------------------------------------------------
966// [Obsolete("Use new SCR_TaskManagerUIComponent methods instead")]
967// void ToggleHUDIcon(bool show, bool fade = true)
968// {
969// if (show)
970// {
971// AnimateWidget.StopAnimation(m_wHUDIcon, WidgetAnimationOpacity);
972// m_wHUDIcon.SetOpacity(1);
973// }
974// else
975// {
976// if (fade)
977// {
978// //SCR_UITaskManagerComponent.GetInstance().KeepHUDIconUpdated(1000, this);
979// AnimateWidget.Opacity(m_wHUDIcon, 0, 1);
980// }
981// else
982// {
983// AnimateWidget.StopAnimation(m_wHUDIcon, WidgetAnimationOpacity);
984// m_wHUDIcon.SetOpacity(0);
985// }
986// }
987// }
988//
989// //------------------------------------------------------------------------------------------------
990// void UpdateHUDIcon()
991// {
992// vector pos = GetGame().GetWorkspace().ProjWorldToScreen(GetOrigin(), GetWorld());
993// if (pos[2] > 0)
994// {
995// if (!AnimateWidget.IsAnimating(m_wHUDIcon))
996// m_wHUDIcon.SetOpacity(1);
997// FrameSlot.SetPos(m_wHUDIcon, pos[0], pos[1]);
998// }
999// else
1000// m_wHUDIcon.SetOpacity(0);
1001// }
1002//
1003// //------------------------------------------------------------------------------------------------
1004// Widget GetTaskIconkWidget()
1005// {
1006// return m_wMapTaskIcon;
1007// }
1008//
1009// //------------------------------------------------------------------------------------------------
1010// void SetTaskIconWidget(Widget w)
1011// {
1012// m_wMapTaskIcon = w;
1013// }
1014//
1015// //************************//
1016// //PROTECTED MEMBER METHODS//
1017// //************************//
1018//
1019// protected void ShowPopUpNotification(string subtitle)
1020// {
1021// SCR_PopUpNotification.GetInstance().PopupMsg(GetTitleText(), text2: subtitle);
1022// }
1023//
1024// //------------------------------------------------------------------------------------------------
1025// protected void UpdateMapInfo()
1026// {
1027// }
1028//
1029// //------------------------------------------------------------------------------------------------
1030// protected bool DoneByAssignee()
1031// {
1032// }
1033//
1034// //------------------------------------------------------------------------------------------------
1035// protected void ShowTaskProgress(bool showMsg = true)
1036// {
1037// }
1038//
1039// //------------------------------------------------------------------------------------------------
1040// //! Shows a message informing about this task being available
1041// protected void ShowAvailableTask(bool afterAssigneeRemoved = false)
1042// {
1043// }
1044//
1045// //------------------------------------------------------------------------------------------------
1046// //! Returns whether this task is assigned to the local player
1047// protected bool IsAssignedToLocalPlayer()
1048// {
1049// if (!IsAssigned())
1050// return false;
1051//
1052// SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
1053// int localExecutorID = SCR_BaseTaskExecutor.GetTaskExecutorID(localExecutor);
1054//
1055// foreach (SCR_BaseTaskExecutor assignee : m_aAssignees)
1056// {
1057// int assigneeID = SCR_BaseTaskExecutor.GetTaskExecutorID(assignee);
1058// if (assigneeID == localExecutorID)
1059// return true;
1060// }
1061//
1062// return false;
1063// }
1064//
1065// //------------------------------------------------------------------------------------------------
1066// //! Changes the state of this task to the parameter.
1067// //! Don't use this directly, use the following methods instead: SCR_BaseTaskManager.FinishTask/CancelTask/FailTask
1068// void SetState(SCR_TaskState state)
1069// {
1070// if (state == m_eState)
1071// return;
1072//
1073// // Let the script know that the state of this task has changed.
1074// OnStateChanged(m_eState, state);
1075//
1076// m_eState = state;
1077// }
1078//
1079// //******************************//
1080// //PROTECTED MEMBER EVENT METHODS//
1081// //******************************//
1082//
1083// //------------------------------------------------------------------------------------------------
1084// //! An event called when an assignee has been removed from this task.
1085// protected void OnAssigneeRemoved(SCR_BaseTaskExecutor oldAssignee)
1086// {
1087// if (oldAssignee)
1088// oldAssignee.AssignNewTask(null);
1089//
1090// if (m_aAssignees.Count() <= 0)
1091// SetState(SCR_TaskState.OPENED);
1092//
1093// UpdateMapTaskIcon();
1094// UpdatePriorityMapTaskIcon();
1095// UpdateTaskListAssignee();
1096//
1097// }
1098//
1099// //------------------------------------------------------------------------------------------------
1100// //! An event called when a new assignee has been added to this task.
1101// protected void OnAssigneeAdded(SCR_BaseTaskExecutor newAssignee)
1102// {
1103// if (newAssignee)
1104// newAssignee.AssignNewTask(this);
1105// UpdateMapTaskIcon();
1106// UpdatePriorityMapTaskIcon();
1107// UpdateTaskListAssignee();
1108// }
1109//
1110// //------------------------------------------------------------------------------------------------
1111// //! An event called when the state of this task has been changed.
1112// protected void OnStateChanged(SCR_TaskState previousState, SCR_TaskState newState)
1113// {
1114// }
1115//
1116// //------------------------------------------------------------------------------------------------
1117// //! Registers task event mask for OnTaskUpdate
1118// //void RegisterTaskUpdate(SCR_ETaskEventMask TaskEventMask)
1119// //{
1120// //if (GetTaskManager())
1121// //GetTaskManager().OnTaskUpdate(this, TaskEventMask);
1122// }
1123//
1124// //------------------------------------------------------------------------------------------------
1125// void Serialize(ScriptBitWriter writer)
1126// {
1127// // Make sure that the server tells clients whether it had the faction manager
1128// // during serialization or not. Because tasks can't some from non-replicated
1129// // prefabs, this will help us avoid deserialization issues mentioned in Deserialize.
1130// FactionManager factionManager = GetGame().GetFactionManager();
1131// if (!factionManager)
1132// {
1133// writer.WriteBool(false);
1134// return;
1135// }
1136// writer.WriteBool(true);
1137//
1138// int factionIndex = factionManager.GetFactionIndex(m_TargetFaction);
1139// writer.Write(factionIndex, 4);
1140// writer.WriteInt(m_iTaskID);
1141// writer.WriteInt(GetTaskState());
1142// writer.WriteInt(GetTaskManager().m_mTaskEventMaskMap.Get(this));
1143// writer.WriteBool(m_bIndividualTask);
1144// writer.WriteFloat(GetLastAssigneeAddedTimestamp());
1145// writer.WriteString(GetTitle());
1146// writer.WriteString(GetDescription());
1147//
1148// int assigneesCount = m_aAssignees.Count();
1149// writer.Write(assigneesCount, 7);
1150//
1151// for (int i = 0; i < assigneesCount; i++)
1152// {
1153// int assigneeID = SCR_BaseTaskExecutor.GetTaskExecutorID(m_aAssignees[i]);
1154// writer.WriteInt(assigneeID);
1155// }
1156//
1157// writer.WriteVector(GetOrigin());
1158// }
1159//
1160// //------------------------------------------------------------------------------------------------
1161// void Deserialize(ScriptBitReader reader)
1162// {
1163// // Make sure that the server actually had the faction manager
1164// // during serialization. If it did not, we can safely return
1165// // because the server is guaranteed to not have written anything.
1166// bool serverHadFactionManager;
1167// reader.ReadBool(serverHadFactionManager);
1168// if (!serverHadFactionManager)
1169// return;
1170//
1171// // https://jira.bistudio.com/browse/ARMA4-62494
1172// // If there's no faction manager we won't be able to update the faction
1173// // index. However, if we simply returned right now, we'd create a huge problem
1174// // because we wouldn't read the rest of our data.
1175// // A task following after this one would therefore read data that would still
1176// // partially belong to this one. That would result in undefined behavior and
1177// // most likely in crashes during ScriptBitReader's data serialization.
1178// // For this reason, even if the faction manager is not present, we proceed.
1179// // We simply won't be able to set the faction properly.
1180// FactionManager factionManager = GetGame().GetFactionManager();
1181// //if (!factionManager)
1182// // return; <<< DON'T DO THIS
1183//
1184// // Reading factionIndex
1185// int factionIndex = 0;
1186// reader.Read(factionIndex, 4);
1187//
1188// if (factionManager)
1189// SetTargetFaction(factionManager.GetFactionByIndex(factionIndex));
1190//
1191// // Reading m_iTaskID
1192// reader.ReadInt(m_iTaskID);
1193//
1194// // Reading Task State
1195// int taskState;
1196// reader.ReadInt(taskState);
1197// SetState(taskState);
1198//
1199// // Reading Task Mask
1200// int taskMask;
1201// reader.ReadInt(taskMask);
1202// GetTaskManager().m_mTaskEventMaskMap.Set(this, taskMask);
1203//
1204// // Reading m_bIndividualTask
1205// reader.ReadBool(m_bIndividualTask);
1206//
1207// // Reading m_fLastAssigneeAddedTimestamp
1208// reader.ReadFloat(m_fLastAssigneeAddedTimestamp);
1209//
1210// string text;
1211// // Reading title
1212// reader.ReadString(text);
1213// SetTitle(text);
1214//
1215// // Reading description
1216// reader.ReadString(text);
1217// SetDescription(text);
1218//
1219// // Reading target m_aAssignees.Count()
1220// int assigneesCount;
1221// reader.Read(assigneesCount, 7);
1222//
1223// int assigneeID;
1224// for (int i = 0; i < assigneesCount; i++)
1225// {
1226// // Reading assignee ID
1227// reader.ReadInt(assigneeID);
1228// SCR_BaseTaskExecutor assignee = SCR_BaseTaskExecutor.GetTaskExecutorByID(assigneeID);
1229// m_aAssignees.Insert(assignee);
1230// }
1231//
1232// // Reading position
1233// vector origin;
1234// reader.ReadVector(origin);
1235// SetOrigin(origin);
1236//
1237// GetTaskManager().RegisterTask(this);
1238// }
1239//
1240// //------------------------------------------------------------------------------------------------
1241// override void EOnInit(IEntity owner)
1242// {
1243// if (SCR_Global.IsEditMode(this) || !GetGame().GetGameMode())
1244// return;
1245//
1246// if (!GetTaskManager().IsProxy())
1247// {
1248// m_iTaskID = s_iCurrentTaskID;
1249// s_iCurrentTaskID++;
1250// }
1251//
1252// GetTaskManager().RegisterTask(this);
1253//
1254// SCR_BaseTaskManager.s_OnTaskCreated.Invoke(this);
1255//
1256// RegisterTaskUpdate(SCR_ETaskEventMask.TASK_CREATED);
1257//
1258// m_MapDescriptor = SCR_MapDescriptorComponent.Cast(FindComponent(SCR_MapDescriptorComponent));
1259//
1260// if (m_MapDescriptor)
1261// {
1262// SCR_MapEntity.GetOnMapOpen().Insert(OnMapOpen);
1263// SCR_MapEntity.GetOnHoverItem().Insert(OnHoverItem);
1264// }
1265// }
1266//
1267// //************************//
1268// //CONSTRUCTOR & DESTRUCTOR//
1269// //************************//
1270//
1271// //------------------------------------------------------------------------------------------------
1272// void SCR_BaseTask(IEntitySource src, IEntity parent)
1273// {
1274// SetEventMask(EntityEvent.INIT);
1275//
1276// CreateMapUIIcon();
1277//
1278// //HUD Icon setup
1279// Widget HUDIconRoot = GetGame().GetWorkspace().CreateWidgets(m_sHUDIcon);
1280// m_wHUDIcon = ImageWidget.Cast(HUDIconRoot.FindAnyWidget("TaskIcon"));
1281// m_wHUDIcon.SetOpacity(0);
1282// SetHUDIcon();
1283// //End of HUD Icon setup
1284// }
1285//
1286// //------------------------------------------------------------------------------------------------
1287// void ~SCR_BaseTask()
1288// {
1289// if (m_aAssignees)
1290// {
1291// m_aAssignees.Clear();
1292// m_aAssignees = null;
1293// }
1294//
1295// if (GetTaskManager())
1296// SCR_BaseTaskManager.s_OnTaskDeleted.Invoke(this);
1297// }
1298//}