Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayerProfileManagerComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/GameMode", description: "Takes care of loading and storing player profile data.", color: "0 0 255 255")]
3 {
4 }
5 
7 {
8  //************************//
9  //RUNTIME STATIC VARIABLES//
10  //************************//
11  protected static SCR_RespawnSystemComponent s_RespawnSystemComponent = null;
12 
13  //*****************//
14  //MEMBER ATTRIBUTES//
15  //*****************//
16  [Attribute("1", "Refresh time for profile loading. [s]")]
17  protected float m_fRefreshTime;
18 
19  //************************//
20  //RUNTIME MEMBER VARIABLES//
21  //************************//
22  protected ref map<int, ref CareerBackendData> m_mPlayerProfiles = null;
23  protected ref array<int> m_aPlayerIDsToLoadProfile = {};
24  protected float m_fCurrentRefreshTime = 1;
26 
27  //------------------------------------------------------------------------------------------------
28  protected Faction GetPlayerFaction(int playerID)
29  {
30  return SCR_FactionManager.SGetPlayerFaction(playerID);
31  }
32 
33  //------------------------------------------------------------------------------------------------
37  {
39  return m_mPlayerProfiles.Get(playerID);
40 
41  return null;
42  }
43 
44  //------------------------------------------------------------------------------------------------
48  override void HandleOnFactionAssigned(int playerID, Faction assignedFaction)
49  {
50  if (!assignedFaction)
51  return;
52 
53  CareerBackendData playerProfile = GetPlayerProfile(playerID);
54 
55  if (!playerProfile)
56  return;
57 
58  playerProfile.SetFaction(assignedFaction.GetFactionKey());
59  }
60 
61  //------------------------------------------------------------------------------------------------
67  protected override void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
68  {
69  super.OnPlayerKilled(playerId, playerEntity, killerEntity, killer);
70 
71  CareerBackendData victimProfile = GetPlayerProfile(playerId);
72  int killerId = killer.GetInstigatorPlayerID();
73 
74  // Victim profile exists
75  if (victimProfile)
76  {
77  // Add death no matter what
78  victimProfile.AddDeath();
79 
80  // Suicide?
81  if (playerId == killerId)
82  {
83  // Return, the rest of the code is irrelevant in this case, don't add kill to anyone
84  return;
85  }
86  }
87 
88  CareerBackendData killerProfile = GetPlayerProfile(killerId);
89  Faction victimFaction = GetPlayerFaction(playerId);
90  Faction killerFaction = GetPlayerFaction(killerId);
91 
92  // Killer profile exists
93  if (killerProfile)
94  {
95  // Both killer & victim factions exist
96  if (killerFaction && victimFaction)
97  {
98  // Check faction friendliness
99  if (killerFaction.IsFactionFriendly(victimFaction))
100  {
101  // Bad luck, the factions were friendly, add team kill
102  killerProfile.AddKill(true);
103 
104  // Return, we don't want to add a regular kill to this team-killing monster
105  return;
106  }
107  }
108 
109  // It wasn't a team kill, add a regular kill
110  killerProfile.AddKill();
111  }
112  }
113 
114  //------------------------------------------------------------------------------------------------
119  override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
120  {
121  StoreProfile(playerId, true);
122  }
123 
124  //------------------------------------------------------------------------------------------------
128  void StoreProfile(int playerID, bool disconnecting = false)
129  {
130  if (!GetGame().GetBackendApi())
131  return;
132 
133  CareerBackendData playerProfile = GetPlayerProfile(playerID);
134 
135  SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
136 
137  if (!playerProfile || !m_Callback || !campaign)
138  return;
139 
140  if (disconnecting)
141  playerProfile.SetLogoutTime();
142 
143  #ifndef WORKBENCH
144  GetGame().GetBackendApi().PlayerRequest(EBackendRequest.EBREQ_GAME_CharacterUpdateS2S,m_Callback,playerProfile,playerID);
145  #else
146  GetGame().GetBackendApi().PlayerRequest(EBackendRequest.EBREQ_GAME_DevCharacterUpdate,m_Callback,playerProfile,playerID);
147  #endif
148  }
149 
150  //------------------------------------------------------------------------------------------------
154  bool LoadPlayerProfileFromBackend(int playerID)
155  {
156  if (m_mPlayerProfiles && GetGame().GetBackendApi())
157  {
158  if (GetGame().GetBackendApi().GetDSSession() && GetGame().GetBackendApi().GetDSSession().Status() == EDsSessionState.EDSESSION_ACTIVE)
159  {
160  CareerBackendData playerProfile = new CareerBackendData();
161  m_mPlayerProfiles.Set(playerID, playerProfile);
162  playerProfile = GetPlayerProfile(playerID);
163 
164  if (m_Callback)
165  GetGame().GetBackendApi().PlayerData(playerProfile, playerID);
166 
167  return true;
168  }
169  else
170  {
171  return false;
172  }
173  }
174 
175  return false;
176  }
177 
178  //------------------------------------------------------------------------------------------------
181  void LoadConnectingPlayerProfile(int playerID)
182  {
183  if (!LoadPlayerProfileFromBackend(playerID))
184  {
185  m_aPlayerIDsToLoadProfile.Insert(playerID);
186  }
187  else
188  {
189  CareerBackendData playerProfile = GetPlayerProfile(playerID);
190 
191  if (!playerProfile)
192  return;
193 
194  playerProfile.SetLoginTime();
195  }
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  override void EOnFrame(IEntity owner, float timeSlice)
200  {
201  m_fCurrentRefreshTime -= timeSlice;
202 
203  if (m_fCurrentRefreshTime > 0)
204  return;
205 
207 
208  for (int count = m_aPlayerIDsToLoadProfile.Count(), i = count - 1; i >= 0; i--)
209  {
211 
212  if (success)
213  {
215 
216  if (!playerProfile)
217  return;
218 
219  playerProfile.SetLoginTime();
220  m_aPlayerIDsToLoadProfile.Remove(i);
221  }
222  }
223  }
224 
225  //------------------------------------------------------------------------------------------------
226  override void OnPostInit(IEntity owner)
227  {
228  SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME);
229  owner.SetFlags(EntityFlags.NO_TREE | EntityFlags.NO_LINK);
230  }
231 
232  //------------------------------------------------------------------------------------------------
233  override void EOnInit(IEntity owner)
234  {
236  m_mPlayerProfiles = new map<int, ref CareerBackendData>();
237  SCR_RespawnSystemComponent respawnSystem = SCR_RespawnSystemComponent.Cast(owner.FindComponent(SCR_RespawnSystemComponent));
238 
239  if (!respawnSystem)
240  {
241  Print("There is no RespawnSystemComponent attached to the GameMode entity. Faction scoring will not work.", LogLevel.WARNING);
242  return;
243  }
244 
245  s_RespawnSystemComponent = respawnSystem;
246  }
247 
248  //------------------------------------------------------------------------------------------------
249  // constructor
253  void SCR_PlayerProfileManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
254  {
255  }
256 }
m_fCurrentRefreshTime
protected float m_fCurrentRefreshTime
Definition: SCR_PlayerProfileManagerComponent.c:24
GetPlayerFaction
protected Faction GetPlayerFaction(int playerID)
Definition: SCR_PlayerProfileManagerComponent.c:28
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_fRefreshTime
protected float m_fRefreshTime
Definition: SCR_PlayerProfileManagerComponent.c:17
s_RespawnSystemComponent
SCR_PlayerProfileManagerComponentClass s_RespawnSystemComponent
EOnFrame
override void EOnFrame(IEntity owner, float timeSlice)
Definition: SCR_PlayerProfileManagerComponent.c:199
CampaignCallback
Definition: CareerBackend.c:271
m_Callback
protected ref CampaignCallback m_Callback
Definition: SCR_PlayerProfileManagerComponent.c:25
StoreProfile
void StoreProfile(int playerID, bool disconnecting=false)
Definition: SCR_PlayerProfileManagerComponent.c:128
KickCauseCode
KickCauseCode
Definition: KickCauseCode.c:19
SCR_PlayerProfileManagerComponent
void SCR_PlayerProfileManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_PlayerProfileManagerComponent.c:253
Instigator
Definition: Instigator.c:6
m_mPlayerProfiles
protected ref map< int, ref CareerBackendData > m_mPlayerProfiles
Definition: SCR_PlayerProfileManagerComponent.c:22
SCR_GameModeCampaign
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
Definition: SCR_GameModeCampaign.c:1927
SCR_PlayerProfileManagerComponentClass
Definition: SCR_PlayerProfileManagerComponent.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
OnPlayerKilled
protected override void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
Definition: SCR_PlayerProfileManagerComponent.c:67
GetPlayerProfile
CareerBackendData GetPlayerProfile(int playerID)
Definition: SCR_PlayerProfileManagerComponent.c:36
LoadPlayerProfileFromBackend
bool LoadPlayerProfileFromBackend(int playerID)
Definition: SCR_PlayerProfileManagerComponent.c:154
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_PlayerProfileManagerComponent.c:226
CareerBackendData
Definition: CareerBackend.c:43
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_PlayerProfileManagerComponent.c:233
Faction
Definition: Faction.c:12
LoadConnectingPlayerProfile
void LoadConnectingPlayerProfile(int playerID)
Definition: SCR_PlayerProfileManagerComponent.c:181
m_aPlayerIDsToLoadProfile
protected ref array< int > m_aPlayerIDsToLoadProfile
Definition: SCR_PlayerProfileManagerComponent.c:23
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
HandleOnFactionAssigned
override void HandleOnFactionAssigned(int playerID, Faction assignedFaction)
What happens when a player is assigned a faction.
Definition: SCR_PlayerProfileManagerComponent.c:48
OnPlayerDisconnected
override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
Definition: SCR_PlayerProfileManagerComponent.c:119
SCR_BaseGameModeComponentClass
Definition: SCR_BaseGameModeComponent.c:2
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BaseGameModeComponent.c:199