1 [
EntityEditorProps(
category:
"GameScripted/DataCollection/", description:
"Main component used for collecting player data.")]
9 protected ref array<ref SCR_DataCollectorModule> m_aModules;
14 [
Attribute(
"3",
desc:
"Optional kicking: Penalty score for killing a friendly player.")]
17 [
Attribute(
"1",
desc:
"Penalty score for killing a friendly AI.")]
20 [
Attribute(
"10",
desc:
"Penalty score limit for a kick from the match.")]
23 [
Attribute(
"1800",
desc:
"Ban duration after a kick (in seconds, -1 for a session-long ban).")]
26 [
Attribute(
"900",
desc:
"How often penalty score subtraction happens (in seconds).")]
29 [
Attribute(
"2",
desc:
"How many penalty points get substracted after each subtraction period.")]
34 protected ref map<int, ref SCR_PlayerData>
m_mPlayerData =
new map<int, ref SCR_PlayerData>();
40 protected ref map<FactionKey, ref array<float>>
m_mFactionScore =
new map<FactionKey, ref array<float>>();
43 protected bool m_bLocalEntityListening =
false;
44 protected int m_iInitializingTimer = 0;
45 protected bool m_bVisualDisplay =
false;
53 module.OnGameModeEnd();
58 PlayerController playerController;
59 SCR_DataCollectorCommunicationComponent communicationComponent;
62 SCR_ChimeraCharacter playerChimera;
72 playerChimera = SCR_ChimeraCharacter.Cast(playerManager.GetPlayerControlledEntity(playerID));
76 faction = playerChimera.GetFaction();
85 array<FactionKey> factionKeys = {};
86 array<float> factionValues = {};
91 factionKeys.Insert(key);
92 factionValues.InsertAll(value);
94 valuesSize = value.Count();
100 playerController = playerManager.GetPlayerController(playerID);
101 if (!playerController)
104 communicationComponent = SCR_DataCollectorCommunicationComponent.Cast(playerController.FindComponent(SCR_DataCollectorCommunicationComponent));
105 if (!communicationComponent)
108 communicationComponent.SendData(
m_mPlayerData.Get(playerID), factionKeys, factionValues, valuesSize);
148 int statsCount = stats.Count();
150 if (statsCount == 0 || factionStats.Count() != statsCount)
152 Print(
"ERROR WHEN ADDING FACTIONSTATS IN DATA COLLECTOR: Size of faction stats is different than expected size! Expected size was" + statsCount +
" but real size was "+ factionStats.Count(), LogLevel.WARNING);
156 for (
int i = 0; i < statsCount; i++)
158 factionStats[i] = factionStats[i] + stats[i];
171 playerData.StoreProfile();
181 for (
int i = m_aModules.Count() - 1; i >= 0; i--)
183 if (m_aModules[i].Type() ==
type)
184 return m_aModules[i];
192 RplComponent rplComponent = RplComponent.Cast(
GetOwner().FindComponent(RplComponent));
193 return (rplComponent && rplComponent.IsMaster());
206 return playerData.GetDataEventStats();
223 if (!playerData && createNew)
225 playerData =
new SCR_PlayerData(playerID,
true, requestFromBackend);
250 Print(
"Player with id " + playerId +
" was auditted succesfully and admitted on the Data Collector", LogLevel.DEBUG);
257 module.OnPlayerAuditSuccess(playerId);
274 module.OnPlayerDisconnected(playerId);
277 playerDisconnectedData.StoreProfile();
286 IEntity player =
GetGame().GetPlayerManager().GetPlayerControlledEntity(playerId);
287 SCR_ChimeraCharacter playerChimera = SCR_ChimeraCharacter.Cast(player);
290 Faction faction = playerChimera.GetFaction();
292 AddStatsToFaction(faction.GetFactionKey(), playerDisconnectedData.CalculateStatsDifference());
308 module.OnPlayerSpawned(playerId, controlledEntity);
317 module.OnPlayerKilled(playerId, playerEntity, killerEntity, killer);
329 module.OnAIKilled(AIEntity, killerEntity, killer);
341 if (!SCR_ChimeraCharacter.Cast(entity))
351 int playerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(entity);
365 void OnPlayerEntityChanged(IEntity from, IEntity to)
369 module.OnControlledEntityChanged(from, to);
375 protected void ListenToLocalControllerEntityChanged()
379 if (playerController)
381 m_bLocalEntityListening =
true;
382 playerController.m_OnControlledEntityChanged.Insert(OnPlayerEntityChanged);
388 protected void CreateStatVisualizations()
393 for (
int i = m_aModules.Count() - 1; i >= 0; i--)
395 m_aModules[i].CreateVisualization();
442 bool writingRights =
false;
443 BackendApi ba =
GetGame().GetBackendApi();
447 SessionStorage baStorage = ba.GetStorage();
449 writingRights = baStorage.GetOnlineWritePrivilege();
454 Print(
"DataCollectorComponent: StartDataCollectorSession: This server has no writing privileges. Will use local storage instead.", LogLevel.DEBUG);
456 Print(
"DataCollectorComponent: StartDataCollectorSession: Using online backend storage.", LogLevel.DEBUG);
459 Print(
"DataCollectorComponent: StartDataCollectorSession: m_Owner is null. Can't add the EntityEvent.FRAME flag thus data collector will not work properly.", LogLevel.ERROR);
461 SetEventMask(
m_Owner, EntityEvent.FRAME);
465 protected override void EOnFrame(IEntity owner,
float timeSlice)
486 if (m_bVisualDisplay != DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_DATA_COLLECTION_ENABLE_DIAG))
489 CreateStatVisualizations();
491 m_bVisualDisplay = DiagMenu.GetBool(
SCR_DebugMenuID.DEBUGUI_DATA_COLLECTION_ENABLE_DIAG);
496 for (
int i = m_aModules.Count() - 1; i >= 0; i--)
498 m_aModules[i].Update(timeSlice);
512 GetGame().RegisterDataCollector(
this);