From 0a7f0b0a0648aabdfc44924902659916ac1c8553 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Fri, 27 May 2022 21:18:37 +0200 Subject: [PATCH] GH-139 Move max flight's speed getter into an util --- fleet1.php | 19 ++++-------- modules/flightControl/_includes.php | 1 + .../helpers/getSlowestShipSpeed.helper.php | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 modules/flightControl/utils/helpers/getSlowestShipSpeed.helper.php diff --git a/fleet1.php b/fleet1.php index 75f9f5d1..8aecf902 100644 --- a/fleet1.php +++ b/fleet1.php @@ -122,19 +122,6 @@ } } -$slowestShipSpeed = min( - array_map_withkeys($shipsDetails, function ($shipDetails) { - return $shipDetails['speed']; - }) -); - -// Speed modifier -if (MORALE_ENABLED) { - if ($_User['morale_level'] <= MORALE_PENALTY_FLEETSLOWDOWN) { - $slowestShipSpeed *= MORALE_PENALTY_FLEETSLOWDOWN_VALUE; - } -} - $_Lang['P_HideACSJoining'] = $Hide; $GetACSData = intval($_POST['getacsdata']); $SetPosNotEmpty = false; @@ -202,9 +189,15 @@ $_Lang['SetTargetMission'] = 2; } +$slowestShipSpeed = FlightControl\Utils\Helpers\getSlowestShipSpeed([ + 'shipsDetails' => $shipsDetails, + 'user' => &$_User, +]); + // Show info boxes $_Lang['P_SFBInfobox'] = FlightControl\Components\SmartFleetBlockadeInfoBox\render()['componentHTML']; + $_Lang['P_ShipsDetailsJSON'] = json_encode($shipsDetails, JSON_FORCE_OBJECT); $_Lang['speedallsmin'] = $slowestShipSpeed; $_Lang['MaxSpeedPretty'] = prettyNumber($slowestShipSpeed); diff --git a/modules/flightControl/_includes.php b/modules/flightControl/_includes.php index ad92a219..210ec816 100644 --- a/modules/flightControl/_includes.php +++ b/modules/flightControl/_includes.php @@ -68,6 +68,7 @@ include($includePath . './utils/helpers/getFleetUnionJoinData.helper.php'); include($includePath . './utils/helpers/getFlightParams.helper.php'); include($includePath . './utils/helpers/getQuantumGateStateDetails.helper.php'); + include($includePath . './utils/helpers/getSlowestShipSpeed.helper.php'); include($includePath . './utils/helpers/getTargetInfo.helper.php'); include($includePath . './utils/helpers/getUserExpeditionSlotsCount.helper.php'); include($includePath . './utils/helpers/getUserFleetSlotsCount.helper.php'); diff --git a/modules/flightControl/utils/helpers/getSlowestShipSpeed.helper.php b/modules/flightControl/utils/helpers/getSlowestShipSpeed.helper.php new file mode 100644 index 00000000..aab2ee22 --- /dev/null +++ b/modules/flightControl/utils/helpers/getSlowestShipSpeed.helper.php @@ -0,0 +1,30 @@ + $params['shipsDetails'] + * @param ref $params['user'] + */ +function getSlowestShipSpeed($params) { + $shipsDetails = $params['shipsDetails']; + $user = &$params['user']; + + $slowestShipSpeed = min( + array_map_withkeys($shipsDetails, function ($shipDetails) { + return $shipDetails['speed']; + }) + ); + + if ( + MORALE_ENABLED && + $user['morale_level'] <= MORALE_PENALTY_FLEETSLOWDOWN + ) { + $slowestShipSpeed *= MORALE_PENALTY_FLEETSLOWDOWN_VALUE; + } + + return $slowestShipSpeed; +} + +?>