29 protected string m_sDeliveryTriggerName;
31 protected int m_iObjectState = 0;
32 protected SCR_BaseTriggerEntity m_TriggerDeliver;
33 protected bool m_bDeliveryItemFound;
34 protected bool m_bTaskPositionUpdated;
38 int GetTaskDeliverState()
40 return m_iObjectState;
44 void SetDeliveryTrigger()
49 if (m_sDeliveryTriggerName.IsEmpty())
51 Print(
"ScenarioFramework: Task Deliver trigger is set with empty attribute SetDeliveryTrigger", LogLevel.ERROR);
55 IEntity entity =
GetGame().GetWorld().FindEntityByName(m_sDeliveryTriggerName);
59 SetDeliveryTrigger(SCR_BaseTriggerEntity.Cast(entity));
63 void SetDeliveryTrigger(SCR_BaseTriggerEntity trigger)
68 m_TriggerDeliver = trigger;
69 trigger.GetOnActivate().Insert(OnDeliveryTriggerActivated);
73 void SetTriggerNameToDeliver(
string triggerName)
75 if (triggerName.IsEmpty())
77 Print(
"ScenarioFramework: Task Deliver trigger is set with empty attribute SetTriggerNameToDeliver", LogLevel.ERROR);
81 m_sDeliveryTriggerName = triggerName;
85 string GetTriggerNameToDeliver()
87 return m_sDeliveryTriggerName;
93 if (!m_SupportEntity || !m_Asset)
96 array<IEntity> entitiesInside = {};
97 array<SCR_ChimeraCharacter> chimeraCharacters = {};
98 trigger.GetEntitiesInside(entitiesInside);
99 foreach (IEntity entity : entitiesInside)
101 if (entity == m_Asset)
103 m_SupportEntity.FinishTask(
this);
107 if (SCR_ChimeraCharacter.Cast(entity))
108 chimeraCharacters.Insert(SCR_ChimeraCharacter.Cast(entity))
111 foreach (SCR_ChimeraCharacter character : chimeraCharacters)
114 if (!inventoryComponent)
117 if (inventoryComponent.Contains(m_Asset))
119 m_SupportEntity.FinishTask(
this);
126 void OnObjectPossessed(IEntity item, BaseInventoryStorageComponent pStorageOwner)
128 if(!item || item != m_Asset)
131 UpdateTaskTitleAndDescription(1);
132 if (!m_bDeliveryItemFound)
134 m_bDeliveryItemFound =
true;
140 void OnObjectDropped(IEntity item, BaseInventoryStorageComponent pStorageOwner)
142 if(!item || item != m_Asset)
146 UpdateTaskTitleAndDescription(0);
150 void UpdateTaskTitleAndDescription(
int iPossessed = -1)
152 if (iPossessed == -1)
156 if (m_iObjectState & 0x01)
163 if (!m_TriggerDeliver)
174 if (!m_bTaskPositionUpdated)
175 UpdateDroppedTaskMarker();
183 m_SupportEntity.MoveTask(m_TriggerDeliver.GetOrigin(),
this.GetTaskID());
189 if (!m_bTaskPositionUpdated)
190 UpdateDroppedTaskMarker();
197 SCR_ScenarioFrameworkSlotTask subject = m_LayerTask.GetSlotTask();
201 if (GetTitle() != subject.GetTaskTitle(m_iObjectState))
202 m_SupportEntity.SetTaskTitle(
this, subject.GetTaskTitle(m_iObjectState));
204 if (GetDescription() != subject.GetTaskDescription(m_iObjectState))
205 m_SupportEntity.SetTaskDescription(
this, subject.GetTaskDescription(m_iObjectState));
209 protected void UpdateDroppedTaskMarker()
211 m_bTaskPositionUpdated =
true;
213 if (!layerTaskDeliver)
215 Print(
"ScenarioFramework: Task Deliver failed to access LayerTask", LogLevel.ERROR);
220 GetGame().GetCallqueue().CallLater(MoveTaskMarkerPosition, 1000 * layerTaskDeliver.GetIntelMapMarkerUpdateDelay(),
false);
224 protected void MoveTaskMarkerPosition()
226 m_bTaskPositionUpdated =
false;
228 m_SupportEntity.MoveTask(m_Asset.GetOrigin(),
this.GetTaskID());
230 Print(
"ScenarioFramework: Task Deliver does not have m_Asset properly assigned for MoveTaskMarkerPosition", LogLevel.ERROR);
234 override void UpdateMapTaskIcon()
236 super.UpdateMapTaskIcon();
237 if (!GetTaskIconkWidget())
240 if (m_iObjectState == 1)
242 GetTaskIconkWidget().SetOpacity(0);
243 GetTaskIconkWidget().SetVisible(
false);
247 GetTaskIconkWidget().SetOpacity(1);
248 GetTaskIconkWidget().SetVisible(
true);
257 EventHandlerManagerComponent EventHandlerMgr = EventHandlerManagerComponent.Cast(oldSlot.GetOwner().FindComponent(EventHandlerManagerComponent));
259 EventHandlerMgr.RemoveScriptHandler(
"OnDestroyed",
this, OnDestroyed);
264 EventHandlerManagerComponent EventHandlerMgr = EventHandlerManagerComponent.Cast(newSlot.GetOwner().FindComponent(EventHandlerManagerComponent));
266 EventHandlerMgr.RegisterScriptHandler(
"OnDestroyed",
this, OnDestroyed);
272 protected void OnDestroyed(IEntity destroyedEntity)
274 if (!destroyedEntity)
289 if (!inventoryComponent)
292 if (inventoryComponent.Contains(m_Asset))
294 inventoryComponent.TryRemoveItemFromStorage(m_Asset, parentSlot.GetStorage());
295 m_Asset.SetOrigin(destroyedEntity.GetOrigin());
301 protected void OnDisconnected(
int iPlayerID)
303 IEntity player =
GetGame().GetPlayerManager().GetPlayerControlledEntity(iPlayerID);
311 protected void RegisterPlayer(
int iPlayerID, IEntity playerEntity)
313 IEntity player =
GetGame().GetPlayerManager().GetPlayerControlledEntity(iPlayerID);
317 SCR_InventoryStorageManagerComponent inventoryComponent = SCR_InventoryStorageManagerComponent.Cast(player.FindComponent(SCR_InventoryStorageManagerComponent));
318 if (!inventoryComponent)
321 inventoryComponent.m_OnItemAddedInvoker.Insert(OnObjectPossessed);
322 inventoryComponent.m_OnItemRemovedInvoker.Insert(OnObjectDropped);
324 EventHandlerManagerComponent EventHandlerMgr = EventHandlerManagerComponent.Cast(player.FindComponent(EventHandlerManagerComponent));
326 EventHandlerMgr.RegisterScriptHandler(
"OnDestroyed",
this, OnDestroyed);
330 override bool SetSupportEntity()
334 if (!m_SupportEntity)
336 Print(
"ScenarioFramework: Task Deliver support entity not found in the world, task won't be created!", LogLevel.ERROR);
355 invComp.m_OnParentSlotChangedInvoker.Insert(OnItemCarrierChanged);
357 array<int> aPlayerIDs = {};
358 int iNrOfPlayersConnected =
GetGame().GetPlayerManager().GetPlayers(aPlayerIDs);
360 foreach (
int i : aPlayerIDs)
362 RegisterPlayer(i,
null);
369 gameMode.GetOnPlayerSpawned().Insert(RegisterPlayer);
370 gameMode.GetOnPlayerDisconnected().Insert(OnDisconnected);
374 protected void InvokedSetDeliveryTrigger()
376 SetDeliveryTrigger();