Skip to content

Commit

Permalink
GH-91 Move combat techs mapping to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Jul 29, 2022
1 parent 4d81c52 commit 1be8827
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
2 changes: 2 additions & 0 deletions modules/attackSimulator/_includes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
include($includePath . './components/ShipInput/ShipInput.component.php');
include($includePath . './components/TechInput/TechInput.component.php');

include($includePath . './utils/combatTechs.utils.php');

});

?>
36 changes: 36 additions & 0 deletions modules/attackSimulator/utils/combatTechs.utils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace UniEngine\Engine\Modules\AttackSimulator\Utils\CombatTechs;

/**
* Returns a list of combat techs with their "packed counterpart mapping"
*
* Note: should be synced with $_Vars_ElementCategories['techPurpose']['combat']
*/
function _getTechsMapping() {
return [
109 => 1,
110 => 2,
111 => 3,
120 => 4,
121 => 5,
122 => 6,
125 => 7,
126 => 8,
199 => 9,
];
}

function getTechsList() {
return array_keys(_getTechsMapping());
}

function getTechPackedKey($elementId) {
return _getTechsMapping()[$elementId];
}

function getTechStandardKey($packedId) {
return array_flip(_getTechsMapping())[$packedId];
}

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

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

?>
22 changes: 6 additions & 16 deletions simulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,8 @@
$_Lang['rows'] = '';
$_Lang['SimResult'] = '';

$TechEquivalents = [
1 => 109,
2 => 110,
3 => 111,
4 => 120,
5 => 121,
6 => 122,
7 => 125,
8 => 126,
9 => 199,
];
$TechCount = count($TechEquivalents);
$combatTechs = AttackSimulator\Utils\CombatTechs\getTechsList();

$MaxACSSlots = ACS_MAX_JOINED_FLEETS + 1;
$MaxStringLength = 30;

Expand All @@ -37,12 +27,12 @@
$_POST['def_techs'][1] = (isset($_POST['spyreport']['tech']) ? $_POST['spyreport']['tech'] : null);
$_POST['def_techs'][1] = object_map(
$_POST['def_techs'][1],
function ($value, $key) use ($TechEquivalents) {
function ($value, $key) {
$safeKey = intval($key, 10);

return [
$value,
$TechEquivalents[$safeKey],
AttackSimulator\Utils\CombatTechs\getTechStandardKey($safeKey),
];
}
);
Expand Down Expand Up @@ -561,7 +551,7 @@ function ($value, $key) use ($TechEquivalents) {
$parse['RowText2'] = '<a class="orange point fillTech_def">'.$_Lang['FillMyTechs'].'</a> / <a class="orange point clnTech_def">'.$_Lang['Fill_Clean'].'</a>';
$ThisSlot['txt'] .= parsetemplate($TPL_NoBoth, $parse);

foreach ($TechEquivalents as $elementId) {
foreach ($combatTechs as $elementId) {
$ThisRow_InsertValue_Atk = isset($_POST['atk_techs'][$i][$elementId]) ? $_POST['atk_techs'][$i][$elementId] : null;
$ThisRow_InsertValue_Def = isset($_POST['def_techs'][$i][$elementId]) ? $_POST['def_techs'][$i][$elementId] : null;

Expand Down Expand Up @@ -654,7 +644,7 @@ function ($value, $key) use ($TechEquivalents) {
$isUsingPrettyInputs = ($_User['settings_useprettyinputbox'] == 1);

$ownTechLevels = object_map(
$TechEquivalents,
$combatTechs,
function ($elementId) use (&$_Planet, &$_User) {
$currentLevel = World\Elements\getElementCurrentLevel($elementId, $_Planet, $_User);

Expand Down

0 comments on commit 1be8827

Please sign in to comment.