From 30db9af8ec5161b493af6bb8b0275cee06c619c5 Mon Sep 17 00:00:00 2001 From: Michal Dziekonski Date: Fri, 20 Nov 2020 21:37:50 +0200 Subject: [PATCH] GH-131 Create shields takedown calculator --- includes/ares/calculations.php | 41 ++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/includes/ares/calculations.php b/includes/ares/calculations.php index f7fe1a0ed..f77b17227 100644 --- a/includes/ares/calculations.php +++ b/includes/ares/calculations.php @@ -2,6 +2,8 @@ namespace UniEngine\Engine\Includes\Ares\Calculations; +use UniEngine\Engine\Includes\Ares; + function calculateShipForce($params) { global $_Vars_CombatUpgrades, $_Vars_CombatData; @@ -62,4 +64,43 @@ function calculateShipHull($params) { ); } +function calculateShieldsTakeDownStats($params) { + $shotForce = $params['shotForce']; + $targetUserId = $params['targetUserId']; + $targetShipId = $params['targetShipId']; + $targetShipShield = $params['targetShipShield']; + $targetShipCount = $params['targetShipCount']; + $roundShieldStateCache = $params['roundShieldStateCacheByTargetKey']; + + $targetKey = "{$targetShipId}|{$targetUserId}"; + + $isShotBypassingShield = Ares\Evaluators\isShotBypassingShield([ + 'shotForce' => $shotForce, + 'targetShipShield' => $targetShipShield, + ]); + + if ($isShotBypassingShield) { + return [ + 'forceNeeded' => 0, + 'isShotBypassingShield' => true, + ]; + } + + $isTargetsShieldDamaged = ( + isset($roundShieldStateCache[$targetKey]['left']) && + $roundShieldStateCache[$targetKey]['left'] === true + ); + + $forceNeeded = ( + $isTargetsShieldDamaged ? + $roundShieldStateCache[$targetKey]['shield'] : + ($targetShipShield * $targetShipCount) + ); + + return [ + 'forceNeeded' => $forceNeeded, + 'isShotBypassingShield' => false, + ]; +} + ?>