Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlayerXPHandlerComponent.c
Go to the documentation of this file.
4
5void OnPlayerXPChangedMethod(int playerId, int currentXP, int XPToAdd, SCR_EXPRewards rewardId);
7typedef ScriptInvokerBase<OnPlayerXPChangedMethod> OnPlayerXPChanged;
8
12{
13 [RplProp(condition: RplCondition.OwnerOnly)]
14 protected int m_iPlayerXP = 0;
15
17
19
21
23
25
28
30
31 //------------------------------------------------------------------------------------------------
34 {
35 return m_iPlayerXP;
36 }
37
38 //------------------------------------------------------------------------------------------------
45
46 //------------------------------------------------------------------------------------------------
52
53 //------------------------------------------------------------------------------------------------
55 void SetSuicidePenaltyTimestamp(float timestamp)
56 {
58 }
59
60 //------------------------------------------------------------------------------------------------
66
67 //------------------------------------------------------------------------------------------------
68 void SetSurvivalRewardCycle(int cycle)
69 {
71 }
72
73 //------------------------------------------------------------------------------------------------
78
79 //------------------------------------------------------------------------------------------------
81 SCR_ECharacterRank GetPlayerRankByXP()
82 {
83 SCR_PlayerController playerController = SCR_PlayerController.Cast(GetOwner());
84 if (!playerController)
85 return SCR_ECharacterRank.PRIVATE;
86
87 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
88 if (!factionManager)
89 return SCR_ECharacterRank.PRIVATE;
90
91 SCR_RankContainer ranks = factionManager.GetFactionRanks(playerController.GetPlayerId());
92 return ranks.GetRankByXP(m_iPlayerXP);
93 }
94
95 //------------------------------------------------------------------------------------------------
98 {
99 if (!m_OnXPChanged)
101
102 return m_OnXPChanged;
103 }
104
105 //------------------------------------------------------------------------------------------------
114
115 //------------------------------------------------------------------------------------------------
117 bool IsProxy()
118 {
119 RplComponent rpl = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
120
121 return (rpl && rpl.IsProxy());
122 }
123
124 //------------------------------------------------------------------------------------------------
127 {
129 }
130
131 //------------------------------------------------------------------------------------------------
134 void UpdatePlayerRank(bool notify = true)
135 {
136 SCR_PlayerController playerController = SCR_PlayerController.Cast(GetOwner());
137
138 if (!playerController)
139 return;
140
141 IEntity player = playerController.GetMainEntity();
142
143 if (!player)
144 return;
145
147 if (!comp)
148 return;
149
150 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
151 if (!factionManager)
152 return;
153
154 const SCR_ECharacterRank newRank = factionManager.GetFactionRanks(playerController.GetPlayerId()).GetRankByXP(m_iPlayerXP);
155 comp.SetCharacterRank(newRank, !notify);
156 }
157
158 //------------------------------------------------------------------------------------------------
160 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
161 protected void RpcAsk_CheatRank(bool demote)
162 {
163 if (!GetGame().IsDev())
164 return;
165
167 if (!owner)
168 return;
169
170 int playerID = owner.GetPlayerId();
171
172 SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
173
174 SCR_RankContainer ranks = factionManager.GetFactionRanks(playerID);
175
176 SCR_ECharacterRank rank = ranks.GetRankByXP(m_iPlayerXP);
177 int reqXP;
178
179 if (demote)
180 {
181 SCR_ECharacterRank newRank = ranks.GetPreviousRank(rank);
182
183 if (newRank == SCR_ECharacterRank.INVALID)
184 return;
185
186 reqXP = ranks.GetRequiredRankXP(newRank) - m_iPlayerXP;
187 }
188 else
189 {
190 SCR_ECharacterRank newRank = ranks.GetNextRank(rank);
191
192 if (newRank == SCR_ECharacterRank.INVALID)
193 return;
194
195 reqXP = ranks.GetRequiredRankXP(newRank) - m_iPlayerXP;
196 }
197
198 SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
199
200 if (!comp)
201 return;
202
203 comp.AwardXP(playerID, SCR_EXPRewards.CHEAT, reqXP);
204 }
205
206 //------------------------------------------------------------------------------------------------
208 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
209 protected void RpcAsk_CheatXP(int xpChange)
210 {
211 if (!GetGame().IsDev())
212 return;
213
215 if (!owner)
216 return;
217
218 int playerID = owner.GetPlayerId();
219
220 SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
221
222 if (!comp)
223 return;
224
225 comp.AwardXP(playerID, SCR_EXPRewards.CHEAT, xpChange);
226 }
227
228 //------------------------------------------------------------------------------------------------
230 void CheatRank(bool demote = false)
231 {
232 Rpc(RpcAsk_CheatRank, demote);
233 }
234
235 //------------------------------------------------------------------------------------------------
237 void CheatXP(int xpChange)
238 {
239 Rpc(RpcAsk_CheatXP, xpChange);
240 }
241
242 //------------------------------------------------------------------------------------------------
243 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
244 protected void RpcDo_OnPlayerXPChanged(int currentXP, int XPToAdd, bool volunteer, SCR_EXPRewards rewardID, bool profileUsed, int skillLevel)
245 {
246 if (m_OnXPChanged)
247 m_OnXPChanged.Invoke(currentXP, rewardID, XPToAdd, volunteer, profileUsed, skillLevel);
248 }
249
250 //------------------------------------------------------------------------------------------------
253 {
254 BaseGameMode gameMode = GetGame().GetGameMode();
255 if (!gameMode)
256 return;
257
258 SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(gameMode.FindComponent(SCR_XPHandlerComponent));
259 if (!comp)
260 return;
261
262 // Call SurvivalReward periodically while the player is alive
263 const int survivalRewardCycleDuration = comp.GetSurvivalRewardCooldown();
264 if (survivalRewardCycleDuration > 0)
265 GetGame().GetCallqueue().CallLater(SurvivalReward, survivalRewardCycleDuration * 1000, true);
266 }
267
268 //------------------------------------------------------------------------------------------------
271 {
272 // Remove SurvivalReward from call queue on player death
273 GetGame().GetCallqueue().Remove(SurvivalReward);
275 }
276
277 //------------------------------------------------------------------------------------------------
280 {
281 BaseGameMode gameMode = GetGame().GetGameMode();
282 if (!gameMode)
283 return;
284
285 SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(gameMode.FindComponent(SCR_XPHandlerComponent));
286 if (!comp)
287 return;
288
289 SCR_PlayerController playerController = SCR_PlayerController.Cast(GetOwner());
290 if (!playerController)
291 return;
292
293 int playerID = playerController.GetPlayerId();
294 if (playerID == 0)
295 return;
296
297 int baseXPReward = comp.GetXPRewardAmount(SCR_EXPRewards.SURVIVAL);
299 // Reward XP gets scaled up more the more cycles player survives, the maximum amount of xp gained is limited by survival scale max cycle amount
300 int xpReward = Math.Min(m_iSurvivalRewardCycle * baseXPReward, baseXPReward * comp.GetSurvivalScaleMaxCycleAmount());
301
302 if (xpReward == 0)
303 return;
304
305 comp.AwardXP(playerID, SCR_EXPRewards.SURVIVAL, xpReward);
306 }
307
308 //------------------------------------------------------------------------------------------------
311 {
313 return;
314
315 BaseGameMode gameMode = GetGame().GetGameMode();
316 if (!gameMode)
317 return;
318
319 SCR_XPHandlerComponent xpHandlerComponent = SCR_XPHandlerComponent.Cast(gameMode.FindComponent(SCR_XPHandlerComponent));
320 if (!xpHandlerComponent)
321 return;
322
323 int seizingRewardCycleDuration = xpHandlerComponent.GetSeizeBaseProgressionRewardTimer();
324 if (seizingRewardCycleDuration == 0)
325 return;
326
327 // Seizing progress reward is called periodically while the base is being seized
328 GetGame().GetCallqueue().CallLater(SeizingProgressReward, seizingRewardCycleDuration * 1000, true, xpHandlerComponent);
329
332 }
333
334 //------------------------------------------------------------------------------------------------
337 {
339 return;
340
342 return;
343
344 // Base is no longer being seized, stop calling the seizing progress reward
345 GetGame().GetCallqueue().Remove(SeizingProgressReward);
346
349 }
350
351 //------------------------------------------------------------------------------------------------
354 void SeizingProgressReward(SCR_XPHandlerComponent xpHandlerComponent)
355 {
357 return;
358
359 if (!xpHandlerComponent)
360 return;
361
362 SCR_PlayerController playerController = SCR_PlayerController.Cast(GetOwner());
363 if (!playerController)
364 return;
365
366 // Only players are awarded XP
367 int playerID = playerController.GetPlayerId();
368 if (playerID == 0)
369 return;
370
371 Faction baseFaction = m_SeizedBaseComponent.GetFaction();
372 if (!baseFaction)
373 return;
374
375 Faction capturingFaction = m_SeizedBaseComponent.GetCapturingFaction();
376 if (!capturingFaction)
377 {
379 return;
380 }
381
382 Faction playerFaction = SCR_FactionManager.SGetPlayerFaction(playerID);
383 if (!playerFaction || playerFaction != capturingFaction)
384 return;
385
386 // XP reward is dependent on base Faction
387 int xpReward = xpHandlerComponent.GetSeizeBaseProgressionXP(baseFaction.GetFactionKey());
388 if (xpReward == 0)
389 return;
390
391 xpHandlerComponent.AwardXP(playerID, SCR_EXPRewards.BASE_SEIZED, 1, false, xpReward);
392 }
393
394 //------------------------------------------------------------------------------------------------
398 {
399 ChimeraWorld world = GetGame().GetWorld();
400 if (!world)
401 return false;
402
403 WorldTimestamp cooldownTimestamp;
404 if (!m_mRewardCooldowns.Find(rewardID, cooldownTimestamp))
405 return false;
406
407 return !world.GetServerTimestamp().Greater(cooldownTimestamp);
408 }
409
410 //------------------------------------------------------------------------------------------------
414 protected void SetPlayerRewardCooldown(SCR_EXPRewards rewardID, float cooldown)
415 {
416 ChimeraWorld world = GetGame().GetWorld();
417 if (!world)
418 return;
419
420 m_mRewardCooldowns.Set(rewardID, world.GetServerTimestamp().PlusSeconds(cooldown));
421 }
422
423 //------------------------------------------------------------------------------------------------
429 void AddPlayerXP(SCR_EXPRewards rewardID, float multiplier = 1.0, bool volunteer = false, int addDirectly = 0)
430 {
431 if (IsProxy())
432 return;
433
434 BaseGameMode gameMode = GetGame().GetGameMode();
435
436 if (!gameMode)
437 return;
438
439 SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(gameMode.FindComponent(SCR_XPHandlerComponent));
440
441 if (!comp)
442 return;
443
444 // checks whether the player can receive an XP reward depending on if the reward cooldown has expired
445 SCR_XPRewardInfo rewardInfo = comp.GetXpRewardInfo(rewardID);
446 if (rewardInfo && rewardInfo.CanUseRewardCooldown())
447 {
448 if (HasPlayerRewardCooldown(rewardID))
449 return;
450
451 SetPlayerRewardCooldown(rewardID, rewardInfo.GetRewardCooldown());
452 }
453
454 SCR_PlayerController playerController = SCR_PlayerController.Cast(GetOwner());
455
456 if (addDirectly != 0)
457 {
458 m_iPlayerXP += (addDirectly);
459
460 if (playerController && m_OnPlayerXPChanged)
461 m_OnPlayerXPChanged.Invoke(playerController.GetPlayerId(), m_iPlayerXP, addDirectly, rewardID);
462
463 Replication.BumpMe();
464 UpdatePlayerRank(false);
465 Rpc(RpcDo_OnPlayerXPChanged, m_iPlayerXP, addDirectly, false, rewardID, false, 0);
466 return;
467 }
468
469 int XP = comp.GetXPRewardAmount(rewardID);
470
471 if (XP == 0)
472 return;
473
474 //EProfileSkillID skillID = comp.GetXPRewardSkill(rewardID);
475 //auto profileManager = campaign.FindComponent(SCR_PlayerProfileManagerComponent); Replaced by SCR_PlayerData
476
477 // 35% XP bonus when the player volunteered for the task
478 if (volunteer)
479 multiplier += 0.35;
480
481 int XPToAdd = Math.Round(XP * multiplier * comp.GetXPMultiplier());
482
483 const int XPToAddBySkill = 0; // TODO: check for good const usage
484 bool profileUsed = false;
485 const int skillLevel = 0; // TODO: check for good const usage
486 /***** Replaced by SCR_PlayerData
487 //****
488 // Handle skill XP
489 if (profileManager && XP > 0)
490 {
491 SCR_PlayerProfileManagerComponent profileManagerCast = SCR_PlayerProfileManagerComponent.Cast(profileManager);
492 CareerBackendData profile = profileManagerCast.GetPlayerProfile(m_PlayerController.GetPlayerId());
493
494 if (profile)
495 {
496 profileUsed = true;
497 skillLevel = Math.Min(Math.Floor(profile.GetSkillXP(skillID) / SCR_GameModeCampaign.SKILL_LEVEL_XP_COST), SCR_GameModeCampaign.SKILL_LEVEL_MAX);
498 XPToAddBySkill = Math.Round(XPToAdd * skillLevel * SCR_GameModeCampaign.SKILL_LEVEL_XP_BONUS);
499 profile.AddSkillXP(skillID, XP * multiplier);
500 }
501 }
502 //****
503 *****/
504 if (XPToAdd + XPToAddBySkill == 0)
505 return;
506
507 m_iPlayerXP += (XPToAdd + XPToAddBySkill);
508
509 if (rewardID != SCR_EXPRewards.VETERANCY)
510 m_iPlayerXPSinceLastSpawn += (XPToAdd + XPToAddBySkill);
511
512 if (playerController && m_OnPlayerXPChanged)
513 m_OnPlayerXPChanged.Invoke(playerController.GetPlayerId(), m_iPlayerXP, XPToAdd, rewardID);
514
515 Replication.BumpMe();
517
518 Rpc(RpcDo_OnPlayerXPChanged, m_iPlayerXP, XPToAdd + XPToAddBySkill, volunteer, rewardID, profileUsed, skillLevel);
519 }
520
521 #ifdef ENABLE_DIAG
522 //------------------------------------------------------------------------------------------------
523 override protected void EOnDiag(IEntity owner, float timeSlice)
524 {
525 super.EOnDiag(owner, timeSlice);
526
527 if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_CHARACTER_SHOW_XP))
528 {
529 int xp = GetPlayerXP();
530
531 DbgUI.Begin("Player XP Debug", 50, 50);
532 DbgUI.Text("Player XP: " + xp);
533 DbgUI.End();
534 }
535 }
536 #endif
537
538 //------------------------------------------------------------------------------------------------
539 override protected void OnPostInit(IEntity owner)
540 {
541 super.OnPostInit(owner);
542
543 #ifdef ENABLE_DIAG
544 ConnectToDiagSystem(owner);
545 DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_CHARACTER_SHOW_XP, "", "Show Player XP", "Character");
546 #endif
547 }
548
549 //------------------------------------------------------------------------------------------------
550 override protected void OnDelete(IEntity owner)
551 {
552 #ifdef ENABLE_DIAG
553 DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_CHARACTER_SHOW_XP);
554 #endif
555
556 super.OnDelete(owner);
557 }
558}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_FactionManager(IEntitySource src, IEntity parent)
ScriptInvokerBase< OnPlayerXPChangedMethod > OnPlayerXPChanged
func OnPlayerXPChangedMethod
Definition DbgUI.c:66
Diagnostic and developer menu system.
Definition DiagMenu.c:18
proto external GenericComponent FindComponent(typename typeName)
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
void ConnectToDiagSystem(IEntity owner)
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
Main replication API.
Definition Replication.c:14
SCR_CampaignMilitaryBaseComponent m_SeizedBaseComponent
void RpcAsk_CheatXP(int xpChange)
Cheat method to change player's XP - server side.
int GetPlayerXPSinceLastSpawn()
Getter for player XP accumulated since last respawn.
void SeizingProgressReward(SCR_XPHandlerComponent xpHandlerComponent)
void RpcDo_OnPlayerXPChanged(int currentXP, int XPToAdd, bool volunteer, SCR_EXPRewards rewardID, bool profileUsed, int skillLevel)
ref map< SCR_EXPRewards, WorldTimestamp > m_mRewardCooldowns
<XPReward type, cooldownTimestamp>
bool HasPlayerRewardCooldown(SCR_EXPRewards rewardID)
void StartSeizingProgressReward(notnull SCR_CampaignMilitaryBaseComponent base)
void StopSeizingProgressReward(notnull SCR_CampaignMilitaryBaseComponent base)
void SetPlayerRewardCooldown(SCR_EXPRewards rewardID, float cooldown)
void AddPlayerXP(SCR_EXPRewards rewardID, float multiplier=1.0, bool volunteer=false, int addDirectly=0)
void RpcAsk_CheatRank(bool demote)
Cheat method to change player's rank - server side.
SCR_ECharacterRank GetNextRank(SCR_ECharacterRank rankID)
SCR_ECharacterRank GetRankByXP(int XP)
SCR_ECharacterRank GetPreviousRank(SCR_ECharacterRank rankID)
int GetRequiredRankXP(SCR_ECharacterRank rankID)
Config template for XP rewards.
float GetRewardCooldown()
return reward cooldown [s]
bool CanUseRewardCooldown()
return true if player can use cooldown for this reward type
void EOnDiag(IEntity owner, float timeSlice)
proto external GenericEntity GetOwner()
Get owner entity.
Definition Types.c:486
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplCondition
Conditional replication rule. Fine grained selection of receivers.
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134