8 class SCR_ScenarioFrameworkTaskType
10 [
Attribute(
"Type of task", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(SCR_ESFTaskType))]
11 protected SCR_ESFTaskType m_eTypeOfTask;
26 [
Attribute(uiwidget: UIWidgets.ResourcePickerThumbnail,
"Trigger for area",
category:
"Trigger")]
27 ResourceName m_sTriggerResource;
32 [
Attribute(defvalue:
"1", UIWidgets.CheckBox,
desc:
"Activate the trigger once or everytime the activation condition is true?",
category:
"Trigger")]
35 [
Attribute(
desc:
"Actions that will be activated when Trigger gets activated",
category:
"OnActivation")]
36 ref array<ref SCR_ScenarioFrameworkActionBase> m_aTriggerActions;
38 [
Attribute(
desc:
"Should the dynamic Spawn/Despawn based on distance from observer cameras be enabled?",
category:
"Activation")]
39 bool m_bDynamicDespawn;
41 [
Attribute(defvalue:
"750",
desc:
"How close at least one observer camera must be in order to trigger spawn",
category:
"Activation")]
42 int m_iDynamicDespawnRange;
44 SCR_BaseTriggerEntity m_Trigger;
45 ref ScriptInvoker<SCR_ScenarioFrameworkArea, SCR_ScenarioFrameworkEActivationType> m_OnTriggerActivated;
46 ref ScriptInvoker m_OnAreaInit =
new ScriptInvoker();
49 string m_sItemDeliveryPointName;
50 SCR_ScenarioFrameworkLayerTask m_LayerTask;
51 SCR_ScenarioFrameworkSlotTask m_SlotTask;
54 protected bool m_bShowDebugShapesInWorkbench;
58 bool GetDynamicDespawnEnabled()
65 void SetDynamicDespawnEnabled(
bool enabled)
72 int GetDynamicDespawnRange()
74 return m_iDynamicDespawnRange;
79 void SetDynamicDespawnRange(
int range)
81 m_iDynamicDespawnRange = range;
93 SCR_ScenarioFrameworkSlotTask GetSlotTask()
100 void SetSlotTask(SCR_ScenarioFrameworkSlotTask slotTask)
102 m_SlotTask = slotTask;
106 override SCR_ScenarioFrameworkLayerTask GetLayerTask()
113 void SetLayerTask(SCR_ScenarioFrameworkLayerTask layerTask)
115 m_LayerTask = layerTask;
120 string GetLayerTaskName()
122 return m_LayerTask.GetOwner().GetName();
127 SCR_ESFTaskType GetLayerTaskType()
129 return m_LayerTask.GetTaskType();
134 string GetDeliveryPointName()
136 return m_sItemDeliveryPointName;
142 void StoreDeliveryPoint(
string sDeliveryPointName)
144 m_sItemDeliveryPointName = sDeliveryPointName;
162 SCR_ScenarioFrameworkLayerTask Create()
164 array<SCR_ScenarioFrameworkLayerBase> aSlotsOut = {};
165 GetAllSlots(aSlotsOut);
166 if (aSlotsOut.IsEmpty())
174 return SCR_ScenarioFrameworkLayerTask.Cast(layer);
181 SCR_ScenarioFrameworkLayerTask Create(SCR_ESFTaskType eTaskType)
183 array<SCR_ScenarioFrameworkLayerBase> aSlotsOut = {};
184 GetSuitableLayersForTaskType(aSlotsOut, eTaskType);
185 if (aSlotsOut.IsEmpty())
190 m_LayerTask = SCR_ScenarioFrameworkLayerTask.Cast(aSlotsOut.GetRandomElement());
192 m_LayerTask.Init(
this, SCR_ScenarioFrameworkEActivationType.ON_TASKS_INIT);
200 void Create(SCR_ScenarioFrameworkLayerTask layerTask)
205 m_LayerTask = layerTask;
206 m_LayerTask.Init(
this, SCR_ScenarioFrameworkEActivationType.ON_TASKS_INIT);
211 SCR_BaseTriggerEntity GetTrigger()
220 Resource resource = Resource.Load(m_sTriggerResource);
224 EntitySpawnParams spawnParams =
new EntitySpawnParams();
225 spawnParams.TransformMode = ETransformMode.WORLD;
226 GetOwner().GetWorldTransform(spawnParams.Transform);
229 vector angles = Math3D.MatrixToAngles(spawnParams.Transform);
230 Math3D.AnglesToMatrix(angles, spawnParams.Transform);
234 BaseResourceObject resourceObject = resource.GetResource();
238 string resourceName = resourceObject.GetResourceName();
239 m_Trigger = SCR_BaseTriggerEntity.Cast(
GetGame().SpawnEntityPrefab(resource,
GetGame().GetWorld(), spawnParams));
244 m_Trigger.SetSphereRadius(m_fAreaRadius);
245 m_Trigger.GetOnActivate().Insert(OnAreaTriggerActivated);
248 if (characterTrigger)
249 characterTrigger.SetOnce(
m_bOnce);
264 bool GetIsTaskSuitableForArea(SCR_ESFTaskType eTaskType)
266 array<SCR_ESFTaskType> aTaskTypes = {};
267 GetAvailableTaskTypes(aTaskTypes);
268 if (aTaskTypes.IsEmpty())
271 return aTaskTypes.Find(eTaskType) != -1;
276 void GetAvailableTaskTypes(out array<SCR_ESFTaskType> aTaskTypes)
278 array<SCR_ScenarioFrameworkLayerBase> aSlots = {};
280 SCR_ESFTaskType eType;
281 SCR_ScenarioFrameworkLayerTask pos;
284 pos = SCR_ScenarioFrameworkLayerTask.Cast(layer);
288 eType = pos.GetTaskType();
289 if (aTaskTypes.Find(eType) == -1)
290 aTaskTypes.Insert(eType);
297 void GetSuitableLayersForTaskType(out notnull array<SCR_ScenarioFrameworkLayerBase> aSlotsOut, SCR_ESFTaskType eTaskType)
299 SCR_ESFTaskType eType;
300 array<SCR_ScenarioFrameworkLayerBase> aSlots = {};
302 SCR_ScenarioFrameworkLayerTask pos;
305 pos = SCR_ScenarioFrameworkLayerTask.Cast(layer);
309 eType = pos.GetTaskType();
310 if (eTaskType == eType)
311 aSlotsOut.Insert(pos);
317 void GetAllSlots(out array<SCR_ScenarioFrameworkLayerBase> aSlots)
320 IEntity child =
GetOwner().GetChildren();
326 aSlots.Insert(slotComponent);
328 child = child.GetSibling();
334 void GetAllLayerTasks(out notnull array<SCR_ScenarioFrameworkLayerTask> aLayerTasks)
337 SCR_ScenarioFrameworkLayerTask layerTask;
338 IEntity child =
GetOwner().GetChildren();
341 layerTask = SCR_ScenarioFrameworkLayerTask.Cast(child.FindComponent(SCR_ScenarioFrameworkLayerTask));
343 aLayerTasks.Insert(layerTask);
345 child = child.GetSibling();
351 void SetAreaSelected(
bool bSet)
353 m_bAreaSelected = bSet;
358 bool GetIsAreaSelected()
360 return m_bAreaSelected;
365 void OnAreaTriggerActivated(IEntity entity)
367 if (m_OnTriggerActivated)
369 m_OnTriggerActivated.Invoke(
this, SCR_ScenarioFrameworkEActivationType.ON_AREA_TRIGGER_ACTIVATION,
false);
370 m_OnTriggerActivated.Clear();
374 m_Trigger.Deactivate();
380 ScriptInvoker GetOnAreaTriggerActivated()
382 if (!m_OnTriggerActivated)
383 m_OnTriggerActivated =
new ScriptInvoker<SCR_ScenarioFrameworkArea, SCR_ScenarioFrameworkEActivationType>();
385 return m_OnTriggerActivated;
390 ScriptInvoker GetOnAreaInit()
397 override void RestoreToDefault(
bool includeChildren =
false,
bool reinitAfterRestoration =
false)
400 m_sItemDeliveryPointName =
"";
404 super.RestoreToDefault(includeChildren, reinitAfterRestoration);
408 override void DynamicReinit()
423 child.DynamicDespawn(
this);
430 override void Init(
SCR_ScenarioFrameworkArea area =
null, SCR_ScenarioFrameworkEActivationType activation = SCR_ScenarioFrameworkEActivationType.SAME_AS_PARENT)
438 if (!activationCondition.Init(
GetOwner()))
446 PrintFormat(
"ScenarioFramework: Area %1 is set to %2 activation type, but area will always spawn on Init as default",
GetOwner().
GetName(), activation, LogLevel.WARNING);
452 super.Init(
this, SCR_ScenarioFrameworkEActivationType.ON_INIT);
458 triggerAction.Init(m_Trigger);
464 override void EOnInit(IEntity owner)
470 SCR_GameModeSFManager gameModeManager = SCR_GameModeSFManager.Cast(gameMode.FindComponent(SCR_GameModeSFManager));
472 gameModeManager.RegisterArea(
this);
475 override void OnPostInit(IEntity owner)
477 SetEventMask(owner, EntityEvent.INIT);
479 super.OnPostInit(owner);
483 override protected void DrawDebugShape(
bool draw)
485 Shape dbgShape =
null;
489 dbgShape = Shape.CreateSphere(
491 ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE | ShapeFlags.ONCE | ShapeFlags.NOOUTLINE,
496 if (m_sTriggerResource.IsEmpty())
499 Shape triggerdbgShape =
null;
500 triggerdbgShape = Shape.CreateSphere(
501 ARGB(100, 0x99, 0x10, 0xF2),
502 ShapeFlags.TRANSP | ShapeFlags.DOUBLESIDE | ShapeFlags.NOZWRITE | ShapeFlags.ONCE | ShapeFlags.NOOUTLINE,
510 override void _WB_AfterWorldUpdate(IEntity owner,
float timeSlice)
512 DrawDebugShape(m_bShowDebugShapesInWorkbench);
516 override bool _WB_OnKeyChanged(IEntity owner, BaseContainer src,
string key, BaseContainerList ownerContainers, IEntity parent)
518 if (key ==
"m_bShowDebugShapesInWorkbench")
519 DrawDebugShape(m_bShowDebugShapesInWorkbench);