コード例 #1
0
 public static function detectChanceOfWin(Team $userTeam, Team $enemyTeam)
 {
     $userSumParameters = $userTeam->getParameterSum();
     $enemySumParameters = $userTeam->getParameterSum();
     if ($userSumParameters == 0 || $enemySumParameters == 0) {
         return 1;
     }
     /*   if($userSumParameters >= $enemySumParameters){
              return 1;
          }*/
     $max = max($userSumParameters, $enemySumParameters);
     $min = min($userSumParameters, $enemySumParameters);
     $percent = $min * 100 / $max;
     if ($percent < 90) {
         if ($userSumParameters > $enemySumParameters) {
             return 1;
         } else {
             return -1;
         }
     }
     $rand = mt_rand(0, 99);
     $SumParameters = $enemySumParameters + $userSumParameters;
     if ($SumParameters == 0) {
         $SumParameters = 100;
     }
     $userPercentParameters = floor($userSumParameters * 100 / $SumParameters);
     if ($userTeam->getLevel() < 3) {
         $userPercentParameters += 35;
     } elseif ($userTeam->getLevel() < 6) {
         $userPercentParameters += 30;
     } elseif ($userTeam->getLevel() < 9) {
         $userPercentParameters += 25;
     }
     if ($userPercentParameters - GlobalParameters::DETECT_RESULT_FOR_TIE < $rand && $userPercentParameters + GlobalParameters::DETECT_RESULT_FOR_TIE > $rand) {
         // стоит подумать о ничье
         $score = rand(1, 2) - 1;
     } elseif ($rand <= $userPercentParameters) {
         // С учётом коефициента на ничью
         $score = 1;
     } else {
         $score = -1;
     }
     return $score;
 }
コード例 #2
0
 public static function team(Team $team)
 {
     $forJSON = array("level" => $team->getLevel(), "experience" => $team->getExperience(), "money" => $team->getMoney(), "realMoney" => $team->getRealMoney(), "studyPoints" => $team->getStudyPoints(), "energy" => $team->getCurrentEnergy(), "energyMax" => floor($team->getEnergyMax()), "trainerId" => $team->getTrainerId(), "teamName" => $team->getTeamName(), "teamLogoId" => $team->getTeamLogoId(), "paramForward" => $team->getParameterForward(), "paramHalf" => $team->getParameterHalf(), "paramSafe" => $team->getParameterSafe(), "isInstalled" => $team->getIsInstalled(), "socialUserId" => $team->getSocialUserId(), "userPhoto" => $team->getUserPhoto(), "userName" => $team->getUserName(), "isInTeam" => $team->getIsInTeam(), "studyPointsViaPrize" => $team->getStudyPointsViaPrize(), "inGroup" => $team->getInGroup(), "counterChoose" => $team->getCounterChoose(), "counterWon" => $team->getCounterWon(), "counterLose" => $team->getCounterLose(), "stadiumId" => $team->getStadiumId(), "needDailyBonus" => $team->isNeedDailyBonus(), "placeCountry" => $team->getPlaceCountry(), "placeCity" => $team->getPlaceCity(), "placeUniversity" => $team->getPlaceUniversity(), "placeVK" => $team->getPlaceVK(), "tourIIIcounter" => $team->getTourIII(), "tourPlaceCountry" => $team->getTourPlaceCountry(), "tourPlaceCity" => $team->getTourPlaceCity(), "tourPlaceUniversity" => $team->getTourPlaceUniversity(), "tourPlaceVK" => $team->getTourPlaceVK(), "tourNotify" => $team->getTourNotify(), "tourBonus" => $team->getTourBonus(), "tourBonusTime" => $team->getTourBonusTime(), "counterChoose" => $team->getCounterChoose(), "counterWon" => $team->getCounterWon(), "counterLose" => $team->getCounterLose(), "totalPlace" => $team->getTotalPlace(), "place" => isset($team->place) ? $team->place : 99);
     if (count($team->getFootballers())) {
         $forJSON["footballers"] = JSONPrepare::footballers($team->getFootballers());
     }
     if (count($team->getSponsors())) {
         $forJSON["sponsors"] = JSONPrepare::sponsors($team->getSponsors());
     }
     return $forJSON;
 }
コード例 #3
0
ファイル: Team.php プロジェクト: rootree/vk-footboller-server
 public function initFromRAM(Team $team)
 {
     $this->socialUserId = $team->getSocialUserId();
     $this->setLevel($team->getLevel());
     $this->setExperience($team->getExperience());
     $this->setMoney($team->getMoney());
     $this->setRealMoney($team->getRealMoney());
     $this->setStudyPoints($team->getStudyPoints());
     $this->setStudyPointsViaPrize($team->getStudyPointsViaPrize());
     $this->setInGroup($team->getInGroup());
     $this->setParameterForward($team->getParameterForward());
     $this->setParameterHalf($team->getParameterHalf());
     $this->setParameterSafe($team->getParameterSafe());
     $this->setEnergy($team->getCurrentEnergy());
     $this->setMaxEnergy($team->getEnergyMax());
     $this->trainerId = $team->getTrainerId();
     $this->teamName = trim($team->getTeamName());
     $this->teamLogoId = $team->getTeamLogoId();
     $this->inTeam = $team->getIsInTeam();
     $this->isAbleToChoose = $team->getIsAbleToChoose();
     $this->userPhoto = trim($team->getUserPhoto());
     $this->userName = trim($team->getUserName());
     $this->counterWon = $team->getCounterWon();
     $this->counterChoose = $team->getCounterChoose();
     $this->counterLose = $team->getCounterLose();
     $this->counterTie = $team->getCounterTie();
     $this->stadiumId = $team->getStadiumId();
     $this->setUserCountry($team->getUserCountry());
     $this->setUserCity($team->getUserCity());
     $this->setUserUniversity($team->getUserUniversity());
     $this->setPlaceCountry($team->getPlaceCountry());
     $this->setPlaceCity($team->getPlaceCity());
     $this->setPlaceUniversity($team->getPlaceUniversity());
     $this->setPlaceVK($team->getPlaceVK());
     $this->setTourIII($team->getTourIII());
     $this->setDailyBonus($team->isNeedDailyBonus());
     $this->setTourPlaceCountry($team->getTourPlaceCountry());
     $this->setTourPlaceCity($team->getTourPlaceCity());
     $this->setTourPlaceUniversity($team->getTourPlaceUniversity());
     $this->setTourPlaceVK($team->getTourPlaceVK());
     $this->setTourNotify($team->getTourNotify());
     $this->setTourBonus($team->getTourBonus());
     $this->setTourBonusTime($team->getTourBonusTime());
     $this->setIsPrized($team->getIsPrized());
     $this->setParameterSum($team->getParameterSum());
     $this->setTotalPlace($team->getTotalPlace());
     $this->setAllFootballersCount($team->getAllFootballersCount());
     $this->setAllFootballersFriendsCount($team->getAllFootballersFriendsCount());
     $this->setSponsorsCount($team->getSponsorsCount());
 }
コード例 #4
0
 private function getFriendsTeams()
 {
     $this->result['teams'] = array();
     $this->result['news'] = array();
     $this->result['rating'] = array();
     if ($this->parameters->groupSourceId) {
         logGroupSource($this->parameters->groupSourceId);
     }
     $needToUpgrade = false;
     $userCountry = intval($this->parameters->userCountry);
     $userCity = intval($this->parameters->userCity);
     $userUniversity = intval($this->parameters->userUniversity);
     track_stats();
     // Отслеживаем производительность
     if ($userCountry != $this->teamProfile->getUserCountry()) {
         $this->teamProfile->setUserCountry($userCountry);
         $needToUpgrade = true;
     }
     if ($userCity != $this->teamProfile->getUserCity()) {
         $this->teamProfile->setUserCity($userCity);
         $needToUpgrade = true;
     }
     if ($userUniversity != $this->teamProfile->getUserUniversity()) {
         $this->teamProfile->setUserUniversity($userUniversity);
         $needToUpgrade = true;
     }
     if (isset($this->parameters->groupBonusNeeded) && $this->parameters->groupBonusNeeded == 1 && $this->teamProfile->getInGroup() == 0) {
         $this->teamProfile->setInGroup(1);
         $this->teamProfile->setRealMoney($this->teamProfile->getRealMoney() + GlobalParameters::GROUP_BONUS_REAL);
         $needToUpgrade = true;
     }
     track_stats();
     // Отслеживаем производительность
     if ($needToUpgrade) {
         $actionResult = $this->teamProfile->save();
         if ($actionResult instanceof ErrorPoint) {
             return $actionResult;
         }
     }
     if ($this->parameters->uids) {
         if (!is_object($this->parameters->uids)) {
             $this->parameters->uids = str_replace('\\\\', '', $this->parameters->uids);
             $this->parameters->uids = str_replace('\\"', '', $this->parameters->uids);
             $this->parameters->uids = json_decode($this->parameters->uids);
         }
         track_stats();
         // Отслеживаем производительность
         $sql_template = "SELECT\n    teams.team_name,\n    teams.param_forward,\n    teams.param_half,\n    teams.param_safe,\n    teams.user_photo,\n    teams.user_name, \n    teams.team_logo_id, \n    teams.vk_id,\n    teams.level\nFROM teams\nWHERE teams.vk_id IN (%s) order by teams.level desc,  teams.counter_won desc ";
         $sql = sprintf($sql_template, Utils::IdsSeparetedByComma($this->parameters->uids));
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         if ($SQLresult->num_rows) {
             $counterPlace = 1;
             while ($teamObject = $SQLresult->fetch_object()) {
                 $team = new Team();
                 $team->initFromDB($teamObject, false);
                 if ($team->getLevel() == 0) {
                     continue;
                 }
                 $team->place = $counterPlace;
                 $teamInJSON = JSONPrepare::team($team);
                 $counterPlace++;
                 $this->result['teams'][] = $teamInJSON;
                 //  $this->result['teams'][] = $teamObject;
             }
         }
     }
     $this->result['news'] = RAM::getInstance()->getNews();
     if (count($this->result['news']) == 0) {
         $sql_template = "SELECT news_sport.* FROM news_sport ORDER BY news_id";
         $sql = $sql_template;
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         if ($SQLresult->num_rows) {
             $counter = 0;
             while ($newsObject = $SQLresult->fetch_object()) {
                 $news = new NewsEntry($newsObject);
                 $news->id = $counter;
                 $this->result['news'][] = $news;
                 RAM::getInstance()->setNews($news);
                 $counter++;
             }
         }
     }
     $leadTeams = RAM::getInstance()->getLeaders();
     if (count($leadTeams) == 0) {
         $sql_template = "SELECT teams.* FROM teams WHERE total_place is not NULL ORDER BY total_place  LIMIT 6";
         $sql = $sql_template;
         $SQLresult = SQL::getInstance()->query($sql);
         if ($SQLresult instanceof ErrorPoint) {
             return $SQLresult;
         }
         if ($SQLresult->num_rows) {
             $counter = 0;
             while ($teamObject = $SQLresult->fetch_object()) {
                 $team = new Team();
                 $team->initFromDB($teamObject);
                 RAM::getInstance()->setLeader($team, $counter);
                 $counter++;
                 $teamInJSON = JSONPrepare::team($team);
                 $this->result['rating'][] = $teamInJSON;
             }
         }
     } else {
         foreach ($leadTeams as $team) {
             $teamInJSON = JSONPrepare::team($team);
             $this->result['rating'][] = $teamInJSON;
         }
     }
 }