public function action() { $friendId = intval($this->parameters->friendId); if (empty($friendId)) { $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Получен не правильный номер друга", ErrorPoint::TYPE_USER); return $actionResult; } track_stats(); // Отслеживаем производительность $actionResult = TeamSatellite::isAvailableToPrize($friendId); if ($actionResult instanceof ErrorPoint) { return $actionResult; } if ($actionResult === false) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Выбранному пользователю вы уже дарили подарок. Теперь только завтра", ErrorPoint::TYPE_USER); } track_stats(); // Отслеживаем производительность SQL::getInstance()->autocommit(false); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } track_stats(); // Отслеживаем производительность $actionResult = TeamSatellite::cratePrizeDateLabel($friendId); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } track_stats(); // Отслеживаем производительность $actionResult = TeamSatellite::prizeStudyPoint($friendId); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } SQL::getInstance()->commit(); track_stats(); // Отслеживаем производительность $api = new VKapi(VK_API_SECRET, VK_API_ID, VK_MAILING_SPEED); $api->setCounter($friendId, TeamSatellite::getPrizeStudyPoint($friendId)); return $actionResult; }
public function action() { $friendId = intval($this->parameters->friendId); if (empty($friendId)) { $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Получен не правильный номер друга", ErrorPoint::TYPE_USER); return $actionResult; } track_stats(); // Отслеживаем производительность $alreadyExists = $this->teamProfile->getFootballerById($friendId); if ($alreadyExists) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ваш друг уже играет за вас", ErrorPoint::TYPE_USER); } track_stats(); // Отслеживаем производительность $actionResult = FootballerSatellite::getFootballerOwner($friendId); if ($actionResult instanceof ErrorPoint) { return $actionResult; } if ($actionResult !== false) { return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Ваш друг уже числиться в другом футбольном клубе", ErrorPoint::TYPE_USER); } track_stats(); // Отслеживаем производительность SQL::getInstance()->autocommit(false); $friendFootballer = new Footballer(); $actionResult = $friendFootballer->addFriend($friendId, NULL, $this->teamProfile->getActiveCount()); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } track_stats(); // Отслеживаем производительность $addonPoints = 0; if (TeamSatellite::isFreshFriend($friendId)) { // Даються очьку обучения как среднее по всех футболистов if (count($this->teamProfile->getFootballers()) != 0) { $addonPoints = floor($this->teamProfile->getFootballerSumLevel() / count($this->teamProfile->getFootballers())); $this->teamProfile->setStudyPoints($this->teamProfile->getStudyPoints() + $addonPoints); $actionResult = $this->teamProfile->save(); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } } } track_stats(); // Отслеживаем производительность $actionResult = Team::markTeamAsSelected($friendId); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } track_stats(); // Отслеживаем производительность RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersFriendsCount', $this->teamProfile->getAllFootballersFriendsCount() + 1); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); } else { SQL::getInstance()->commit(); $this->result['footballer'] = $friendFootballer; $this->result['addonStadyPoints'] = $addonPoints; $this->result['totalStadyPoints'] = $this->teamProfile->getStudyPoints(); } track_stats(); // Отслеживаем производительность return $actionResult; }
public function action() { $this->result["isInstalled"] = $this->teamProfile->getIsInstalled(); track_stats(); // ќтслеживаем производительность $startAt = RAM::getInstance()->getTourStart(); $finishAt = RAM::getInstance()->getTourFinish(); track_stats(); // ќтслеживаем производительность if (empty($startAt) || empty($finishAt)) { $tourTimer = TourSatellite::getTimerDate(); $startAt = $tourTimer->startAt; $finishAt = $tourTimer->finishAt; RAM::getInstance()->setTourStart($startAt); RAM::getInstance()->setTourFinish($finishAt); } track_stats(); // ќтслеживаем производительность $this->result["tourStartAt"] = $startAt; $this->result["tourFinishedAt"] = $finishAt; $this->result["serverTime"] = time(); if ($this->teamProfile->getIsInstalled()) { track_stats(); // ќтслеживаем производительность $energyTimer = RAM::getInstance()->getEnergyLastUpdate(); if (empty($energyTimer)) { $energyTimer = filemtime(SYSTEM_LOGS . "/cron.updateEnergy.log"); // microtime RAM::getInstance()->setEnergyLastUpdate($energyTimer); } $this->result['energyTimer'] = $energyTimer; track_stats(); // ќтслеживаем производительность if ($this->teamProfile->isNeedDailyBonus()) { $dailyBonus = $this->teamProfile->getTotalStadiumBonus(); $this->teamProfile->setMoney($this->teamProfile->getMoney() + $dailyBonus); $actionResult = TeamSatellite::accrueDailyBonus(UserParameters::getUserId(), $this->teamProfile->getMoney()); if ($actionResult instanceof ErrorPoint) { return $actionResult; } } track_stats(); // ќтслеживаем производительность if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() == 0) { $finishBonusAt = time() + 1 * 24 * 60 * 60; $actionResult = TeamSatellite::startTourBonus(UserParameters::getUserId(), $finishBonusAt); if ($actionResult instanceof ErrorPoint) { return $actionResult; } $this->teamProfile->setTourBonusTime($finishBonusAt); } track_stats(); // ќтслеживаем производительность $this->result["teamInfo"] = JSONPrepare::team($this->teamProfile); track_stats(); // ќтслеживаем производительность // Ёто надо обновить после отдачи профайла if ($this->teamProfile->getTourNotify() == TOUR_NOTIFY_START || $this->teamProfile->getTourNotify() == TOUR_NOTIFY_NEW) { $actionResult = TeamSatellite::updateTourNotify(UserParameters::getUserId(), $this->teamProfile->getTourNotify() - 2); if ($actionResult instanceof ErrorPoint) { return $actionResult; } } track_stats(); // ќтслеживаем производительность if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() > 0 && $this->teamProfile->getTourBonusTime() < time()) { $actionResult = TeamSatellite::eraseTourBonus(UserParameters::getUserId()); if ($actionResult instanceof ErrorPoint) { return $actionResult; } $this->teamProfile->setTourBonus(0); $this->teamProfile->setTourBonusTime(0); } track_stats(); // ќтслеживаем производительность if ($this->teamProfile->getStudyPointsViaPrize() > 0) { $actionResult = TeamSatellite::resetPrizeStudyPoint(UserParameters::getUserId()); if ($actionResult instanceof ErrorPoint) { return $actionResult; } } //Utils::forDebug($this->teamProfile); } }
public function action() { track_stats(); // Отслеживаем производительность $actionResult = NULL; $sellId = intval($this->parameters->footballerId); $footballerInstance = $this->teamProfile->getFootballerById($sellId); if ($footballerInstance === false) { $errorMessage = "Анулирование контракта невозможно"; // Utils::forDebug($errorMessage . " sellId : $sellId - UserId : " . $this->teamProfile->getSocialUserId()); return new ErrorPoint(ErrorPoint::CODE_LOGIC, "Анулирование контракта невозможно", ErrorPoint::TYPE_USER); } if ($footballerInstance->getIsActive()) { switch ($footballerInstance->getType()) { case TYPE_FOOTBALLER_FORWARD_CODE: $this->teamProfile->setParameterForward($this->teamProfile->getParameterForward() - $footballerInstance->getLevel()); break; case TYPE_FOOTBALLER_SAFER_CODE: case TYPE_FOOTBALLER_GOALKEEPER_CODE: $this->teamProfile->setParameterSafe($this->teamProfile->getParameterSafe() - $footballerInstance->getLevel()); break; case TYPE_FOOTBALLER_HALFSAFER_CODE: $this->teamProfile->setParameterHalf($this->teamProfile->getParameterHalf() - $footballerInstance->getLevel()); break; } } track_stats(); // Отслеживаем производительность $this->result['teamParameters'] = array("Forward" => $this->teamProfile->getParameterForward(), "Safe" => $this->teamProfile->getParameterSafe(), "Half" => $this->teamProfile->getParameterHalf()); track_stats(); // Отслеживаем производительность SQL::getInstance()->autocommit(false); track_stats(); // Отслеживаем производительность $deleteResult = $this->teamProfile->deleteFootballerFromStore($footballerInstance); if ($deleteResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $deleteResult; } track_stats(); // Отслеживаем производительность if ($footballerInstance->getIsFriend()) { $markAsFreeResult = TeamSatellite::markFriendAsFree($footballerInstance->getId(), $free = true); if ($markAsFreeResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $markAsFreeResult; } } track_stats(); // Отслеживаем производительность $footballerPrice = FootballerSatellite::detectPrice($footballerInstance, $this->teamProfile->getStudyPointCost()); $footballerPrice = $footballerInstance->getIsSuper() ? $footballerPrice * 3 : $footballerPrice; $footballerPrice *= 0.25; track_stats(); // Отслеживаем производительность $tourBonus = 1; if ($this->teamProfile->isNewTour() && $this->teamProfile->getTourBonus() != 0 && $this->teamProfile->getTourBonusTime() > 0 && $this->teamProfile->getTourBonusTime() > time()) { $tourBonus = $this->teamProfile->getTourBonus(); $tourBonus -= 1; $tourBonus = 1 - $tourBonus; } if ($tourBonus == 0) { $tourBonus = 1; } track_stats(); // Отслеживаем производительность $footballerPrice = $footballerPrice * $tourBonus; $this->teamProfile->setMoney($this->teamProfile->getMoney() + $footballerPrice); $actionResult = $this->teamProfile->save(); track_stats(); // Отслеживаем производительность if ($footballerInstance->getIsFriend()) { RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersFriendsCount', $this->teamProfile->getAllFootballersFriendsCount() - 1); } else { RAM::getInstance()->changeTeamField($this->teamProfile->getSocialUserId(), 'footballersCount', $this->teamProfile->getAllFootballersCount() - 1); } track_stats(); // Отслеживаем производительность if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); } else { SQL::getInstance()->commit(); } track_stats(); // Отслеживаем производительность return $actionResult; }
public function action() { $detailId = 0; if (isset($this->parameters->detailId)) { $detailId = intval($this->parameters->detailId); } $typeTour = 0; if (isset($this->parameters->typeTour)) { $typeTour = intval($this->parameters->typeTour); } if ($this->teamProfile->getCurrentEnergy() < GlobalParameters::ENERGY_PER_MATCH) { return new ErrorPoint(ErrorPoint::CODE_SECURITY, "Для проведения новых матчей нужна энергия. На новый матч надо " . GlobalParameters::ENERGY_PER_MATCH, ErrorPoint::TYPE_USER); } track_stats(); // Отслеживаем производительность $enemyTeam = new Team(); $actionResult = $enemyTeam->initById($this->parameters->enemyTeamId); if ($actionResult instanceof ErrorPoint) { return $actionResult; } track_stats(); // Отслеживаем производительность $isTourRun = isset($this->parameters->type) && $detailId && $typeTour; $this->result = JSONPrepare::footballers($enemyTeam->getFootballers()); track_stats(); // Отслеживаем производительность $this->result["healthDown"] = 0; $score1 = md5("1" . $this->parameters->enemyTeamId . SECRET_KEY); $score2 = md5("-1" . $this->parameters->enemyTeamId . SECRET_KEY); $score3 = md5("0" . $this->parameters->enemyTeamId . SECRET_KEY); $scoreTE = 0; $addonExperiance = GlobalParameters::EXPERIANCE_PER_MATCH_TIE; $addonMoney = GlobalParameters::MONEY_PER_MATCH_TIE; switch ($this->parameters->score) { case $score1: $scoreTE = 1; if (1 == rand(1, 100) && $this->teamProfile->getLevel() > 3) { $this->result["healthDown"] = $this->healthDownFootballer(); } $addonExperiance = GlobalParameters::EXPERIANCE_PER_MATCH; $addonMoney = GlobalParameters::MONEY_PER_MATCH; $this->teamProfile->increaseWonRating(); if (!$isTourRun) { $this->teamProfile->setTourIII($this->teamProfile->getTourIII() + 3); } break; case $score2: $scoreTE = -1; if (1 == rand(1, 30) && $this->teamProfile->getLevel() > 3) { $this->result["healthDown"] = $this->healthDownFootballer(); } $addonExperiance = GlobalParameters::EXPERIANCE_PER_MATCH_LOSE; $addonMoney = GlobalParameters::MONEY_PER_MATCH_LOSE; $this->teamProfile->increaseLoseRating(); break; case $score3: if (1 == rand(1, 60) && $this->teamProfile->getLevel() > 5) { $this->result["healthDown"] = $this->healthDownFootballer(); } $addonExperiance = GlobalParameters::EXPERIANCE_PER_MATCH_TIE; $addonMoney = GlobalParameters::MONEY_PER_MATCH_TIE; $this->teamProfile->increaseTieRating(); if (!$isTourRun) { $this->teamProfile->setTourIII($this->teamProfile->getTourIII() + 1); } break; } track_stats(); // Отслеживаем производительность $addonExperiance = $this->getAddOnXPorMoney($addonExperiance, $this->teamProfile->getLevel()); $addonMoney = $this->getAddOnXPorMoney($addonMoney, $this->teamProfile->getLevel(), 10); $stadiumMoney = 0; if ($this->teamProfile->getStadiumId() && 1 == rand(1, 10)) { $stadiumMoney = $addonMoney * ($scoreTE + 2); } $stadiumMoney = $stadiumMoney < 10000 ? $stadiumMoney : 0; $addonExperiance = $addonExperiance < 10000 ? $addonExperiance : 0; $addonMoney = $addonMoney < 10000 ? $addonMoney : 0; $this->teamProfile->setEnergy($this->teamProfile->getCurrentEnergy() - GlobalParameters::ENERGY_PER_MATCH); $this->teamProfile->addExperience($addonExperiance); $this->teamProfile->setMoney($this->teamProfile->getMoney() + $addonMoney + $stadiumMoney); $this->result["stadiumBonus"] = $stadiumMoney; $this->result["addonEx"] = $addonExperiance; $this->result["addonMoney"] = $addonMoney; $this->result["currentEnergy"] = $this->teamProfile->getCurrentEnergy(); $this->result["maxEnergy"] = $this->teamProfile->getEnergyMax(); $this->result["score"] = $scoreTE; $this->result["bonus"] = null; $this->result["bonusTime"] = null; $this->result["totalBonus"] = null; track_stats(); // Отслеживаем производительность $markAsFreeResult = TeamSatellite::increaseChooseRating($this->parameters->enemyTeamId); if ($markAsFreeResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $markAsFreeResult; } track_stats(); // Отслеживаем производительность if ($isTourRun) { $sql = NULL; switch ($this->parameters->type) { case 'groupsFight': $sqlTemplate = "UPDATE tour_groups_details SET finished = 1 WHERE vk_id = %d AND group_details_id = %d"; $sql = sprintf($sqlTemplate, UserParameters::getUserId(), $detailId); break; case 'playOffFight': $sqlTemplate = "UPDATE tour_play_off SET finished = 1 WHERE vk_id = %d AND play_off_id = %d and tour_type = %d"; $sql = sprintf($sqlTemplate, UserParameters::getUserId(), $detailId, $typeTour); break; } track_stats(); // Отслеживаем производительность if (!is_null($sql)) { $SQLResult = SQL::getInstance()->query($sql); if ($SQLResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $SQLResult; } track_stats(); // Отслеживаем производительность if ($this->parameters->type == 'playOffFight' && SQL::getInstance()->affected_rows == 1) { $tourFinished = TeamSatellite::isTourWasFinished($typeTour, $detailId); if ($tourFinished instanceof ErrorPoint) { return $tourFinished; } if ($tourFinished) { $bonus = 1; switch ($typeTour) { case TOUR_TYPE_VK: $bonus = GoldCointsGrid::getInstance()->getBonusByPlace($typeTour, $this->teamProfile->getTourPlaceVK()); break; case TOUR_TYPE_COUNTRY: $bonus = GoldCointsGrid::getInstance()->getBonusByPlace($typeTour, $this->teamProfile->getTourPlaceCountry()); break; case TOUR_TYPE_CITY: $bonus = GoldCointsGrid::getInstance()->getBonusByPlace($typeTour, $this->teamProfile->getTourPlaceCity()); break; case TOUR_TYPE_UNI: $bonus = GoldCointsGrid::getInstance()->getBonusByPlace($typeTour, $this->teamProfile->getTourPlaceUniversity()); break; } $this->teamProfile->setTourBonus($this->teamProfile->getTourBonus() > 0 ? $bonus * $this->teamProfile->getTourBonus() : $bonus); $this->result["bonus"] = $bonus; //$this->result["bonusTime"] = $this->teamProfile->getTourBonusTime(); $this->result["totalBonus"] = $this->teamProfile->getTourBonus(); } } track_stats(); // Отслеживаем производительность } } if (is_infinite($this->teamProfile->getMoney())) { $this->teamProfile->setMoney(10000); } $actionResult = $this->teamProfile->save(); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } track_stats(); // Отслеживаем производительность logUserEnergy(); track_stats(); // Отслеживаем производительность SQL::getInstance()->commit(); track_stats(); // Отслеживаем производительность }