Skip to content

Commit

Permalink
GH-139 Create getAvailableSpeeds helper
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Dec 8, 2020
1 parent ae3dfbd commit 597d090
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/flightControl/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

$includePath = $_EnginePath . 'modules/flightControl/';

include($includePath . './utils/helpers/getAvailableSpeeds.helper.php');
include($includePath . './utils/validators/fleetArray.validator.php');

});
Expand Down
55 changes: 55 additions & 0 deletions modules/flightControl/utils/helpers/getAvailableSpeeds.helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace UniEngine\Engine\Modules\FlightControl\Utils\Helpers;

/**
* @param array $props
* @param ref $props['user']
* @param number $props['timestamp']
*/
function getAvailableSpeeds ($props) {
$user = &$props['user'];
$timestamp = $props['timestamp'];

$speedsAvailable = [
10,
9,
8,
7,
6,
5,
4,
3,
2,
1,
];

if ($user['admiral_time'] > $timestamp) {
$speedsAvailable[] = 12;
$speedsAvailable[] = 11;
$speedsAvailable[] = 0.5;
$speedsAvailable[] = 0.25;
}

if (MORALE_ENABLED) {
$maxSpeedAvailable = max($speedsAvailable);

if ($user['morale_level'] >= MORALE_BONUS_FLEETSPEEDUP1) {
$speedBoostValue = $maxSpeedAvailable + (MORALE_BONUS_FLEETSPEEDUP1_VALUE / 10);

$speedsAvailable[] = $speedBoostValue;
}

if ($user['morale_level'] >= MORALE_BONUS_FLEETSPEEDUP2) {
$speedBoostValue = $maxSpeedAvailable + (MORALE_BONUS_FLEETSPEEDUP2_VALUE / 10);

$speedsAvailable[] = $speedBoostValue;
}
}

rsort($speedsAvailable);

return $speedsAvailable;
}

?>
5 changes: 5 additions & 0 deletions modules/flightControl/utils/helpers/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

header("Location: ../index.php");

?>

0 comments on commit 597d090

Please sign in to comment.