Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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")]
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 //************************//
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 //------------------------------------------------------------------------------------------------
45 protected override void OnPlayerKilled(notnull SCR_InstigatorContextData instigatorContextData)
46 {
47 super.OnPlayerKilled(instigatorContextData);
48
49 CareerBackendData victimProfile = GetPlayerProfile(instigatorContextData.GetVictimPlayerID());
50 int killerId = instigatorContextData.GetKillerPlayerID();
51
52 // If victim profile exists, then add death no matter what
53 if (victimProfile)
54 victimProfile.AddDeath();
55
56 //~ Not a player kill so ignore (Like suicide)
57 if (!instigatorContextData.HasAnyVictimKillerRelation(SCR_ECharacterDeathStatusRelations.KILLED_BY_ENEMY_PLAYER | SCR_ECharacterDeathStatusRelations.KILLED_BY_FRIENDLY_PLAYER))
58 return;
59
60 //~ Possessed AI kills are never counted. Though any kills made without possessing, admin or not, will count
61 SCR_ECharacterControlType killerControlType = instigatorContextData.GetKillerCharacterControlType();
62 if (killerControlType == SCR_ECharacterControlType.POSSESSED_AI)
63 return;
64
65 //~ Check if killer profile exists
66 CareerBackendData killerProfile = GetPlayerProfile(killerId);
67 if (!killerProfile)
68 return;
69
70 //~ Is a teamkill, so add teamkill to profile
71 if (instigatorContextData.HasAnyVictimKillerRelation(SCR_ECharacterDeathStatusRelations.KILLED_BY_FRIENDLY_PLAYER))
72 {
73 if (instigatorContextData.DoesPlayerKillCountAsTeamKill())
74 killerProfile.AddKill(true);
75 return;
76 }
77
78 // It wasn't a team kill, add a regular kill
79 killerProfile.AddKill();
80 }
81
82 //------------------------------------------------------------------------------------------------
87 override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
88 {
89 StoreProfile(playerId, true);
90 }
91
92 //------------------------------------------------------------------------------------------------
96 void StoreProfile(int playerID, bool disconnecting = false)
97 {
98 if (!GetGame().GetBackendApi())
99 return;
100
101 CareerBackendData playerProfile = GetPlayerProfile(playerID);
102
103 SCR_GameModeCampaign campaign = SCR_GameModeCampaign.GetInstance();
104
105 if (!playerProfile || !m_Callback || !campaign)
106 return;
107
108 if (disconnecting)
109 playerProfile.SetLogoutTime();
110
111 BackendApi backendAPI = GetGame().GetBackendApi();
112
113 #ifndef WORKBENCH
114 backendAPI.PlayerCharacterUpdateS2S(m_Callback, playerProfile, playerID);
115 #else
116 backendAPI.PlayerDevCharacterUpdate(m_Callback, playerProfile, playerID);
117 #endif
118 }
119
120 //------------------------------------------------------------------------------------------------
125 {
126 if (m_mPlayerProfiles && GetGame().GetBackendApi())
127 {
128 if (GetGame().GetBackendApi().GetDSSession() && GetGame().GetBackendApi().GetDSSession().Status() == EDsSessionState.EDSESSION_ACTIVE)
129 {
130 CareerBackendData playerProfile = new CareerBackendData();
131 m_mPlayerProfiles.Set(playerID, playerProfile);
132 playerProfile = GetPlayerProfile(playerID);
133
134 if (m_Callback)
135 GetGame().GetBackendApi().PlayerData(playerProfile, playerID);
136
137 return true;
138 }
139 else
140 {
141 return false;
142 }
143 }
144
145 return false;
146 }
147
148 //------------------------------------------------------------------------------------------------
152 {
153 if (!LoadPlayerProfileFromBackend(playerID))
154 {
155 m_aPlayerIDsToLoadProfile.Insert(playerID);
156 }
157 else
158 {
159 CareerBackendData playerProfile = GetPlayerProfile(playerID);
160
161 if (!playerProfile)
162 return;
163
164 playerProfile.SetLoginTime();
165 }
166 }
167
168 //------------------------------------------------------------------------------------------------
169 override void EOnFrame(IEntity owner, float timeSlice)
170 {
171 m_fCurrentRefreshTime -= timeSlice;
172
173 if (m_fCurrentRefreshTime > 0)
174 return;
175
177
178 for (int count = m_aPlayerIDsToLoadProfile.Count(), i = count - 1; i >= 0; i--)
179 {
181
182 if (success)
183 {
185
186 if (!playerProfile)
187 return;
188
189 playerProfile.SetLoginTime();
191 }
192 }
193 }
194
195 //------------------------------------------------------------------------------------------------
196 override void OnPostInit(IEntity owner)
197 {
198 SetEventMask(owner, EntityEvent.INIT | EntityEvent.FRAME);
199 owner.SetFlags(EntityFlags.NO_TREE | EntityFlags.NO_LINK);
200 }
201
202 //------------------------------------------------------------------------------------------------
203 override void EOnInit(IEntity owner)
204 {
207 SCR_RespawnSystemComponent respawnSystem = SCR_RespawnSystemComponent.Cast(owner.FindComponent(SCR_RespawnSystemComponent));
208
209 if (!respawnSystem)
210 {
211 Print("There is no RespawnSystemComponent attached to the GameMode entity. Faction scoring will not work.", LogLevel.WARNING);
212 return;
213 }
214
215 s_RespawnSystemComponent = respawnSystem;
216 }
217
218 //------------------------------------------------------------------------------------------------
219 // constructor
226}
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void OnPlayerKilled(notnull SCR_InstigatorContextData instigatorContextData)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
SCR_ECharacterControlType
What kind of controller the character or (in some cases vehicle) has, eg: AI, Player,...
void SCR_FactionManager(IEntitySource src, IEntity parent)
void SCR_GameModeCampaign(IEntitySource src, IEntity parent)
bool LoadPlayerProfileFromBackend(int playerID)
override void EOnFrame(IEntity owner, float timeSlice)
void SCR_PlayerProfileManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
CareerBackendData GetPlayerProfile(int playerID)
ref BackendCallback m_Callback
ref map< int, ref CareerBackendData > m_mPlayerProfiles
void StoreProfile(int playerID, bool disconnecting=false)
void LoadConnectingPlayerProfile(int playerID)
Faction GetPlayerFaction(int playerID)
ref array< int > m_aPlayerIDsToLoadProfile
SCR_PlayerProfileManagerComponentClass s_RespawnSystemComponent
Backend Api instance.
Definition BackendApi.c:14
void AddKill(bool friendly=false)
proto external Managed FindComponent(typename typeName)
proto external EntityFlags SetFlags(EntityFlags flags, bool recursively=false)
Definition Types.c:486
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
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
EntityFlags
Various entity flags.
Definition EntityFlags.c:14
override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
EDsSessionState
Session state.