18 protected ref map<int, ref SCR_DataCollectorDriverModuleContext> m_mTrackedPlayersInVehicles =
new map<int, ref SCR_DataCollectorDriverModuleContext>();
21 protected override void AddInvokers(IEntity player)
23 super.AddInvokers(player);
29 if (!compartmentAccessComponent)
32 compartmentAccessComponent.GetOnCompartmentEntered().Insert(OnCompartmentEntered);
33 compartmentAccessComponent.GetOnCompartmentLeft().Insert(OnCompartmentLeft);
37 protected override void RemoveInvokers(IEntity player)
39 super.RemoveInvokers(player);
45 if (!compartmentAccessComponent)
48 compartmentAccessComponent.GetOnCompartmentEntered().Remove(OnCompartmentEntered);
49 compartmentAccessComponent.GetOnCompartmentLeft().Remove(OnCompartmentLeft);
53 protected void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager,
int mgrID,
int slotID,
bool move)
55 if (!targetEntity || !manager)
57 Print(
"ERROR IN DATACOLLECTOR DRIVER MODULE: TARGETENTITY OR MANAGER ARE EMPTY.", LogLevel.ERROR);
61 BaseCompartmentSlot compartment = manager.FindCompartment(slotID, mgrID);
65 IEntity playerEntity = compartment.GetOccupant();
69 int playerID =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(playerEntity);
77 protected void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager,
int mgrID,
int slotID,
bool move)
79 BaseCompartmentSlot compartment = manager.FindCompartment(slotID, mgrID);
83 int playerID =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(compartment.GetOccupant());
94 ChimeraCharacter playerChimeraCharacter = ChimeraCharacter.Cast(playerContext.m_Player);
95 if (playerChimeraCharacter && playerChimeraCharacter.GetDamageManager().GetState() ==
EDamageState.DESTROYED)
96 PlayerDied(playerID, playerContext);
98 m_mTrackedPlayersInVehicles.Remove(playerID);
130 SCR_BaseCompartmentManagerComponent compartmentManager = SCR_BaseCompartmentManagerComponent.Cast(playerContext.m_Vehicle.FindComponent(SCR_BaseCompartmentManagerComponent));
131 if (!compartmentManager)
134 array<IEntity> occupants = {};
135 compartmentManager.GetOccupants(occupants);
137 if (occupants.Count() <= 1)
141 if (playerContext.m_bPilot)
143 array<IEntity> checkPilot = {};
146 if (checkPilot.IsEmpty())
148 Print(
"DataCollectorDriveModule: Pilot died but according to the compartmentManager there's no pilot. !!!", LogLevel.ERROR);
151 else if (playerContext.m_Player != checkPilot.Get(0))
153 Print(
"DataCollectorDriveModule: The pilot from the context is not the pilot from the compartments. !!", LogLevel.ERROR);
158 GetGame().GetDataCollector().GetPlayerData(PlayerID).AddStat(
SCR_EDataStats.PLAYERS_DIED_IN_VEHICLE, occupants.Count()-1);
163 array<IEntity> pilot = {};
171 int pilotID =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pilot.Get(0));
177 GetGame().GetDataCollector().GetPlayerData(PlayerID).AddStat(
SCR_EDataStats.PLAYERS_DIED_IN_VEHICLE, 1);
182 override void OnPlayerKilled(
int playerId, IEntity playerEntity, IEntity killerEntity, notnull
Instigator killer)
187 if (killer.GetInstigatorType() !=
InstigatorType.INSTIGATOR_PLAYER)
191 int killerId = killer.GetInstigatorPlayerID();
192 if (killerId == playerId)
195 SCR_ChimeraCharacter playerEntityChar = SCR_ChimeraCharacter.Cast(playerEntity);
196 if (!playerEntityChar)
203 Faction factionKiller =
Faction.Cast(factionManager.GetPlayerFaction(killerId));
209 if (!killerContext || !killerContext.m_bPilot)
217 if (factionKiller.IsFactionFriendly(playerEntityChar.GetFaction()))
224 override void OnAIKilled(IEntity AIEntity, IEntity killerEntity, notnull
Instigator killer)
231 if (killer.GetInstigatorType() !=
InstigatorType.INSTIGATOR_PLAYER)
234 int killerId = killer.GetInstigatorPlayerID();
236 SCR_ChimeraCharacter AIEntityChar = SCR_ChimeraCharacter.Cast(AIEntity);
242 if (!killerContext || !killerContext.m_bPilot)
252 Faction factionKiller =
Faction.Cast(factionManager.GetPlayerFaction(killerId));
257 if (factionKiller.IsFactionFriendly(AIEntityChar.GetFaction()))
264 override void OnPlayerDisconnected(
int playerID, IEntity controlledEntity =
null)
266 if (!controlledEntity)
267 controlledEntity =
GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
268 super.OnPlayerDisconnected(playerID, controlledEntity);
270 m_mTrackedPlayersInVehicles.Remove(playerID);
274 override void Update(
float timeTick)
277 if (m_mTrackedPlayersInVehicles.IsEmpty())
286 array<int> playerIDsToRemove = {};
289 if (!playerContext.m_Player || !playerContext.m_Vehicle)
291 Print(
"DataCollectorDriverModule:Update: this context's player or vehicle is null. Player ID: " + playerId +
". Seems wrong", LogLevel.WARNING);
293 if (!playerIDsToRemove.Contains(playerId))
294 playerIDsToRemove.Insert(playerId);
299 Physics physics = playerContext.m_Vehicle.GetPhysics();
302 Print(
"DataCollectorDriverModule:Update: Couldn't find the vehicle's physics. Player ID: " + playerId +
". Player is a pilot: " + playerContext.m_bPilot, LogLevel.WARNING);
304 if (!playerIDsToRemove.Contains(playerId))
305 playerIDsToRemove.Insert(playerId);
311 if (distanceTraveled < 1)
317 if (playerContext.m_bPilot)
319 playerData.AddStat(
SCR_EDataStats.DISTANCE_DRIVEN, distanceTraveled);
323 SCR_BaseCompartmentManagerComponent compartmentManagerComponent = SCR_BaseCompartmentManagerComponent.Cast(playerContext.m_Vehicle.FindComponent(SCR_BaseCompartmentManagerComponent));
324 if (!compartmentManagerComponent)
326 Print(
"DataCollectorDriverModule:Update: Could not add POINTS_AS_DRIVER_OF_PLAYERS because could find this vehicle's compartmentManagerComponent", LogLevel.WARNING);
330 array<IEntity> occupants = {};
331 compartmentManagerComponent.GetOccupants(occupants);
332 int crewSize = occupants.Count();
335 foreach (IEntity occupant : occupants)
337 ChimeraCharacter character = ChimeraCharacter.Cast(occupant);
342 CharacterControllerComponent characterController = character.GetCharacterController();
344 if (!characterController || !characterController.IsDead())
353 playerData.AddStat(
SCR_EDataStats.POINTS_AS_DRIVER_OF_PLAYERS, distanceTraveled * (crewSize - 1) * playerData.GetConfigs().MODIFIER_DRIVER_OF_PLAYERS);
358 playerData.AddStat(
SCR_EDataStats.DISTANCE_AS_OCCUPANT, distanceTraveled);
363 if (m_StatsVisualization)
365 m_StatsVisualization.Get(EDriverModuleStats.MetersDriven).SetText(playerData.GetStat(
SCR_EDataStats.DISTANCE_DRIVEN).ToString());
366 m_StatsVisualization.Get(EDriverModuleStats.MetersAsOccupant).SetText(playerData.GetStat(
SCR_EDataStats.DISTANCE_AS_OCCUPANT).ToString());
367 m_StatsVisualization.Get(EDriverModuleStats.PointsAsDriver).SetText(playerData.GetStat(
SCR_EDataStats.POINTS_AS_DRIVER_OF_PLAYERS).ToString());
368 m_StatsVisualization.Get(EDriverModuleStats.RoadKills).SetText(playerData.GetStat(
SCR_EDataStats.ROADKILLS).ToString());
369 m_StatsVisualization.Get(EDriverModuleStats.AIRoadKills).SetText(playerData.GetStat(
SCR_EDataStats.AI_ROADKILLS).ToString());
370 m_StatsVisualization.Get(EDriverModuleStats.FriendlyRoadKills).SetText(playerData.GetStat(
SCR_EDataStats.FRIENDLY_ROADKILLS).ToString());
371 m_StatsVisualization.Get(EDriverModuleStats.FriendlyAIRoadKills).SetText(playerData.GetStat(
SCR_EDataStats.FRIENDLY_AI_KILLS).ToString());
372 m_StatsVisualization.Get(EDriverModuleStats.PlayersDiedInVehicle).SetText(playerData.GetStat(
SCR_EDataStats.PLAYERS_DIED_IN_VEHICLE).ToString());
377 foreach (
int playerIdToRemove : playerIDsToRemove)
379 m_mTrackedPlayersInVehicles.Remove(playerIdToRemove);
387 override void CreateVisualization()
389 super.CreateVisualization();
390 if (!m_StatsVisualization)
393 CreateEntry(
"Meters driven: ", 0, EDriverModuleStats.MetersDriven);
394 CreateEntry(
"Meters as Occupant: ", 0, EDriverModuleStats.MetersAsOccupant);
395 CreateEntry(
"Points as Driver of ppl: ", 0, EDriverModuleStats.PointsAsDriver);
396 CreateEntry(
"RoadKills: ", 0, EDriverModuleStats.RoadKills);
397 CreateEntry(
"AI RoadKills: ", 0, EDriverModuleStats.AIRoadKills);
398 CreateEntry(
"Friendly RoadKills: ", 0, EDriverModuleStats.FriendlyRoadKills);
399 CreateEntry(
"Friendly AI RoadKills: ", 0, EDriverModuleStats.FriendlyAIRoadKills);
400 CreateEntry(
"DeadPlayers at ur Vehicle: ", 0, EDriverModuleStats.PlayersDiedInVehicle);
406 enum EDriverModuleStats