Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayerXPHandlerComponent.c
Go to the documentation of this file.
1 class SCR_PlayerXPHandlerComponentClass : ScriptComponentClass
2 {
3 }
4 
7 class SCR_PlayerXPHandlerComponent : ScriptComponent
8 {
9  [RplProp(condition: RplCondition.OwnerOnly)]
10  protected int m_iPlayerXP = 0;
11 
13 
14  protected float m_fSuicidePenaltyTimestamp;
15 
16  protected ref ScriptInvoker m_OnXPChanged;
17 
18  //------------------------------------------------------------------------------------------------
21  {
22  return m_iPlayerXP;
23  }
24 
25  //------------------------------------------------------------------------------------------------
29  {
31  }
32 
33  //------------------------------------------------------------------------------------------------
36  {
38  }
39 
40  //------------------------------------------------------------------------------------------------
42  void SetSuicidePenaltyTimestamp(float timestamp)
43  {
44  m_fSuicidePenaltyTimestamp = timestamp;
45  }
46 
47  //------------------------------------------------------------------------------------------------
50  {
52  }
53 
54  //------------------------------------------------------------------------------------------------
56  ScriptInvoker GetOnXPChanged()
57  {
58  if (!m_OnXPChanged)
59  m_OnXPChanged = new ScriptInvoker();
60 
61  return m_OnXPChanged;
62  }
63 
64  //------------------------------------------------------------------------------------------------
66  bool IsProxy()
67  {
68  RplComponent rpl = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
69 
70  return (rpl && rpl.IsProxy());
71  }
72 
73  //------------------------------------------------------------------------------------------------
76  {
78  }
79 
80  //------------------------------------------------------------------------------------------------
83  void UpdatePlayerRank(bool notify = true)
84  {
85  SCR_PlayerController playerController = SCR_PlayerController.Cast(GetOwner());
86 
87  if (!playerController)
88  return;
89 
90  IEntity player = playerController.GetMainEntity();
91 
92  if (!player)
93  return;
94 
96 
97  if (!comp)
98  return;
99 
100  SCR_ECharacterRank curRank = comp.GetCharacterRank(player);
101  SCR_ECharacterRank newRank = SCR_FactionManager.Cast(GetGame().GetFactionManager()).GetRankByXP(m_iPlayerXP);
102 
103  if (newRank == curRank)
104  return;
105 
106  comp.SetCharacterRank(newRank, !notify);
107  }
108 
109  //------------------------------------------------------------------------------------------------
111  [RplRpc(RplChannel.Reliable, RplRcver.Server)]
112  protected void RpcAsk_CheatRank(int playerID, bool demote)
113  {
114  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
115 
116  SCR_ECharacterRank rank = factionManager.GetRankByXP(m_iPlayerXP);
117  int reqXP;
118 
119  if (demote)
120  {
121  SCR_ECharacterRank newRank = factionManager.GetRankPrev(rank);
122 
123  if (newRank == SCR_ECharacterRank.INVALID)
124  return;
125 
126  reqXP = factionManager.GetRequiredRankXP(newRank) - m_iPlayerXP;
127  }
128  else
129  {
130  SCR_ECharacterRank newRank = factionManager.GetRankNext(rank);
131 
132  if (newRank == SCR_ECharacterRank.INVALID)
133  return;
134 
135  reqXP = factionManager.GetRequiredRankXP(newRank) - m_iPlayerXP;
136  }
137 
138  SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
139 
140  if (!comp)
141  return;
142 
143  comp.AwardXP(playerID, SCR_EXPRewards.CHEAT, reqXP);
144  }
145 
146  //------------------------------------------------------------------------------------------------
148  void CheatRank(bool demote = false)
149  {
150  SCR_PlayerController playerController = SCR_PlayerController.Cast(GetOwner());
151 
152  if (!playerController)
153  return;
154 
155  int playerID = playerController.GetPlayerId();
156  Rpc(RpcAsk_CheatRank, playerID, demote);
157  }
158 
159  //------------------------------------------------------------------------------------------------
160  [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
161  protected void RpcDo_OnPlayerXPChanged(int currentXP, int XPToAdd, bool volunteer, SCR_EXPRewards rewardID, bool profileUsed, int skillLevel)
162  {
163  if (m_OnXPChanged)
164  m_OnXPChanged.Invoke(currentXP, rewardID, XPToAdd, volunteer, profileUsed, skillLevel);
165  }
166 
167  //------------------------------------------------------------------------------------------------
173  void AddPlayerXP(SCR_EXPRewards rewardID, float multiplier = 1.0, bool volunteer = false, int addDirectly = 0)
174  {
175  if (IsProxy())
176  return;
177 
178  SCR_XPHandlerComponent comp = SCR_XPHandlerComponent.Cast(GetGame().GetGameMode().FindComponent(SCR_XPHandlerComponent));
179 
180  if (addDirectly != 0)
181  {
182  m_iPlayerXP += (addDirectly);
183  Replication.BumpMe();
184  UpdatePlayerRank(false);
185  Rpc(RpcDo_OnPlayerXPChanged, m_iPlayerXP, addDirectly, false, SCR_EXPRewards.UNDEFINED, false, 0);
186  return;
187  }
188 
189  int XP = comp.GetXPRewardAmount(rewardID);
190 
191  if (XP == 0)
192  return;
193 
194  float skillXPMultiplier = 1;
195  //EProfileSkillID skillID = comp.GetXPRewardSkill(rewardID);
196  //auto profileManager = campaign.FindComponent(SCR_PlayerProfileManagerComponent); Replaced by SCR_PlayerData
197 
198  // 35% XP bonus when the player volunteered for the task
199  if (volunteer)
200  multiplier += 0.35;
201 
202  int XPToAdd = Math.Round(XP * multiplier * comp.GetXPMultiplier());
203 
204  int XPToAddBySkill = 0;
205  bool profileUsed = false;
206  int skillLevel = 0;
207  /***** Replaced by SCR_PlayerData
208  //****
209  // Handle skill XP
210  if (profileManager && XP > 0)
211  {
212  SCR_PlayerProfileManagerComponent profileManagerCast = SCR_PlayerProfileManagerComponent.Cast(profileManager);
213  CareerBackendData profile = profileManagerCast.GetPlayerProfile(m_PlayerController.GetPlayerId());
214 
215  if (profile)
216  {
217  profileUsed = true;
218  skillLevel = Math.Min(Math.Floor(profile.GetSkillXP(skillID) / SCR_GameModeCampaign.SKILL_LEVEL_XP_COST), SCR_GameModeCampaign.SKILL_LEVEL_MAX);
219  XPToAddBySkill = Math.Round(XPToAdd * skillLevel * SCR_GameModeCampaign.SKILL_LEVEL_XP_BONUS);
220  profile.AddSkillXP(skillID, XP * multiplier);
221  }
222  }
223  //****
224  *****/
225  if (XPToAdd + XPToAddBySkill == 0)
226  return;
227 
228  m_iPlayerXP += (XPToAdd + XPToAddBySkill);
229 
230  if (rewardID != SCR_EXPRewards.VETERANCY)
231  m_iPlayerXPSinceLastSpawn += (XPToAdd + XPToAddBySkill);
232 
233  Replication.BumpMe();
235 
236  Rpc(RpcDo_OnPlayerXPChanged, m_iPlayerXP, XPToAdd + XPToAddBySkill, volunteer, rewardID, profileUsed, skillLevel);
237  }
238 }
RpcDo_OnPlayerXPChanged
protected void RpcDo_OnPlayerXPChanged(int currentXP, int XPToAdd, bool volunteer, SCR_EXPRewards rewardID, bool profileUsed, int skillLevel)
Definition: SCR_PlayerXPHandlerComponent.c:161
SCR_PlayerController
Definition: SCR_PlayerController.c:31
SetPlayerXPSinceLastSpawn
void SetPlayerXPSinceLastSpawn(int xp)
Definition: SCR_PlayerXPHandlerComponent.c:28
ScriptComponent
SCR_SiteSlotEntityClass ScriptComponent
m_OnXPChanged
protected ref ScriptInvoker m_OnXPChanged
Definition: SCR_PlayerXPHandlerComponent.c:16
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
UpdatePlayerRank
void UpdatePlayerRank(bool notify=true)
Definition: SCR_PlayerXPHandlerComponent.c:83
GetPlayerXPSinceLastSpawn
int GetPlayerXPSinceLastSpawn()
Getter for player XP accumulated since last respawn.
Definition: SCR_PlayerXPHandlerComponent.c:35
SCR_ECharacterRank
SCR_ECharacterRank
Definition: SCR_CharacterRankComponent.c:305
GetSuicidePenaltyTimestamp
float GetSuicidePenaltyTimestamp()
Definition: SCR_PlayerXPHandlerComponent.c:49
RpcAsk_CheatRank
protected void RpcAsk_CheatRank(int playerID, bool demote)
Cheat method to change player's rank - server side.
Definition: SCR_PlayerXPHandlerComponent.c:112
RplRpc
SCR_AchievementsHandlerClass ScriptComponentClass RplRpc(RplChannel.Reliable, RplRcver.Owner)] void UnlockOnClient(AchievementId achievement)
Definition: SCR_AchievementsHandler.c:11
SCR_CharacterRankComponent
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_CharacterRankComponent.c:209
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
GetPlayerXP
int GetPlayerXP()
Getter for player XP.
Definition: SCR_PlayerXPHandlerComponent.c:20
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_fSuicidePenaltyTimestamp
protected float m_fSuicidePenaltyTimestamp
Definition: SCR_PlayerXPHandlerComponent.c:14
CheatRank
void CheatRank(bool demote=false)
Cheat method to change player's rank.
Definition: SCR_PlayerXPHandlerComponent.c:148
SetSuicidePenaltyTimestamp
void SetSuicidePenaltyTimestamp(float timestamp)
Definition: SCR_PlayerXPHandlerComponent.c:42
SCR_PlayerXPHandlerComponentClass
Definition: SCR_PlayerXPHandlerComponent.c:1
SCR_EXPRewards
SCR_EXPRewards
Definition: SCR_XPHandlerComponent.c:403
m_iPlayerXPSinceLastSpawn
protected int m_iPlayerXPSinceLastSpawn
Definition: SCR_PlayerXPHandlerComponent.c:12
OnPlayerKilled
void OnPlayerKilled()
Definition: SCR_PlayerXPHandlerComponent.c:75
GetOnXPChanged
ScriptInvoker GetOnXPChanged()
Definition: SCR_PlayerXPHandlerComponent.c:56
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
RplProp
SCR_PlayerXPHandlerComponentClass ScriptComponentClass RplProp(condition:RplCondition.OwnerOnly)] protected int m_iPlayerXP=0
IsProxy
bool IsProxy()
Definition: SCR_PlayerXPHandlerComponent.c:66
AddPlayerXP
void AddPlayerXP(SCR_EXPRewards rewardID, float multiplier=1.0, bool volunteer=false, int addDirectly=0)
Definition: SCR_PlayerXPHandlerComponent.c:173