Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseTaskSupportEntity.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
2 [EntityEditorProps(category: "GameScripted/Tasks", description: "Base task support entity.", color: "0 0 255 255")]
3 class SCR_BaseTaskSupportEntityClass: GenericEntityClass
4 {
5 };
6 
7 //------------------------------------------------------------------------------------------------
9 {
10  [Attribute("{1844F5647E6D772A}UI/layouts/Tasks/TaskListEntry.layout")]
11  protected ResourceName m_sTaskDescriptionWidgetResource;
12 
13  [Attribute()]
14  protected ResourceName m_sTaskPrefab;
15 
16  //------------------------------------------------------------------------------------------------
17  void SetTargetFaction(notnull SCR_BaseTask task, notnull Faction faction)
18  {
19  if (!GetTaskManager())
20  return;
21 
22  FactionManager factionManager = GetGame().GetFactionManager();
23  if (!factionManager)
24  return;
25 
26  int taskID, factionIndex;
27  taskID = task.GetTaskID();
28  factionIndex = factionManager.GetFactionIndex(faction);
29 
30  Rpc(RPC_SetTargetFaction, taskID, factionIndex);
31  RPC_SetTargetFaction(taskID, factionIndex);
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
36  void RPC_SetTargetFaction(int taskID, int factionIndex)
37  {
38  if (!GetTaskManager())
39  return;
40 
41  FactionManager factionManager = GetGame().GetFactionManager();
42  if (!factionManager)
43  return;
44 
45  SCR_BaseTask task = SCR_BaseTask.Cast(GetTaskManager().GetTask(taskID));
46  if (!task)
47  return;
48 
49  task.SetTargetFaction(factionManager.GetFactionByIndex(factionIndex));
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  SCR_BaseTask CreateTask()
54  {
55  if (!GetTaskManager())
56  return null;
57 
58  return SCR_BaseTask.Cast(GetTaskManager().SpawnTask(GetResourceName())); // Also spawns task on clients
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  void Initialize()
63  {
64  }
65 
66  //------------------------------------------------------------------------------------------------
67  //Called when task list is opened
68  void OnTaskListOpen(notnull SCR_UITaskManagerComponent uiTaskManagerComponent)
69  {
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  ResourceName GetTaskDescriptionWidgetResource()
74  {
75  return m_sTaskDescriptionWidgetResource;
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  ResourceName GetResourceName()
80  {
81  return m_sTaskPrefab;
82  }
83 
84  //------------------------------------------------------------------------------------------------
85  Resource GetTaskPrefab()
86  {
87  if (m_sTaskPrefab.IsEmpty())
88  return null;
89 
90  return Resource.Load(m_sTaskPrefab);
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  void MoveTask(vector newPosition, int taskID)
95  {
96  if (!GetTaskManager())
97  return;
98 
99  SCR_BaseTask task = GetTaskManager().GetTask(taskID);
100  if (!task)
101  return;
102 
103  task.SetOrigin(newPosition);
104 
105  if (GetTaskManager().IsProxy())
106  return;
107 
108  Rpc(RPC_MoveTask, taskID, newPosition);
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
113  void RPC_MoveTask(int taskID, vector newPosition)
114  {
115  MoveTask(newPosition, taskID);
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  //This should only be called on the server!
120  void AssignTask(notnull SCR_BaseTask task, notnull SCR_BaseTaskExecutor assignee, bool forced = false)
121  {
122  if (!GetTaskManager())
123  return;
124 
125  Rpc(RPC_AssignTask, SCR_BaseTaskExecutor.GetTaskExecutorID(assignee), task.GetTaskID(), GetTaskManager().GetTimestamp(), forced);
126  RPC_AssignTask(SCR_BaseTaskExecutor.GetTaskExecutorID(assignee), task.GetTaskID(), GetTaskManager().GetTimestamp(), forced);
127  }
128 
129  //------------------------------------------------------------------------------------------------
131  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
132  void RPC_AssignTask(int playerID, int taskID, float timestamp, bool forced)
133  {
134  if (!GetTaskManager())
135  return;
136 
137  SCR_BaseTask task = GetTaskManager().GetTask(taskID);
138  if (!task)
139  return;
140 
141  SCR_BaseTaskExecutor assignee = SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID);
142  if (!assignee)
143  return;
144 
145  task.AddAssignee(assignee, timestamp);
146  SCR_BaseTaskManager.s_OnTaskAssigned.Invoke(task);
147 
148  if (forced && assignee == SCR_BaseTaskExecutor.GetLocalExecutor())
149  SCR_PopUpNotification.GetInstance().PopupMsg(GetTaskManager().m_sAssignPopupGM);
150  }
151 
152  //------------------------------------------------------------------------------------------------
153  //This should only be called on the server!
154  void CancelTask(int taskID)
155  {
156  Rpc(RPC_CancelTask, taskID);
157  RPC_CancelTask(taskID);
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
162  protected void RPC_CancelTask(int taskID)
163  {
164  if (!GetTaskManager())
165  return;
166 
167  SCR_BaseTask task = GetTaskManager().GetTask(taskID);
168 
169  if (!task)
170  return;
171 
172  task.Cancel();
173  GetTaskManager().DeleteTask(task);
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  //This should only be called on the server!
178  void FinishTask(notnull SCR_BaseTask task)
179  {
180  int taskID = task.GetTaskID();
181  Rpc(RPC_FinishTask, taskID);
182  RPC_FinishTask(taskID);
183  }
184 
185  //------------------------------------------------------------------------------------------------
186  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
187  protected void RPC_FinishTask(int taskID)
188  {
189  if (!GetTaskManager())
190  return;
191 
192  SCR_BaseTask task = GetTaskManager().GetTask(taskID);
193 
194  if (!task)
195  return;
196 
197  task.Finish();
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  //This should only be called on the server!
202  void FailTask(notnull SCR_BaseTask task)
203  {
204  int taskID = task.GetTaskID();
205  Rpc(RPC_FailTask, taskID);
206  RPC_FailTask(taskID);
207  }
208 
209  //------------------------------------------------------------------------------------------------
210  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
211  protected void RPC_FailTask(int taskID)
212  {
213  if (!GetTaskManager())
214  return;
215 
216  SCR_BaseTask task = GetTaskManager().GetTask(taskID);
217 
218  if (!task)
219  task = GetTaskManager().GetFinishedTask(taskID);
220 
221  if (!task)
222  return;
223 
224  task.Fail();
225  GetTaskManager().DeleteTask(task);
226  }
227 
228  //------------------------------------------------------------------------------------------------
229  //This should only be called on the server!
230  void UnassignTask(notnull SCR_BaseTask task, notnull SCR_BaseTaskExecutor assignee, SCR_EUnassignReason reason)
231  {
232  int taskID = task.GetTaskID();
233  int executorID = SCR_BaseTaskExecutor.GetTaskExecutorID(assignee);
234  Rpc(RPC_UnassignTask, taskID, executorID, reason);
235  RPC_UnassignTask(taskID, executorID, reason);
236  }
237 
238  //------------------------------------------------------------------------------------------------
240  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
241  void RPC_UnassignTask(int taskID, int playerID, SCR_EUnassignReason reason)
242  {
243  if (!GetTaskManager())
244  return;
245 
246  SCR_BaseTask task = GetTaskManager().GetTask(taskID);
247  if (!task)
248  return;
249 
250  SCR_BaseTaskExecutor assignee = SCR_BaseTaskExecutor.GetTaskExecutorByID(playerID);
251  if (!assignee)
252  return;
253 
254  switch (reason)
255  {
256  case SCR_EUnassignReason.ASSIGNEE_TIMEOUT:
257  break;
258  case SCR_EUnassignReason.ASSIGNEE_DISCONNECT:
259  break;
260  case SCR_EUnassignReason.ASSIGNEE_ABANDON:
261  {
262  GetTaskManager().AddAssigneeAbandoned(assignee);
263  break;
264  }
265  case SCR_EUnassignReason.GM_REASSIGN:
266  {
267  if (assignee == SCR_BaseTaskExecutor.GetLocalExecutor())
268  SCR_PopUpNotification.GetInstance().PopupMsg(GetTaskManager().GetReassignText());
269  break;
270  }
271  }
272 
273  task.RemoveAssignee(assignee, reason);
274  SCR_BaseTaskManager.s_OnTaskUnassigned.Invoke(task);
275  }
276 
277  //------------------------------------------------------------------------------------------------
278  //This should only be called on the server!
279  void SetTaskDescription(notnull SCR_BaseTask task, string description)
280  {
281  int taskID = task.GetTaskID();
282  RPC_SetTaskDescription(taskID, description);
283  Rpc(RPC_SetTaskDescription, taskID, description);
284  }
285 
286  //------------------------------------------------------------------------------------------------
287  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
288  void RPC_SetTaskDescription(int taskID, string description)
289  {
290  if (!GetTaskManager())
291  return;
292 
293  SCR_BaseTask task = GetTaskManager().GetTask(taskID);
294  if (!task)
295  return;
296 
297  task.SetDescription(description);
298  }
299 
300  //------------------------------------------------------------------------------------------------
301  //This should only be called on the server!
302  void SetTaskTitle(notnull SCR_BaseTask task, string title)
303  {
304  int taskID = task.GetTaskID();
305  RPC_SetTaskTitle(taskID, title);
306  Rpc(RPC_SetTaskTitle, taskID, title);
307  }
308 
309  //------------------------------------------------------------------------------------------------
310  [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
311  void RPC_SetTaskTitle(int taskID, string title)
312  {
313  if (!GetTaskManager())
314  return;
315 
316  SCR_BaseTask task = GetTaskManager().GetTask(taskID);
317  if (!task)
318  return;
319 
320  task.SetTitle(title);
321  }
322 
323  //------------------------------------------------------------------------------------------------
324  protected void RegisterContextualMenuCallbacks()
325  {
326  }
327 
328  //------------------------------------------------------------------------------------------------
329  void OnMapOpen(MapConfiguration config)
330  {
331  RegisterContextualMenuCallbacks();
332  }
333 
334  //------------------------------------------------------------------------------------------------
335  override void EOnInit(IEntity owner)
336  {
337  if (!GetTaskManager())
338  return;
339 
340  GetTaskManager().RegisterSupportEntity(this);
341  }
342 
343  //------------------------------------------------------------------------------------------------
344  void SCR_BaseTaskSupportEntity(IEntitySource src, IEntity parent)
345  {
346  SetEventMask(EntityEvent.INIT);
347  SCR_MapEntity.GetMapInstance().GetOnMapOpen().Insert(OnMapOpen);
348 
349  if (!GetTaskManager())
350  return;
351 
352  RplComponent rplComponent = RplComponent.Cast(GetTaskManager().FindComponent(RplComponent));
353  if (!rplComponent)
354  return;
355 
356  rplComponent.InsertItem(this);
357  }
358 
359  //------------------------------------------------------------------------------------------------
361  {
362  if (!GetTaskManager())
363  return;
364 
365  GetTaskManager().UnregisterSupportEntity(this);
366  }
367 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
SCR_BaseTaskSupportEntityClass
Definition: SCR_BaseTaskSupportEntity.c:3
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
GetTask
SCR_ScenarioFrameworkTask GetTask()
Definition: SCR_ScenarioFrameworkLayerTask.c:65
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
SCR_PopUpNotification
Takes care of dynamic and static onscreen popups.
Definition: SCR_PopupNotification.c:24
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
SCR_UITaskManagerComponent
void SCR_UITaskManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_UITaskManagerComponent.c:1096
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignBuildingCompositionComponent.c:456
Attribute
typedef Attribute
Post-process effect of scripted camera.
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_BaseTaskSupportEntity
Definition: SCR_BaseTaskSupportEntity.c:8
Faction
Definition: Faction.c:12
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180