Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_RepairRequestedTaskEntity.c
Go to the documentation of this file.
4
5class SCR_RepairRequestedTaskEntity : SCR_BaseRequestedTaskEntity
6{
7 protected const int PERIODICAL_CHECK_INTERVAL = 5000; // ms
8 protected const int DISTANCE_CHECK_INTERVAL = 2000; // ms
9
10 [Attribute("150", UIWidgets.EditBox, "Area radius [m]", "0 inf")]
11 protected float m_fAreaRadius;
12
13 [Attribute("900", UIWidgets.EditBox, "After this time [s], task is cancelled", "0 inf")]
14 protected float m_fAutoCancelTime;
15
16 protected RplComponent m_RplComponent;
17 protected float m_fAreaRadiusSq;
19 protected bool m_bIsAreaCheckRunning;
21
22 //------------------------------------------------------------------------------------------------
24 {
26 return;
27
29 GetGame().GetCallqueue().CallLater(CheckDistanceToArea, DISTANCE_CHECK_INTERVAL, true);
30 }
31
32 //------------------------------------------------------------------------------------------------
34 {
36 return;
37
39 GetGame().GetCallqueue().Remove(CheckDistanceToArea);
40 }
41
42 //------------------------------------------------------------------------------------------------
43 protected void CheckDistanceToArea()
44 {
46 if (!player)
47 return;
48
49 float distance = vector.DistanceSqXZ(player.GetOrigin(), GetTaskPosition());
50
52 {
54 SCR_NotificationsComponent.SendLocal(ENotification.GROUP_TASK_REPAIR_ENTERED_AREA);
55 }
57 {
59 SCR_NotificationsComponent.SendLocal(ENotification.GROUP_TASK_REPAIR_LEAVED_AREA);
60 }
61 }
62
63 //------------------------------------------------------------------------------------------------
64 protected void OnTaskAssigneeAdded(SCR_Task task, SCR_TaskExecutor executor, int requesterID)
65 {
66 if (task != this)
67 return;
68
70 }
71
72 //------------------------------------------------------------------------------------------------
73 protected void OnTaskAssigneeRemoved(SCR_Task task, SCR_TaskExecutor executor, int requesterID)
74 {
75 if (task != this)
76 return;
77
79 }
80
81 //------------------------------------------------------------------------------------------------
82 protected void OnDataLoaded()
83 {
85 }
86
87 //------------------------------------------------------------------------------------------------
88 override bool RplLoad(ScriptBitReader reader)
89 {
90 bool loaded = super.RplLoad(reader);
91 if (loaded)
93
94 return loaded;
95 }
96
97 //------------------------------------------------------------------------------------------------
98 protected void PeriodicalCheck()
99 {
100 PlayerManager pManager = GetGame().GetPlayerManager();
101 SCR_ChimeraCharacter character;
102 CharacterControllerComponent charControl;
103 array<int> assigneePlayerIDs = GetTaskAssigneePlayerIDs();
104 if (!assigneePlayerIDs)
105 return;
106
107 ChimeraWorld world = GetGame().GetWorld();
108 if (!world)
109 return;
110
111 foreach (int playerId : assigneePlayerIDs)
112 {
113 character = SCR_ChimeraCharacter.Cast(pManager.GetPlayerControlledEntity(playerId));
114 if (!character)
115 continue;
116
117 charControl = character.GetCharacterController();
118 if (!charControl || charControl.IsDead())
119 continue;
120
121 if (vector.DistanceSqXZ(character.GetOrigin(), GetTaskPosition()) > m_fAreaRadiusSq)
122 continue;
123
124 // assigned player is in zone -> reset auto cancel timer
125 m_AutoCancelTimestamp = world.GetServerTimestamp().PlusSeconds(m_fAutoCancelTime);
126
127 return;
128 }
129
130 // when auto cancel timer ends, the task is cancelled
131 if (world.GetServerTimestamp().Greater(m_AutoCancelTimestamp))
132 {
133 SetTaskState(SCR_ETaskState.CANCELLED);
134 DeleteTask();
135 }
136 }
137
138 //------------------------------------------------------------------------------------------------
139 protected void OnVehicleRepaired(SCR_BaseSupportStationComponent supportStation, ESupportStationType supportStationType, IEntity actionTarget, IEntity actionUser, SCR_BaseUseSupportStationAction action)
140 {
141 if (!m_TaskSystem)
142 return;
143
144 // Support station is not a repair station
145 if (supportStationType != ESupportStationType.REPAIR)
146 return;
147
148 if (!action || !supportStation)
149 return;
150
151 IEntity repairedVehicle = actionTarget.GetRootParent();
152 if (!repairedVehicle)
153 return;
154
155 // User is not a player
156 int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(actionUser);
157 if (playerId == 0)
158 return;
159
160 if (vector.DistanceSqXZ(repairedVehicle.GetOrigin(), GetTaskPosition()) > m_fAreaRadiusSq)
161 return;
162
163 if (!IsTaskAssignedTo(SCR_TaskExecutorPlayer.FromPlayerID(playerId)))
164 return;
165
166 Vehicle vehicleWithRepairBox = Vehicle.Cast(supportStation.GetOwner().GetParent());
167 if (!vehicleWithRepairBox)
168 {
169 SCR_NotificationsComponent.SendToPlayer(playerId, ENotification.GROUP_TASK_REPAIR_TRUCK_IS_NOT_IN_RANGE);
170 return;
171 }
172
173 SCR_EditableVehicleComponent editableVehicleWithRepairBox = SCR_EditableVehicleComponent.Cast(vehicleWithRepairBox.FindComponent(SCR_EditableVehicleComponent));
174 if (!editableVehicleWithRepairBox)
175 {
176 SCR_NotificationsComponent.SendToPlayer(playerId, ENotification.GROUP_TASK_REPAIR_TRUCK_IS_NOT_IN_RANGE);
177 return;
178 }
179
180 // check if it is repair truck
181 SCR_EditableEntityUIInfo info = SCR_EditableEntityUIInfo.Cast(editableVehicleWithRepairBox.GetInfo());
182 if (!info || !info.HasEntityLabel(EEditableEntityLabel.TRAIT_REPAIRING))
183 {
184 SCR_NotificationsComponent.SendToPlayer(playerId, ENotification.GROUP_TASK_REPAIR_TRUCK_IS_NOT_IN_RANGE);
185 return;
186 }
187
188 if (!IsVehiclePartFullyRepaired(actionTarget))
189 return;
190
191 m_TaskSystem.SetTaskState(this, SCR_ETaskState.COMPLETED);
192 DeleteTask();
193 }
194
195 //------------------------------------------------------------------------------------------------
196 protected void AddXPReward()
197 {
198 SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
199 if (!comp || !m_RplComponent || m_RplComponent.IsProxy())
200 return;
201
202 // add XP to all players in the assigned group
203 array<int> assigneePlayerIDs = GetTaskAssigneePlayerIDs();
204 if (!assigneePlayerIDs)
205 return;
206
207 foreach (int playerID : assigneePlayerIDs)
208 {
209 comp.AwardXP(playerID, SCR_EXPRewards.REPAIR_TASK_COMPLETED, 1.0, false);
210 }
211 }
212
213 //------------------------------------------------------------------------------------------------
214 override void SetTaskState(SCR_ETaskState state)
215 {
216 if (state == SCR_ETaskState.COMPLETED)
217 AddXPReward();
218
219 super.SetTaskState(state);
220 }
221
222 //------------------------------------------------------------------------------------------------
223 protected bool IsVehiclePartFullyRepaired(IEntity actionTarget)
224 {
225 SCR_DamageManagerComponent damageComponent = SCR_DamageManagerComponent.GetDamageManager(actionTarget);
226 if (!damageComponent)
227 return false;
228
229 HitZone hitZone = damageComponent.GetDefaultHitZone();
230 return hitZone.GetHealthScaled() == 1;
231 }
232
233 //------------------------------------------------------------------------------------------------
234 protected bool IsVehicleFullyRepaired(IEntity vehicle)
235 {
236 SCR_DamageManagerComponent damageComponent = SCR_DamageManagerComponent.GetDamageManager(vehicle);
237 if (!damageComponent)
238 return false;
239
240 // Check if any hit zone is damaged
241 array<HitZone> hitZones = {};
242 damageComponent.GetAllHitZonesInHierarchy(hitZones);
243 SCR_FlammableHitZone flammableHitZone;
244 foreach (HitZone hitZone : hitZones)
245 {
246 if (hitZone && hitZone.GetDamageState() != EDamageState.UNDAMAGED)
247 return false;
248
249 // Flammable hit zone may be smoking
250 flammableHitZone = SCR_FlammableHitZone.Cast(hitZone);
251 if (flammableHitZone && damageComponent.IsOnFire(flammableHitZone))
252 return false;
253 }
254
255 return true;
256 }
257
258 //------------------------------------------------------------------------------------------------
259 override void EOnInit(IEntity owner)
260 {
261 super.EOnInit(owner);
262
263 if (SCR_Global.IsEditMode(this))
264 return;
265
267
268 if (!System.IsConsoleApp())
269 {
270 GetOnTaskAssigneeAdded().Insert(OnTaskAssigneeAdded);
271 GetOnTaskAssigneeRemoved().Insert(OnTaskAssigneeRemoved);
272 }
273
274 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
275 if (!m_RplComponent || m_RplComponent.IsProxy())
276 return;
277
278 ChimeraWorld world = GetGame().GetWorld();
279 if (world)
280 m_AutoCancelTimestamp = world.GetServerTimestamp().PlusSeconds(m_fAutoCancelTime);
281
283 if (supportStationManager)
284 supportStationManager.GetOnSupportStationExecutedSuccessfully().Insert(OnVehicleRepaired);
285
286 GetGame().GetCallqueue().CallLater(PeriodicalCheck, PERIODICAL_CHECK_INTERVAL, true);
287 }
288
289 //------------------------------------------------------------------------------------------------
291 {
292 GetOnTaskAssigneeAdded().Remove(OnTaskAssigneeAdded);
293 GetOnTaskAssigneeRemoved().Remove(OnTaskAssigneeRemoved);
294 GetGame().GetCallqueue().Remove(CheckDistanceToArea);
295
297 if (supportStationManager)
298 supportStationManager.GetOnSupportStationExecutedSuccessfully().Remove(OnVehicleRepaired);
299
300 GetGame().GetCallqueue().Remove(PeriodicalCheck);
301 }
302}
EEditableEntityLabel
ENotification
ESupportStationType
ArmaReforgerScripted GetGame()
Definition game.c:1398
override bool RplLoad(ScriptBitReader reader)
void DeleteTask()
void PeriodicalCheck()
override void SetTaskState(SCR_ETaskState state)
float m_fAreaRadius
SCR_AttackTaskEntityClass PERIODICAL_CHECK_INTERVAL
float m_fAreaRadiusSq
SCR_BaseGameMode GetGameMode()
RplComponent m_RplComponent
void OnTaskAssigneeAdded(SCR_Task task, SCR_TaskExecutor executor, int requesterID)
void AddXPReward()
float distance
void OnTaskAssigneeRemoved(SCR_Task task, SCR_TaskExecutor executor, int requesterID)
void OnDataLoaded()
bool IsVehiclePartFullyRepaired(IEntity actionTarget)
void StartCheckingDistanceToArea()
const int DISTANCE_CHECK_INTERVAL
WorldTimestamp m_AutoCancelTimestamp
void CheckDistanceToArea()
void StopCheckingDistanceToArea()
void ~SCR_RepairRequestedTaskEntity()
bool IsVehicleFullyRepaired(IEntity vehicle)
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
bool IsTaskAssignedTo(SCR_TaskExecutor executor, out SCR_TaskExecutor match=null)
Definition SCR_Task.c:493
SCR_TaskSystem m_TaskSystem
void OnVehicleRepaired(SCR_BaseSupportStationComponent supportStation, ESupportStationType supportStationType, IEntity actionTarget, IEntity actionUser, SCR_BaseUseSupportStationAction action)
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
proto external IEntity GetRootParent()
bool HasEntityLabel(EEditableEntityLabel label)
static bool IsEditMode()
Definition Functions.c:1566
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
static IEntity GetLocalControlledEntity()
ScriptInvokerBase< SupportStation_OnSupportStationExecuted > GetOnSupportStationExecutedSuccessfully()
static SCR_SupportStationManagerComponent GetInstance()
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
override void EOnInit(IEntity owner)
SCR_FieldOfViewSettings Attribute
EDamageState