Skip to content

Commit

Permalink
GH-131 Move shield bypassing evaluation into its separate utility
Browse files Browse the repository at this point in the history
  • Loading branch information
mdziekon committed Nov 16, 2020
1 parent 8a60e70 commit 6681b9e
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 44 deletions.
108 changes: 64 additions & 44 deletions includes/CombatEngineAres.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,23 +304,28 @@ function Combat($Attacker, $Defender, $AttackerTech, $DefenderTech, $UseRapidFir

$AvailableForce = $AForce * $ACount;
$Force2TDShield = 0;
if(($AForce * 0.01) < $DefShipsShield[$TKey])
{
if(isset($DefShields[$TKey]['left']) && $DefShields[$TKey]['left'] === true)
{

$isShotBypassingShield = Ares\Evaluators\isShotBypassingShield([
'shotForce' => $AForce,
'targetShipShield' => $DefShipsShield[$TKey],
]);

if (!$isShotBypassingShield) {
if (
isset($DefShields[$TKey]['left']) &&
$DefShields[$TKey]['left'] === true
) {
$Force2TDShield = $DefShields[$TKey]['shield'];
}
else
{
} else {
$Force2TDShield = $DefShipsShield[$TKey] * $DefShipsTypesCount[$TShip][$TUser];
}
}
if($AvailableForce > $Force2TDShield)
{
if(($AForce * 0.01) < $DefShipsShield[$TKey])
{

if ($AvailableForce > $Force2TDShield) {
if (!$isShotBypassingShield) {
$DefShields[$TKey] = array('left' => true, 'shield' => 0);
}

$LeftForce = $AvailableForce - $Force2TDShield;
if($ACount < ($DefShipsTypesCount[$TShip][$TUser] - (isset($AlreadyDestroyedDef[$TKey]) ? $AlreadyDestroyedDef[$TKey] : 0)))
{
Expand Down Expand Up @@ -561,23 +566,28 @@ function Combat($Attacker, $Defender, $AttackerTech, $DefenderTech, $UseRapidFir

$AvailableForce = $AForce * $ACount;
$Force2TDShield = 0;
if(($AForce * 0.01) < $DefShipsShield[$TKey])
{
if(isset($DefShields[$TKey]['left']) && $DefShields[$TKey]['left'] === true)
{

$isShotBypassingShield = Ares\Evaluators\isShotBypassingShield([
'shotForce' => $AForce,
'targetShipShield' => $DefShipsShield[$TKey],
]);

if (!$isShotBypassingShield) {
if (
isset($DefShields[$TKey]['left']) &&
$DefShields[$TKey]['left'] === true
) {
$Force2TDShield = $DefShields[$TKey]['shield'];
}
else
{
} else {
$Force2TDShield = $DefShipsShield[$TKey] * $DefShipsTypesCount[$TShip][$TUser];
}
}
if($AvailableForce > $Force2TDShield)
{
if(($AForce * 0.01) < $DefShipsShield[$TKey])
{

if ($AvailableForce > $Force2TDShield) {
if (!$isShotBypassingShield) {
$DefShields[$TKey] = array('left' => true, 'shield' => 0);
}

$LeftForce = $AvailableForce - $Force2TDShield;
if($ACount < ($DefShipsTypesCount[$TShip][$TUser] - (isset($AlreadyDestroyedDef[$TKey]) ? $AlreadyDestroyedDef[$TKey] : 0)))
{
Expand Down Expand Up @@ -760,23 +770,28 @@ function Combat($Attacker, $Defender, $AttackerTech, $DefenderTech, $UseRapidFir

$AvailableForce = $AForce * $ACount;
$Force2TDShield = 0;
if(($AForce * 0.01) < $AtkShipsShield[$TKey])
{
if(isset($AtkShields[$TKey]['left']) && $AtkShields[$TKey]['left'] === true)
{

$isShotBypassingShield = Ares\Evaluators\isShotBypassingShield([
'shotForce' => $AForce,
'targetShipShield' => $AtkShipsShield[$TKey],
]);

if (!$isShotBypassingShield) {
if (
isset($AtkShields[$TKey]['left']) &&
$AtkShields[$TKey]['left'] === true
) {
$Force2TDShield = $AtkShields[$TKey]['shield'];
}
else
{
} else {
$Force2TDShield = $AtkShipsShield[$TKey] * $AtkShipsTypesCount[$TShip][$TUser];
}
}
if($AvailableForce > $Force2TDShield)
{
if(($AForce * 0.01) < $AtkShipsShield[$TKey])
{

if ($AvailableForce > $Force2TDShield) {
if (!$isShotBypassingShield) {
$AtkShields[$TKey] = array('left' => true, 'shield' => 0);
}

$LeftForce = $AvailableForce - $Force2TDShield;
if($ACount < ($AtkShipsTypesCount[$TShip][$TUser] - (isset($AlreadyDestroyedAtk[$TKey]) ? $AlreadyDestroyedAtk[$TKey] : 0)))
{
Expand Down Expand Up @@ -1017,23 +1032,28 @@ function Combat($Attacker, $Defender, $AttackerTech, $DefenderTech, $UseRapidFir

$AvailableForce = $AForce * $ACount;
$Force2TDShield = 0;
if(($AForce * 0.01) < $AtkShipsShield[$TKey])
{
if(isset($AtkShields[$TKey]['left']) && $AtkShields[$TKey]['left'] === true)
{

$isShotBypassingShield = Ares\Evaluators\isShotBypassingShield([
'shotForce' => $AForce,
'targetShipShield' => $AtkShipsShield[$TKey],
]);

if (!$isShotBypassingShield) {
if (
isset($AtkShields[$TKey]['left']) &&
$AtkShields[$TKey]['left'] === true
) {
$Force2TDShield = $AtkShields[$TKey]['shield'];
}
else
{
} else {
$Force2TDShield = $AtkShipsShield[$TKey] * $AtkShipsTypesCount[$TShip][$TUser];
}
}
if($AvailableForce > $Force2TDShield)
{
if(($AForce * 0.01) < $AtkShipsShield[$TKey])
{

if ($AvailableForce > $Force2TDShield) {
if (!$isShotBypassingShield) {
$AtkShields[$TKey] = array('left' => true, 'shield' => 0);
}

$LeftForce = $AvailableForce - $Force2TDShield;
if($ACount < ($AtkShipsTypesCount[$TShip][$TUser] - (isset($AlreadyDestroyedAtk[$TKey]) ? $AlreadyDestroyedAtk[$TKey] : 0)))
{
Expand Down
14 changes: 14 additions & 0 deletions includes/ares/evaluators.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ function isShieldImpenetrable($params) {
return ($shotForce < ($targetShipShield * 0.01));
}

/**
* Determine if the targeted shot is strong enough to completely
* bypass the shield without any attenuation of its force.
*
* [Alternatively] Determine if the targeted ship's shield is too weak to absorb
* any shot's force, meaning that the entire force is passing through directly to the hull.
*/
function isShotBypassingShield($params) {
$shotForce = $params['shotForce'];
$targetShipShield = $params['targetShipShield'];

return (($shotForce * 0.01) >= $targetShipShield);
}

?>

0 comments on commit 6681b9e

Please sign in to comment.