Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ReinforceRequestedTaskEntity.c
Go to the documentation of this file.
4
5class SCR_ReinforceRequestedTaskEntity : SCR_BaseRequestedTaskEntity
6{
7 protected const int PERIODICAL_CHECK_INTERVAL = 2000; // ms
8
9 [Attribute("150", UIWidgets.EditBox, "Area radius [m]", "0 inf")]
10 protected float m_fAreaRadius;
11
12 [Attribute("300", UIWidgets.EditBox, "[s] time since activation when the task fail", "0 inf")]
13 protected float m_fFailTime;
14
15 protected ref array<int> m_aArrivedPlayers = {};
16 protected ref array<int> m_aDeadPlayers = {};
18 protected float m_fAreaRadiusSq;
19 protected RplComponent m_RplComponent;
21 protected bool m_bWasAnyPlayerInArea;
22 protected bool m_bIsAreaCheckRunning;
24
25 //------------------------------------------------------------------------------------------------
26 protected void AddXPReward()
27 {
28 SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
29 if (!comp || !m_RplComponent || m_RplComponent.IsProxy())
30 return;
31
32 // add XP to all players in the assigned group
33 array<int> assigneePlayerIDs = GetTaskAssigneePlayerIDs();
34 if (!assigneePlayerIDs)
35 return;
36
37 foreach (int playerID : assigneePlayerIDs)
38 {
39 comp.AwardXP(playerID, SCR_EXPRewards.REINFORCE_TASK_COMPLETED, 1.0, false);
40 }
41 }
42
43 //------------------------------------------------------------------------------------------------
44 override void SetTaskState(SCR_ETaskState state)
45 {
46 if (state == SCR_ETaskState.COMPLETED)
48
49 super.SetTaskState(state);
50 }
51
52 //------------------------------------------------------------------------------------------------
53 protected void StartCheckingArea()
54 {
56 return;
57
59 return;
60
62 GetGame().GetCallqueue().CallLater(CheckReinforcementArea, SCR_GameModeCampaign.DEFAULT_DELAY, true);
63 }
64
65 //------------------------------------------------------------------------------------------------
66 protected void StopCheckingArea()
67 {
69 return;
70
72 GetGame().GetCallqueue().Remove(CheckReinforcementArea);
73 }
74
75 //------------------------------------------------------------------------------------------------
76 protected void PeriodicalCheck()
77 {
78 ChimeraWorld world = GetGame().GetWorld();
79 if (!world)
80 return;
81
82 PlayerManager pManager = GetGame().GetPlayerManager();
83 SCR_ChimeraCharacter character;
84 CharacterControllerComponent charControl;
85 array<int> assigneePlayerIDs = GetTaskAssigneePlayerIDs();
86 if (!assigneePlayerIDs)
87 return;
88
89 foreach (int playerId : assigneePlayerIDs)
90 {
91 character = SCR_ChimeraCharacter.Cast(pManager.GetPlayerControlledEntity(playerId));
92 if (!character)
93 continue;
94
95 charControl = character.GetCharacterController();
96 if (!charControl || charControl.IsDead())
97 continue;
98
99 if (vector.DistanceSqXZ(character.GetOrigin(), GetTaskPosition()) > m_fAreaRadiusSq)
100 continue;
101
103 {
104 m_TaskActivatedTimestamp = world.GetServerTimestamp();
106 }
107
108 if (!m_aArrivedPlayers.Contains(playerId))
109 {
110 m_aArrivedPlayers.Insert(playerId);
111
112 #ifdef REINFORCE_TASK_DEBUG
113 Print("Reinforce requested task, playerId "+playerId+" is registered to evaluation player list", LogLevel.DEBUG);
114 #endif
115 }
116 }
117
118 int halfAssignedPlayers = assigneePlayerIDs.Count() * 0.5;
119
120 #ifdef REINFORCE_TASK_DEBUG
122 PrintFormat("Reinforce requested task, fail timer remaining time:%1", world.GetServerTimestamp().DiffSeconds(m_TaskActivatedTimestamp.PlusSeconds(m_fFailTime)), level: LogLevel.DEBUG);
123 #endif
124
125 if (m_aArrivedPlayers.Count() > (halfAssignedPlayers))
126 {
127 #ifdef REINFORCE_TASK_DEBUG
128 Print("Reinforce requested task, completed", LogLevel.DEBUG);
129 #endif
130
131 m_TaskSystem.SetTaskState(this, SCR_ETaskState.COMPLETED);
132 DeleteTask();
133 return;
134 }
135
136 if (m_aDeadPlayers.Count() > halfAssignedPlayers ||
137 m_bWasAnyPlayerInArea && world.GetServerTimestamp().GreaterEqual(m_TaskActivatedTimestamp.PlusSeconds(m_fFailTime)))
138 {
139 #ifdef REINFORCE_TASK_DEBUG
140 Print("Reinforce requested task, failed", LogLevel.DEBUG);
141 #endif
142
143 m_TaskSystem.SetTaskState(this, SCR_ETaskState.FAILED);
144 DeleteTask();
145 }
146 }
147
148 //------------------------------------------------------------------------------------------------
149 protected void CheckReinforcementArea()
150 {
152 if (!player)
153 return;
154
155 #ifdef REINFORCE_TASK_DEBUG
156 Print("Reinforce requested task, CheckReinforcementArea", level: LogLevel.DEBUG);
157 #endif
158
159 if (!m_bWasLocalPlayerInArea && vector.DistanceSqXZ(player.GetOrigin(), GetTaskPosition()) <= m_fAreaRadiusSq)
160 {
162 SCR_NotificationsComponent.SendLocal(ENotification.GROUP_TASK_REINFORCE_ENTERED_AREA);
164 }
165 }
166
167 //------------------------------------------------------------------------------------------------
168 protected void OnControllableDestroyed(notnull SCR_InstigatorContextData instigatorContextData)
169 {
170 int victimPlayerID = instigatorContextData.GetVictimPlayerID();
171
172 if (victimPlayerID == 0)
173 return;
174
175 if (!IsTaskAssignedTo(SCR_TaskExecutorPlayer.FromPlayerID(victimPlayerID)))
176 return;
177
178 // add a player to the dead player list if he dies
179 if (!m_aDeadPlayers.Contains(victimPlayerID))
180 {
181 m_aDeadPlayers.Insert(victimPlayerID);
182
183 #ifdef REINFORCE_TASK_DEBUG
184 PrintFormat("Reinforce requested task, playerID:%1 was killed and added to dead player list", victimPlayerID, level: LogLevel.DEBUG);
185 #endif
186 }
187 }
188
189 //------------------------------------------------------------------------------------------------
190 protected void OnTaskAssigneeAdded(SCR_Task task, SCR_TaskExecutor executor, int requesterID)
191 {
192 if (task != this)
193 return;
194
196 }
197
198 //------------------------------------------------------------------------------------------------
199 protected void OnTaskAssigneeRemoved(SCR_Task task, SCR_TaskExecutor executor, int requesterID)
200 {
201 if (task != this)
202 return;
203
205 }
206
207 //------------------------------------------------------------------------------------------------
208 protected void OnDataLoaded()
209 {
211 }
212
213 //------------------------------------------------------------------------------------------------
214 override bool RplLoad(ScriptBitReader reader)
215 {
216 bool loaded = super.RplLoad(reader);
217 if (loaded)
218 OnDataLoaded();
219
220 return loaded;
221 }
222
223 //------------------------------------------------------------------------------------------------
224 override void EOnInit(IEntity owner)
225 {
226 super.EOnInit(owner);
227
228 if (SCR_Global.IsEditMode(this))
229 return;
230
232 if (!gameMode)
233 return;
234
236 m_RplComponent = RplComponent.Cast(owner.FindComponent(RplComponent));
238
239 if (!System.IsConsoleApp())
240 {
241 GetOnTaskAssigneeAdded().Insert(OnTaskAssigneeAdded);
242 GetOnTaskAssigneeRemoved().Insert(OnTaskAssigneeRemoved);
243 }
244
245 if (!m_RplComponent || m_RplComponent.IsProxy())
246 return;
247
248 GetGame().GetCallqueue().CallLater(PeriodicalCheck, PERIODICAL_CHECK_INTERVAL, true);
250 }
251
252 //------------------------------------------------------------------------------------------------
254 {
255 GetOnTaskAssigneeAdded().Remove(OnTaskAssigneeAdded);
256 GetOnTaskAssigneeRemoved().Remove(OnTaskAssigneeRemoved);
257 GetGame().GetCallqueue().Remove(PeriodicalCheck);
258 GetGame().GetCallqueue().Remove(CheckReinforcementArea);
259
261 if (!gameMode)
262 return;
263
265 }
266}
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
override bool RplLoad(ScriptBitReader reader)
void DeleteTask()
void PeriodicalCheck()
override void SetTaskState(SCR_ETaskState state)
float m_fAreaRadius
WorldTimestamp m_TaskActivatedTimestamp
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()
void OnTaskAssigneeRemoved(SCR_Task task, SCR_TaskExecutor executor, int requesterID)
void OnDataLoaded()
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void OnControllableDestroyed(IEntity entity, IEntity killerEntity, Instigator instigator, notnull SCR_InstigatorContextData instigatorContextData)
SCR_GroupsManagerComponent m_GroupsManager
ref array< int > m_aArrivedPlayers
void CheckReinforcementArea()
ref array< int > m_aDeadPlayers
array of playerIDs
void ~SCR_ReinforceRequestedTaskEntity()
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
proto external Managed FindComponent(typename typeName)
proto external vector GetOrigin()
ScriptInvokerBase< SCR_BaseGameMode_OnControllableDestroyed > GetOnControllableDestroyed()
static bool IsEditMode()
Definition Functions.c:1566
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
static IEntity GetLocalControlledEntity()
override void EOnInit(IEntity owner)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute