/** * Sets the flag for current player with ball. Also increases statistics for ball contacts and moves existing player with ball * to previous player with ball. * * @param SimulationPlayer $player player to set */ public function setPlayerWithBall($player) { if ($this->playerWithBall !== NULL && $this->playerWithBall->id !== $player->id) { $player->setBallContacts($player->getBallContacts() + 1); $this->previousPlayerWithBall = $this->playerWithBall; } $this->playerWithBall = $player; }
private function updatePlayer(SimulationMatch $match, SimulationPlayer $player, $isTeamWinner, $isTie) { $fromTable = $this->_websoccer->getConfig('db_prefix') . '_spieler'; $whereCondition = 'id = %d'; $parameters = $player->id; $minMinutes = (int) $this->_websoccer->getConfig('sim_played_min_minutes'); $blockYellowCards = (int) $this->_websoccer->getConfig('sim_block_player_after_yellowcards'); $staminaChange = (int) $this->_websoccer->getConfig('sim_strengthchange_stamina'); $satisfactionChange = (int) $this->_websoccer->getConfig('sim_strengthchange_satisfaction'); if ($player->team->isNationalTeam) { $columns['gesperrt_nationalteam'] = $player->blocked; } elseif ($match->type == 'Pokalspiel') { $columns['gesperrt_cups'] = $player->blocked; } else { $columns['gesperrt'] = $player->blocked; } // get previous player statistics and lending info $pcolumns = 'id,vorname,nachname,kunstname,verein_id,vertrag_spiele,st_tore,st_assists,st_spiele,st_karten_gelb,st_karten_gelb_rot,st_karten_rot,sa_tore,sa_assists,sa_spiele,sa_karten_gelb,sa_karten_gelb_rot,sa_karten_rot,lending_fee,lending_owner_id,lending_matches'; $result = $this->_db->querySelect($pcolumns, $fromTable, $whereCondition, $parameters); $playerinfo = $result->fetch_array(); $result->free(); // update statistic $columns['st_tore'] = $playerinfo['st_tore'] + $player->getGoals(); $columns['sa_tore'] = $playerinfo['sa_tore'] + $player->getGoals(); $columns['st_assists'] = $playerinfo['st_assists'] + $player->getAssists(); $columns['sa_assists'] = $playerinfo['sa_assists'] + $player->getAssists(); $columns['st_spiele'] = $playerinfo['st_spiele'] + 1; $columns['sa_spiele'] = $playerinfo['sa_spiele'] + 1; if ($player->redCard) { $columns['st_karten_rot'] = $playerinfo['st_karten_rot'] + 1; $columns['sa_karten_rot'] = $playerinfo['sa_karten_rot'] + 1; } else { if ($player->yellowCards) { if ($player->yellowCards == 2) { $columns['st_karten_gelb_rot'] = $playerinfo['st_karten_gelb_rot'] + 1; $columns['sa_karten_gelb_rot'] = $playerinfo['sa_karten_gelb_rot'] + 1; if ($player->team->isNationalTeam) { $columns['gesperrt_nationalteam'] = '1'; } elseif ($match->type == 'Pokalspiel') { $columns['gesperrt_cups'] = '1'; } else { $columns['gesperrt'] = '1'; } } elseif (!$player->team->isNationalTeam) { $columns['st_karten_gelb'] = $playerinfo['st_karten_gelb'] + 1; $columns['sa_karten_gelb'] = $playerinfo['sa_karten_gelb'] + 1; // block after certain number of matches ('Gelbsperre') if ($match->type == 'Ligaspiel' && $blockYellowCards > 0 && $columns['sa_karten_gelb'] % $blockYellowCards == 0) { $columns['gesperrt'] = 1; } } } } if (!$player->team->isNationalTeam) { $columns['vertrag_spiele'] = max(0, $playerinfo['vertrag_spiele'] - 1); if ($columns['vertrag_spiele'] == 5) { $this->_teamsWithSoonEndingContracts[$player->team->id] = TRUE; } } // update other fields if (!$player->team->isNationalTeam || $this->_websoccer->getConfig('sim_playerupdate_through_nationalteam')) { $columns['w_frische'] = $player->strengthFreshness; $columns['verletzt'] = $player->injured; if ($player->getMinutesPlayed() >= $minMinutes) { $columns['w_kondition'] = min(100, $player->strengthStamina + $staminaChange); $columns['w_zufriedenheit'] = min(100, $player->strengthSatisfaction + $satisfactionChange); } else { $columns['w_kondition'] = max(1, $player->strengthStamina - $staminaChange); $columns['w_zufriedenheit'] = max(1, $player->strengthSatisfaction - $satisfactionChange); } // result dependent satisfaction change if (!$isTie) { if ($isTeamWinner) { $columns['w_zufriedenheit'] = min(100, $columns['w_zufriedenheit'] + $satisfactionChange); } else { $columns['w_zufriedenheit'] = max(1, $columns['w_zufriedenheit'] - $satisfactionChange); } } } if (!$player->team->isNationalTeam && $playerinfo['lending_matches'] > 0) { $this->handleBorrowedPlayer($columns, $playerinfo); } $this->_db->queryUpdate($columns, $fromTable, $whereCondition, $parameters); }
private static function loadTeam(WebSoccer $websoccer, DbConnection $db, $matchId, SimulationTeam $team) { // get players $columns['spieler_id'] = 'player_id'; $columns['name'] = 'name'; $columns['note'] = 'mark'; $columns['minuten_gespielt'] = 'minutes_played'; $columns['karte_gelb'] = 'yellow_cards'; $columns['karte_rot'] = 'red_cards'; $columns['verletzt'] = 'injured'; $columns['gesperrt'] = 'blocked'; $columns['tore'] = 'goals'; $columns['feld'] = 'field_area'; $columns['position'] = 'position'; $columns['position_main'] = 'main_position'; $columns['age'] = 'age'; $columns['w_staerke'] = 'strength'; $columns['w_technik'] = 'strength_tech'; $columns['w_kondition'] = 'strength_stamina'; $columns['w_frische'] = 'strength_freshness'; $columns['w_zufriedenheit'] = 'strength_satisfaction'; $columns['ballcontacts'] = 'ballcontacts'; $columns['wontackles'] = 'wontackles'; $columns['losttackles'] = 'losttackles'; $columns['shoots'] = 'shoots'; $columns['passes_successed'] = 'passes_successed'; $columns['passes_failed'] = 'passes_failed'; $columns['assists'] = 'assists'; $fromTable = $websoccer->getConfig('db_prefix') . '_spiel_berechnung'; $whereCondition = 'spiel_id = %d AND team_id = %d ORDER BY id ASC'; $parameters = array($matchId, $team->id); $result = $db->querySelect($columns, $fromTable, $whereCondition, $parameters); while ($playerinfo = $result->fetch_array()) { $player = new SimulationPlayer($playerinfo['player_id'], $team, $playerinfo['position'], $playerinfo['main_position'], $playerinfo['mark'], $playerinfo['age'], $playerinfo['strength'], $playerinfo['strength_tech'], $playerinfo['strength_stamina'], $playerinfo['strength_freshness'], $playerinfo['strength_satisfaction']); $player->name = $playerinfo['name']; $player->setBallContacts($playerinfo['ballcontacts']); $player->setWonTackles($playerinfo['wontackles']); $player->setLostTackles($playerinfo['losttackles']); $player->setGoals($playerinfo['goals']); $player->setShoots($playerinfo['shoots']); $player->setPassesSuccessed($playerinfo['passes_successed']); $player->setPassesFailed($playerinfo['passes_failed']); $player->setAssists($playerinfo['assists']); $player->setMinutesPlayed($playerinfo['minutes_played'], FALSE); $player->yellowCards = $playerinfo['yellow_cards']; $player->redCard = $playerinfo['red_cards']; $player->injured = $playerinfo['injured']; $player->blocked = $playerinfo['blocked']; // add player self::$_addedPlayers[$player->id] = $player; if ($playerinfo['field_area'] == 'Ausgewechselt') { $team->removedPlayers[$player->id] = $player; } else { if ($playerinfo['field_area'] == 'Ersatzbank') { $team->playersOnBench[$player->id] = $player; } else { $team->positionsAndPlayers[$player->position][] = $player; } } } $result->free(); }
/** * Computes strength change after match, depending on player's grade/mark. * * @param SimulationPlayer $player * @return int number of strength points which the player gained. */ private function _computeStrengthChange(SimulationPlayer $player) { $mark = $player->getMark(); if ($mark <= 1.3) { return $this->_websoccer->getConfig('youth_strengthchange_verygood'); } else { if ($mark <= 2.3) { return $this->_websoccer->getConfig('youth_strengthchange_good'); } else { if ($mark > 4.25 && $mark <= 5) { return $this->_websoccer->getConfig('youth_strengthchange_bad'); } else { if ($mark > 5) { return $this->_websoccer->getConfig('youth_strengthchange_verybad'); } } } } return 0; }
/** * (non-PHPdoc) * @see ISimulationObserver::onFreeKick() */ public function onFreeKick(SimulationMatch $match, SimulationPlayer $player, SimulationPlayer $goaly, $successful) { $player->setShoots($player->getShoots() + 1); // adapt grades if ($successful) { $player->improveMark(MARK_IMPROVE_GOAL_SCORER); // do not decrease goaly's grade since it is probably not his fault, poor guy.. // update goals $player->team->setGoals($player->team->getGoals() + 1); $player->setGoals($player->getGoals() + 1); } else { $player->downgradeMark(MARK_DOWNGRADE_SHOOTFAILURE); $goaly->improveMark(MARK_IMPROVE_SHOOTFAILURE_GOALY); } }