Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_XPHandlerComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_XPHandlerComponent : SCR_BaseGameModeComponent
6 {
7  [Attribute("{E6FC4537B53EA00B}Configs/Campaign/XPRewards.conf", params: "conf class=SCR_XPRewardList")]
8  private ResourceName m_sXPRewardsConfig;
9 
10  [Attribute("300", UIWidgets.EditBox, "How many XP a player needs to gain in a single life to get the Veterancy award. 0 = disabled.", params: "0 inf 1")]
11  protected int m_iVeterancyXPAwardThreshold;
12 
13  [Attribute("1800", UIWidgets.EditBox, "If suicide is committed more than once in this time (seconds), a penalty is issued.", params: "0 inf 1")]
14  protected int m_iSuicidePenaltyCooldown;
15 
16  //static const int SKILL_LEVEL_MAX = 10;
17  //static const int SKILL_LEVEL_XP_COST = 1000; // how much XP is needed for new level
18 
19  //static const float SKILL_LEVEL_XP_BONUS = 0.1;
20 
21  protected static const float TRANSPORT_POINTS_TO_XP_RATIO = 0.01;
22  protected static const float TRANSPORT_HELI_MULTIPLIER = 0.25;
23  protected static const int TRANSPORT_XP_PAYOFF_THRESHOLD = 15;
24 
25  protected ref array<ref SCR_XPRewardInfo> m_aXPRewardList = {};
26 
27  protected ref map<int, float> m_mPlayerTransportPoints = new map<int, float>();
28 
29  protected float m_fXpMultiplier = 1;
30 
31  //------------------------------------------------------------------------------------------------
32  override void OnPlayerSpawned(int playerId, IEntity controlledEntity)
33  {
34  super.OnPlayerSpawned(playerId, controlledEntity);
35 
36  if (!IsProxy())
37  {
38  SCR_CompartmentAccessComponent compartmentAccessComponent = SCR_CompartmentAccessComponent.Cast(controlledEntity.FindComponent(SCR_CompartmentAccessComponent));
39 
40  if (compartmentAccessComponent)
41  compartmentAccessComponent.GetOnCompartmentLeft().Insert(OnCompartmentLeft);
42  }
43 
44  PlayerController pc = GetGame().GetPlayerManager().GetPlayerController(playerId);
45 
46  if (!pc)
47  return;
48 
49  SCR_PlayerXPHandlerComponent compXP = SCR_PlayerXPHandlerComponent.Cast(pc.FindComponent(SCR_PlayerXPHandlerComponent));
50 
51  if (compXP)
52  compXP.UpdatePlayerRank(false);
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
57  {
58  super.OnPlayerDisconnected(playerId, cause, timeout);
59 
60  m_mPlayerTransportPoints.Remove(playerId);
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  override void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
65  {
66  super.OnPlayerKilled(playerId, playerEntity, killerEntity, killer);
67 
68  if (IsProxy())
69  return;
70 
71  if (playerId == killer.GetInstigatorPlayerID())
72  ProcessSuicide(playerId);
73 
74  PlayerController pc = GetGame().GetPlayerManager().GetPlayerController(playerId);
75 
76  if (pc)
77  {
78  SCR_PlayerXPHandlerComponent compXP = SCR_PlayerXPHandlerComponent.Cast(pc.FindComponent(SCR_PlayerXPHandlerComponent));
79 
80  if (compXP)
81  compXP.OnPlayerKilled();
82  }
83 
84  AwardTransportXP(playerId);
85  SCR_CompartmentAccessComponent compartmentAccessComponent = SCR_CompartmentAccessComponent.Cast(playerEntity.FindComponent(SCR_CompartmentAccessComponent));
86 
87  if (!compartmentAccessComponent)
88  return;
89 
90  compartmentAccessComponent.GetOnCompartmentLeft().Remove(OnCompartmentLeft);
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  override void OnControllableDestroyed(IEntity entity, IEntity killerEntity, notnull Instigator killer)
95  {
96  super.OnControllableDestroyed(entity, killerEntity, killer);
97 
98  // Handle XP for kill
99  if (killer.GetInstigatorType() != InstigatorType.INSTIGATOR_PLAYER)
100  return;
101 
102  int killerId = killer.GetInstigatorPlayerID();
103  int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(entity);
104 
105  SCR_ChimeraCharacter entityChar = SCR_ChimeraCharacter.Cast(entity);
106  if (!entityChar)
107  return;
108 
109  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
110  if (!factionManager)
111  return;
112 
113  Faction factionKiller = Faction.Cast(factionManager.GetPlayerFaction(killerId));
114  if (!factionKiller)
115  return;
116 
117  if (factionKiller.IsFactionFriendly(entityChar.GetFaction()))
118  {
119  if (killerId != playerId)
120  AwardXP(killerId, SCR_EXPRewards.FRIENDLY_KILL);
121  }
122  else
123  {
124  SCR_ChimeraCharacter instigatorChar = SCR_ChimeraCharacter.Cast(killerEntity);
125 
126  if (!instigatorChar || !instigatorChar.IsInVehicle())
127  AwardXP(killerId, SCR_EXPRewards.ENEMY_KILL);
128  else
129  AwardXP(killerId, SCR_EXPRewards.ENEMY_KILL_VEH);
130  }
131  }
132 
133  //------------------------------------------------------------------------------------------------
134  protected void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
135  {
136  BaseCompartmentSlot compartment = manager.FindCompartment(slotID, mgrID);
137 
138  if (!compartment)
139  return;
140 
141  int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(compartment.GetOccupant());
142 
143  if (playerId == 0)
144  return;
145 
146  AwardTransportXP(playerId);
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected void OnStatPointsAdded(int playerId, SCR_EDataStats stat, float amount, bool temp)
151  {
152  //Print(temp);
153  //Print(SCR_Enum.GetEnumName(SCR_EDataStats, stat));
154 
155  if (!temp || stat != SCR_EDataStats.POINTS_AS_DRIVER_OF_PLAYERS)
156  return;
157 
158  SCR_ChimeraCharacter player = SCR_ChimeraCharacter.Cast(GetGame().GetPlayerManager().GetPlayerControlledEntity(playerId));
159  IEntity vehicle = CompartmentAccessComponent.GetVehicleIn(player);
160 
161  if (vehicle)
162  {
163  VehicleHelicopterSimulation heliSim = VehicleHelicopterSimulation.Cast(vehicle.FindComponent(VehicleHelicopterSimulation));
164 
165  // Award lower XP per distance travelled in a helicopter
166  if (heliSim)
167  amount *= TRANSPORT_HELI_MULTIPLIER;
168  }
169 
170  int newValue = m_mPlayerTransportPoints.Get(playerId) + amount;
171  m_mPlayerTransportPoints.Set(playerId, newValue);
172 
173  //Print(newValue);
174 
175  if (newValue * TRANSPORT_POINTS_TO_XP_RATIO >= TRANSPORT_XP_PAYOFF_THRESHOLD)
176  AwardTransportXP(playerId);
177  }
178 
179  //------------------------------------------------------------------------------------------------
182  void ProcessSuicide(int playerId)
183  {
184 #ifdef NO_SUICIDE_PENALTY
185  return;
186 #endif
187  PlayerController pc = GetGame().GetPlayerManager().GetPlayerController(playerId);
188 
189  if (!pc)
190  return;
191 
192  SCR_PlayerXPHandlerComponent compXPPlayer = SCR_PlayerXPHandlerComponent.Cast(pc.FindComponent(SCR_PlayerXPHandlerComponent));
193 
194  if (!compXPPlayer)
195  return;
196 
197  SCR_FactionManager fm = SCR_FactionManager.Cast(GetGame().GetFactionManager());
198 
199  if (!fm)
200  return;
201 
202  // Check for cooldown on the penalty
203  float curTime = GetGame().GetWorld().GetWorldTime();
204  float penaltyTimestamp = compXPPlayer.GetSuicidePenaltyTimestamp();
205  compXPPlayer.SetSuicidePenaltyTimestamp(curTime + ((float)m_iSuicidePenaltyCooldown * 1000));
206 
207  if (curTime > penaltyTimestamp)
208  return;
209 
210  // Don't make player renegade just by suiciding
211  int penalty = GetXPRewardAmount(SCR_EXPRewards.SUICIDE);
212  int playerXPWithPenalty = compXPPlayer.GetPlayerXP() + penalty;
213  SCR_ECharacterRank newRank = fm.GetRankByXP(playerXPWithPenalty);
214 
215  if (fm.IsRankRenegade(newRank))
216  return;
217 
218  AwardXP(pc.GetPlayerId(), SCR_EXPRewards.SUICIDE);
219  }
220 
221  //------------------------------------------------------------------------------------------------
222  protected void AwardTransportXP(int playerId)
223  {
224  float toAward = m_mPlayerTransportPoints.Get(playerId) * TRANSPORT_POINTS_TO_XP_RATIO;
225 
226  if (toAward <= 0)
227  return;
228 
229  PlayerController controller = GetGame().GetPlayerManager().GetPlayerController(playerId);
230 
231  if (!controller)
232  return;
233 
234  m_mPlayerTransportPoints.Set(playerId, 0);
235 
236  AwardXP(controller, SCR_EXPRewards.TASK_TRANSPORT, toAward);
237  }
238 
239  //------------------------------------------------------------------------------------------------
240  protected bool IsProxy()
241  {
242  RplComponent rplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
243 
244  return rplComponent && rplComponent.IsProxy();
245  }
246 
247  //------------------------------------------------------------------------------------------------
254  void AwardXP(int playerId, SCR_EXPRewards rewardID, float multiplier = 1.0, bool volunteer = false, int customXP = 0)
255  {
256  if (IsProxy())
257  return;
258 
259  PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
260 
261  if (playerController)
262  AwardXP(playerController, rewardID, multiplier, volunteer, customXP);
263  }
264 
265  //------------------------------------------------------------------------------------------------
272  void AwardXP(notnull PlayerController controller, SCR_EXPRewards rewardID, float multiplier = 1.0, bool volunteer = false, int customXP = 0)
273  {
274  if (IsProxy())
275  return;
276 
277  SCR_PlayerXPHandlerComponent comp = SCR_PlayerXPHandlerComponent.Cast(controller.FindComponent(SCR_PlayerXPHandlerComponent));
278 
279  if (!comp)
280  return;
281 
282  comp.AddPlayerXP(rewardID, multiplier, volunteer, customXP);
283 
284  // Do not handle veterancy award if it's being processed already or disabled
285  if (rewardID == SCR_EXPRewards.VETERANCY || m_iVeterancyXPAwardThreshold == 0 || customXP != 0)
286  return;
287 
288  int singleLifeXP = comp.GetPlayerXPSinceLastSpawn();
289  float veterancyAwards = Math.Floor(singleLifeXP / m_iVeterancyXPAwardThreshold);
290 
291  if (veterancyAwards < 1)
292  return;
293 
294  int leftoverXP = singleLifeXP % m_iVeterancyXPAwardThreshold;
295  comp.SetPlayerXPSinceLastSpawn(leftoverXP);
296 
297  // Award veterancy bonus with a delay so the UI isn't overwritten immediately
298  GetGame().GetCallqueue().CallLater(VeterancyAward, 2000, false, controller, veterancyAwards);
299  }
300 
301  //------------------------------------------------------------------------------------------------
305  void VeterancyAward(notnull PlayerController controller, float multiplier)
306  {
307  AwardXP(controller, SCR_EXPRewards.VETERANCY, multiplier);
308  }
309 
310  //------------------------------------------------------------------------------------------------
315  {
316  int rewardsCnt = m_aXPRewardList.Count();
317 
318  for (int i = 0; i < rewardsCnt; i++)
319  {
320  if (m_aXPRewardList[i].GetRewardID() == reward)
321  return m_aXPRewardList[i].GetRewardXP();
322  }
323 
324  return 0;
325  }
326 
327  //------------------------------------------------------------------------------------------------
331  {
332  return m_fXpMultiplier;
333  }
334 
335  //------------------------------------------------------------------------------------------------
340  {
341  int rewardsCnt = m_aXPRewardList.Count();
342 
343  for (int i = 0; i < rewardsCnt; i++)
344  {
345  if (m_aXPRewardList[i].GetRewardID() == reward)
346  return m_aXPRewardList[i].GetRewardName();
347  }
348 
349  return "";
350  }
351 
352  //------------------------------------------------------------------------------------------------
357  {
358  int rewardsCnt = m_aXPRewardList.Count();
359 
360  for (int i = 0; i < rewardsCnt; i++)
361  {
362  if (m_aXPRewardList[i].GetRewardID() == reward)
363  return m_aXPRewardList[i].AllowNotification();
364  }
365 
366  return false;
367  }
368 
369  //------------------------------------------------------------------------------------------------
373 // EProfileSkillID GetXPRewardSkill(SCR_EXPRewards reward)
374 // {
375 // int rewardsCnt = m_aXPRewardList.Count();
376 //
377 // for (int i = 0; i < rewardsCnt; i++)
378 // {
379 // if (m_aXPRewardList[i].GetRewardID() == reward)
380 // return m_aXPRewardList[i].GetRewardSkill();
381 // }
382 //
383 // return EProfileSkillID.GLOBAL;
384 // }
385 
386  //------------------------------------------------------------------------------------------------
387  override void OnPostInit(IEntity owner)
388  {
389  //Parse & register XP reward list
390  Resource container = BaseContainerTools.LoadContainer(m_sXPRewardsConfig);
391  SCR_XPRewardList list = SCR_XPRewardList.Cast(BaseContainerTools.CreateInstanceFromContainer(container.GetResource().ToBaseContainer()));
392  list.GetRewardList(m_aXPRewardList);
393 
394  SCR_MissionHeader header = SCR_MissionHeader.Cast(GetGame().GetMissionHeader());
395 
396  if (header)
397  m_fXpMultiplier = header.m_fXpMultiplier;
398 
399  SCR_PlayerData.s_OnStatAdded.Insert(OnStatPointsAdded);
400  }
401 }
402 
404 {
444 }
ENEMY_KILL
@ ENEMY_KILL
Definition: SCR_XPHandlerComponent.c:407
OnControllableDestroyed
override void OnControllableDestroyed(IEntity entity, IEntity killerEntity, notnull Instigator killer)
Definition: SCR_XPHandlerComponent.c:94
TASK_DEFEND
@ TASK_DEFEND
Definition: SCR_XPHandlerComponent.c:417
AwardTransportXP
protected void AwardTransportXP(int playerId)
Definition: SCR_XPHandlerComponent.c:222
CUSTOM_1
@ CUSTOM_1
Definition: SCR_XPHandlerComponent.c:424
InstigatorType
InstigatorType
Definition: InstigatorType.c:12
BASE_SEIZED
@ BASE_SEIZED
Definition: SCR_XPHandlerComponent.c:412
SUPPORT_FUEL
@ SUPPORT_FUEL
Definition: SCR_XPHandlerComponent.c:416
SCR_XPHandlerComponentClass
Definition: SCR_XPHandlerComponent.c:1
CUSTOM_8
@ CUSTOM_8
Definition: SCR_XPHandlerComponent.c:431
CUSTOM_7
@ CUSTOM_7
Definition: SCR_XPHandlerComponent.c:430
SCR_CompartmentAccessComponent
Definition: SCR_CompartmentAccessComponent.c:15
CUSTOM_13
@ CUSTOM_13
Definition: SCR_XPHandlerComponent.c:436
CUSTOM_6
@ CUSTOM_6
Definition: SCR_XPHandlerComponent.c:429
CUSTOM_19
@ CUSTOM_19
Definition: SCR_XPHandlerComponent.c:442
VETERANCY
@ VETERANCY
Definition: SCR_XPHandlerComponent.c:421
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
CUSTOM_5
@ CUSTOM_5
Definition: SCR_XPHandlerComponent.c:428
RELAY_DISCOVERED
@ RELAY_DISCOVERED
Definition: SCR_XPHandlerComponent.c:410
RELAY_RECONFIGURED
@ RELAY_RECONFIGURED
Definition: SCR_XPHandlerComponent.c:411
SCR_ECharacterRank
SCR_ECharacterRank
Definition: SCR_CharacterRankComponent.c:305
CUSTOM_20
@ CUSTOM_20
Definition: SCR_XPHandlerComponent.c:443
IsProxy
protected bool IsProxy()
Definition: SCR_XPHandlerComponent.c:240
SCR_PlayerData
Definition: SCR_PlayerData.c:2
UNDEFINED
@ UNDEFINED
Definition: SCR_XPHandlerComponent.c:405
GetXPMultiplier
float GetXPMultiplier()
Definition: SCR_XPHandlerComponent.c:330
FRIENDLY_KILL
@ FRIENDLY_KILL
Definition: SCR_XPHandlerComponent.c:409
KickCauseCode
KickCauseCode
Definition: KickCauseCode.c:19
Instigator
Definition: Instigator.c:6
GetXPRewardAmount
int GetXPRewardAmount(SCR_EXPRewards reward)
Definition: SCR_XPHandlerComponent.c:314
SCR_XPRewardList
Definition: SCR_CampaignXPRewardList.c:54
TASK_TRANSPORT
@ TASK_TRANSPORT
Definition: SCR_XPHandlerComponent.c:418
CUSTOM_17
@ CUSTOM_17
Definition: SCR_XPHandlerComponent.c:440
CUSTOM_11
@ CUSTOM_11
Definition: SCR_XPHandlerComponent.c:434
m_fXpMultiplier
protected float m_fXpMultiplier
Definition: SCR_XPHandlerComponent.c:29
ENEMY_KILL_VEH
@ ENEMY_KILL_VEH
Definition: SCR_XPHandlerComponent.c:408
OnPlayerKilled
override void OnPlayerKilled(int playerId, IEntity playerEntity, IEntity killerEntity, notnull Instigator killer)
Definition: SCR_XPHandlerComponent.c:64
OnStatPointsAdded
protected void OnStatPointsAdded(int playerId, SCR_EDataStats stat, float amount, bool temp)
Definition: SCR_XPHandlerComponent.c:150
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_XPHandlerComponent.c:387
SPAWN_PROVIDER
@ SPAWN_PROVIDER
Definition: SCR_XPHandlerComponent.c:422
CUSTOM_3
@ CUSTOM_3
Definition: SCR_XPHandlerComponent.c:426
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
CUSTOM_10
@ CUSTOM_10
Definition: SCR_XPHandlerComponent.c:433
OnPlayerSpawned
override void OnPlayerSpawned(int playerId, IEntity controlledEntity)
Definition: SCR_XPHandlerComponent.c:32
AllowNotification
bool AllowNotification(SCR_EXPRewards reward)
Definition: SCR_XPHandlerComponent.c:356
CUSTOM_2
@ CUSTOM_2
Definition: SCR_XPHandlerComponent.c:425
Faction
Definition: Faction.c:12
Attribute
SCR_XPHandlerComponentClass SCR_BaseGameModeComponentClass Attribute("{E6FC4537B53EA00B}Configs/Campaign/XPRewards.conf")
Definition: SCR_XPHandlerComponent.c:7
SCR_EXPRewards
SCR_EXPRewards
Definition: SCR_XPHandlerComponent.c:403
SCR_EDataStats
SCR_EDataStats
Definition: SCR_PlayerData.c:950
SERVICE_BUILD
@ SERVICE_BUILD
Definition: SCR_XPHandlerComponent.c:419
CUSTOM_18
@ CUSTOM_18
Definition: SCR_XPHandlerComponent.c:441
AwardXP
void AwardXP(int playerId, SCR_EXPRewards rewardID, float multiplier=1.0, bool volunteer=false, int customXP=0)
Definition: SCR_XPHandlerComponent.c:254
CUSTOM_14
@ CUSTOM_14
Definition: SCR_XPHandlerComponent.c:437
CUSTOM_4
@ CUSTOM_4
Definition: SCR_XPHandlerComponent.c:427
CUSTOM_15
@ CUSTOM_15
Definition: SCR_XPHandlerComponent.c:438
GetXPRewardName
string GetXPRewardName(SCR_EXPRewards reward)
Definition: SCR_XPHandlerComponent.c:339
BASE_DEFENDED
@ BASE_DEFENDED
Definition: SCR_XPHandlerComponent.c:413
VeterancyAward
void VeterancyAward(notnull PlayerController controller, float multiplier)
Definition: SCR_XPHandlerComponent.c:305
OnCompartmentLeft
protected void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
Definition: SCR_XPHandlerComponent.c:134
m_iSuicidePenaltyCooldown
protected int m_iSuicidePenaltyCooldown
Definition: SCR_GameModeCampaign.c:76
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
FREE_ROAM_BUILDING_BUILT
@ FREE_ROAM_BUILDING_BUILT
Definition: SCR_XPHandlerComponent.c:423
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
CUSTOM_12
@ CUSTOM_12
Definition: SCR_XPHandlerComponent.c:435
CUSTOM_9
@ CUSTOM_9
Definition: SCR_XPHandlerComponent.c:432
m_mPlayerTransportPoints
protected ref map< int, float > m_mPlayerTransportPoints
Definition: SCR_XPHandlerComponent.c:27
CHEAT
@ CHEAT
Definition: SCR_XPHandlerComponent.c:406
CUSTOM_16
@ CUSTOM_16
Definition: SCR_XPHandlerComponent.c:439
ProcessSuicide
void ProcessSuicide(int playerId)
Definition: SCR_XPHandlerComponent.c:182
SUPPLIES_DELIVERED
@ SUPPLIES_DELIVERED
Definition: SCR_XPHandlerComponent.c:414
OnPlayerDisconnected
override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
Definition: SCR_XPHandlerComponent.c:56
SCR_BaseGameModeComponentClass
Definition: SCR_BaseGameModeComponent.c:2
SUICIDE
@ SUICIDE
Definition: SCR_XPHandlerComponent.c:420
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1
SUPPORT_EVAC
@ SUPPORT_EVAC
Definition: SCR_XPHandlerComponent.c:415
SCR_BaseGameModeComponent
void SCR_BaseGameModeComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_BaseGameModeComponent.c:199