Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayerArsenalLoadout.c
Go to the documentation of this file.
1 [BaseContainerProps(configRoot: true), BaseContainerCustomTitleField("m_sLoadoutName")]
3 {
4  static const string ARSENALLOADOUT_FACTIONKEY_NONE = "none";
5  static const string ARSENALLOADOUT_KEY = "arsenalLoadout";
6  static const string ARSENALLOADOUT_FACTION_KEY = "faction";
7 
8  //------------------------------------------------------------------------------------------------
9  override bool IsLoadoutAvailable(int playerId)
10  {
11  SCR_ArsenalManagerComponent arsenalManager;
12  if (SCR_ArsenalManagerComponent.GetArsenalManager(arsenalManager))
13  {
14  SCR_ArsenalPlayerLoadout arsenalLoadout;
15  return arsenalManager.GetPlayerArsenalLoadout(GetGame().GetBackendApi().GetPlayerIdentityId(playerId), arsenalLoadout);
16  }
17  return false;
18  }
19 
20  //------------------------------------------------------------------------------------------------
21  override bool IsLoadoutAvailableClient()
22  {
23  SCR_ArsenalManagerComponent arsenalManager;
24  if (SCR_ArsenalManagerComponent.GetArsenalManager(arsenalManager))
25  return arsenalManager.GetLocalPlayerLoadoutAvailable();
26 
27  return false;
28  }
29 
30  //------------------------------------------------------------------------------------------------
33  static float GetLoadoutSuppliesCost(string playerUID)
34  {
35  SCR_ArsenalManagerComponent arsenalManager;
36  if (SCR_ArsenalManagerComponent.GetArsenalManager(arsenalManager))
37  {
38  float supplyCostMulti = arsenalManager.GetLoadoutSpawnSupplyCostMultiplier();
39 
40  //~ No need to get supply cost if multiplier is 0
41  if (supplyCostMulti <= 0)
42  return 0;
43 
44  SCR_ArsenalPlayerLoadout arsenalLoadout;
45  if (arsenalManager.GetPlayerArsenalLoadout(playerUID, arsenalLoadout))
46  return arsenalLoadout.suppliesCost * supplyCostMulti;
47  }
48 
49  return 0;
50  }
51 
52  //------------------------------------------------------------------------------------------------
55  static float GetLoadoutSuppliesCost(int playerID)
56  {
57  string playerUID = GetGame().GetBackendApi().GetPlayerIdentityId(playerID);
58  return GetLoadoutSuppliesCost(playerUID);
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  override void OnLoadoutSpawned(GenericEntity pOwner, int playerId)
63  {
64  super.OnLoadoutSpawned(pOwner, playerId);
65  SCR_ArsenalManagerComponent arsenalManager;
66  if (!SCR_ArsenalManagerComponent.GetArsenalManager(arsenalManager))
67  return;
68 
69  string playerUID = GetGame().GetBackendApi().GetPlayerIdentityId(playerId);
70  GameEntity playerEntity = GameEntity.Cast(pOwner);
71  SCR_ArsenalPlayerLoadout playerArsenalItems;
72  if (!playerEntity || !arsenalManager.GetPlayerArsenalLoadout(playerUID, playerArsenalItems))
73  return;
74 
75  FactionAffiliationComponent factionComponent = FactionAffiliationComponent.Cast(playerEntity.FindComponent(FactionAffiliationComponent));
76  if (!factionComponent)
77  return;
78 
79  SCR_JsonLoadContext context = new SCR_JsonLoadContext();
80  bool loadSuccess = true;
81  loadSuccess &= context.ImportFromString(playerArsenalItems.loadout);
82  // Read faction key and ensure same faction, otherwise delete saved arsenal loadout
83  string factionKey;
84  loadSuccess &= context.ReadValue(ARSENALLOADOUT_FACTION_KEY, factionKey) && factionKey != ARSENALLOADOUT_FACTIONKEY_NONE;
85  loadSuccess &= factionKey == factionComponent.GetAffiliatedFaction().GetFactionKey();
86  loadSuccess &= context.ReadValue(ARSENALLOADOUT_KEY, playerEntity);
87 
88  // Deserialisation failed, delete saved arsenal loadout
89  if (!loadSuccess)
90  arsenalManager.SetPlayerArsenalLoadout(playerId, null, null, SCR_EArsenalSupplyCostType.RESPAWN_COST);
91  }
92 }
SCR_ArsenalPlayerLoadout
Definition: SCR_ArsenalManagerComponent.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
BaseContainerCustomTitleField
class SCR_KeyBindingFilter BaseContainerCustomTitleField("m_sBindString")
Definition: SCR_KeyBindingMenuConfig.c:113
SCR_FactionPlayerLoadout
Definition: SCR_PlayerFactionLoadout.c:2
SCR_PlayerArsenalLoadout
Definition: SCR_PlayerArsenalLoadout.c:2
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468