Skip to content

Commit

Permalink
GH-139 Move storage counter to an util
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed May 26, 2022
1 parent 95b5a75 commit fb195d3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
11 changes: 4 additions & 7 deletions fleet1.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,12 @@

$Fleet['array'] = $fleetArrayParsingResult['payload']['parsedFleet'];

foreach ($Fleet['array'] as $shipId => $shipCount) {
$allShipsOfTypeStorage = getShipsStorageCapacity($shipId) * $shipCount;
$shipsTotalStorage = FlightControl\Utils\Helpers\FleetArray\getShipsTotalStorage($Fleet['array']);

if (canShipPillage($shipId)) {
$Fleet['storage'] += $allShipsOfTypeStorage;
} else {
$Fleet['FuelStorage'] += $allShipsOfTypeStorage;
}
$Fleet['storage'] = $shipsTotalStorage['allPurpose'];
$Fleet['FuelStorage'] = $shipsTotalStorage['fuelOnly'];

foreach ($Fleet['array'] as $shipId => $shipCount) {
$shipSpeed = getShipsCurrentSpeed($shipId, $_User);
$shipConsumption = getShipsCurrentConsumption($shipId, $_User);
$allShipsConsumption = ($shipConsumption * $shipCount);
Expand Down
13 changes: 4 additions & 9 deletions fleet2.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,12 @@
}

$Fleet['array'] = $fleetArrayParsingResult['payload']['parsedFleet'];
$Fleet['count'] = FlightControl\Utils\Helpers\FleetArray\getAllShipsCount($Fleet['array']);

foreach ($Fleet['array'] as $shipID => $shipCount) {
$allShipsOfTypeStorage = getShipsStorageCapacity($shipID) * $shipCount;
$shipsTotalStorage = FlightControl\Utils\Helpers\FleetArray\getShipsTotalStorage($Fleet['array']);

if (canShipPillage($shipID)) {
$Fleet['storage'] += $allShipsOfTypeStorage;
} else {
$Fleet['FuelStorage'] += $allShipsOfTypeStorage;
}
}
$Fleet['count'] = FlightControl\Utils\Helpers\FleetArray\getAllShipsCount($Fleet['array']);
$Fleet['storage'] = $shipsTotalStorage['allPurpose'];
$Fleet['FuelStorage'] = $shipsTotalStorage['fuelOnly'];

$AvailableMissions = FlightControl\Utils\Helpers\getValidMissionTypes([
'targetCoordinates' => $Target,
Expand Down
13 changes: 4 additions & 9 deletions fleet3.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,12 @@ function messageRed($Text, $Title)
}

$Fleet['array'] = $fleetArrayParsingResult['payload']['parsedFleet'];
$Fleet['count'] = FlightControl\Utils\Helpers\FleetArray\getAllShipsCount($Fleet['array']);

foreach ($Fleet['array'] as $shipID => $shipCount) {
$allShipsOfTypeStorage = getShipsStorageCapacity($shipID) * $shipCount;
$shipsTotalStorage = FlightControl\Utils\Helpers\FleetArray\getShipsTotalStorage($Fleet['array']);

if (canShipPillage($shipID)) {
$Fleet['storage'] += $allShipsOfTypeStorage;
} else {
$Fleet['FuelStorage'] += $allShipsOfTypeStorage;
}
}
$Fleet['count'] = FlightControl\Utils\Helpers\FleetArray\getAllShipsCount($Fleet['array']);
$Fleet['storage'] = $shipsTotalStorage['allPurpose'];
$Fleet['FuelStorage'] = $shipsTotalStorage['fuelOnly'];

$validMissionTypes = FlightControl\Utils\Helpers\getValidMissionTypes([
'targetCoordinates' => $Target,
Expand Down
19 changes: 19 additions & 0 deletions modules/flightControl/utils/helpers/getFleetArrayInfo.helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,23 @@ function getAllShipsCount($fleetArray) {
return array_sum($fleetArray);
}

function getShipsTotalStorage($fleetArray) {
$storages = [
'allPurpose' => 0,
'fuelOnly' => 0,
];

foreach ($fleetArray as $shipID => $shipCount) {
$allShipsOfTypeStorage = getShipsStorageCapacity($shipID) * $shipCount;

if (canShipPillage($shipID)) {
$storages['allPurpose'] += $allShipsOfTypeStorage;
} else {
$storages['fuelOnly'] += $allShipsOfTypeStorage;
}
}

return $storages;
}

?>

0 comments on commit fb195d3

Please sign in to comment.