Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DrainFuelUserAction.c
Go to the documentation of this file.
1
3{
4 [Attribute("#AR-FuelCanister_Drain_Action_Invalid_Empty")]
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
13 protected SCR_DamageManagerComponent m_DamageComponent;
14
15 //------------------------------------------------------------------------------------------------
16 override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
17 {
18 super.Init(pOwnerEntity, pManagerComponent);
19
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)
34 //~ Is empty
35 else
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
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}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_BaseGameMode GetGameMode()
void SCR_FuelManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
proto external float GetActionDuration()
Returns the duration of this action in seconds.
string m_sCannotPerformReason
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
Main replication API.
Definition Replication.c:14
A scripted action class having optional logic for playing audio as well as checking if the faction is...
sealed bool IsMaster()
Allows players to drain an entity with a fuel manager. Use with care as it might create a lot of grie...
override void OnActionCanceled(IEntity pOwnerEntity, IEntity pUserEntity)
override bool CanBeShownScript(IEntity user)
override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
override void OnActionStart(IEntity pUserEntity)
override string GetCannotPerformReason()
override bool CanBePerformedScript(IEntity user)
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
SCR_FuelManagerComponent m_FuelManager
override bool GetActionNameScript(out string outName)
SCR_DamageManagerComponent m_DamageComponent
override void PerformContinuousAction(IEntity pOwnerEntity, IEntity pUserEntity, float timeSlice)
bool LoopActionUpdate(float timeSlice)
UIInfo - allows to define UI elements.
Definition UIInfo.c:14
SCR_FieldOfViewSettings Attribute
EDamageState
@ PerformAction