From b4c616f7a7863f4043b82884f4f7e9931c29a1fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dzieko=C5=84ski?= Date: Tue, 26 Jul 2022 00:19:22 +0200 Subject: [PATCH] GH-91 Simplify morale details init code a bit --- simulator.php | 65 ++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 34 deletions(-) diff --git a/simulator.php b/simulator.php index 4deb8fc3..086d5382 100644 --- a/simulator.php +++ b/simulator.php @@ -215,45 +215,42 @@ function ($value, $key) use ($TechEquivalents) { } if (MORALE_ENABLED) { - if (!empty($AttackingFleets)) { - foreach ($AttackingFleets as $ThisUser => $ThisData) { - $ThisMoraleLevel = intval($_POST['atk_morale'][($ThisUser + 1)]); - $ThisMoraleLevel = keepInRange($ThisMoraleLevel, -100, 100); - - $AttackersData[$ThisUser]['moraleData'] = [ - 'morale_level' => $ThisMoraleLevel, - 'morale_points' => 0, - ]; + foreach ($AttackingFleets as $ThisUser => $ThisData) { + $ThisMoraleLevel = intval($_POST['atk_morale'][($ThisUser + 1)]); + $ThisMoraleLevel = keepInRange($ThisMoraleLevel, -100, 100); - $moraleCombatModifiers = Flights\Utils\Modifiers\calculateMoraleCombatModifiers([ - 'moraleLevel' => $ThisMoraleLevel, - ]); + $AttackersData[$ThisUser]['moraleData'] = [ + 'morale_level' => $ThisMoraleLevel, + 'morale_points' => 0, + ]; - $AttackingTechs[$ThisUser] = array_merge( - $AttackingTechs[$ThisUser], - $moraleCombatModifiers - ); - } + $moraleCombatModifiers = Flights\Utils\Modifiers\calculateMoraleCombatModifiers([ + 'moraleLevel' => $ThisMoraleLevel, + ]); + + $AttackingTechs[$ThisUser] = array_merge( + $AttackingTechs[$ThisUser], + $moraleCombatModifiers + ); } - if (!empty($DefendingFleets)) { - foreach ($DefendingFleets as $ThisUser => $ThisData) { - $ThisMoraleLevel = intval($_POST['def_morale'][($ThisUser + 1)]); - $ThisMoraleLevel = keepInRange($ThisMoraleLevel, -100, 100); - - $DefendersData[$ThisUser]['moraleData'] = [ - 'morale_level' => $ThisMoraleLevel, - 'morale_points' => 0, - ]; - $moraleCombatModifiers = Flights\Utils\Modifiers\calculateMoraleCombatModifiers([ - 'moraleLevel' => $ThisMoraleLevel, - ]); + foreach ($DefendingFleets as $ThisUser => $ThisData) { + $ThisMoraleLevel = intval($_POST['def_morale'][($ThisUser + 1)]); + $ThisMoraleLevel = keepInRange($ThisMoraleLevel, -100, 100); - $DefendingTechs[$ThisUser] = array_merge( - $DefendingTechs[$ThisUser], - $moraleCombatModifiers - ); - } + $DefendersData[$ThisUser]['moraleData'] = [ + 'morale_level' => $ThisMoraleLevel, + 'morale_points' => 0, + ]; + + $moraleCombatModifiers = Flights\Utils\Modifiers\calculateMoraleCombatModifiers([ + 'moraleLevel' => $ThisMoraleLevel, + ]); + + $DefendingTechs[$ThisUser] = array_merge( + $DefendingTechs[$ThisUser], + $moraleCombatModifiers + ); } }