Esempio n. 1
0
 /**
  * Based on overall Assist + Goal conversion check out if team scored
  *
  * @return bool
  */
 private function didScore()
 {
     $overallConversion = $this->attackTeam->getOverallSuccessConversion();
     $random = \Offside\Random::generateRandomWithPotential($overallConversion, 100);
     if ($overallConversion == $random) {
         return true;
     } else {
         return false;
     }
 }
 public function getNumberOfActions()
 {
     $numberOfActionsDevider = Random::generateRandomWithPotential(8, 10) == 8 ? 10 : 7;
     return round(($this->getOverallStamina() + $this->getOverallCreativity()) / $numberOfActionsDevider, 0, PHP_ROUND_HALF_UP);
 }
Esempio n. 3
0
 private function generateActions($team, $match)
 {
     $firstTeamPlayers = $team->getPlayers();
     $_firstTeamPlayerAttackers = array();
     $_firstTeamPlayerDefenders = array();
     $_firstTeamPlayerCreative = array();
     $actions = [];
     foreach ($firstTeamPlayers as $player) {
         $_firstTeamPlayerAttackers[$player->id] = $player->attack;
         $_firstTeamPlayerDefenders[$player->id] = $player->defense;
         $_firstTeamPlayerCreative[$player->id] = $player->creativity;
     }
     foreach ($team->actions as $action) {
         $goal = $action->didGoalSucceed();
         $passed = $action->didPassedDefense();
         $scorer = null;
         $defender = null;
         $creative = Random::randomgWeightedElement($_firstTeamPlayerCreative);
         $message = 0;
         if (!$passed) {
             //Fail at defense
             $message = rand(0, count(config("offside.comments")['fail_at_defense']) - 1);
         } elseif ($passed && !$goal) {
             //Fail at goal
             $message = rand(0, count(config("offside.comments")['fail_at_goal']) - 1);
         } else {
             //Scored
             $message = rand(0, count(config("offside.comments")['score']) - 1);
         }
         $scorer = Random::randomgWeightedElement($_firstTeamPlayerAttackers, $creative);
         $defender = Random::randomgWeightedElement($_firstTeamPlayerDefenders, $creative);
         $actions[] = ['match_id' => $match->id, 'team_id' => $team->getTeamID(), 'attacker_id' => $scorer, 'defender_id' => $defender, 'creative_id' => $creative, 'passed_defense' => $passed, 'message' => $message, 'scored' => $goal];
     }
     return $actions;
 }