Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScenarioFrameworkTask.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4 };
5 
6 //------------------------------------------------------------------------------------------------
8 {
9  protected IEntity m_Asset;
10  protected SCR_ScenarioFrameworkTaskSupportEntity m_SupportEntity;
11  protected SCR_ScenarioFrameworkLayerTask m_LayerTask;
12  protected SCR_ScenarioFrameworkSlotTask m_SlotTask;
13  protected string m_sTaskExecutionBriefing;
14  string m_sTaskIntroVoiceline;
15  protected string m_sSpawnedEntityName;
16 
17  //------------------------------------------------------------------------------------------------
18  void SetTaskState(SCR_TaskState state)
19  {
20  SetState(state);
21  }
22 
23  //------------------------------------------------------------------------------------------------
24  void SetLayerTask(SCR_ScenarioFrameworkLayerTask layer)
25  {
26  m_LayerTask = layer;
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  SCR_ScenarioFrameworkLayerTask GetLayerTask()
31  {
32  return m_LayerTask;
33  }
34 
35  //------------------------------------------------------------------------------------------------
37  override void OnStateChanged(SCR_TaskState previousState, SCR_TaskState newState)
38  {
39  if (!m_LayerTask)
40  return;
41 
42  SCR_GameModeSFManager gameModeManager = SCR_GameModeSFManager.Cast(GetGame().GetGameMode().FindComponent(SCR_GameModeSFManager));
43  if (!gameModeManager || !gameModeManager.IsMaster())
44  return;
45 
46  if (m_SlotTask)
47  {
48  m_SlotTask.OnTaskStateChanged(newState);
49  }
50  else
51  {
52  SCR_ScenarioFrameworkSlotTask slotTask = m_LayerTask.GetSlotTask();
53  if (slotTask)
54  slotTask.OnTaskStateChanged(newState);
55  else
56  Print("ScenarioFramework: Task Subject not found for task", LogLevel.ERROR);
57  }
58 
59  m_LayerTask.OnTaskStateChanged(previousState, newState);
60 
61  if (newState == SCR_TaskState.FINISHED)
62  gameModeManager.PopUpMessage(GetTitle(), "#AR-Tasks_StatusFinished-UC", m_TargetFaction.GetFactionKey());
63 
64  if (newState == SCR_TaskState.CANCELLED)
65  gameModeManager.PopUpMessage(GetTitle(), "#AR-Tasks_StatusFailed-UC", m_TargetFaction.GetFactionKey());
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  override void Finish(bool showMsg = true)
70  {
71  showMsg = SCR_FactionManager.SGetLocalPlayerFaction() == m_TargetFaction;
72  super.Finish(showMsg);
73  }
74 
75  //------------------------------------------------------------------------------------------------
76  void SetTaskAsset(IEntity object)
77  {
78  m_Asset = object;
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  void RehookTaskAsset(IEntity object)
83  {
84  m_Asset = object;
85 
86  if (m_SupportEntity)
87  m_SupportEntity.SetTaskEntity(m_Asset);
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  IEntity GetAsset()
92  {
93  return m_Asset;
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  void SetSlotTask(SCR_ScenarioFrameworkSlotTask slotTask)
98  {
99  m_SlotTask = slotTask;
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  SCR_ScenarioFrameworkSlotTask GetSlotTask()
104  {
105  return m_SlotTask;
106  }
107 
108  //------------------------------------------------------------------------------------------------
109  SCR_ScenarioFrameworkTaskSupportEntity GetSupportEntity()
110  {
111  return m_SupportEntity;
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  void SetTaskExecutionBriefing(string text)
116  {
117  m_sTaskExecutionBriefing = text;
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  string GetTaskExecutionBriefing()
122  {
123  return m_sTaskExecutionBriefing;
124  }
125 
126  //------------------------------------------------------------------------------------------------
127  void SetSpawnedEntityName(string name)
128  {
129  m_sSpawnedEntityName = name;
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  string GetSpawnedEntityName()
134  {
135  return m_sSpawnedEntityName;
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  //Description fetch for the Task List
140  override string GetTaskListTaskText()
141  {
142  return string.Format(WidgetManager.Translate(m_sDescription, m_sSpawnedEntityName));
143  }
144 
145  //------------------------------------------------------------------------------------------------
146  protected bool SetSupportEntity()
147  {
149 
150  if (!m_SupportEntity)
151  {
152  Print("ScenarioFramework: Default Task support entity not found in the world, task won't be created!", LogLevel.ERROR);
153  return false;
154  }
155 
156  return m_SupportEntity != null;
157  }
158 
159  //------------------------------------------------------------------------------------------------
160  override void Serialize(ScriptBitWriter writer)
161  {
162  super.Serialize(writer);
163 
164  writer.WriteString(m_sTaskExecutionBriefing);
165  writer.WriteString(m_sSpawnedEntityName);
166  }
167 
168  //------------------------------------------------------------------------------------------------
169  override void Deserialize(ScriptBitReader reader)
170  {
171  super.Deserialize(reader);
172 
173  string taskExecutionBriefing;
174  //Reading task execution briefing
175  reader.ReadString(taskExecutionBriefing);
176  SetTaskExecutionBriefing(taskExecutionBriefing);
177 
178  string spawnedEntityName;
179  //Reading spawned entity name
180  reader.ReadString(spawnedEntityName);
181  SetSpawnedEntityName(spawnedEntityName);
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  void Init()
186  {
187  if (SCR_Global.IsEditMode(this))
188  return;
189 
190  SetSupportEntity();
191  if (!m_SupportEntity)
192  return;
193 
194  m_Asset = m_SupportEntity.GetTaskEntity();
195  if (!m_Asset)
196  {
197  if (m_SlotTask)
198  m_Asset = m_SlotTask.GetSpawnedEntity();
199 
200  if (!m_Asset)
201  {
202  m_SupportEntity.CancelTask(this.GetTaskID());
203  Print("ScenarioFramework: Task subject not found!", LogLevel.ERROR);
204  return;
205  }
206 
207  m_SupportEntity.SetTaskEntity(m_Asset);
208  }
209 
210  SCR_GameModeSFManager gameModeManager = SCR_GameModeSFManager.Cast(GetGame().GetGameMode().FindComponent(SCR_GameModeSFManager));
211  if (!gameModeManager)
212  return;
213  }
214 
215  //------------------------------------------------------------------------------------------------
216  override void EOnInit(IEntity owner)
217  {
218  super.EOnInit(owner);
219 
220  if (!GetTaskManager() || GetTaskManager().IsProxy())
221  return;
222 
223  Init();
224  }
225 }
SCR_BaseTaskClass
Definition: SCR_BaseTask.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_BaseTask
A base class for tasks.
Definition: SCR_BaseTask.c:8
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
IsProxy
protected bool IsProxy()
Definition: SCR_CampaignBuildingCompositionComponent.c:456
m_TargetFaction
protected Faction m_TargetFaction
Definition: SCR_EditableTaskComponent.c:22
m_sDescription
string m_sDescription
Definition: SCR_FlashlightComponent.c:3
GetTaskManager
SCR_BaseTaskManager GetTaskManager()
Definition: SCR_BaseTaskManager.c:7
SCR_ScenarioFrameworkTaskSupportEntity
Definition: SCR_ScenarioFrameworkTaskSupportEntity.c:8
SCR_Global
Definition: Functions.c:6
SCR_TaskState
SCR_TaskState
Definition: SCR_TaskState.c:2
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_ScenarioFrameworkTask
Definition: SCR_ScenarioFrameworkTask.c:7
SCR_ScenarioFrameworkTaskClass
Definition: SCR_ScenarioFrameworkTask.c:2