/** * @return MatchResult */ public function simulate() { $homePoints = $this->homeTeam->getAvgSkill(); $awayPoints = $this->awayTeam->getAvgSkill(); $homePoints += $this->malusModule($this->homeTeam->coach->favouriteModule, $this->homeTeam->playersPerRoleArray()); $awayPoints += $this->malusModule($this->awayTeam->coach->favouriteModule, $this->awayTeam->playersPerRoleArray()); $goalHome = 0; $goalAway = 0; if (Randomizer::boolOnPercentage(80)) { if ($homePoints - $awayPoints < 0) { $goalAway = ($awayPoints - $homePoints) % 6; $goalHome += $this->chance(); $goalAway += $this->chance(); $goalHome += $this->bonusHome(); } else { $goalHome = ($homePoints - $awayPoints) % 6; $goalAway += $this->chance(); $goalHome += $this->bonusHome(); } } else { $goalHome += $this->chance(); $goalAway += $this->chance(); $goalHome += $this->bonusHome(); } $goalHome += $this->bonusAge($this->homeTeam); $goalAway += $this->bonusAge($this->awayTeam); //Bonus on Good GoalKeeper $goalies = $this->homeTeam->getBestPlayerForRole("GK"); $goalAway -= $this->bonusGoalKeeper($goalies); $goalies = $this->awayTeam->getBestPlayerForRole("GK"); $goalHome -= $this->bonusGoalKeeper($goalies); // $homeModule = new Module($this->homeTeam->coach->favouriteModule); $awayModule = new Module($this->awayTeam->coach->favouriteModule); if ($homeModule->isOffensive()) { $goalHome += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; $goalAway += Randomizer::boolOnPercentage(20) ? 1 : 0; } if ($awayModule->isOffensive()) { $goalAway += Randomizer::boolOnPercentage(50) ? rand(1, 2) : 0; $goalHome += Randomizer::boolOnPercentage(20) ? 1 : 0; } if ($awayModule->isDefensive()) { $goalHome -= Randomizer::boolOnPercentage(50) ? 1 : 0; } if ($homeModule->isDefensive()) { $goalAway -= Randomizer::boolOnPercentage(50) ? 1 : 0; } $goalHome = $goalHome < 0 ? 0 : $goalHome; $goalAway = $goalAway < 0 ? 0 : $goalAway; return new MatchResult($goalHome, $goalAway, $this->homeTeam, $this->awayTeam); }
/** * @param Team $team * @return bool */ public function isApplicableToTeam(Team $team) { return $this->isApplicableToArray($team->playersPerRoleArray()); }