Created
September 13, 2019 00:17
-
-
Save marcelotk15/b8899ba4d7903e6dddd6812c61fe92dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Created by PhpStorm. | |
* User: marce | |
* Date: 16/05/2017 | |
* Time: 00:19 | |
*/ | |
namespace App\Traits; | |
trait PlayerRealOveralls | |
{ | |
private function calculateRealOverall(array $data) | |
{ | |
$overall = array_map(function ($stat) { | |
$values = explode("|", $stat); | |
if (isset($this->stats->{$values[0]}->{$values[1]})) { | |
return $this->stats->{$values[0]}->{$values[1]} * floatval($values[2]); | |
} | |
return 0; | |
}, $data); | |
return array_sum($overall); | |
} | |
private function getGKRealOverall() | |
{ | |
$statsData = [ | |
'goal_keeping|gk_diving|.21', | |
'goal_keeping|gk_handling|.21', | |
'goal_keeping|gk_positioning|.21', | |
'goal_keeping|gk_reflexes|.21', | |
'dribbling|reactions|.11', | |
'goal_keeping|gk_kicking|.05', | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRWBLWBRealOverall() | |
{ | |
$statsData = [ | |
'pace|acceleration|.04', | |
'pace|sprint_speed|.06', | |
'physical|stamina|.10', | |
'dribbling|reactions|.08', | |
'defending|interceptions|.12', | |
'dribbling|ball_control|.08', | |
'passing|crossing|.12', | |
'dribbling|dribbling|.04', | |
'passing|short_passing|.10', | |
'defending|marking|.07', | |
'defending|standing_tackle|.08', | |
'defending|sliding_tackle|.11', | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRBLBRealOverall() | |
{ | |
$statsData = [ | |
'pace|acceleration|.05', | |
'pace|sprint_speed|.07', | |
'physical|stamina|.08', | |
'dribbling|reactions|.08', | |
'defending|interceptions|.12', | |
'dribbling|ball_control|.07', | |
'passing|crossing|.09', | |
'defending|heading|.04', | |
'passing|short_passing|.07', | |
'defending|marking|.08', | |
'defending|standing_tackle|.11', | |
'defending|sliding_tackle|.14', | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRCBCBLCBRealOverall() | |
{ | |
$statsData = [ | |
'physical|jumping|.03', | |
'pace|sprint_speed|.02', | |
'physical|strength|.10', | |
'dribbling|reactions|.05', | |
'physical|aggression|.07', | |
'defending|interceptions|.13', | |
'dribbling|ball_control|.04', | |
'defending|heading|.10', | |
'passing|short_passing|.05', | |
'defending|marking|.14', | |
'defending|standing_tackle|.17', | |
'defending|sliding_tackle|.10', | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRDMCDMLDMRealOverall() | |
{ | |
$statsData = [ | |
'physical|stamina|.06', | |
'physical|strength|.04', | |
'dribbling|reactions|.07', | |
'physical|aggression|.05', | |
'passing|vision|.04', | |
'dribbling|ball_control|.10', | |
'passing|long_passing|.10', | |
'passing|short_passing|.14', | |
'defending|marking|.09', | |
'defending|standing_tackle|.12', | |
'defending|sliding_tackle|.05', | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRSSTLSRealOverall() | |
{ | |
$statsData = [ | |
'pace|acceleration|.04', | |
'pace|sprint_speed|.05', | |
'physical|strenght|.05', | |
'dribbling|reactions|.08', | |
'shooting|positioning|.13', | |
'dribbling|ball_control|.1', | |
'dribbling|dribbling|.07', | |
'shooting|finishing|.18', | |
'defending|heading|.1', | |
'passing|short_passing|.05', | |
'shooting|shot_power|.1', | |
'shooting|long_shots|.03', | |
'shooting|volleys|.02' | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRWLWRealOverall() | |
{ | |
$statsData = [ | |
'pace|acceleration|.07', | |
'pace|sprint_speed|.06', | |
'dribbling|agility|.03', | |
'dribbling|reactions|.07', | |
'shooting|positioning|.09', | |
'passing|vision|.06', | |
'dribbling|ball_control|.14', | |
'passing|crossing|.09', | |
'dribbling|dribbling|.16', | |
'shooting|finishing|.1', | |
'passing|short_passing|.09', | |
'shooting|long_shots|.04' | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRFCFLFRealOverall() | |
{ | |
$statsData = [ | |
'pace|acceleration|.05', | |
'pace|sprint_speed|.05', | |
'dribbling|reactions|.09', | |
'shooting|positioning|.13', | |
'passing|vision|.08', | |
'dribbling|ball_control|.15', | |
'dribbling|dribbling|.14', | |
'shooting|finishing|.11', | |
'defending|heading|.02', | |
'passing|short_passing|.09', | |
'shooting|shot_power|.05', | |
'shooting|long_shots|.04', | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRAMCAMLAMRealOverall() | |
{ | |
$statsData = [ | |
'pace|acceleration|.04', | |
'pace|sprint_speed|.03', | |
'dribbling|agility|.03', | |
'dribbling|reactions|.07', | |
'shooting|positioning|.09', | |
'passing|vision|.14', | |
'dribbling|ball_control|.15', | |
'dribbling|dribbling|.13', | |
'shooting|finishing|.07', | |
'passing|long_passing|.04', | |
'passing|short_passing|.16', | |
'shooting|long_shots|.05', | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRCMCMLCMRealOverall() | |
{ | |
$statsData = [ | |
'physical|stamina|.06', | |
'dribbling|reactions|.08', | |
'defending|interceptions|.05', | |
'shooting|positioning|.06', | |
'passing|vision|.13', | |
'dribbling|ball_control|.14', | |
'dribbling|dribbling|.07', | |
'shooting|finishing|.02', | |
'passing|long_passing|.13', | |
'shooting|long_shots|.04', | |
'defending|sliding_tackle|.05', | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getRMLMRealOverall() | |
{ | |
$statsData = [ | |
'pace|acceleration|.07', | |
'pace|sprint_speed|.06', | |
'physical|stamina|.05', | |
'dribbling|reactions|.07', | |
'shooting|positioning|.08', | |
'passing|vision|.07', | |
'dribbling|ball_control|.13', | |
'passing|crossing|.1', | |
'dribbling|dribbling|.15', | |
'shooting|finishing|.06', | |
'passing|long_passing|.05', | |
'passing|short_passing|.11', | |
]; | |
return round($this->calculateRealOverall($statsData)); | |
} | |
private function getTypeAIntlRep($overall) | |
{ | |
$a = $overall * 1; | |
$d = $this->potential; | |
$i = $this->stats->other->international_reputation * 1 - 1; | |
$i = $i > 1 ? $i : 1; | |
$i = $d < $a + $i ? $d - $a : $i; | |
$a = $a + $i - $a; | |
return round($a); | |
} | |
private function getTypeBIntlRep($overall) | |
{ | |
$a = $overall * 1; | |
$d = $this->potential; | |
$i = $this->stats->other->international_reputation * 1 - 2; | |
$i = $i > 1 ? $i : 1; | |
$i = $d < ($a + $i) ? ($d - $a) : $i; | |
return $a + $i - $a; | |
} | |
private function getTypeIntlRep($overall) | |
{ | |
$a = $overall * 1; | |
$d = $this->potential; | |
$i = $this->stats->other->international_reputation * 1; | |
$a = ($i - 2) > 0 ? $a + $i - 2 : $a; | |
$a = $d < $a ? $d : $a; | |
return $a - $overall; | |
} | |
private function makeRealOverallStats() | |
{ | |
$finalStats = []; | |
$allOverallStats = [ | |
'GK' => $this->getGKRealOverall(), | |
'RWB_LWB' => $this->getRWBLWBRealOverall(), | |
'RB_LB' => $this->getRBLBRealOverall(), | |
'RCB_CB_LCB' => $this->getRCBCBLCBRealOverall(), | |
'RDM_CDM_LDM' => $this->getRDMCDMLDMRealOverall(), | |
'RM_LM' => $this->getRMLMRealOverall(), | |
'RCM_CM_LCM' => $this->getRCMCMLCMRealOverall(), | |
'RAM_CAM_LAM' => $this->getRAMCAMLAMRealOverall(), | |
'RF_CF_LF' => $this->getRFCFLFRealOverall(), | |
'RW_LW' => $this->getRWLWRealOverall(), | |
'RS_ST_LS' => $this->getRSSTLSRealOverall() | |
]; | |
$reputationType = [ | |
'GK' => 'getTypeAIntlRep', | |
'RWB_LWB' => 'getTypeAIntlRep', | |
'RB_LB' => 'getTypeAIntlRep', | |
'RCB_CB_LCB' => 'getTypeAIntlRep', | |
'RDM_CDM_LDM' => 'getTypeAIntlRep', | |
'RM_LM' => 'getTypeAIntlRep', | |
'RCM_CM_LCM' => 'getTypeAIntlRep', | |
'RAM_CAM_LAM' => 'getTypeAIntlRep', | |
'RF_CF_LF' => 'getTypeBIntlRep', | |
'RW_LW' => 'getTypeBIntlRep', | |
'RS_ST_LS' => 'getTypeAIntlRep', | |
]; | |
foreach ($allOverallStats as $position => $overall) { | |
$finalStats[$position] = [ | |
'overall' => $overall, | |
'int_reputation' => call_user_func(array($this, $reputationType[$position]), $overall) | |
]; | |
} | |
return $finalStats; | |
} | |
public function getRealOverallAttribute($value) | |
{ | |
if (is_object($value)) { | |
return $value; | |
} | |
return $this->convertSerializedArray(serialize($this->makeRealOverallStats())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment