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))); }
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 _shootPenalty(SimulationMatch $match, SimulationPlayer $player) { $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); // probability is between 30 and 80% $pGoal[TRUE] = max(30, min($player->strength - $shootReduction, 80)); $pGoal[FALSE] = 100 - $pGoal[TRUE]; $result = SimulationHelper::selectItemFromProbabilities($pGoal); foreach ($this->_observers as $observer) { $observer->onPenaltyShoot($match, $player, $goaly, $result); } return $result; }
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)); } }