Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ClearTaskEntity.c
Go to the documentation of this file.
4
5class SCR_ClearTaskEntity : SCR_Task
6{
7 protected const int PERIODICAL_CHECK_INTERVAL = 5000; // ms
8
9 [Attribute("50", UIWidgets.EditBox, "Area radius [m]", "0 inf")]
10 protected float m_fAreaRadius;
11
12 protected ref array<IEntity> m_aObstacleEntities = {};
13 protected ref array<int> m_aAssigneesInArea = {};
14
15 protected RplComponent m_RplComponent;
16 protected bool m_bWasActivated;
17
18 //------------------------------------------------------------------------------------------------
19 protected void PeriodicalCheck()
20 {
21 array<int> assigneePlayerIDs = GetTaskAssigneePlayerIDs();
22 if (!assigneePlayerIDs || assigneePlayerIDs.IsEmpty())
23 return;
24
25 SCR_ChimeraCharacter character;
26 CharacterControllerComponent charControl;
27 PlayerManager playerManager = GetGame().GetPlayerManager();
28 vector taskPosition = GetTaskPosition();
29 m_aAssigneesInArea.Clear();
30
31 foreach (int playerId : assigneePlayerIDs)
32 {
33 character = SCR_ChimeraCharacter.Cast(playerManager.GetPlayerControlledEntity(playerId));
34 if (!character)
35 continue;
36
37 charControl = character.GetCharacterController();
38 if (!charControl || charControl.IsDead())
39 continue;
40
41 if (vector.DistanceSqXZ(character.GetOrigin(), taskPosition) > m_fAreaRadius * m_fAreaRadius)
42 continue;
43
44 m_aAssigneesInArea.Insert(playerId);
45 }
46
47 if (m_aAssigneesInArea.IsEmpty())
48 return;
49
50 int obstacleCount = m_aObstacleEntities.Count();
51 m_aObstacleEntities.Clear();
52 GetGame().GetWorld().QueryEntitiesBySphere(taskPosition, m_fAreaRadius, QueryCallback);
53
54 if (m_bWasActivated && obstacleCount > m_aObstacleEntities.Count())
55 {
56 // Obstacle was removed, objective successful
58 m_TaskSystem.DeleteTask(this);
59 return;
60 }
61
62 if (!m_bWasActivated)
63 {
64 m_bWasActivated = true;
65
66 // Fail objective if nothing to be cleared found on first activation
67 if (m_aObstacleEntities.IsEmpty())
68 {
70 m_TaskSystem.DeleteTask(this);
71 return;
72 }
73
74 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_CampaignBuildingManagerComponent));
75 if (buildingManagerComponent)
76 buildingManagerComponent.GetOnCompositionUnregistered().Insert(OnCompositionUnregistered);
77 }
78 }
79
80 //------------------------------------------------------------------------------------------------
82 protected bool QueryCallback(IEntity e)
83 {
84 SCR_CampaignBuildingCompositionComponent buildingComp = SCR_CampaignBuildingCompositionComponent.Cast(e.FindComponent(SCR_CampaignBuildingCompositionComponent));
85 if (buildingComp && buildingComp.IsCompositionSpawned())
86 m_aObstacleEntities.Insert(e);
87
89 if (triggerComp && triggerComp.IsActivated())
90 m_aObstacleEntities.Insert(e);
91
92 return true;
93 }
94
95 //------------------------------------------------------------------------------------------------
96 protected void OnCompositionUnregistered(SCR_CampaignBuildingCompositionComponent composition)
97 {
98 if (m_aObstacleEntities.IsEmpty())
99 return;
100
101 IEntity owner = composition.GetOwner();
102 if (!owner || !m_aObstacleEntities.Contains(owner))
103 return;
104
105 // Obstacle cleared, objective successful
106 SetTaskState(SCR_ETaskState.COMPLETED);
107 m_TaskSystem.DeleteTask(this);
108 }
109
110 //------------------------------------------------------------------------------------------------
111 protected void AddXPReward()
112 {
113 if (m_RplComponent.IsProxy())
114 return;
115
116 SCR_XPHandlerComponent xpHandler = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
117 if (!xpHandler)
118 return;
119
120 foreach (int playerId : m_aAssigneesInArea)
121 {
122 xpHandler.AwardXP(playerId, SCR_EXPRewards.CLEAR_TASK_COMPLETED);
123 }
124 }
125
126 //------------------------------------------------------------------------------------------------
127 override void SetTaskState(SCR_ETaskState state)
128 {
129 if (state == SCR_ETaskState.COMPLETED)
130 {
131 AddXPReward();
132 GetGame().GetCallqueue().Remove(PeriodicalCheck);
133 }
134 else if (state == SCR_ETaskState.FAILED || state == SCR_ETaskState.CANCELLED)
135 {
136 GetGame().GetCallqueue().Remove(PeriodicalCheck);
137 }
138
139 super.SetTaskState(state);
140 }
141
142 //------------------------------------------------------------------------------------------------
143 override void EOnInit(IEntity owner)
144 {
145 super.EOnInit(owner);
146
147 if (SCR_Global.IsEditMode(this))
148 return;
149
150 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
151 if (!m_RplComponent || m_RplComponent.IsProxy())
152 return;
153
154 GetGame().GetCallqueue().CallLater(PeriodicalCheck, PERIODICAL_CHECK_INTERVAL, true);
155 }
156
157 //------------------------------------------------------------------------------------------------
159 {
160 if (SCR_Global.IsEditMode(this))
161 return;
162
163 GetGame().GetCallqueue().Remove(PeriodicalCheck);
164
165 BaseGameMode gameMode = GetGame().GetGameMode();
166 if (!gameMode)
167 return;
168
169 SCR_CampaignBuildingManagerComponent buildingManagerComponent = SCR_CampaignBuildingManagerComponent.Cast(gameMode.FindComponent(SCR_CampaignBuildingManagerComponent));
170 if (buildingManagerComponent)
171 buildingManagerComponent.GetOnCompositionUnregistered().Remove(OnCompositionUnregistered);
172 }
173}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void PeriodicalCheck()
bool m_bWasActivated
array of playerIDs
override void SetTaskState(SCR_ETaskState state)
float m_fAreaRadius
SCR_AttackTaskEntityClass PERIODICAL_CHECK_INTERVAL
SCR_BaseGameMode GetGameMode()
void SCR_BaseTriggerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void OnCompositionUnregistered(SCR_CampaignBuildingCompositionComponent composition)
RplComponent m_RplComponent
void AddXPReward()
ref array< int > m_aAssigneesInArea
bool QueryCallback(IEntity e)
Inserts compositions and active mines to list of obstacles.
ref array< IEntity > m_aObstacleEntities
void ~SCR_ClearTaskEntity()
array< int > GetTaskAssigneePlayerIDs()
Definition SCR_Task.c:458
vector GetTaskPosition()
Definition SCR_Task.c:1282
void SCR_Task(IEntitySource src, IEntity parent)
Definition SCR_Task.c:1938
SCR_ETaskState
Definition SCR_Task.c:3
SCR_TaskSystem m_TaskSystem
proto external Managed FindComponent(typename typeName)
static bool IsEditMode()
Definition Functions.c:1566
override void EOnInit(IEntity owner)
SCR_FieldOfViewSettings Attribute