Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DrainFuelUserAction.c
Go to the documentation of this file.
3 {
4  [Attribute("#AR-FuelCanister_Drain_Action_Invalid_Empty")]
5  protected LocalizedString m_sCannotPerformNoFuel;
6 
7  protected IEntity m_ActionUser; //~ The player that uses is currently using the action
8  protected bool m_bIsMaster;
9 
10  protected bool m_bExecutingAction;
11 
12  protected SCR_FuelManagerComponent m_FuelManager;
13  protected SCR_DamageManagerComponent m_DamageComponent;
14 
15  //------------------------------------------------------------------------------------------------
16  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
17  {
18  super.Init(pOwnerEntity, pManagerComponent);
19 
20  m_FuelManager = SCR_FuelManagerComponent.Cast(pOwnerEntity.FindComponent(SCR_FuelManagerComponent));
21  m_DamageComponent = SCR_DamageManagerComponent.GetDamageManager(pOwnerEntity);
22 
24  if ((gameMode && gameMode.IsMaster()) || (!gameMode && Replication.IsServer()))
25  m_bIsMaster = true;
26  }
27 
28  //------------------------------------------------------------------------------------------------
29  override string GetCannotPerformReason()
30  {
31  //~ Another user is using it
32  if (m_ActionUser)
33  return m_sCannotPerformReason;
34  //~ Is empty
35  else
36  return m_sCannotPerformNoFuel;
37  }
38 
39  //------------------------------------------------------------------------------------------------
40  override bool CanBeShownScript(IEntity user)
41  {
42  if (!super.CanBeShownScript(user))
43  return false;
44 
45  if (!m_FuelManager)
46  return false;
47 
48  array<SCR_FuelNode> fuelNodes = {};
49  if (m_FuelManager.GetScriptedFuelNodesList(fuelNodes) <= 0)
50  return false;
51 
52  //~ Don't show if damage manager destroyed
53  if (m_DamageComponent)
54  return m_DamageComponent.GetState() != EDamageState.DESTROYED;
55 
56  //~ No damage system present
57  return true;
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  override bool CanBePerformedScript(IEntity user)
62  {
63  if (m_ActionUser && m_ActionUser != user)
64  return false;
65 
66  float totalFuel, totalMaxFuel, totalFuelPercentage
67  m_FuelManager.GetTotalValuesOfFuelNodes(totalFuel, totalMaxFuel, totalFuelPercentage, SCR_EFuelNodeTypeFlag.CAN_BE_DRAINED);
68 
69  return !float.AlmostEqual(totalFuel, 0);
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  //~ If continues action it will only execute everytime the duration is done
74  override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
75  {
76  if (!LoopActionUpdate(timeSlice))
77  return;
78 
79  PerformAction(pOwnerEntity, pUserEntity);
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
84  {
85  if (!m_FuelManager)
86  return;
87 
88  //~ Execute Audio broadcast
89  super.PerformAction(pOwnerEntity, pUserEntity);
90 
91  if (!m_bIsMaster)
92  return;
93 
94  float totalFuel, totalMaxFuel, totalFuelPercentage
95 
96  m_FuelManager.GetTotalValuesOfFuelNodes(totalFuel, totalMaxFuel, totalFuelPercentage, SCR_EFuelNodeTypeFlag.CAN_BE_DRAINED);
97 
98  array<SCR_FuelNode> fuelNodes = {};
99  m_FuelManager.GetScriptedFuelNodesList(fuelNodes);
100 
101  float actionDuration = GetActionDuration();
102  if (actionDuration < 0)
103  actionDuration *= -1;
104  else if (actionDuration == 0)
105  actionDuration = 1;
106 
107  //~ Todo: Replace with SCR_FuelManager with functions Support Manager fuel
108  float fuelRemovePercentage = Math.Clamp((m_FuelManager.GetTotalFuel() - ((fuelNodes[0].GetMaxFlowCapacityOut() / 60) * actionDuration)) / m_FuelManager.GetTotalMaxFuel(), 0, 1);
109 
110  m_FuelManager.SetTotalFuelPercentage(fuelRemovePercentage, SCR_EFuelNodeTypeFlag.CAN_BE_DRAINED);
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  override void OnActionStart(IEntity pUserEntity)
115  {
116  super.OnActionStart(pUserEntity);
117 
118  m_ActionUser = pUserEntity;
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
123  {
124  m_ActionUser = null;
125  }
126 
127  //------------------------------------------------------------------------------------------------
128  override bool GetActionNameScript(out string outName)
129  {
130  UIInfo uiInfo = GetUIInfo();
131  if (!uiInfo)
132  return false;
133 
134  string percentageString = SCR_FormatHelper.FloatToStringNoZeroDecimalEndings((m_FuelManager.GetTotalFuel() / m_FuelManager.GetTotalMaxFuel()) * 100, 1);
135  outName = WidgetManager.Translate(uiInfo.GetName(), percentageString);
136  return true;
137  }
138 }
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
UIInfo
UIInfo - declare object, allows to define UI elements.
Definition: UIInfo.c:13
EDamageState
EDamageState
Definition: EDamageState.c:12
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
GetUIInfo
SCR_UIInfo GetUIInfo()
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:27
m_FuelManager
protected FuelManagerComponent m_FuelManager
Definition: SCR_VehicleDamageManagerComponent.c:215
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_DrainFuelUserAction
Allows players to drain an entity with a fuel manager. Use with care as it might create a lot of grie...
Definition: SCR_DrainFuelUserAction.c:2
SCR_BaseAudioScriptedUserAction
A scripted action class having optional logic for playing audio as well as checking if the faction is...
Definition: SCR_BaseAudioScriptedUserAction.c:2
SCR_FuelManagerComponent
void SCR_FuelManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_FuelManagerComponent.c:475
LocalizedString
Definition: LocalizedString.c:21