Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
CareerBackend.c
Go to the documentation of this file.
2 {
3  protected EProfileSkillID m_eTraitID;
4  protected int m_iTraitXP;
5 
6  void GameplayTrait(EProfileSkillID thisId, int n)
7  {
8  m_eTraitID = thisId;
9  m_iTraitXP = n;
10 
11  RegV("m_eTraitID");
12  RegV("m_iTraitXP");
13  }
14 
15  EProfileSkillID GetTraitID()
16  {
17  return m_eTraitID;
18  }
19 
20  int GetTraitXP()
21  {
22  return m_iTraitXP;
23  }
24 
25  void AddXP(int n)
26  {
27  m_iTraitXP+=n;
28  }
29 
30  #ifdef ENABLE_DIAG
31  string toString()
32  {
33  string toRet = "";
34  toRet += "Gameplay Trait ID is "+m_eTraitID;
35  toRet+= ", XP is "+m_iTraitXP;
36  return toRet;
37  }
38  #endif
39 };
40 
41 
42 
44 {
45  protected ref SCR_SessionInfo m_sessionInfo;
46  protected static const int SESSIONS_TO_STORE = 8;
47 
48  // Backend-stored variables
49  float m_fRank;
50  protected int m_iKills;
51  protected int m_iFriendlyKills;
52  protected int m_iDeaths;
53  protected float m_fTravelledDistance;
54 
55  protected ref array<ref GameplayTrait> m_aGameplayTraits;
56  protected ref array<ref SCR_SessionInfo> m_aSessionInfos;
57 
58  //------------------------------------------------------------------------------------------------
59  void AddKill(bool friendly = false)
60  {
61  if (friendly)
62  m_iFriendlyKills++;
63  else
64  m_iKills++;
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  void AddDeath()
69  {
70  m_iDeaths++;
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  void AddSkillXP(EProfileSkillID skillID, int XP)
75  {
76  if(skillID >= 0 && skillID < m_aGameplayTraits.Count())
77  m_aGameplayTraits.Get(skillID).AddXP(XP);
78  else
79  Print("CareerBackend::AddSkillXP Wrong skillID! Can't add experience to the unknown skillID: "+skillID, LogLevel.ERROR);
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  float GetTravelledDistance()
84  {
85  return m_fTravelledDistance;
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  int GetFriendlyKills()
90  {
91  return m_iFriendlyKills;
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  int GetKills()
96  {
97  return m_iKills;
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  int GetDeaths()
102  {
103  return m_iDeaths;
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  int GetSkillXP(EProfileSkillID skillID)
108  {
109  if(skillID >= 0 && skillID < m_aGameplayTraits.Count())
110  return m_aGameplayTraits.Get(skillID).GetTraitXP();
111  else
112  {
113  Print("CareerBackend::GetSkillXP Wrong skillID!", LogLevel.ERROR);
114  return -1;
115  }
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  //Called upon faction selection
120  void SetFaction(string factionKey)
121  {
122  GetSessionInfo().SetFactionKey(factionKey);
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  //Called upon login
127  void SetLoginTime()
128  {
129  int year, month, day, hour, minute, second;
130 
131  System.GetYearMonthDay(year, month, day);
132  System.GetHourMinuteSecond(hour, minute, second);
133 
134  GetSessionInfo().SetLoginTime(year, month, day, hour, minute, second);
135  }
136 
137  //------------------------------------------------------------------------------------------------
138  //Called upon logout
139  void SetLogoutTime()
140  {
141  int year, month, day, hour, minute, second;
142 
143  System.GetYearMonthDay(year, month, day);
144  System.GetHourMinuteSecond(hour, minute, second);
145 
146  GetSessionInfo().SetLogoutTime(year, month, day, hour, minute, second);
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  SCR_SessionInfo GetSessionInfo()
151  {
152  if (!m_sessionInfo)
153  {
154  m_sessionInfo = new SCR_SessionInfo();
155  BackendApi bApi = GetGame().GetBackendApi();
156 
157  if (bApi)
158  {
159  DSSession session = bApi.GetDSSession();
160 
161  if (session)
162  m_sessionInfo.SetRoomID(session.RoomID());
163  }
164  }
165 
166  return m_sessionInfo;
167  }
168 
169  //****************//
170  //OVERRIDE METHODS//
171  //****************//
172 
173  //------------------------------------------------------------------------------------------------
174  override void OnSuccess( int errorCode )
175  {
176  // Register infos array if needed, resize if it overflows max size, make sure newest data is first
177  int sessionsCnt;
178 
179  if (!m_aSessionInfos)
180  m_aSessionInfos = new array<ref SCR_SessionInfo>();
181  else
182  {
183  sessionsCnt = m_aSessionInfos.Count();
184 
185  if (sessionsCnt >= SESSIONS_TO_STORE)
186  {
187  m_aSessionInfos.Resize(SESSIONS_TO_STORE - 1);
188  sessionsCnt = SESSIONS_TO_STORE - 1;
189  }
190  }
191 
192  // Check m_aSessionInfos for data stored for this session
193  BackendApi bApi = GetGame().GetBackendApi();
194 
195  if (bApi && sessionsCnt != 0)
196  {
197  DSSession session = bApi.GetDSSession();
198 
199  if (session)
200  {
201  string roomID = session.RoomID();
202 
203  if (!roomID.IsEmpty())
204  {
205  for (int i = 0; i < sessionsCnt; i++)
206  {
207  SCR_SessionInfo sessionInfo = m_aSessionInfos[i];
208 
209  if (!sessionInfo)
210  continue;
211 
212  if (sessionInfo.GetRoomID() == roomID)
213  {
214  // Session data found - register and set as the first element
215  m_sessionInfo = sessionInfo;
216  m_aSessionInfos.RemoveOrdered(i);
217  m_aSessionInfos.InsertAt(m_sessionInfo, 0);
218  break;
219  }
220  }
221  }
222  }
223  }
224 
225  // Session data not stored, store new instance if backend returns proper ID
226  if (!m_sessionInfo)
227  {
228  SCR_SessionInfo sessionInfo = GetSessionInfo();
229 
230  if (!sessionInfo.GetRoomID().IsEmpty())
231  m_aSessionInfos.InsertAt(GetSessionInfo(), 0);
232  }
233 
234  if (!CareerMenuUI.m_sInstance)
235  return;
236 
237  if (CareerMenuUI.m_sInstance)
238  CareerMenuUI.m_sInstance.UpdateCareerData();
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  override void OnError( int errorCode )
243  {
244  Print("OnError: " + errorCode );
245  }
246 
247  //------------------------------------------------------------------------------------------------
248  void CareerBackendData()
249  {
250  m_aGameplayTraits = {};
251 
252  typename type = EProfileSkillID;
253 
254  for(int i = 0; i < type.GetVariableCount(); i++)
255  {
256  m_aGameplayTraits.Insert(new GameplayTrait(i, 0));
257  }
258 
259  RegV("m_fRank");
260  RegV("m_iKills");
261  RegV("m_iFriendlyKills");
262  RegV("m_iDeaths");
263  RegV("m_fTravelledDistance");
264 
265  RegV("m_aGameplayTraits");
266  RegV("m_aSessionInfos");
267  }
268 };
269 
270 //------------------------------------------------------------------------------------------------
272 {
277  override void OnError( int code, int restCode, int apiCode )
278  {
279  Print("[BackendCallback] OnError: "+ GetGame().GetBackendApi().GetErrorCode(code));
280  }
281 
286  override void OnSuccess( int code )
287  {
288  Print("[BackendCallback] OnSuccess");
289  }
290 
294  override void OnTimeout()
295  {
296  Print("[BackendCallback] OnTimeout");
297  }
298 };
299 
300 //------------------------------------------------------------------------------------------------
303 {
309 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
JsonApiStruct
Parameters for joining server.
Definition: FeedbackDialogUI.c:2
CampaignCallback
Definition: CareerBackend.c:271
GLOBAL
@ GLOBAL
Definition: CareerBackend.c:304
DRIVER
@ DRIVER
Definition: CareerBackend.c:306
WEAPON_HANDLER
@ WEAPON_HANDLER
Definition: CareerBackend.c:305
OPERATOR
@ OPERATOR
Definition: CareerBackend.c:308
GameplayTrait
Definition: CareerBackend.c:1
EProfileSkillID
EProfileSkillID
Used to identify various player skills.
Definition: CareerBackend.c:302
SCR_SessionInfo
Definition: SCR_SessionInfo.c:1
CareerBackendData
Definition: CareerBackend.c:43
BackendCallback
Base server browser callback.
Definition: SCR_ServerListComponent.c:4
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
CareerMenuUI
Definition: CareerMenuUI.c:2
SCOUT
@ SCOUT
Definition: CareerBackend.c:307