Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceContainerVehicleUnloadAction.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("-1", "Amount of resources transfered on each action execute, -1 means max is transfer", params: "-1 inf")]
7  protected float m_fTransferAmount;
8 
9  protected SCR_ResourcePlayerControllerInventoryComponent m_ResourceInventoryPlayerComponent;
10  protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer;
11  protected SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleGenerator;
12  protected SCR_ResourceComponent m_ResourceComponent;
13  protected SCR_ResourceGenerator m_ResourceGenerator;
14  protected SCR_ResourceConsumer m_ResourceConsumer;
15  protected RplId m_ResourceInventoryPlayerComponentRplId;
16  protected float m_fMaxStoredResource;
17  protected float m_fCurrentResource;
18  protected float m_fCurrentTransferValue;
19  protected bool m_bCanPerform;
20 
21  //------------------------------------------------------------------------------------------------
22  //~ If continues action it will only execute everytime the duration is done
23  override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
24  {
25  if (!LoopActionUpdate(timeSlice))
26  return;
27 
28  PerformAction(pOwnerEntity, pUserEntity);
29  }
30 
31  //------------------------------------------------------------------------------------------------
32  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
33  {
35  if (!gamemode || !gamemode.IsMaster())
36  return;
37 
39  || !m_ResourceGenerator && !m_ResourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_UNLOAD, m_eResourceType, m_ResourceGenerator)
40  || !m_ResourceConsumer && !m_ResourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, m_eResourceType, m_ResourceConsumer))
41  return;
42 
43  GetResourceValues(m_fCurrentResource, m_fMaxStoredResource, m_fCurrentTransferValue);
44 
45  m_ResourceConsumer.RequestConsumtion(m_fCurrentTransferValue);
46  m_ResourceGenerator.RequestGeneration(m_fCurrentTransferValue);
47 
48  int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
49  PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
50 
51  if (!playerController)
52  return;
53 
55 
56  if (!resourcePlayerControllerComponent)
57  return;
58 
59  resourcePlayerControllerComponent.OnPlayerInteraction(EResourcePlayerInteractionType.VEHICLE_UNLOAD, m_ResourceConsumer.GetComponent(), m_ResourceGenerator.GetComponent(), m_eResourceType, m_fCurrentTransferValue);
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  protected void GetResourceValues(out float currentResource, out float maxResource, out float transferAmount)
64  {
65  currentResource = m_ResourceConsumer.GetAggregatedResourceValue();
66  maxResource = Math.Min(m_ResourceGenerator.GetAggregatedMaxResourceValue() - m_ResourceGenerator.GetAggregatedResourceValue(), currentResource);
67 
68  if (m_fTransferAmount <= 0 || m_fTransferAmount > maxResource)
69  transferAmount = maxResource;
70  else
71  transferAmount = m_fTransferAmount;
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  override bool GetActionNameScript(out string outName)
76  {
77  if (!m_bCanPerform
79  || !m_ResourceInventoryPlayerComponentRplId.IsValid()
80  || !m_ResourceGenerator && !m_ResourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_UNLOAD, m_eResourceType, m_ResourceGenerator)
81  || !m_ResourceConsumer && !m_ResourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, m_eResourceType, m_ResourceConsumer))
82  return false;
83 
84  outName = WidgetManager.Translate(GetUIInfo().GetDescription(), m_fCurrentTransferValue, m_fCurrentResource, m_ResourceConsumer.GetAggregatedMaxResourceValue());
85  outName = WidgetManager.Translate("#AR-ActionFormat_SupplyCost", outName, m_ResourceGenerator.GetAggregatedResourceValue(), m_ResourceGenerator.GetAggregatedMaxResourceValue());
86 
87  return true;
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  /*override bool CanBeShownScript(IEntity user)
92  {
93  if (!super.CanBeShownScript(user))
94  return false;
95 
96  if (!m_ResourceComponent || !m_ResourceComponent.AreSuppliesEnabled())
97  return false;
98 
99  return true;
100  }*/
101 
102  //------------------------------------------------------------------------------------------------
103  override event bool CanBePerformedScript(IEntity user)
104  {
105  m_bCanPerform = false;
106 
107  if (!m_ResourceInventoryPlayerComponentRplId || !m_ResourceInventoryPlayerComponentRplId.IsValid())
108  m_ResourceInventoryPlayerComponentRplId = Replication.FindId(SCR_ResourcePlayerControllerInventoryComponent.Cast(GetGame().GetPlayerController().FindComponent(SCR_ResourcePlayerControllerInventoryComponent)));
109 
110  if (!m_ResourceComponent
111  || !m_ResourceInventoryPlayerComponentRplId.IsValid()
112  || !m_ResourceGenerator && !m_ResourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_UNLOAD, m_eResourceType, m_ResourceGenerator)
113  || !m_ResourceConsumer && !m_ResourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, m_eResourceType, m_ResourceConsumer))
114  {
115  SetCannotPerformReason("#AR-Supplies_CannotPerform_Generic");
116 
117  return false;
118  }
119 
122  else
123  m_ResourceSubscriptionHandleConsumer = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceConsumer, m_ResourceInventoryPlayerComponentRplId);
124 
125  if (m_ResourceSubscriptionHandleGenerator)
126  m_ResourceSubscriptionHandleGenerator.Poke();
127  else
128  m_ResourceSubscriptionHandleGenerator = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceGenerator, m_ResourceInventoryPlayerComponentRplId);
129 
130  GetResourceValues(m_fCurrentResource, m_fMaxStoredResource, m_fCurrentTransferValue);
131 
132  if (m_ResourceGenerator.GetAggregatedMaxResourceValue() == 0.0)
133  SetCannotPerformReason("#AR-Supplies_CannotPerform_Vehicle_NoStorage");
134  else if (m_fCurrentResource == 0.0)
135  SetCannotPerformReason("#AR-Supplies_CannotPerform_Vehicle_StorageEmpty");
136  else if (m_fCurrentTransferValue == 0.0)
137  SetCannotPerformReason("#AR-Supplies_CannotPerform_Container_StorageFull");
138 
139  m_bCanPerform = m_fMaxStoredResource > 0.0 && m_fMaxStoredResource <= m_fCurrentResource;
140 
141  return m_bCanPerform;
142  }
143 
144  //------------------------------------------------------------------------------------------------
145  override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
146  {
147  m_ResourceComponent = SCR_ResourceComponent.Cast(pOwnerEntity.FindComponent(SCR_ResourceComponent));
148 
149  if (!m_ResourceComponent)
150  return;
151 
152  m_ResourceGenerator = m_ResourceComponent.GetGenerator(EResourceGeneratorID.VEHICLE_UNLOAD, m_eResourceType);
153  m_ResourceConsumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, m_eResourceType);
154  }
155 }
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
SCR_ResourceContainerVehicleUnloadAction
Definition: SCR_ResourceContainerVehicleUnloadAction.c:1
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.
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
m_ResourceComponent
protected SCR_ResourceComponent m_ResourceComponent
Definition: SCR_CampaignBuildingProviderComponent.c:51
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
SCR_ResourceGenerator
Definition: SCR_ResourceGenerator.c:79
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1