private function _createMessage($match, $messageType, $playerNames = null, $isHomeActive = TRUE) { if (!isset($this->_availableTexts[$messageType])) { return; } $texts = count($this->_availableTexts[$messageType]); $index = SimulationHelper::getMagicNumber(0, $texts - 1); $messageId = $this->_availableTexts[$messageType][$index]; $players = ''; if ($playerNames != null) { $players = implode(';', $playerNames); } $fromTable = $this->_websoccer->getConfig('db_prefix') . '_matchreport'; $columns['match_id'] = $match->id; $columns['minute'] = $match->minute; $columns['message_id'] = $messageId; $columns['playernames'] = $players; $columns['active_home'] = $isHomeActive; $this->_db->queryInsert($columns, $fromTable); }
private function checkStadiumConstructions() { $constructions = StadiumsDataService::getDueConstructionOrders($this->_websoccer, $this->_db); $newDeadline = $this->_websoccer->getNowAsTimestamp() + $this->_websoccer->getConfig('stadium_construction_delay') * 24 * 3600; foreach ($constructions as $construction) { // is actually completed? $pStatus = array(); $pStatus['completed'] = $construction['builder_reliability']; $pStatus['notcompleted'] = 100 - $pStatus['completed']; $constructionResult = SimulationHelper::selectItemFromProbabilities($pStatus); // not completed: postpone deadline if ($constructionResult == 'notcompleted') { $this->_db->queryUpdate(array('deadline' => $newDeadline), $this->_websoccer->getConfig('db_prefix') . '_stadium_construction', 'id = %d', $construction['id']); // send notification if ($construction['user_id']) { NotificationsDataService::createNotification($this->_websoccer, $this->_db, $construction['user_id'], 'stadium_construction_notification_delay', null, 'stadium_construction', 'stadium'); } // completed } else { // update stadium $stadium = StadiumsDataService::getStadiumByTeamId($this->_websoccer, $this->_db, $construction['team_id']); $columns = array(); $columns['p_steh'] = $stadium['places_stands'] + $construction['p_steh']; $columns['p_sitz'] = $stadium['places_seats'] + $construction['p_sitz']; $columns['p_haupt_steh'] = $stadium['places_stands_grand'] + $construction['p_haupt_steh']; $columns['p_haupt_sitz'] = $stadium['places_seats_grand'] + $construction['p_haupt_sitz']; $columns['p_vip'] = $stadium['places_vip'] + $construction['p_vip']; $this->_db->queryUpdate($columns, $this->_websoccer->getConfig('db_prefix') . '_stadion', 'id = %d', $stadium['stadium_id']); // delete order $this->_db->queryDelete($this->_websoccer->getConfig('db_prefix') . '_stadium_construction', 'id = %d', $construction['id']); // send notification if ($construction['user_id']) { NotificationsDataService::createNotification($this->_websoccer, $this->_db, $construction['user_id'], 'stadium_construction_notification_completed', null, 'stadium_construction', 'stadium'); } } } }
/** * (non-PHPdoc) * @see IActionController::executeAction() */ public function executeAction($parameters) { $user = $this->_websoccer->getUser(); $clubId = $user->getClubId($this->_websoccer, $this->_db); // verify that it is due $construction = StadiumsDataService::getCurrentConstructionOrderOfTeam($this->_websoccer, $this->_db, $clubId); if ($construction == NULL || $construction["deadline"] > $this->_websoccer->getNowAsTimestamp()) { throw new Exception($this->_i18n->getMessage("stadium_acceptconstruction_err_nonedue")); } // is completed? $pStatus["completed"] = $construction["builder_reliability"]; $pStatus["notcompleted"] = 100 - $pStatus["completed"]; $constructionResult = SimulationHelper::selectItemFromProbabilities($pStatus); // not completed: postpone deadline if ($constructionResult == "notcompleted") { $newDeadline = $this->_websoccer->getNowAsTimestamp() + $this->_websoccer->getConfig("stadium_construction_delay") * 24 * 3600; $this->_db->queryUpdate(array("deadline" => $newDeadline), $this->_websoccer->getConfig("db_prefix") . "_stadium_construction", "id = %d", $construction["id"]); // show warning alert $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_WARNING, $this->_i18n->getMessage("stadium_acceptconstruction_notcompleted_title"), $this->_i18n->getMessage("stadium_acceptconstruction_notcompleted_details"))); // completed } else { // update stadium $stadium = StadiumsDataService::getStadiumByTeamId($this->_websoccer, $this->_db, $clubId); $columns = array(); $columns["p_steh"] = $stadium["places_stands"] + $construction["p_steh"]; $columns["p_sitz"] = $stadium["places_seats"] + $construction["p_sitz"]; $columns["p_haupt_steh"] = $stadium["places_stands_grand"] + $construction["p_haupt_steh"]; $columns["p_haupt_sitz"] = $stadium["places_seats_grand"] + $construction["p_haupt_sitz"]; $columns["p_vip"] = $stadium["places_vip"] + $construction["p_vip"]; $this->_db->queryUpdate($columns, $this->_websoccer->getConfig("db_prefix") . "_stadion", "id = %d", $stadium["stadium_id"]); // delete order $this->_db->queryDelete($this->_websoccer->getConfig("db_prefix") . "_stadium_construction", "id = %d", $construction["id"]); // create success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("stadium_acceptconstruction_completed_title"), $this->_i18n->getMessage("stadium_acceptconstruction_completed_details"))); } return null; }
private function createYouthPlayer($clubId, $scout, $country) { $firstName = $this->getItemFromFile(NAMES_DIRECTORY . "/" . $country . "/firstnames.txt"); $lastName = $this->getItemFromFile(NAMES_DIRECTORY . "/" . $country . "/lastnames.txt"); // strength computation (always compute since plug-ins might override scouting-success-flag) $minStrength = (int) $this->_websoccer->getConfig("youth_scouting_min_strength"); $maxStrength = (int) $this->_websoccer->getConfig("youth_scouting_max_strength"); $scoutFactor = $scout["expertise"] / 100; $strength = $minStrength + round(($maxStrength - $minStrength) * $scoutFactor); // consider random deviation $deviation = (int) $this->_websoccer->getConfig("youth_scouting_standard_deviation"); $strength = $strength + SimulationHelper::getMagicNumber(0 - $deviation, $deviation); $strength = max($minStrength, min($maxStrength, $strength)); // make sure that condigured boundaries are not violated // determine position if ($scout["speciality"] == "Torwart") { $positionProbabilities = array("Torwart" => 40, "Abwehr" => 30, "Mittelfeld" => 25, "Sturm" => 5); } elseif ($scout["speciality"] == "Abwehr") { $positionProbabilities = array("Torwart" => 10, "Abwehr" => 50, "Mittelfeld" => 30, "Sturm" => 10); } elseif ($scout["speciality"] == "Mittelfeld") { $positionProbabilities = array("Torwart" => 10, "Abwehr" => 15, "Mittelfeld" => 60, "Sturm" => 15); } elseif ($scout["speciality"] == "Sturm") { $positionProbabilities = array("Torwart" => 5, "Abwehr" => 15, "Mittelfeld" => 40, "Sturm" => 40); } else { $positionProbabilities = array("Torwart" => 15, "Abwehr" => 30, "Mittelfeld" => 35, "Sturm" => 20); } $position = SimulationHelper::selectItemFromProbabilities($positionProbabilities); $minAge = $this->_websoccer->getConfig("youth_scouting_min_age"); $maxAge = $this->_websoccer->getConfig("youth_min_age_professional"); $age = $minAge + SimulationHelper::getMagicNumber(0, abs($maxAge - $minAge)); // create player $this->_db->queryInsert(array("team_id" => $clubId, "firstname" => $firstName, "lastname" => $lastName, "age" => $age, "position" => $position, "nation" => $country, "strength" => $strength), $this->_websoccer->getConfig("db_prefix") . "_youthplayer"); // trigger event for plug-ins $event = new YouthPlayerScoutedEvent($this->_websoccer, $this->_db, $this->_i18n, $clubId, $scout["id"], $this->_db->getLastInsertedId()); PluginMediator::dispatchEvent($event); // create success message $this->_websoccer->addFrontMessage(new FrontMessage(MESSAGE_TYPE_SUCCESS, $this->_i18n->getMessage("youthteam_scouting_success"), $this->_i18n->getMessage("youthteam_scouting_success_details", $firstName . " " . $lastName))); }
/** * Simulates the specified match by the number of specified minutes. * * @param SimulationMatch $match match to simulate. * @param int $minutes number of minutes to simuate. */ public function simulateMatch(SimulationMatch $match, $minutes) { if ($match->minute == null) { $match->minute = 0; } // start the match if ($match->minute == 0) { foreach ($this->_observers as $observer) { $observer->onBeforeMatchStarts($match); } } // match might be completed already before simulation, e.g. when there is no formation provided if ($match->isCompleted) { $this->completeMatch($match); return; } // complete match if team has no players if (!$this->_hasPlayers($match->homeTeam) || !$this->_hasPlayers($match->guestTeam)) { $this->completeMatch($match); return; } for ($simMinute = 1; $simMinute <= $minutes; $simMinute++) { $match->minute = $match->minute + 1; if ($match->minute == 1) { $this->_simStrategy->kickoff($match); } else { SimulationHelper::checkAndExecuteSubstitutions($match, $match->homeTeam, $this->_observers); SimulationHelper::checkAndExecuteSubstitutions($match, $match->guestTeam, $this->_observers); } // execute next action $actionName = $this->_simStrategy->nextAction($match); $this->_simStrategy->{$actionName}($match); // increase minutes played $this->_increaseMinutesPlayed($match->homeTeam); $this->_increaseMinutesPlayed($match->guestTeam); // match ended? // two possibilities: // a. Normal matches end after regular time // b. if penalty shooting is enabled, play extension if there is no result after 90 minutes $lastMinute = 90 + SimulationHelper::getMagicNumber(1, 5); if ($match->penaltyShootingEnabled || $match->type == 'Pokalspiel') { // match ended after regular or extension time with a winner if (($match->minute == 91 || $match->minute == 121) && ($match->type != 'Pokalspiel' && $match->homeTeam->getGoals() != $match->guestTeam->getGoals() || $match->type == 'Pokalspiel' && !SimulationCupMatchHelper::checkIfExtensionIsRequired($this->_websoccer, $this->_db, $match))) { $this->completeMatch($match); break; // no winner after extension time -> penalty shooting } elseif ($match->minute == 121 && ($match->type != 'Pokalspiel' && $match->homeTeam->getGoals() == $match->guestTeam->getGoals() || $match->type == 'Pokalspiel' && SimulationCupMatchHelper::checkIfExtensionIsRequired($this->_websoccer, $this->_db, $match))) { $this->_simStrategy->penaltyShooting($match); // we have a winner now if ($match->type == 'Pokalspiel') { // home team won if ($match->homeTeam->getGoals() > $match->guestTeam->getGoals()) { SimulationCupMatchHelper::createNextRoundMatchAndPayAwards($this->_websoccer, $this->_db, $match->homeTeam->id, $match->guestTeam->id, $match->cupName, $match->cupRoundName); // guest team won } else { SimulationCupMatchHelper::createNextRoundMatchAndPayAwards($this->_websoccer, $this->_db, $match->guestTeam->id, $match->homeTeam->id, $match->cupName, $match->cupRoundName); } } $this->completeMatch($match); break; } // regular match } elseif ($match->minute >= $lastMinute) { $this->completeMatch($match); break; } } }
private function trainPlayers($teamId, $trainer, $unit) { // compute effect on every player $players = PlayersDataService::getPlayersOfTeamById($this->_websoccer, $this->_db, $teamId); // freshness decrease for stamina and technique training $freshnessDecrease = round(1 + $unit["intensity"] / 100 * 5); $fromTable = $this->_websoccer->getConfig("db_prefix") . "_spieler"; $whereCondition = "id = %d"; $trainingEffects = array(); foreach ($players as $player) { // injured player only refreshes and looses stamina $effectFreshness = 0; $effectStamina = 0; $effectTechnique = 0; $effectSatisfaction = 0; if ($player["matches_injured"]) { $effectFreshness = 1; $effectStamina = -1; } else { // regeneration training if ($unit["focus"] == "FR") { $effectFreshness = 5; $effectStamina = -2; $effectSatisfaction = 1; // motivation training } else { if ($unit["focus"] == "MOT") { $effectFreshness = 1; $effectStamina = -1; $effectSatisfaction = 5; // stamina training } else { if ($unit["focus"] == "STA") { $effectSatisfaction = -1; // freshness depends on intensity $effectFreshness = -$freshnessDecrease; // success depends on trainer skills and intensity $staminaIncrease = 1; if ($unit["intensity"] > 50) { $successFactor = $unit["intensity"] * $trainer["p_stamina"] / 100; $pStamina[5] = $successFactor; $pStamina[1] = 100 - $successFactor; $staminaIncrease += SimulationHelper::selectItemFromProbabilities($pStamina); } $effectStamina = $staminaIncrease; // technique } else { $effectFreshness = -$freshnessDecrease; if ($unit["intensity"] > 20) { $effectStamina = 1; } $techIncrease = 0; if ($unit["intensity"] > 75) { $successFactor = $unit["intensity"] * $trainer["p_technique"] / 100; $pTech[2] = $successFactor; $pTech[0] = 100 - $successFactor; $techIncrease += SimulationHelper::selectItemFromProbabilities($pTech); } $effectTechnique = $techIncrease; } } } } // call plugins $event = new PlayerTrainedEvent($this->_websoccer, $this->_db, $this->_i18n, $player["id"], $teamId, $trainer["id"], $effectFreshness, $effectTechnique, $effectStamina, $effectSatisfaction); PluginMediator::dispatchEvent($event); // update player $columns = array("w_frische" => min(100, max(1, $player["strength_freshness"] + $effectFreshness)), "w_technik" => min(100, max(1, $player["strength_technic"] + $effectTechnique)), "w_kondition" => min(100, max(1, $player["strength_stamina"] + $effectStamina)), "w_zufriedenheit" => min(100, max(1, $player["strength_satisfaction"] + $effectSatisfaction))); $this->_db->queryUpdate($columns, $fromTable, $whereCondition, $player["id"]); // add effect $trainingEffects[$player["id"]] = array("name" => $player["pseudonym"] ? $player["pseudonym"] : $player["firstname"] . " " . $player["lastname"], "freshness" => $effectFreshness, "technique" => $effectTechnique, "stamina" => $effectStamina, "satisfaction" => $effectSatisfaction); } $this->_websoccer->addContextParameter("trainingEffects", $trainingEffects); }
private function _kickoff(SimulationMatch $match, SimulationPlayer $scorer) { // let kick-off the opponent $match->setPlayerWithBall(SimulationHelper::selectPlayer(SimulationHelper::getOpponentTeam($scorer, $match), PLAYER_POSITION_DEFENCE, null)); }
/** * Creates a new formation for specified team. * Will simply take the first 11 players and place them in a 4-4-2 formation. * * @param WebSoccer $websoccer Application context. * @param DbConnection $db DB connection. * @param SimulationMatch $match match model. * @param SimulationTeam $team team model. */ private static function _createRandomFormation(WebSoccer $websoccer, DbConnection $db, SimulationMatch $match, SimulationTeam $team) { // better delete possible previous formation with too few players $db->queryDelete($websoccer->getConfig('db_prefix') . '_youthmatch_player', 'match_id = %d AND team_id = %d', array($match->id, $team->id)); // define the exact default formation $formationPositions = array('T', 'LV', 'IV', 'IV', 'RV', 'LM', 'ZM', 'ZM', 'RM', 'LS', 'RS'); $positionMapping = SimulationHelper::getPositionsMapping(); // set players $players = YouthPlayersDataService::getYouthPlayersOfTeam($websoccer, $db, $team->id); $positionIndex = 0; foreach ($players as $playerinfo) { $mainPosition = $formationPositions[$positionIndex]; $position = $positionMapping[$mainPosition]; $player = new SimulationPlayer($playerinfo['id'], $team, $position, $mainPosition, 3.0, DEFAULT_PLAYER_AGE, $playerinfo['strength'], $playerinfo['strength'], YOUTH_STRENGTH_STAMINA, YOUTH_STRENGTH_FRESHNESS, YOUTH_STRENGTH_SATISFACTION); $player->name = $playerinfo['firstname'] . ' ' . $playerinfo['lastname']; // strength adaption required? if ($player->position != $playerinfo['position']) { $player->strength = round($playerinfo['strength'] * (1 - $websoccer->getConfig('sim_strength_reduction_wrongposition') / 100)); } try { // create record $columns = array('match_id' => $match->id, 'team_id' => $team->id, 'player_id' => $player->id, 'playernumber' => $positionIndex + 1, 'position' => $player->position, 'position_main' => $player->mainPosition, 'name' => $player->name); $db->queryInsert($columns, $websoccer->getConfig('db_prefix') . '_youthmatch_player'); $team->positionsAndPlayers[$player->position][] = $player; } catch (Exception $e) { // could not be stored. Can happen when the youth player moved from the opponent to this team. // then we get a PK violation. We just don't add this player then. } $positionIndex++; if ($positionIndex == 11) { break; } } }
private static function createMatchForTeamAndRound(WebSoccer $websoccer, DbConnection $db, $teamId, $roundId, $firstRoundDate, $secondRoundDate, $cupName, $cupRound) { // get opponent team from pending list $pendingTable = $websoccer->getConfig('db_prefix') . '_cup_round_pending'; $result = $db->querySelect('team_id', $pendingTable, 'cup_round_id = %d', $roundId, 1); $opponent = $result->fetch_array(); $result->free(); // no opponent -> add to pending list if (!$opponent) { $db->queryInsert(array('team_id' => $teamId, 'cup_round_id' => $roundId), $pendingTable); } else { $matchTable = $websoccer->getConfig('db_prefix') . '_spiel'; $type = 'Pokalspiel'; // determine home team of first round (choose randomly) if (SimulationHelper::selectItemFromProbabilities(array(1 => 50, 0 => 50))) { $homeTeam = $teamId; $guestTeam = $opponent['team_id']; } else { $homeTeam = $opponent['team_id']; $guestTeam = $teamId; } // create first round $db->queryInsert(array('spieltyp' => $type, 'pokalname' => $cupName, 'pokalrunde' => $cupRound, 'home_verein' => $homeTeam, 'gast_verein' => $guestTeam, 'datum' => $firstRoundDate), $matchTable); // create second round if ($secondRoundDate) { $db->queryInsert(array('spieltyp' => $type, 'pokalname' => $cupName, 'pokalrunde' => $cupRound, 'home_verein' => $guestTeam, 'gast_verein' => $homeTeam, 'datum' => $secondRoundDate), $matchTable); } // remove opponent team from pending list $db->queryDelete($pendingTable, 'team_id = %d AND cup_round_id = %d', array($opponent['team_id'], $roundId)); } }
/** * Selects a random player from specified team of specified position. If there is no player at the specified position available, take * one from the next best position. * * @param SimulationTeam $team target player's team * @param string $position target position * @param SimulationPlayer $excludePlayer exclude this player from possible selection. * @return SimulationPlayer the selected player. */ public static function selectPlayer($team, $position, $excludePlayer = null) { $players = array(); if (isset($team->positionsAndPlayers[$position])) { if ($excludePlayer == null || $excludePlayer->position != $position) { $players = $team->positionsAndPlayers[$position]; // filter excludePlayer } else { foreach ($team->positionsAndPlayers[$position] as $player) { if ($player->id !== $excludePlayer->id) { $players[] = $player; } } } } $noOfPlayers = count($players); // no player at this position, take next best position if ($noOfPlayers < 1) { if ($position == PLAYER_POSITION_STRIKER) { return self::selectPlayer($team, PLAYER_POSITION_MIDFIELD, $excludePlayer); } else { if ($position == PLAYER_POSITION_MIDFIELD) { return self::selectPlayer($team, PLAYER_POSITION_DEFENCE, $excludePlayer); } else { if ($position == PLAYER_POSITION_DEFENCE) { return self::selectPlayer($team, PLAYER_POSITION_GOALY, $excludePlayer); } } } // if no goaly available, get just next available player in order to avoid infinite loop foreach ($team->positionsAndPlayers as $pposition => $pplayers) { foreach ($pplayers as $player) { if ($player->id !== $excludePlayer->id) { return $player; } } } } $player = $players[SimulationHelper::getMagicNumber(0, $noOfPlayers - 1)]; return $player; }
/** * @see ISimulationObserver::onInjury() */ public function onInjury(SimulationMatch $match, SimulationPlayer $player, $numberOfMatches) { $player->injured = $numberOfMatches; // try to substitute in next minute $substituted = SimulationHelper::createUnplannedSubstitutionForPlayer($match->minute + 1, $player); // not possible, hence just remove player if (!$substituted) { $player->team->removePlayer($player); } }
public static function addPlayers(WebSoccer $websoccer, DbConnection $db, SimulationTeam $team, $matchinfo, $columnPrefix) { $fromTable = $websoccer->getConfig('db_prefix') . '_spieler'; $columns['verein_id'] = 'team_id'; $columns['nation'] = 'nation'; $columns['position'] = 'position'; $columns['position_main'] = 'mainPosition'; $columns['position_second'] = 'secondPosition'; $columns['vorname'] = 'firstName'; $columns['nachname'] = 'lastName'; $columns['kunstname'] = 'pseudonym'; $columns['w_staerke'] = 'strength'; $columns['w_technik'] = 'technique'; $columns['w_kondition'] = 'stamina'; $columns['w_frische'] = 'freshness'; $columns['w_zufriedenheit'] = 'satisfaction'; $columns['st_spiele'] = 'matches_played'; if ($websoccer->getConfig('players_aging') == 'birthday') { $ageColumn = 'TIMESTAMPDIFF(YEAR,geburtstag,CURDATE())'; } else { $ageColumn = 'age'; } $columns[$ageColumn] = 'age'; $whereCondition = 'id = %d AND verletzt = 0'; // player must not be blocked if ($team->isNationalTeam) { $whereCondition .= ' AND gesperrt_nationalteam = 0'; } elseif ($matchinfo['type'] == 'Pokalspiel') { $whereCondition .= ' AND gesperrt_cups = 0'; } elseif ($matchinfo['type'] != 'Freundschaft') { $whereCondition .= ' AND gesperrt = 0'; } $positionMapping = SimulationHelper::getPositionsMapping(); $addedPlayers = 0; for ($playerNo = 1; $playerNo <= 11; $playerNo++) { $playerId = $matchinfo[$columnPrefix . '_formation_player' . $playerNo]; $mainPosition = $matchinfo[$columnPrefix . '_formation_player_pos_' . $playerNo]; $result = $db->querySelect($columns, $fromTable, $whereCondition, $playerId); $playerinfo = $result->fetch_array(); $result->free(); // is player still in team? if (isset($playerinfo['team_id']) && $playerinfo['team_id'] == $team->id || $team->isNationalTeam && $playerinfo['nation'] == $team->name) { $position = $positionMapping[$mainPosition]; $strength = $playerinfo['strength']; // player becomes weaker: wrong position if ($playerinfo['position'] != $position && $playerinfo['mainPosition'] != $mainPosition && $playerinfo['secondPosition'] != $mainPosition) { $strength = round($strength * (1 - $websoccer->getConfig('sim_strength_reduction_wrongposition') / 100)); // player becomes weaker: secondary position } elseif (strlen($playerinfo['mainPosition']) && $playerinfo['mainPosition'] != $mainPosition && ($playerinfo['position'] == $position || $playerinfo['secondPosition'] == $mainPosition)) { $strength = round($strength * (1 - $websoccer->getConfig('sim_strength_reduction_secondary') / 100)); } $player = new SimulationPlayer($playerId, $team, $position, $mainPosition, 3.0, $playerinfo['age'], $strength, $playerinfo['technique'], $playerinfo['stamina'], $playerinfo['freshness'], $playerinfo['satisfaction']); if (strlen($playerinfo['pseudonym'])) { $player->name = $playerinfo['pseudonym']; } else { $player->name = $playerinfo['firstName'] . ' ' . $playerinfo['lastName']; } $team->positionsAndPlayers[$player->position][] = $player; SimulationStateHelper::createSimulationRecord($websoccer, $db, $matchinfo['match_id'], $player); $addedPlayers++; // is player the team captain? if ($matchinfo[$columnPrefix . '_captain_id'] == $playerId) { self::computeMorale($player, $playerinfo['matches_played']); } // is player free kick taker? if ($matchinfo[$columnPrefix . '_formation_freekickplayer'] == $playerId) { $team->freeKickPlayer = $player; } } } // generate new formation if formation is invalid if ($addedPlayers < 11 && $websoccer->getConfig('sim_createformation_on_invalidsubmission')) { // delete existing invalid formation $db->queryDelete($websoccer->getConfig('db_prefix') . '_spiel_berechnung', 'spiel_id = %d AND team_id = %d', array($matchinfo['match_id'], $team->id)); $team->positionsAndPlayers = array(); // generate a new one SimulationFormationHelper::generateNewFormationForTeam($websoccer, $db, $team, $matchinfo['match_id']); $team->noFormationSet = TRUE; return; } // bench for ($playerNo = 1; $playerNo <= 5; $playerNo++) { $playerId = $matchinfo[$columnPrefix . '_formation_bench' . $playerNo]; $result = $db->querySelect($columns, $fromTable, $whereCondition, $playerId); $playerinfo = $result->fetch_array(); $result->free(); // is player still in team? if (isset($playerinfo['team_id']) && $playerinfo['team_id'] == $team->id || $team->isNationalTeam && $playerinfo['nation'] == $team->name) { $player = new SimulationPlayer($playerId, $team, $playerinfo['position'], $playerinfo['mainPosition'], 3.0, $playerinfo['age'], $playerinfo['strength'], $playerinfo['technique'], $playerinfo['stamina'], $playerinfo['freshness'], $playerinfo['satisfaction']); if (strlen($playerinfo['pseudonym'])) { $player->name = $playerinfo['pseudonym']; } else { $player->name = $playerinfo['firstName'] . ' ' . $playerinfo['lastName']; } $team->playersOnBench[$playerId] = $player; SimulationStateHelper::createSimulationRecord($websoccer, $db, $matchinfo['match_id'], $player, TRUE); } } }