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))]
6 [
Attribute(
"-1",
"Amount of resources transfered on each action execute, -1 means max is transfer",
params:
"-1 inf")]
7 protected float m_fTransferAmount;
12 protected SCR_ResourceComponent m_ResourceComponent;
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;
23 override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity,
float timeSlice)
25 if (!LoopActionUpdate(timeSlice))
28 PerformAction(pOwnerEntity, pUserEntity);
32 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
35 if (!gamemode || !gamemode.IsMaster())
43 GetResourceValues(m_fCurrentResource, m_fMaxStoredResource, m_fCurrentTransferValue);
46 m_ResourceGenerator.RequestGeneration(m_fCurrentTransferValue);
48 int playerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
49 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
51 if (!playerController)
56 if (!resourcePlayerControllerComponent)
63 protected void GetResourceValues(out
float currentResource, out
float maxResource, out
float transferAmount)
66 maxResource = Math.Min(m_ResourceGenerator.GetAggregatedMaxResourceValue() - m_ResourceGenerator.GetAggregatedResourceValue(), currentResource);
68 if (m_fTransferAmount <= 0 || m_fTransferAmount > maxResource)
69 transferAmount = maxResource;
71 transferAmount = m_fTransferAmount;
75 override bool GetActionNameScript(out
string outName)
79 || !m_ResourceInventoryPlayerComponentRplId.IsValid()
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());
103 override event bool CanBePerformedScript(IEntity user)
105 m_bCanPerform =
false;
107 if (!m_ResourceInventoryPlayerComponentRplId || !m_ResourceInventoryPlayerComponentRplId.IsValid())
111 || !m_ResourceInventoryPlayerComponentRplId.IsValid()
115 SetCannotPerformReason(
"#AR-Supplies_CannotPerform_Generic");
125 if (m_ResourceSubscriptionHandleGenerator)
126 m_ResourceSubscriptionHandleGenerator.Poke();
128 m_ResourceSubscriptionHandleGenerator =
GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceGenerator, m_ResourceInventoryPlayerComponentRplId);
130 GetResourceValues(m_fCurrentResource, m_fMaxStoredResource, m_fCurrentTransferValue);
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");
139 m_bCanPerform = m_fMaxStoredResource > 0.0 && m_fMaxStoredResource <= m_fCurrentResource;
141 return m_bCanPerform;
145 override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
147 m_ResourceComponent = SCR_ResourceComponent.Cast(pOwnerEntity.FindComponent(SCR_ResourceComponent));