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(
"2000",
"Amount of resources transfered on each action execute, -1 means max is transfer",
params:
"-1 inf")]
7 protected float m_fTransferAmount;
9 protected const LocalizedString OCCUPIED_BY_CHARACTER =
"#AR-UserAction_SeatOccupied";
13 protected SCR_ResourceComponent m_ResourceComponent;
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;
22 protected SCR_BaseCompartmentManagerComponent m_CompartmentManager;
26 override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity,
float timeSlice)
28 if (!LoopActionUpdate(timeSlice))
31 PerformAction(pOwnerEntity, pUserEntity);
35 override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
38 if (!gamemode || !gamemode.IsMaster())
46 GetResourceValues(m_fCurrentResource, m_fMaxStoredResource, m_fCurrentTransferValue);
49 m_ResourceGenerator.RequestGeneration(m_fCurrentTransferValue);
51 int playerId =
GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
52 PlayerController playerController =
GetGame().GetPlayerManager().GetPlayerController(playerId);
54 if (!playerController)
59 if (!resourcePlayerControllerComponent)
66 protected void GetResourceValues(out
float currentResource, out
float maxResource, out
float transferAmount)
69 maxResource = Math.Min(m_ResourceGenerator.GetAggregatedMaxResourceValue() - m_ResourceGenerator.GetAggregatedResourceValue(), currentResource);
71 if (m_fTransferAmount <= 0 || m_fTransferAmount > maxResource)
72 transferAmount = maxResource;
74 transferAmount = m_fTransferAmount;
78 override bool GetActionNameScript(out
string outName)
82 || !m_ResourceInventoryPlayerComponentRplId.IsValid()
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());
106 override event bool CanBePerformedScript(IEntity user)
108 m_bCanPerform =
false;
113 SetCannotPerformReason(OCCUPIED_BY_CHARACTER);
117 if (!m_ResourceInventoryPlayerComponentRplId || !m_ResourceInventoryPlayerComponentRplId.IsValid())
121 || !m_ResourceInventoryPlayerComponentRplId.IsValid()
125 SetCannotPerformReason(
"#AR-Supplies_CannotPerform_Generic");
135 if (m_ResourceSubscriptionHandleGenerator)
136 m_ResourceSubscriptionHandleGenerator.Poke();
138 m_ResourceSubscriptionHandleGenerator =
GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandleGraceful(m_ResourceGenerator, m_ResourceInventoryPlayerComponentRplId);
140 GetResourceValues(m_fCurrentResource, m_fMaxStoredResource, m_fCurrentTransferValue);
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");
149 m_bCanPerform = m_fMaxStoredResource > 0.0 && m_fMaxStoredResource <= m_fCurrentResource;
151 return m_bCanPerform;
155 override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
157 m_ResourceComponent = SCR_ResourceComponent.Cast(pOwnerEntity.FindComponent(SCR_ResourceComponent));
164 m_CompartmentManager = SCR_BaseCompartmentManagerComponent.Cast(pOwnerEntity.FindComponent(SCR_BaseCompartmentManagerComponent));