Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RequestedTask.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Tasks", description: "A requested task.", color: "0 0 255 255")]
3 {
4 };
5 
6 //THIS TASK TYPE IS NOT SYNCHRONIZED BY ITSELF YET. WHEREAS IT'S INHERITED (E.G.) SCR_EvacuateTask IS.
7 //------------------------------------------------------------------------------------------------
9 {
10  [Attribute(SCR_EXPRewards.SUPPORT_EVAC.ToString(), uiwidget: UIWidgets.ComboBox, enums:ParamEnumArray.FromEnum(SCR_EXPRewards))]
11  SCR_EXPRewards m_AssigneeXPReward;
12 
13  int m_iRequesterID = -1;
14  SCR_BaseTaskExecutor m_Requester;
15 
16  static const string TASK_REQUEST_TRANSMITTED_TEXT = "#AR-Tasks_StatusTransmitted-UC";
17  static const string TASK_SUPPORT_CANCELLED_TEXT = "#AR-Tasks_StatusCancelled-UC";
18  protected static const string LOCAL_PLAYER_REQUEST = "#AR-Tasks_TitleRequest";
19 
20  //------------------------------------------------------------------------------------------------
21  protected override void ShowAvailableTask(bool afterAssigneeRemoved = false)
22  {
23  SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
24  if (localExecutor == m_Requester)
25  {
26  if (!afterAssigneeRemoved)
27  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_REQUEST_TRANSMITTED_TEXT + " " + m_sName, prio: SCR_ECampaignPopupPriority.TASK_AVAILABLE);
28  return;
29  }
30 
31  Faction localPlayerFaction;
32  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
33  if (factionManager)
34  localPlayerFaction = factionManager.GetLocalPlayerFaction();
35 
36  if (localPlayerFaction == GetTargetFaction())
37  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_AVAILABLE_TEXT + " " + m_sName, prio: SCR_ECampaignPopupPriority.TASK_AVAILABLE, text2: TASK_HINT_TEXT, text2param1: SCR_PopUpNotification.TASKS_KEY_IMAGE_FORMAT, sound: SCR_SoundEvent.TASK_CREATED);
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  protected bool IsLocallyRequestedTask()
42  {
43  if (!GetTaskManager())
44  return false;
45 
47  if (!supportEntity)
48  return false;
49 
50  return this == supportEntity.GetLocallyRequestedTask();
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  override void SetTitleWidgetText(notnull TextWidget textWidget, string taskText)
55  {
56  if (IsLocallyRequestedTask())
57  {
58  textWidget.SetTextFormat(GetTaskManager().m_sLocalRequestTitle);
59  return;
60  }
61  if (m_Requester)
62  textWidget.SetTextFormat(taskText, m_Requester.GetPlayerName());
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  override string GetTitleText()
67  {
68  if (IsLocallyRequestedTask())
69  return GetTaskManager().m_sLocalRequestTitle;
70 
71  if (m_Requester)
72  return string.Format("%1 %2", m_sName, m_Requester.GetPlayerName());
73 
74  return string.Empty;
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  override Widget GenerateTaskDescriptionUI(notnull Widget rootWidget, array<Widget> widgets)
79  {
80  Widget w = super.GenerateTaskDescriptionUI(rootWidget, widgets);
81 
82  if (IsLocallyRequestedTask())
83  {
84  Widget description = w.FindAnyWidget("TaskDescription");
85  }
86 
87  return w;
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  override void DoNotifyAssignment(int assigneeID)
92  {
93  SCR_CampaignNetworkComponent assigneeNetworkComponent = SCR_CampaignNetworkComponent.GetCampaignNetworkComponent(assigneeID);
94 
95  if (assigneeNetworkComponent)
96  assigneeNetworkComponent.SendPlayerMessage(GetAssignMessage(), calledID: m_iRequesterID);
97  }
98 
99  //------------------------------------------------------------------------------------------------
100  override void DoNotifyUnassign(int assigneeID)
101  {
102  SCR_CampaignNetworkComponent assigneeNetworkComponent = SCR_CampaignNetworkComponent.GetCampaignNetworkComponent(assigneeID);
103 
104  if (assigneeNetworkComponent)
105  assigneeNetworkComponent.SendPlayerMessage(GetUnassignMessage(), calledID: m_iRequesterID);
106  }
107 
108  //------------------------------------------------------------------------------------------------
109  override void SetDescriptionWidgetText(notnull TextWidget textWidget, string taskText)
110  {
111  textWidget.SetTextFormat(taskText, GetRequesterName());
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  override string GetTaskListTaskText()
116  {
117  if (IsLocallyRequestedTask())
118  return LOCAL_PLAYER_REQUEST;
119 
120  return super.GetTaskListTaskText();
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  override void Cancel(bool showMsg = true)
125  {
126  SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
127  if (localExecutor == m_Requester || localExecutor == GetAssignee())
128  {
129  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_CANCELLED_TEXT + " " + m_sName, prio: SCR_ECampaignPopupPriority.TASK_DONE, sound: SCR_SoundEvent.TASK_CANCELED);
130  }
131 
132  super.Cancel();
133  }
134 
135  //------------------------------------------------------------------------------------------------
137  override void Fail(bool showMsg = true)
138  {
139  SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
140 
141  if (localExecutor == GetAssignee())
142  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_FAILED_TEXT + " " + m_sName, prio: SCR_ECampaignPopupPriority.TASK_DONE, sound: SCR_SoundEvent.TASK_FAILED);
143 
144  if (!m_Requester)
145  {
146  if (localExecutor.GetTaskExecutorID(localExecutor) == m_iRequesterID)
147  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_SUPPORT_CANCELLED_TEXT + " " + m_sName, prio: SCR_ECampaignPopupPriority.TASK_DONE, sound: SCR_SoundEvent.TASK_CANCELED);
148  }
149  else
150  {
151  if (localExecutor == m_Requester)
152  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_SUPPORT_CANCELLED_TEXT + " " + m_sName, prio: SCR_ECampaignPopupPriority.TASK_DONE, sound: SCR_SoundEvent.TASK_CANCELED);
153  }
154 
155  super.Fail(showMsg);
156  }
157 
158  //------------------------------------------------------------------------------------------------
160  override void Finish(bool showMsg = true)
161  {
162  SCR_BaseTaskManager taskManager = GetTaskManager();
163  SCR_BaseTaskExecutor assignee = GetAssignee();
164 
165  if (GetTaskManager().IsProxy())
166  {
167  SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
168  if (localExecutor && (localExecutor == GetRequester() || localExecutor == assignee))
169  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_COMPLETED_TEXT + " " + m_sName, prio: SCR_ECampaignPopupPriority.TASK_DONE, sound: SCR_SoundEvent.TASK_SUCCEED, text2: SCR_BaseTask.TASK_HINT_TEXT, text2param1: SCR_PopUpNotification.TASKS_KEY_IMAGE_FORMAT);
170  return;
171  }
172 
173  if (!assignee)
174  return;
175 
176  // Award XP to the volunteer
177  SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
178 
179  if (comp)
180  comp.AwardXP(SCR_BaseTaskExecutor.GetTaskExecutorID(assignee), m_AssigneeXPReward);
181 
182  super.Finish(showMsg);
183  }
184 
185  //------------------------------------------------------------------------------------------------
186  void RequesterDied()
187  {
188  SCR_BaseTaskManager taskManager = GetTaskManager();
189 
190  if (!taskManager || taskManager.IsProxy())
191  return;
192 
193  SCR_BaseTaskSupportEntity supportEntity = SCR_BaseTaskSupportEntity.Cast(taskManager.FindSupportEntity(SCR_BaseTaskSupportEntity));
194  if (!supportEntity)
195  return;
196 
197  supportEntity.FailTask(this);
198  }
199 
200  //------------------------------------------------------------------------------------------------
201  SCR_BaseTaskExecutor GetRequester()
202  {
203  return m_Requester;
204  }
205 
206  //------------------------------------------------------------------------------------------------
207  string GetRequesterName()
208  {
209  return GetGame().GetPlayerManager().GetPlayerName(m_iRequesterID);
210  }
211 
212  //------------------------------------------------------------------------------------------------
213  void OnEntityDeath(IEntity killedEntity)
214  {
215  if (!m_Requester)
216  return;
217  if (killedEntity == m_Requester.GetControlledEntity())
218  Fail(); //TODO
219  }
220 
221  //------------------------------------------------------------------------------------------------
222  void SetRequesterID(int requesterID)
223  {
224  m_iRequesterID = requesterID;
225  SetEventMask(EntityEvent.FRAME);
226  }
227 
228  //------------------------------------------------------------------------------------------------
229  bool AutoSetRequester()
230  {
231  if (m_iRequesterID == -1)
232  return false;
233 
234  SCR_BaseTaskExecutor requester = SCR_BaseTaskExecutor.GetTaskExecutorByID(m_iRequesterID);
235 
236  if (requester)
237  SetRequester(requester);
238  else
239  return false;
240 
241  return true;
242  }
243 
244  //------------------------------------------------------------------------------------------------
247  override bool CanBeAssigned(out SCR_ECannotAssignReasons reason, int playerID = -1)
248  {
249  SCR_BaseTaskExecutor localExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
250  if (!localExecutor)
251  return false;
252 
253  if (localExecutor == m_Requester)
254  {
255  reason = SCR_ECannotAssignReasons.IS_TASK_REQUESTER;
256  return false;
257  }
258 
259  return super.CanBeAssigned(reason, playerID);
260  }
261 
262  //------------------------------------------------------------------------------------------------
263  void SetRequester(SCR_BaseTaskExecutor requester)
264  {
265  if (!GetTaskManager())
266  return;
267 
269  if (!supportEntity)
270  return;
271 
272  if (!requester)
273  return;
274 
275  m_Requester = requester;
276  m_iRequesterID = SCR_BaseTaskExecutor.GetTaskExecutorID(requester);
277 
278  IEntity requesterEntity = requester.GetControlledEntity();
279  if (!requesterEntity)
280  return;
281 
282  SCR_CharacterControllerComponent characterControllerComponent = SCR_CharacterControllerComponent.Cast(requesterEntity.FindComponent(SCR_CharacterControllerComponent));
283  if (!characterControllerComponent)
284  return;
285 
286  characterControllerComponent.GetOnPlayerDeath().Insert(RequesterDied);
287 
288  SCR_BaseTaskExecutor localTaskExecutor = SCR_BaseTaskExecutor.GetLocalExecutor();
289  if (localTaskExecutor == requester)
290  supportEntity.SetLocallyRequestedTask(this);
291 
292  FactionAffiliationComponent factionAffiliationComponent = FactionAffiliationComponent.Cast(requesterEntity.FindComponent(FactionAffiliationComponent));
293  if (factionAffiliationComponent)
294  m_TargetFaction = factionAffiliationComponent.GetAffiliatedFaction();
295  }
296 
297  //------------------------------------------------------------------------------------------------
298  override void EOnFrame(IEntity owner, float timeSlice)
299  {
300  if (!m_Requester)
301  AutoSetRequester();
302  }
303 
304  //------------------------------------------------------------------------------------------------
305  override void Deserialize(ScriptBitReader reader)
306  {
307  super.Deserialize(reader);
308 
309  int requesterID;
310  reader.ReadInt(requesterID);
311  SetRequesterID(requesterID);
312  }
313 
314  //------------------------------------------------------------------------------------------------
315  override void Serialize(ScriptBitWriter writer)
316  {
317  super.Serialize(writer);
318 
319  writer.WriteInt(m_iRequesterID);
320  }
321 
322  //------------------------------------------------------------------------------------------------
323  override void EOnInit(IEntity owner)
324  {
325  super.EOnInit(owner);
326  }
327 
328  //------------------------------------------------------------------------------------------------
329  void SCR_RequestedTask(IEntitySource src, IEntity parent)
330  {
331  if (SCR_Global.IsEditMode(this))
332  return;
333 
334  SetEventMask(EntityEvent.FRAME);
335  }
336 
337  //------------------------------------------------------------------------------------------------
338  void ~SCR_RequestedTask()
339  {
340  }
341 
342 };
SCR_BaseTaskClass
Definition: SCR_BaseTask.c:2
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SCR_RequestedTaskSupportEntity
Definition: SCR_RequestedTaskSupportEntity.c:8
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_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_ECannotAssignReasons
SCR_ECannotAssignReasons
Definition: SCR_ECampaignTaskReasons.c:1
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignBuildingCompositionComponent.c:456
m_TargetFaction
protected Faction m_TargetFaction
Definition: SCR_EditableTaskComponent.c:22
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_RequestedTaskClass
Definition: SCR_RequestedTask.c:2
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_ECampaignPopupPriority
SCR_ECampaignPopupPriority
Popup message priorities sorted from lowest to highest.
Definition: SCR_CampaignFeedbackComponent.c:1419
SCR_BaseTaskManager
Definition: SCR_BaseTaskManager.c:25
SCR_BaseTaskSupportEntity
Definition: SCR_BaseTaskSupportEntity.c:8
Faction
Definition: Faction.c:12
SCR_BaseTaskExecutor
Definition: SCR_BaseTaskExecutor.c:7
SCR_EXPRewards
SCR_EXPRewards
Definition: SCR_XPHandlerComponent.c:403
SCR_Global
Definition: Functions.c:6
SCR_RequestedTask
Definition: SCR_RequestedTask.c:8
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
m_sName
protected LocalizedString m_sName
Definition: SCR_GroupIdentityComponent.c:19
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180