Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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))]
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
13 protected SCR_ResourceComponent m_ResourceComponent;
15 protected SCR_ResourceConsumer m_ResourceConsumer;
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
44 return;
45
46 const int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
47 const PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
48
49 if (!playerController)
50 return;
51
53
54 if (!resourcePlayerControllerComponent)
55 return;
56
58 resourcePlayerControllerComponent.OnBeforePlayerInteraction(EResourcePlayerInteractionType.VEHICLE_LOAD, m_ResourceConsumer.GetComponent(), m_ResourceGenerator.GetComponent(), m_eResourceType, m_fCurrentTransferValue);
61 resourcePlayerControllerComponent.OnPlayerInteraction(EResourcePlayerInteractionType.VEHICLE_LOAD, m_ResourceConsumer.GetComponent(), m_ResourceGenerator.GetComponent(), m_eResourceType, m_fCurrentTransferValue);
62 }
63
64 //------------------------------------------------------------------------------------------------
65 protected void GetResourceValues(out float currentResource, out float maxResource, out float transferAmount)
66 {
67 currentResource = m_ResourceConsumer.GetAggregatedResourceValue();
68 maxResource = Math.Min(m_ResourceGenerator.GetAggregatedMaxResourceValue() - m_ResourceGenerator.GetAggregatedResourceValue(), currentResource);
69
71 transferAmount = maxResource;
72 else
73 transferAmount = m_fTransferAmount;
74 }
75
76 //------------------------------------------------------------------------------------------------
77 override bool GetActionNameScript(out string outName)
78 {
79 if (!m_bCanPerform
84 return false;
85
86 outName = WidgetManager.Translate(GetUIInfo().GetDescription(), m_fCurrentTransferValue, m_ResourceGenerator.GetAggregatedResourceValue(), m_ResourceGenerator.GetAggregatedMaxResourceValue());
87 outName = WidgetManager.Translate("#AR-ActionFormat_SupplyCost", outName, m_fCurrentResource, m_ResourceConsumer.GetAggregatedMaxResourceValue());
88
89 return true;
90 }
91
92 //------------------------------------------------------------------------------------------------
93 override bool CanBeShownScript(IEntity user)
94 {
95 if (!super.CanBeShownScript(user))
96 return false;
97
98 if (!m_ResourceComponent || !m_ResourceComponent.IsResourceTypeEnabled(m_eResourceType))
99 return false;
100
101 Vehicle vehicle = Vehicle.Cast(GetOwner());
102 if (!vehicle)
103 {
104 vehicle = Vehicle.Cast(GetOwner().GetRootParent());
105 if (!vehicle)
106 return false;
107 }
108
109 SCR_DamageManagerComponent damageMgr = vehicle.GetDamageManager();
110 if (!damageMgr || damageMgr.GetState() == EDamageState.DESTROYED)
111 return false;
112
113 return true;
114 }
115
116 //------------------------------------------------------------------------------------------------
117 override event bool CanBePerformedScript(IEntity user)
118 {
119 m_bCanPerform = false;
120
121 //~ TODO: Hotfix until proper solution, only blocks player does not block AI or Editor actions
122 if (m_CompartmentManager && m_CompartmentManager.BlockSuppliesIfOccupied() && m_CompartmentManager.GetOccupantCount() > 0)
123 {
125 return false;
126 }
127
130
135 {
136 SetCannotPerformReason("#AR-Supplies_CannotPerform_Generic");
137
138 return false;
139 }
140
143 else
144 m_ResourceSubscriptionHandleConsumer = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceConsumer, m_ResourceInventoryPlayerComponentRplId);
145
148 else
149 m_ResourceSubscriptionHandleGenerator = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceGenerator, m_ResourceInventoryPlayerComponentRplId);
150
152
153 if (m_ResourceConsumer.GetAggregatedMaxResourceValue() == 0.0)
154 SetCannotPerformReason("#AR-Supplies_CannotPerform_Vehicle_NoStorage");
155 else if (m_fCurrentResource == 0.0)
156 SetCannotPerformReason("#AR-Supplies_CannotPerform_Generic");
157 else if (m_fMaxStoredResource == 0.0)
158 SetCannotPerformReason("#AR-Supplies_CannotPerform_Vehicle_StorageFull");
159
161
162 return m_bCanPerform;
163 }
164
165 //------------------------------------------------------------------------------------------------
166 override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
167 {
168 m_ResourceComponent = SCR_ResourceComponent.Cast(pOwnerEntity.FindComponent(SCR_ResourceComponent));
169
171 return;
172
175 m_CompartmentManager = SCR_BaseCompartmentManagerComponent.Cast(pOwnerEntity.FindComponent(SCR_BaseCompartmentManagerComponent));
176 }
177}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
EResourceGeneratorID
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void SetCannotPerformReason(string reason)
proto external IEntity GetOwner()
Returns the parent entity of this action.
proto external UIInfo GetUIInfo()
Returns the UIInfo set for this user action or null if none.
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
sealed bool IsMaster()
void GetResourceValues(out float currentResource, out float maxResource, out float transferAmount)
override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleGenerator
SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
void OnPlayerInteraction(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue, bool shouldBroadcast=true)
void OnBeforePlayerInteraction(EResourcePlayerInteractionType interactionType, SCR_ResourceComponent resourceComponentFrom, SCR_ResourceComponent resourceComponentTo, EResourceType resourceType, float resourceValue)
A scripted action class having optional logic to check if vehicle is valid.
bool LoopActionUpdate(float timeSlice)
enum EPhysicsLayerPresets Vehicle
Definition gameLib.c:24
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()
EDamageState
@ PerformAction