Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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))]
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
11 protected SCR_ResourceComponent m_ResourceComponent;
13 protected SCR_ResourceConsumer m_ResourceConsumer;
15 protected float m_fMaxStoredResource;
16 protected float m_fCurrentResource;
17 protected float m_fCurrentTransferValue;
18 protected bool m_bCanPerform;
19
20 //------------------------------------------------------------------------------------------------
21 //~ If continues action it will only execute everytime the duration is done
22 override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
23 {
24 if (!LoopActionUpdate(timeSlice))
25 return;
26
27 PerformAction(pOwnerEntity, pUserEntity);
28 }
29
30 //------------------------------------------------------------------------------------------------
31 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
32 {
34 if (!gamemode || !gamemode.IsMaster())
35 return;
36
40 return;
41
42 const int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
43 const PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
44
45 if (!playerController)
46 return;
47
49
50 if (!resourcePlayerControllerComponent)
51 return;
52
53 resourcePlayerControllerComponent.OnBeforePlayerInteraction(EResourcePlayerInteractionType.VEHICLE_UNLOAD, m_ResourceConsumer.GetComponent(), m_ResourceGenerator.GetComponent(), m_eResourceType, m_fCurrentTransferValue);
57 resourcePlayerControllerComponent.OnPlayerInteraction(EResourcePlayerInteractionType.VEHICLE_UNLOAD, m_ResourceConsumer.GetComponent(), m_ResourceGenerator.GetComponent(), m_eResourceType, m_fCurrentTransferValue);
58 }
59
60 //------------------------------------------------------------------------------------------------
61 protected void GetResourceValues(out float currentResource, out float maxResource, out float transferAmount)
62 {
63 currentResource = m_ResourceConsumer.GetAggregatedResourceValue();
64 maxResource = Math.Min(m_ResourceGenerator.GetAggregatedMaxResourceValue() - m_ResourceGenerator.GetAggregatedResourceValue(), currentResource);
65
67 transferAmount = maxResource;
68 else
69 transferAmount = m_fTransferAmount;
70 }
71
72 //------------------------------------------------------------------------------------------------
73 override bool GetActionNameScript(out string outName)
74 {
75 if (!m_bCanPerform
80 return false;
81
82 outName = WidgetManager.Translate(GetUIInfo().GetDescription(), m_fCurrentTransferValue, m_fCurrentResource, m_ResourceConsumer.GetAggregatedMaxResourceValue());
83 outName = WidgetManager.Translate("#AR-ActionFormat_SupplyCost", outName, m_ResourceGenerator.GetAggregatedResourceValue(), m_ResourceGenerator.GetAggregatedMaxResourceValue());
84
85 return true;
86 }
87
88 //------------------------------------------------------------------------------------------------
89 override bool CanBeShownScript(IEntity user)
90 {
91 if (!super.CanBeShownScript(user))
92 return false;
93
94 if (!m_ResourceComponent || !m_ResourceComponent.IsResourceTypeEnabled(m_eResourceType))
95 return false;
96
97 Vehicle vehicle = Vehicle.Cast(GetOwner());
98 if (!vehicle)
99 {
100 vehicle = Vehicle.Cast(GetOwner().GetRootParent());
101 if (!vehicle)
102 return false;
103 }
104
105 SCR_DamageManagerComponent damageMgr = vehicle.GetDamageManager();
106 if (!damageMgr || damageMgr.GetState() == EDamageState.DESTROYED)
107 return false;
108
109 return true;
110 }
111
112 //------------------------------------------------------------------------------------------------
113 override event bool CanBePerformedScript(IEntity user)
114 {
115 m_bCanPerform = false;
116
119
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
137 else
138 m_ResourceSubscriptionHandleGenerator = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceGenerator, m_ResourceInventoryPlayerComponentRplId);
139
141
142 if (m_ResourceGenerator.GetAggregatedMaxResourceValue() == 0.0)
143 SetCannotPerformReason("#AR-Supplies_CannotPerform_Vehicle_NoStorage");
144 else if (m_fCurrentResource == 0.0)
145 SetCannotPerformReason("#AR-Supplies_CannotPerform_Vehicle_StorageEmpty");
146 else if (m_fCurrentTransferValue == 0.0)
147 SetCannotPerformReason("#AR-Supplies_CannotPerform_Container_StorageFull");
148
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
160 return;
161
164 }
165}
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()
override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
void GetResourceValues(out float currentResource, out float maxResource, out float transferAmount)
override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleGenerator
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