Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignTask.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
8 {
9  static const string CAMPAIGN_TASK_RECONFIGURED_TEXT = "#AR-CampaignTasks_Reconfigured-UC";
10  static const string CAMPAIGN_TASK_RECONFIGURED_BY_TEXT = "#AR-CampaignTasks_ReconfiguredBy-UC";
11 
12  //*****************//
13  //MEMBER ATTRIBUTES//
14  //*****************//
15 
16  [Attribute(defvalue: "Task title for reconfigure.", desc: "The task title visible to the player.")]
17  protected string m_sNameReconfigure;
18  [Attribute(defvalue: "Task description.", desc: "The task description visible to the player.")]
19  protected string m_sDescriptionReconfigure;
20 
21  protected string m_sAffix;
22 
23  //**************************//
24  //PROTECTED MEMBER VARIABLES//
25  //**************************//
26 
27  protected SCR_CampaignTaskType m_eType;
28 
29  //*********************************//
30  //PROTECTED OVERRIDE MEMBER METHODS//
31  //*********************************//
32 
33  //------------------------------------------------------------------------------------------------
34  protected override bool DoneByAssignee()
35  {
36  SCR_BaseTaskExecutor assignee = GetAssignee();
37  if (assignee && m_TargetBase)
38  {
39  int assigneeID = SCR_BaseTaskExecutor.GetTaskExecutorID(assignee);
40  int reconfigurerID = m_TargetBase.GetReconfiguredByID();
41  if (assigneeID == reconfigurerID)
42  return true;
43  }
44 
45  return false;
46  }
47 
48  //------------------------------------------------------------------------------------------------
50  protected override void ShowAvailableTask(bool afterAssigneeRemoved = false)
51  {
53  if (CanBeAssigned(reason))
54  {
55  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
56  if (campaign)
57  {
58  string text = TASK_AVAILABLE_TEXT + " " + GetTitle();
59  string baseName;
60 
61  if (m_TargetBase)
62  baseName = GetBaseNameWithCallsign();
63 
64  SCR_PopUpNotification.GetInstance().PopupMsg(text, prio: SCR_ECampaignPopupPriority.TASK_AVAILABLE, param1: baseName, text2: TASK_HINT_TEXT, text2param1: SCR_PopUpNotification.TASKS_KEY_IMAGE_FORMAT, sound: SCR_SoundEvent.TASK_CREATED);
65  }
66  }
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  override protected void ShowTaskProgress(bool showMsg = true)
71  {
72  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
73  if (campaign && showMsg)
74  {
75  string baseName;
76 
77  if (m_TargetBase)
78  baseName = GetBaseNameWithCallsign();
79 
80  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_PROGRESS_TEXT + " " + GetTitle() + " " + TASK_AMOUNT_COMPLETED_TEXT, prio: SCR_ECampaignPopupPriority.TASK_PROGRESS, param1: baseName);
81  }
82  }
83 
84  //******************************//
85  //PUBLIC OVERRIDE MEMBER METHODS//
86  //******************************//
87 
88  //------------------------------------------------------------------------------------------------
89  override string GetIconSuffix()
90  {
91  if (m_TargetBase && m_TargetBase.GetType() == SCR_ECampaignBaseType.RELAY)
92  return "_Relay";
93 
94  return "";
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  override void DoNotifyAssignment(int assigneeID)
99  {
100  if (m_TargetBase.GetType() != SCR_ECampaignBaseType.BASE)
101  return;
102 
103  SCR_CampaignNetworkComponent assigneeNetworkComponent = SCR_CampaignNetworkComponent.GetCampaignNetworkComponent(assigneeID);
104  if (!assigneeNetworkComponent)
105  return;
106 
107  assigneeNetworkComponent.SendPlayerMessage(GetAssignMessage(), m_TargetBase.GetCallsign());
108  }
109 
110  //------------------------------------------------------------------------------------------------
112  override string GetTitle()
113  {
114  if (m_TargetBase && m_TargetBase.GetType() == SCR_ECampaignBaseType.RELAY)
115  return m_sNameReconfigure;
116 
117  return m_sName;
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  override void SetIsPriority(bool isPrio)
122  {
123  super.SetIsPriority(isPrio);
124 
125  if (isPrio)
126  m_sAffix = "<br/><br/>#AR-Campaign_PriorityTaskInfo";
127  else
128  m_sAffix = string.Empty;
129 
130  RegisterTaskUpdate(SCR_ETaskEventMask.TASK_PROPERTY_CHANGED);
131  }
132 
133  //------------------------------------------------------------------------------------------------
135  override string GetDescription()
136  {
137  if (m_TargetBase && m_TargetBase.GetType() == SCR_ECampaignBaseType.RELAY)
138  return m_sDescriptionReconfigure + m_sAffix;
139 
140  return m_sDescription + m_sAffix;
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  override void Finish(bool showMsg = true)
145  {
146  showMsg = SCR_FactionManager.SGetLocalPlayerFaction() == m_TargetFaction;
147  super.Finish(showMsg);
148 
149  SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
150 
151  // Reward XP for seizing a base or reconfiguring a relay
152  if (comp && !GetTaskManager().IsProxy() && GetType() == SCR_CampaignTaskType.CAPTURE)
153  {
154  PlayerManager playerManager = GetGame().GetPlayerManager();
155  array<int> players = {};
156  playerManager.GetPlayers(players);
157  array<SCR_BaseTaskExecutor> assignees = {};
158  GetAssignees(assignees);
159  vector baseOrigin = m_TargetBase.GetOwner().GetOrigin();
160  int radius = m_TargetBase.GetRadius();
161  int radiusSq;
162  Faction playerFaction;
163  IEntity playerEntity;
164  bool isAssignee;
165  int assigneeID;
166  SCR_EXPRewards rewardID;
167 
168  if (m_TargetBase.GetType() == SCR_ECampaignBaseType.RELAY)
169  rewardID = SCR_EXPRewards.RELAY_RECONFIGURED;
170  else
171  rewardID = SCR_EXPRewards.BASE_SEIZED;
172 
173  if (m_TargetBase.GetType() == SCR_ECampaignBaseType.RELAY)
174  radiusSq = 50 * 50;
175  else
176  radiusSq = radius * radius;
177 
178  foreach (int playerId : players)
179  {
180  playerEntity = playerManager.GetPlayerControlledEntity(playerId);
181 
182  if (!playerEntity)
183  continue;
184 
185  playerFaction = SCR_CampaignReconfigureRelayUserAction.GetPlayerFaction(playerEntity);
186 
187  if (playerFaction != m_TargetFaction)
188  continue;
189 
190  if (vector.DistanceSq(playerEntity.GetOrigin(), baseOrigin) < radiusSq)
191  {
192  isAssignee = false;
193 
194  foreach (SCR_BaseTaskExecutor assignee : assignees)
195  {
196  assigneeID = SCR_BaseTaskExecutor.GetTaskExecutorID(assignee);
197 
198  if (assigneeID == playerId)
199  {
200  isAssignee = true;
201  break;
202  }
203  }
204 
205  float multiplier = 1.0;
206 
207  if (m_bIsPriority)
208  multiplier = 1.5;
209 
210  comp.AwardXP(playerId, rewardID, multiplier, isAssignee);
211  }
212  }
213  }
214 
215  string baseName;
216 
217  if (m_TargetBase)
218  baseName = GetBaseNameWithCallsign();
219 
220  if (showMsg)
221  {
222  // TODO make this nicer
223  if (m_bIndividualTask)
224  {
225  if (IsAssignedToLocalPlayer())
226  {
227  if (DoneByAssignee())
228  {
229  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_COMPLETED_TEXT + " " + GetTitle(), prio: SCR_ECampaignPopupPriority.TASK_DONE, param1: baseName, sound: SCR_SoundEvent.TASK_SUCCEED, text2: SCR_BaseTask.TASK_HINT_TEXT, text2param1: SCR_PopUpNotification.TASKS_KEY_IMAGE_FORMAT);
230  }
231  else
232  {
233  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_FAILED_TEXT + " " + GetTitle(), prio: SCR_ECampaignPopupPriority.TASK_DONE, param1: baseName, sound: SCR_SoundEvent.TASK_FAILED);
234  }
235  }
236  else
237  {
238  if (m_aAssignees && m_aAssignees.Count() > 0)
239  {
240  string text;
241  string par1;
242  string par2;
243  string par3;
244  string par4;
245  string par5;
246  GetFinishTextData(text, par1, par2, par3, par4, par5);
247  SCR_PopUpNotification.GetInstance().PopupMsg(text, prio: SCR_ECampaignPopupPriority.TASK_DONE, param1: par1, param2: par2, param3: par3, param4: par4, sound: SCR_SoundEvent.TASK_SUCCEED);
248  }
249  else
250  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_COMPLETED_TEXT + " " + GetTitle(), prio: SCR_ECampaignPopupPriority.TASK_DONE, param1: baseName, sound: SCR_SoundEvent.TASK_SUCCEED, text2: SCR_BaseTask.TASK_HINT_TEXT, text2param1: SCR_PopUpNotification.TASKS_KEY_IMAGE_FORMAT);
251  }
252  }
253  else
254  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_COMPLETED_TEXT + " " + GetTitle(), prio: SCR_ECampaignPopupPriority.TASK_DONE, param1: baseName, sound: SCR_SoundEvent.TASK_SUCCEED, text2: SCR_BaseTask.TASK_HINT_TEXT, text2param1: SCR_PopUpNotification.TASKS_KEY_IMAGE_FORMAT);
255  }
256  }
257 
258  //------------------------------------------------------------------------------------------------
260  override void Fail(bool showMsg = true)
261  {
262  showMsg = SCR_FactionManager.SGetLocalPlayerFaction() == m_TargetFaction;
263  super.Fail(showMsg);
264 
265  /*SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
266  if (campaign && showMsg)
267  {
268  string baseName;
269 
270  if (m_TargetBase)
271  baseName = GetBaseNameWithCallsign();
272 
273  SCR_PopUpNotification.GetInstance().PopupMsg(TASK_FAILED_TEXT + " " + GetTitle(), prio: SCR_ECampaignPopupPriority.TASK_DONE, param1: baseName, sound: SCR_SoundEvent.TASK_FAILED);
274  }*/
275  }
276 
277  //------------------------------------------------------------------------------------------------
279  override string GetFinishText()
280  {
281  // TODO Add other types of tasks here once needed...
282  string text = "";
283 
284  switch (m_eType)
285  {
286  case SCR_CampaignTaskType.CAPTURE:
287  {
288  if (m_TargetBase)
289  if (m_bIndividualTask && DoneByAssignee())
290  text = string.Format(CAMPAIGN_TASK_RECONFIGURED_BY_TEXT, GetBaseNameWithCallsign(), GetAllAssigneeNamesString());
291  else
292  text = string.Format(CAMPAIGN_TASK_RECONFIGURED_TEXT, GetBaseNameWithCallsign());
293 
294  break;
295  };
296  }
297 
298  return text;
299  }
300 
301  //------------------------------------------------------------------------------------------------
303  void GetFinishTextData(out string text = "", out string param1 = "", out string param2 = "", out string param3 = "", out string param4 = "", out string param5 = "")
304  {
305  switch (m_eType)
306  {
307  case SCR_CampaignTaskType.CAPTURE:
308  {
309  if (m_TargetBase)
310  if (m_bIndividualTask && DoneByAssignee())
311  {
312  text = CAMPAIGN_TASK_RECONFIGURED_BY_TEXT;
313  param1 = GetBaseNameWithCallsign();
314  param2 = GetAllAssigneeNamesString();
315  }
316  else
317  {
318  text = CAMPAIGN_TASK_RECONFIGURED_TEXT;
319  param1 = GetBaseNameWithCallsign();
320  }
321 
322  break;
323  };
324  }
325  }
326 
327  //------------------------------------------------------------------------------------------------
328  override string GetMapDescriptorText()
329  {
330  return GetTaskListTaskText();
331  }
332 
333  //*********************//
334  //PUBLIC MEMBER METHODS//
335  //*********************//
336 
337  //------------------------------------------------------------------------------------------------
338  override void SetTitleWidgetText(notnull TextWidget textWidget, string taskText)
339  {
340  string baseName;
341 
342  if (m_TargetBase)
343  baseName = GetBaseNameWithCallsign();
344 
345  textWidget.SetTextFormat(taskText, baseName);
346  }
347 
348  //------------------------------------------------------------------------------------------------
349  override string GetTitleText()
350  {
351  string baseName;
352 
353  if (m_TargetBase)
354  baseName = GetBaseNameWithCallsign();
355 
356  return string.Format("%1 %2", m_sName, baseName);
357  }
358 
359  //------------------------------------------------------------------------------------------------
360  override void SetDescriptionWidgetText(notnull TextWidget textWidget, string taskText)
361  {
362  string baseName;
363 
364  if (m_TargetBase)
365  baseName = GetBaseNameWithCallsign();
366 
367  textWidget.SetTextFormat(taskText, baseName);
368  }
369 
370  //------------------------------------------------------------------------------------------------
372  SCR_CampaignTaskType GetType()
373  {
374  return m_eType;
375  }
376 
377  //------------------------------------------------------------------------------------------------
379  void SetType(SCR_CampaignTaskType type)
380  {
381  m_eType = type;
382  }
383 
384  //***************************//
385  //PUBLIC MEMBER EVENT METHODS//
386  //***************************//
387 
388  //------------------------------------------------------------------------------------------------
389  override void Deserialize(ScriptBitReader reader)
390  {
391  super.Deserialize(reader);
392 
394  reader.ReadIntRange(type, 0, SCR_CampaignTaskType.LAST-1);
395  SetType(type);
396  }
397 
398  //------------------------------------------------------------------------------------------------
399  override void Serialize(ScriptBitWriter writer)
400  {
401  super.Serialize(writer);
402 
403  writer.WriteIntRange(GetType(), 0, SCR_CampaignTaskType.LAST-1);
404  }
405 
406  //------------------------------------------------------------------------------------------------
407  override void SetTargetBase(notnull SCR_CampaignMilitaryBaseComponent targetBase)
408  {
409  super.SetTargetBase(targetBase);
410  SCR_MilitaryBaseSystem.GetInstance().GetOnBaseFactionChanged().Insert(OnTargetBaseCaptured);
411  }
412 
413  //------------------------------------------------------------------------------------------------
414  void OnTargetBaseCaptured(SCR_MilitaryBaseComponent base, Faction faction)
415  {
416  if (base != m_TargetBase || !m_TargetFaction || m_eType != SCR_CampaignTaskType.CAPTURE || faction != m_TargetFaction)
417  return;
418 
419  if (!GetTaskManager())
420  return;
421 
423 
424  if (!supportEntity)
425  return;
426 
427  supportEntity.FinishTask(this);
428  }
429 
430  //------------------------------------------------------------------------------------------------
431  void OnCampaignBaseSignalChanged(SCR_CampaignMilitaryBaseComponent base)
432  {
433  if (!m_TargetBase || !base || !m_TargetFaction || m_eType != SCR_CampaignTaskType.CAPTURE || base != m_TargetBase)
434  return;
435 
437 
438  if (!castFaction)
439  return;
440 
441  if (!GetTaskManager())
442  return;
443 
445 
446  if (!supportEntity)
447  return;
448 
449  if (!m_TargetBase.IsHQRadioTrafficPossible(castFaction))
450  supportEntity.FailTask(this);
451  }
452 
453  //------------------------------------------------------------------------------------------------
454  void SCR_CampaignTask(IEntitySource src, IEntity parent)
455  {
456  if (SCR_Global.IsEditMode(this))
457  return;
458 
459  if (!GetTaskManager().IsProxy())
460  {
461  SCR_GameModeCampaign.GetInstance().GetBaseManager().GetOnSignalChanged().Insert(OnCampaignBaseSignalChanged);
462  }
463  }
464 
465  //------------------------------------------------------------------------------------------------
466  void ~SCR_CampaignTask()
467  {
468  if (SCR_Global.IsEditMode(this) || !GetGame().GetGameMode())
469  return;
470 
471  if (!GetTaskManager().IsProxy())
472  {
473  if (m_TargetBase)
474  {
475  SCR_MilitaryBaseSystem system = SCR_MilitaryBaseSystem.GetInstance();
476 
477  if (system)
478  system.GetOnBaseFactionChanged().Remove(OnTargetBaseCaptured);
479  }
480 
481  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
482 
483  if (campaign)
484  campaign.GetBaseManager().GetOnSignalChanged().Remove(OnCampaignBaseSignalChanged);
485  }
486  }
487 };
SCR_CampaignTaskClass
Definition: SCR_CampaignTask.c:2
SCR_CampaignBaseTaskClass
Definition: SCR_CampaignBaseTask.c:2
SCR_CampaignBaseTask
Definition: SCR_CampaignBaseTask.c:9
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SCR_MilitaryBaseSystem
Definition: SCR_MilitaryBaseSystem.c:11
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
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_ECampaignBaseType
SCR_ECampaignBaseType
Definition: SCR_CampaignMilitaryBaseComponent.c:2577
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
SCR_CampaignTask
Definition: SCR_CampaignTask.c:7
SCR_ECannotAssignReasons
SCR_ECannotAssignReasons
Definition: SCR_ECampaignTaskReasons.c:1
SCR_CampaignTaskType
SCR_CampaignTaskType
Definition: SCR_CampaignTaskType.c:2
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.
m_sDescription
string m_sDescription
Definition: SCR_FlashlightComponent.c:3
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_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
m_eType
protected SCR_ECampaignBaseType m_eType
Definition: SCR_CampaignMilitaryBaseComponent.c:59
SCR_ETaskEventMask
SCR_ETaskEventMask
Definition: SCR_BaseTaskManager.c:13
SCR_Global
Definition: Functions.c:6
SCR_CampaignFaction
Definition: SCR_CampaignFaction.c:2
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
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
PlayerManager
Definition: PlayerManager.c:12
SCR_CampaignMilitaryBaseComponent
Definition: SCR_CampaignMilitaryBaseComponent.c:38
SCR_CampaignReconfigureRelayUserAction
Action to reconfigure relays in Campaign.
Definition: SCR_CampaignReconfigureRelayUserAction.c:2