/** * @see ISimulationStrategy::shoot() */ public function shoot(SimulationMatch $match) { $player = $match->getPlayerWithBall(); $goaly = SimulationHelper::selectPlayer(SimulationHelper::getOpponentTeam($player, $match), PLAYER_POSITION_GOALY, null); // get goaly influence from settings. 20 = 20% $goalyInfluence = (int) $this->_websoccer->getConfig('sim_goaly_influence'); $shootReduction = round($goaly->getTotalStrength($this->_websoccer, $match) * $goalyInfluence / 100); // increase / reduce shooting strength by position $shootStrength = round($player->getTotalStrength($this->_websoccer, $match) * $this->_shootStrengthPerPosition[$player->position] / 100); // increase chance with every failed attempt, except when player is only striker - then many attempts are natural. if ($player->position != PLAYER_POSITION_STRIKER || isset($player->team->positionsAndPlayers[PLAYER_POSITION_STRIKER]) && count($player->team->positionsAndPlayers[PLAYER_POSITION_STRIKER]) > 1) { $shootStrength = $shootStrength + $player->getShoots() * 2 - $player->getGoals(); } // reduce probability of too many goals per scorer if ($player->getGoals() > 1) { $shootStrength = round($shootStrength / $player->getGoals()); } $pGoal[TRUE] = max(1, min($shootStrength - $shootReduction, 60)); $pGoal[FALSE] = 100 - $pGoal[TRUE]; $result = SimulationHelper::selectItemFromProbabilities($pGoal); // missed if ($result == FALSE) { foreach ($this->_observers as $observer) { $observer->onShootFailure($match, $player, $goaly); } // always give ball to goaly $match->setPlayerWithBall($goaly); // resulted in a corner? Depends on player's strength $pCorner[TRUE] = round($player->strength / 2); $pCorner[FALSE] = 100 - $pCorner[TRUE]; if (SimulationHelper::selectItemFromProbabilities($pCorner)) { // select players if ($player->team->freeKickPlayer) { $passingPlayer = $player->team->freeKickPlayer; } else { $passingPlayer = SimulationHelper::selectPlayer($player->team, PLAYER_POSITION_MIDFIELD); } $targetPlayer = SimulationHelper::selectPlayer($player->team, PLAYER_POSITION_MIDFIELD, $passingPlayer); foreach ($this->_observers as $observer) { $observer->onCorner($match, $passingPlayer, $targetPlayer); } $match->setPlayerWithBall($targetPlayer); } // scored } else { foreach ($this->_observers as $observer) { $observer->onGoal($match, $player, $goaly); } $this->_kickoff($match, $player); } return $result; }
private static function updateMatch(WebSoccer $websoccer, DbConnection $db, SimulationMatch $match) { if ($match->isCompleted) { $columns['berechnet'] = 1; } $columns['minutes'] = $match->minute; $columns['soldout'] = $match->isSoldOut ? '1' : '0'; $columns['home_tore'] = $match->homeTeam->getGoals(); $columns['gast_tore'] = $match->guestTeam->getGoals(); $columns['home_setup'] = $match->homeTeam->setup; $columns['gast_setup'] = $match->guestTeam->setup; $columns['home_offensive'] = $match->homeTeam->offensive; $columns['gast_offensive'] = $match->guestTeam->offensive; $columns['home_noformation'] = $match->homeTeam->noFormationSet ? '1' : '0'; $columns['guest_noformation'] = $match->guestTeam->noFormationSet ? '1' : '0'; $columns['home_longpasses'] = $match->homeTeam->longPasses ? '1' : '0'; $columns['gast_longpasses'] = $match->guestTeam->longPasses ? '1' : '0'; $columns['home_counterattacks'] = $match->homeTeam->counterattacks ? '1' : '0'; $columns['gast_counterattacks'] = $match->guestTeam->counterattacks ? '1' : '0'; $columns['home_morale'] = $match->homeTeam->morale; $columns['gast_morale'] = $match->guestTeam->morale; if ($match->getPlayerWithBall() != null) { $columns['player_with_ball'] = $match->getPlayerWithBall()->id; } else { $columns['player_with_ball'] = 0; } if ($match->getPreviousPlayerWithBall() != null) { $columns['prev_player_with_ball'] = $match->getPreviousPlayerWithBall()->id; } else { $columns['prev_player_with_ball'] = 0; } $columns['home_freekickplayer'] = $match->homeTeam->freeKickPlayer != NULL ? $match->homeTeam->freeKickPlayer->id : ''; $columns['gast_freekickplayer'] = $match->guestTeam->freeKickPlayer != NULL ? $match->guestTeam->freeKickPlayer->id : ''; // substitutions if (is_array($match->homeTeam->substitutions)) { $subIndex = 1; foreach ($match->homeTeam->substitutions as $substitution) { $columns['home_w' . $subIndex . '_raus'] = $substitution->playerOut->id; $columns['home_w' . $subIndex . '_rein'] = $substitution->playerIn->id; $columns['home_w' . $subIndex . '_minute'] = $substitution->minute; $columns['home_w' . $subIndex . '_condition'] = $substitution->condition; $columns['home_w' . $subIndex . '_position'] = $substitution->position; $subIndex++; } } if (is_array($match->guestTeam->substitutions)) { $subIndex = 1; foreach ($match->guestTeam->substitutions as $substitution) { $columns['gast_w' . $subIndex . '_raus'] = $substitution->playerOut->id; $columns['gast_w' . $subIndex . '_rein'] = $substitution->playerIn->id; $columns['gast_w' . $subIndex . '_minute'] = $substitution->minute; $columns['gast_w' . $subIndex . '_condition'] = $substitution->condition; $columns['gast_w' . $subIndex . '_position'] = $substitution->position; $subIndex++; } } $fromTable = $websoccer->getConfig('db_prefix') . '_spiel'; $whereCondition = 'id = %d'; $parameters = $match->id; $db->queryUpdate($columns, $fromTable, $whereCondition, $parameters); }