Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AnalyticsDataCollectionComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/DataCollection/", description: "Component used for collecting analytics data.")]
5
6class SCR_AnalyticsDataCollectionComponent : SCR_BaseGameModeComponent
7{
8 [Attribute()]
9 protected ref array<ref SCR_AnalyticsDataCollectionModule> m_aModules;
10
11 [Attribute("900", params: "1 inf", desc: "Time in seconds between SessionMeasures events")]
13
14 protected IEntity m_Owner;
15
16 protected float m_fSessionMeasuresTimer;
17
18 #ifdef ENABLE_DIAG
19 protected int m_iCurrentModuleId;
20 protected SCR_AnalyticsDataCollectionModule m_CurrentModule;
21 protected ref array<string> m_aModuleNames;
22 #endif
23
24 //------------------------------------------------------------------------------------------------
25 protected override void OnGameModeStart()
26 {
27 // Track stats only on server
28 RplComponent rplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
29 bool isMaster = (rplComponent && rplComponent.IsMaster());
30 if (!isMaster)
31 return;
32
33 if (!m_Owner)
34 Print("AnalyticsDataCollectionComponent: OnGameModeStart: m_Owner is null. Can't add the EntityEvent.FRAME flag thus data collector might not work properly.", LogLevel.ERROR);
35 else
36 SetEventMask(m_Owner, EntityEvent.FRAME); //Activate the FRAME flag
37
38 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
39 {
40 module.InitModule();
41 }
42
43 if (GetGame().GetPlayerManager().GetPlayerCount() == 0)
44 m_fSessionMeasuresTimer = float.INFINITY;
45 else
47 }
48
49 //------------------------------------------------------------------------------------------------
50 protected override void OnGameModeEnd(SCR_GameModeEndData data)
51 {
52 // Track stats only on server
53 RplComponent rplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
54 bool isMaster = (rplComponent && rplComponent.IsMaster());
55 if (!isMaster)
56 return;
57
58 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
59 {
60 module.OnGameModeEnd();
61 }
62 }
63
64 //------------------------------------------------------------------------------------------------
65 protected override void OnGameEnd()
66 {
67 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
68 {
69 module.OnGameEnd();
70 }
71 }
72
73 //------------------------------------------------------------------------------------------------
74 protected override void OnPlayerConnected(int playerId)
75 {
76 SCR_DataCollectorComponent dataCollector = GetGame().GetDataCollector();
77 if (dataCollector)
78 dataCollector.RemovePlayer(playerId);
79
80 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
81 {
82 module.OnPlayerConnected(playerId);
83 }
84
85 if (GetGame().GetPlayerManager().GetPlayerCount() == 1)
87 }
88
89 //------------------------------------------------------------------------------------------------
90 protected override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
91 {
92 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
93 {
94 module.OnPlayerDisconnected(playerId, cause);
95 }
96
97 if (GetGame().GetPlayerManager().GetPlayerCount() == 0)
98 m_fSessionMeasuresTimer = float.INFINITY;
99 }
100
101 //------------------------------------------------------------------------------------------------
102 protected override void OnPlayerSpawnFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
103 {
104 int playerId = requestComponent.GetPlayerId();
105 if (playerId == 0)
106 {
107 Print("AnalyticsDataCollectionComponent: OnPlayerSpawnFinalize_S: playerId is 0.", LogLevel.ERROR);
108 return;
109 }
110
111 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
112 {
113 module.OnPlayerSpawned(requestComponent, playerId, data, entity);
114 }
115 }
116
117 //------------------------------------------------------------------------------------------------
118 protected override void OnControllableDestroyed(notnull SCR_InstigatorContextData instigatorContextData)
119 {
120 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
121 {
122 module.OnControllableDestroyed(instigatorContextData);
123 }
124 }
125
126 //------------------------------------------------------------------------------------------------
131 {
132 for (int i = m_aModules.Count() - 1; i >= 0; i--)
133 {
134 if (m_aModules[i].Type() == type)
135 return m_aModules[i];
136 }
137 return null;
138 }
139
140 //------------------------------------------------------------------------------------------------
143 array<ref SCR_AnalyticsDataCollectionModule> GetAllModules()
144 {
145 return m_aModules;
146 }
147
148 //------------------------------------------------------------------------------------------------
153 {
154 if (!m_aModules.IsIndexValid(id))
155 return null;
156
157 return m_aModules.Get(id);
158 }
159
160 //------------------------------------------------------------------------------------------------
163 {
164 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
165 {
166 module.Disable();
167 }
168 }
169
170 //------------------------------------------------------------------------------------------------
171 protected override void EOnFrame(IEntity owner, float timeSlice)
172 {
173 m_fSessionMeasuresTimer -= timeSlice;
174
175 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
176 {
177 module.Update(timeSlice);
178
180 module.SessionMeasures();
181 }
182
185 }
186
187 //------------------------------------------------------------------------------------------------
188 protected void SessionMeasures()
189 {
190 if (GetGame().GetPlayerManager().GetPlayerCount() == 0)
191 {
193 return;
194 }
195
196 SCR_DataCollectorComponent dataCollector = GetGame().GetDataCollector();
197 if (!dataCollector)
198 return;
199
200 SCR_SessionData sessionData = dataCollector.GetSessionData();
201 if (!sessionData)
202 return;
203
204 sessionData.SetSessionTimeAndPlayers();
205
206 SCR_SessionDataEvent sessionEvent = sessionData.GetSessionDataEvent();
207 if (!sessionEvent)
208 return;
209
210 GetGame().GetStatsApi().SessionMeasures(sessionEvent);
211
213 }
214
215 //------------------------------------------------------------------------------------------------
216 protected override void OnPostInit(IEntity owner)
217 {
218 m_Owner = owner;
219
220 #ifdef ENABLE_DIAG
221 RegisterToDiag();
222 #endif
223 }
224
225 //------------------------------------------------------------------------------------------------
226 protected override void OnDelete(IEntity owner)
227 {
228 super.OnDelete(owner);
229
230 #ifdef ENABLE_DIAG
231 DisconnectFromDiagSystem(owner);
232 #endif
233 }
234
235 #ifdef ENABLE_DIAG
236 //------------------------------------------------------------------------------------------------
237 protected void RegisterToDiag()
238 {
239 ConnectToDiagSystem(m_Owner);
240 DiagMenu.RegisterMenu(SCR_DebugMenuID.DEBUGUI_ANALYTICS_DATA_COLLECTION, "Analytics Data Collection", "Statistics");
241 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_ANALYTICS_DATA_COLLECTION_ENABLE_DIAG, "", "Enable debug menu", "Analytics Data Collection");
242 m_aModuleNames = new array<string>();
243
244 foreach (SCR_AnalyticsDataCollectionModule module : m_aModules)
245 {
246 m_aModuleNames.Insert(SCR_AnalyticsDataCollectionHelper.GetShortModuleName(module.ToString()));
247 }
248 }
249
250 //------------------------------------------------------------------------------------------------
251 override void EOnDiag(IEntity owner, float timeSlice)
252 {
253 if (!DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_ANALYTICS_DATA_COLLECTION_ENABLE_DIAG))
254 return;
255
256 DrawDiag();
257 }
258
259 //------------------------------------------------------------------------------------------------
260 void DrawDiag()
261 {
262 if (m_aModules.IsEmpty())
263 {
264 DbgUI.Text("No Analytics Data Collection modules found.");
265 return;
266 }
267
268 m_CurrentModule = GetModuleById(m_iCurrentModuleId);
269 int selectedModuleId = m_iCurrentModuleId;
270
271 DbgUI.Begin("SCR_AnalyticsDataCollectionComponent");
272 {
273 DbgUI.Combo("Module: ", selectedModuleId, m_aModuleNames);
274
275 if (selectedModuleId != m_iCurrentModuleId)
276 OnSetCurrentModule(selectedModuleId);
277
278 if (DbgUI.Button("Enable Module"))
279 m_CurrentModule.Enable();
280
281 DbgUI.SameLine();
282
283 if (DbgUI.Button("Disable Module"))
284 m_CurrentModule.Disable();
285
286 DbgUI.Spacer(16);
287
288 m_CurrentModule.DrawContent();
289 }
290 DbgUI.End();
291 }
292
293 //------------------------------------------------------------------------------------------------
294 void OnSetCurrentModule(int id)
295 {
296 int newModuleId = Math.ClampInt(id, 0, m_aModules.Count() - 1);
297 if (m_iCurrentModuleId == newModuleId)
298 return;
299
300 m_iCurrentModuleId = newModuleId;
301 m_CurrentModule = GetModuleById(m_iCurrentModuleId);
302 }
303 #endif
304}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
void DisableAllModules()
Disables all analytics data collection modules.
SCR_AnalyticsDataCollectionModule GetModuleById(int id)
override void OnGameModeEnd(SCR_GameModeEndData data)
array< ref SCR_AnalyticsDataCollectionModule > GetAllModules()
override void OnGameEnd()
Called on all machines when the world ends.
SCR_AnalyticsDataCollectionModule FindModule(typename type)
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
override void OnGameModeStart()
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
EDamageType type
Get all prefabs that have the spawner data
int GetPlayerCount()
void OnControllableDestroyed(IEntity entity, IEntity killerEntity, Instigator instigator, notnull SCR_InstigatorContextData instigatorContextData)
override void EOnFrame(IEntity owner, float timeSlice)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
override void OnPlayerSpawnFinalize_S(SCR_SpawnRequestComponent requestComponent, SCR_SpawnHandlerComponent handlerComponent, SCR_SpawnData data, IEntity entity)
int Type
enum EVehicleType IEntity
SCR_SessionDataEvent GetSessionDataEvent()
void SetSessionTimeAndPlayers()
IEntity GetOwner()
Owner entity of the fuel tank.
override void EOnDiag(IEntity owner, float timeSlice)
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
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
void OnPlayerConnected(int playerId)