Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ResourceContainerStoreAction.c
Go to the documentation of this file.
3 {
4  [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  protected EResourceType m_eResourceType;
6 
7  //~protected static SCR_CharacterResourceRequesterComponent s_CharacterResourceRequester;
8  protected SCR_ResourceGenerator m_ResourceGenerator;
9  protected SCR_ResourceConsumer m_ResourceConsumer;
10  protected float m_fMaxStoredResource;
11  protected float m_fCurrentResource;
12 
13  //------------------------------------------------------------------------------------------------
14  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
15  {
17 
18  if (!gamemode || !gamemode.IsMaster())
19  return;
20 
21  m_fCurrentResource = m_ResourceConsumer.GetAggregatedResourceValue();
22  m_fMaxStoredResource = Math.Min(m_ResourceGenerator.GetAggregatedMaxResourceValue() - m_ResourceGenerator.GetAggregatedResourceValue(), m_fCurrentResource);
23 
24  m_ResourceConsumer.RequestConsumtion(m_fMaxStoredResource);
25  m_ResourceGenerator.RequestGeneration(m_fMaxStoredResource);
26 
27  int playerId = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(pUserEntity);
28  PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerId);
29 
30  if (!playerController)
31  return;
32 
34 
35  if (!resourcePlayerControllerComponent)
36  return;
37 
38  resourcePlayerControllerComponent.OnPlayerInteraction(EResourcePlayerInteractionType.STORAGE, m_ResourceConsumer.GetComponent(), m_ResourceGenerator.GetComponent(), m_eResourceType, m_fMaxStoredResource);
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  override bool GetActionNameScript(out string outName)
43  {
44  /*
45  if (m_fMaxStoredResource > 0 && m_fMaxStoredResource < m_fCurrentResource)
46  outName = string.Format("Store %1/%2 resources", m_fMaxStoredResource, m_fCurrentResource);
47  else
48  outName = string.Format("Store %1 resources", m_fMaxStoredResource);
49 
50  return true;
51  */
52 
53  if (m_fMaxStoredResource > 0 && m_fMaxStoredResource < m_fCurrentResource)
54  outName = WidgetManager.Translate(GetUIInfo().GetName(), m_fMaxStoredResource, m_fCurrentResource);
55  else
56  outName = WidgetManager.Translate(GetUIInfo().GetDescription(), m_fMaxStoredResource);
57 
58  return true;
59 
60  }
61 
62  //------------------------------------------------------------------------------------------------
63  override event bool CanBePerformedScript(IEntity user)
64  {
65  SCR_ResourceComponent component = SCR_ResourceComponent.Cast(GetOwner().FindComponent(SCR_ResourceComponent));
66 
67  if (!component)
68  return false;
69 
70  m_ResourceGenerator = component.GetGenerator(EResourceGeneratorID.DEFAULT_STORAGE, m_eResourceType);
71  m_ResourceConsumer = component.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, m_eResourceType);
72 
73  if (!m_ResourceGenerator || !m_ResourceConsumer)
74  {
75  SetCannotPerformReason(WidgetManager.Translate("#AR-Supplies_CannotPerform_Generic"));
76 
77  return false;
78  }
79 
80  m_fCurrentResource = m_ResourceConsumer.GetAggregatedResourceValue();
81  m_fMaxStoredResource = Math.Min(m_ResourceGenerator.GetAggregatedMaxResourceValue() - m_ResourceGenerator.GetAggregatedResourceValue(), m_fCurrentResource);
82 
83  if (m_ResourceGenerator.GetContainerCount() == 0)
84  SetCannotPerformReason("#AR-Supplies_CannotPerform_Container_NoStorage");
85  else if (m_fMaxStoredResource == 0.0)
86  SetCannotPerformReason("#AR-Supplies_CannotPerform_Container_StorageFull");
87 
88  return m_fMaxStoredResource > 0.0 && m_fMaxStoredResource <= m_fCurrentResource;
89  }
90 
91  //------------------------------------------------------------------------------------------------
92  override event void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
93  {
94  SCR_ResourceComponent component = SCR_ResourceComponent.Cast(pOwnerEntity.FindComponent(SCR_ResourceComponent));
95 
96  if (!component)
97  return;
98 
99  m_ResourceGenerator = component.GetGenerator(EResourceGeneratorID.DEFAULT_STORAGE, m_eResourceType);
100  m_ResourceConsumer = component.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, m_eResourceType);
101  }
102 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
m_ResourceConsumer
protected SCR_ResourceConsumer m_ResourceConsumer
Definition: SCR_BaseSupportStationComponent.c:114
GetName
string GetName()
Definition: SCR_ScenarioFrameworkLayerBase.c:85
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ScriptedUserAction
Definition: ScriptedUserAction.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
GetUIInfo
SCR_UIInfo GetUIInfo()
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:27
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ResourceContainerStoreAction
TODO MARIO: Rework this class to work with multiple containers!!.
Definition: SCR_ResourceContainerStoreAction.c:2
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
SCR_ResourcePlayerControllerInventoryComponent
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:20
EResourcePlayerInteractionType
EResourcePlayerInteractionType
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:1
SCR_ResourceGenerator
Definition: SCR_ResourceGenerator.c:79
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1