4 [
Attribute(
desc:
"Sound effect played when fuel is updated. Broadcast to players. Leave empty if no sfx",
category:
"Fuel Support Station")]
5 protected string m_sOnUpdateSoundEffectEventName;
7 protected ref SCR_AudioSourceConfiguration m_OnUpdateAudioSourceConfiguration;
13 SCR_AudioSourceConfiguration GetOnUpdateAudioConfig()
35 class SCR_FuelSupportStationComponent : SCR_BaseSupportStationComponent
37 [
Attribute(defvalue: EFuelFlowCapacityOut.FUEL_CARGO.ToString(), uiwidget: UIWidgets.SearchComboBox,
desc:
"Maximum Flow Capacity (per minute). Is only used if entity does not have a Fuelmanager with Nodes as scripted fuel nodes have the max flow assigned", enums: ParamEnumArray.FromEnum( EFuelFlowCapacityOut ),
category:
"Fuel Support Station Only")]
38 protected EFuelFlowCapacityOut m_BackupMaxFlowCapacity;
51 super.DelayedInit(owner);
59 if (!super.IsValid(actionOwner, actionUser, action, actionPosition, reasonInvalid, supplyCost))
83 if (!nodeUsedForRefuel)
87 nodeUsedForRefuel.SetFuel(Math.Clamp(nodeUsedForRefuel.GetFuel() - fuelAmount, 0, nodeUsedForRefuel.GetMaxFuel()));
92 protected void GetFuelNodeInfo(out
float maxFlowCapacity, out SCR_FuelNode nodeUsedForRefuel,
float actionDuration)
95 nodeUsedForRefuel =
null;
100 maxFlowCapacity = (m_BackupMaxFlowCapacity / 60) * actionDuration;
104 array<BaseFuelNode> nodes = {};
107 SCR_FuelNode scrNode;
113 scrNode = SCR_FuelNode.Cast(node);
118 if (scrNode.CanProvideFuel() && scrNode.GetFuel() > 0)
120 nodeUsedForRefuel = scrNode;
122 maxFlowCapacity = (scrNode.GetMaxFlowCapacityOut() / 60) * actionDuration;
125 if (scrNode.GetFuel() < maxFlowCapacity)
126 maxFlowCapacity = scrNode.GetFuel();
144 Debug.Error2(
"SCR_FuelSupportStationComponent",
"Was initiated by an user action that does not inherit from 'SCR_RefuelAtSupportStationAction'");
148 array<int> fuelTankIDs = {};
149 refuelAction.GetFuelTankIDs(fuelTankIDs);
153 if (!targetFuelManager || !targetFuelManager.CanBeRefueledScripted(fuelTankIDs))
157 float actionDuration = 1;
160 actionDuration = action.GetActionDuration();
162 if (actionDuration < 0)
163 actionDuration *= -1;
166 float maxFlowCapacityOut;
167 SCR_FuelNode nodeUsedForRefuel;
168 GetFuelNodeInfo(maxFlowCapacityOut, nodeUsedForRefuel, actionDuration);
171 if (maxFlowCapacityOut <= 0)
174 array<BaseFuelNode> nodes = {};
175 targetFuelManager.GetFuelNodesList(nodes);
177 float fuelToAdded = maxFlowCapacityOut;
180 SCR_FuelNode scrNode;
182 bool maxFlowCapacityReached =
false;
183 float maxFlowNode = 1;
186 for (
int i = 0, count = nodes.Count(); i < count; i++)
189 if (!nodes[i] || nodes[i].GetFuel() >= nodes[i].GetMaxFuel())
192 scrNode = SCR_FuelNode.Cast(nodes[i]);
195 if (refuelAction && !refuelAction.CheckIfFuelNodeIsValid(scrNode))
199 preChangeFuel = nodes[i].GetFuel();
204 if (!scrNode.CanReceiveFuel())
207 maxFlowNode = (scrNode.GetMaxFlowCapacityIn() / 60) * actionDuration;
210 maxFlowCapacityReached = fuelToAdded > maxFlowNode;
213 scrNode.SetFuel(Math.Clamp(scrNode.GetFuel() + Math.Clamp(fuelToAdded, 0, maxFlowNode), 0, scrNode.GetMaxFuel()));
218 nodes[i].SetFuel(Math.Clamp(nodes[i].GetFuel() + fuelToAdded, 0, nodes[i].GetMaxFuel()));
221 fuelToAdded -= nodes[i].GetFuel() - preChangeFuel;
223 if (maxFlowCapacityReached)
226 if (fuelToAdded <= 0)
237 float fuelTankFillPercentage = targetFuelManager.GetTotalFuel() / targetFuelManager.GetTotalMaxFuel();
238 bool currentTankFull =
true;
243 if (!refuelAction.CheckIfFuelNodeIsValid(SCR_FuelNode.Cast(node)))
247 if (node.GetFuel() < node.GetMaxFuel())
249 currentTankFull =
false;
259 FindEntityIds(actionOwner, actionUser, ownerId, userId, playerId);
262 OnExecuteFuel(actionOwner, actionUser, playerId, fuelTankFillPercentage, currentTankFull, action);
263 Rpc(
OnExecuteFuelBroadcast, ownerId, userId, playerId, fuelTankFillPercentage, currentTankFull, action.GetActionID());
268 [
RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
269 protected void OnExecuteFuelBroadcast(RplId ownerId, RplId userId,
int userPlayerId,
float fuelTankFillPercentage,
bool currentTankFull,
int actionId)
271 IEntity actionOwner, actionUser;
277 ActionsManagerComponent actionManager = ActionsManagerComponent.Cast(actionOwner.FindComponent(ActionsManagerComponent));
281 OnExecuteFuel(actionOwner, actionUser, userPlayerId, fuelTankFillPercentage, currentTankFull, action);
293 if (fuelPercentage < 1 && !currentTankFull)
298 else if (fuelPercentage < 1 && currentTankFull)
319 if (!userEditableEntity)
322 RplId userRplId = Replication.FindId(userEditableEntity);
325 array<int> playersInVehicle = {};
331 if (fuelPercentage < 1 && !currentTankFull)
332 SCR_NotificationsComponent.SendLocal(
ENotification.SUPPORTSTATION_REFUELED_BY_OTHER_UPDATE, userRplId, fuelPercentage * 1000);
333 else if (fuelPercentage < 1 && currentTankFull)
334 SCR_NotificationsComponent.SendLocal(
ENotification.SUPPORTSTATION_REFUELED_BY_OTHER_TANK_FULL, userRplId, fuelPercentage * 1000);
336 SCR_NotificationsComponent.SendLocal(
ENotification.SUPPORTSTATION_REFUELED_BY_OTHER_DONE, userRplId);
350 ResourceName soundFile;
351 string soundEventName;
358 PlaySoundEffect(classData.GetOnUpdateAudioConfig(), actionOwner, action);