Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceContainerVehicleLoadAction.c
Go to the documentation of this file.
2 {
3  [Attribute(defvalue: EResourceType.SUPPLIES.ToString(), uiwidget: UIWidgets.ComboBox, desc: "Sets the type of Resource to be used.\nOnly a transaction matching Resource types can be successfully concluded.", enums: ParamEnumArray.FromEnum(EResourceType))]
4  protected EResourceType m_eResourceType;
5 
6  [Attribute("2000", "Amount of resources transfered on each action execute, -1 means max is transfer", params: "-1 inf")]
7  protected float m_fTransferAmount;
8 
9  protected const LocalizedString OCCUPIED_BY_CHARACTER = "#AR-UserAction_SeatOccupied";
10 
11  protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer;
12  protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleGenerator;
13  protected SCR_ResourceComponent m_ResourceComponent;
14  protected SCR_ResourceGenerator m_ResourceGenerator;
15  protected SCR_ResourceConsumer m_ResourceConsumer;
16  protected RplId m_ResourceInventoryPlayerComponentRplId;
17  protected float m_fMaxStoredResource;
18  protected float m_fCurrentResource;
19  protected float m_fCurrentTransferValue;
20  protected bool m_bCanPerform;
21 
22  protected SCR_BaseCompartmentManagerComponent m_CompartmentManager;
23 
24  //------------------------------------------------------------------------------------------------
25  //~ If continues action it will only execute everytime the duration is done
26  override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
27  {
28  if (!LoopActionUpdate(timeSlice))
29  return;
30 
31  PerformAction(pOwnerEntity, pUserEntity);
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
36  {
38  if (!gamemode || !gamemode.IsMaster())
39  return;
40 
42  || !m_ResourceGenerator && !m_ResourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_LOAD, m_eResourceType, m_ResourceGenerator)
43  || !m_ResourceConsumer && !m_ResourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_LOAD, m_eResourceType, m_ResourceConsumer))
44  return;
45 
46  GetResourceValues(m_fCurrentResource, m_fMaxStoredResource, m_fCurrentTransferValue);
47 
48  m_ResourceConsumer.RequestConsumtion(m_fCurrentTransferValue);
49  m_ResourceGenerator.RequestGeneration(m_fCurrentTransferValue);
50 
51  int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
52  PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
53 
54  if (!playerController)
55  return;
56 
58 
59  if (!resourcePlayerControllerComponent)
60  return;
61 
62  resourcePlayerControllerComponent.OnPlayerInteraction(EResourcePlayerInteractionType.VEHICLE_LOAD, m_ResourceConsumer.GetComponent(), m_ResourceGenerator.GetComponent(), m_eResourceType, m_fCurrentTransferValue);
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  protected void GetResourceValues(out float currentResource, out float maxResource, out float transferAmount)
67  {
68  currentResource = m_ResourceConsumer.GetAggregatedResourceValue();
69  maxResource = Math.Min(m_ResourceGenerator.GetAggregatedMaxResourceValue() - m_ResourceGenerator.GetAggregatedResourceValue(), currentResource);
70 
71  if (m_fTransferAmount <= 0 || m_fTransferAmount > maxResource)
72  transferAmount = maxResource;
73  else
74  transferAmount = m_fTransferAmount;
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  override bool GetActionNameScript(out string outName)
79  {
80  if (!m_bCanPerform
82  || !m_ResourceInventoryPlayerComponentRplId.IsValid()
83  || !m_ResourceGenerator && !m_ResourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_LOAD, m_eResourceType, m_ResourceGenerator)
84  || !m_ResourceConsumer && !m_ResourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_LOAD, m_eResourceType, m_ResourceConsumer))
85  return false;
86 
87  outName = WidgetManager.Translate(GetUIInfo().GetDescription(), m_fCurrentTransferValue, m_ResourceGenerator.GetAggregatedResourceValue(), m_ResourceGenerator.GetAggregatedMaxResourceValue());
88  outName = WidgetManager.Translate("#AR-ActionFormat_SupplyCost", outName, m_fCurrentResource, m_ResourceConsumer.GetAggregatedMaxResourceValue());
89 
90  return true;
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  /*override bool CanBeShownScript(IEntity user)
95  {
96  if (!super.CanBeShownScript(user))
97  return false;
98 
99  if (!m_ResourceComponent || !m_ResourceComponent.AreSuppliesEnabled())
100  return false;
101 
102  return true;
103  }*/
104 
105  //------------------------------------------------------------------------------------------------
106  override event bool CanBePerformedScript(IEntity user)
107  {
108  m_bCanPerform = false;
109 
110  //~ TODO: Hotfix until proper solution, only blocks player does not block AI or Editor actions
111  if (m_CompartmentManager && m_CompartmentManager.BlockSuppliesIfOccupied() && m_CompartmentManager.GetOccupantCount() > 0)
112  {
113  SetCannotPerformReason(OCCUPIED_BY_CHARACTER);
114  return false;
115  }
116 
117  if (!m_ResourceInventoryPlayerComponentRplId || !m_ResourceInventoryPlayerComponentRplId.IsValid())
118  m_ResourceInventoryPlayerComponentRplId = Replication.FindId(SCR_ResourcePlayerControllerInventoryComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_ResourcePlayerControllerInventoryComponent)));
119 
120  if (!m_ResourceComponent
121  || !m_ResourceInventoryPlayerComponentRplId.IsValid()
122  || !m_ResourceGenerator && !m_ResourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_LOAD, m_eResourceType, m_ResourceGenerator)
123  || !m_ResourceConsumer && !m_ResourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_LOAD, m_eResourceType, m_ResourceConsumer))
124  {
125  SetCannotPerformReason("#AR-Supplies_CannotPerform_Generic");
126 
127  return false;
128  }
129 
132  else
133  m_ResourceSubscriptionHandleConsumer = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceConsumer, m_ResourceInventoryPlayerComponentRplId);
134 
135  if (m_ResourceSubscriptionHandleGenerator)
136  m_ResourceSubscriptionHandleGenerator.Poke();
137  else
138  m_ResourceSubscriptionHandleGenerator = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceGenerator, m_ResourceInventoryPlayerComponentRplId);
139 
140  GetResourceValues(m_fCurrentResource, m_fMaxStoredResource, m_fCurrentTransferValue);
141 
142  if (m_ResourceConsumer.GetAggregatedMaxResourceValue() == 0.0)
143  SetCannotPerformReason("#AR-Supplies_CannotPerform_Vehicle_NoStorage");
144  else if (m_fCurrentResource == 0.0)
145  SetCannotPerformReason("#AR-Supplies_CannotPerform_Generic");
146  else if (m_fMaxStoredResource == 0.0)
147  SetCannotPerformReason("#AR-Supplies_CannotPerform_Vehicle_StorageFull");
148 
149  m_bCanPerform = m_fMaxStoredResource > 0.0 && m_fMaxStoredResource <= m_fCurrentResource;
150 
151  return m_bCanPerform;
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
156  {
157  m_ResourceComponent = SCR_ResourceComponent.Cast(pOwnerEntity.FindComponent(SCR_ResourceComponent));
158 
159  if (!m_ResourceComponent)
160  return;
161 
162  m_ResourceGenerator = m_ResourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_LOAD, m_eResourceType);
163  m_ResourceConsumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_LOAD, m_eResourceType);
164  m_CompartmentManager = SCR_BaseCompartmentManagerComponent.Cast(pOwnerEntity.FindComponent(SCR_BaseCompartmentManagerComponent));
165  }
166 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
m_ResourceConsumer
protected SCR_ResourceConsumer m_ResourceConsumer
Definition: SCR_BaseSupportStationComponent.c:114
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ScriptedUserAction
A scripted action class having optional logic to check if vehicle is valid.
Definition: SCR_ScriptedUserAction.c:2
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
GetUIInfo
SCR_UIInfo GetUIInfo()
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:27
m_ResourceSubscriptionHandleConsumer
protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
Definition: SCR_BaseSupportStationComponent.c:125
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_CompartmentManager
protected SCR_BaseCompartmentManagerComponent m_CompartmentManager
Definition: SCR_VehicleDamageManagerComponent.c:191
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
m_ResourceComponent
protected SCR_ResourceComponent m_ResourceComponent
Definition: SCR_CampaignBuildingProviderComponent.c:51
SCR_ResourceContainerVehicleLoadAction
Definition: SCR_ResourceContainerVehicleLoadAction.c:1
SCR_ResourcePlayerControllerInventoryComponent
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:20
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_ResourceSystemSubscriptionHandleBase
Definition: SCR_ResourceSystemSubscriptionHandleBase.c:1
EResourcePlayerInteractionType
EResourcePlayerInteractionType
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:1
LocalizedString
Definition: LocalizedString.c:21
SCR_ResourceGenerator
Definition: SCR_ResourceGenerator.c:79
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1