Skip to content

Commit

Permalink
GH-91 Simplify morale details init code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 25, 2022
1 parent 8a311a7 commit b4c616f
Showing 1 changed file with 31 additions and 34 deletions.
65 changes: 31 additions & 34 deletions simulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}

Expand Down

0 comments on commit b4c616f

Please sign in to comment.