public static function searchByLevel($level, $experience, $playerId) { $options = []; $options['clearSelect'] = true; $options['select'][] = self::getList(['id', 'experience', 'user_id']); if ($level > 0) { $options['where'][] = ['player.experience BETWEEN ? AND ?', round($experience * 1.3), round($experience * 1.5 + 30)]; } else { if ($level < 0) { $options['where'][] = ['player.experience BETWEEN ? AND ?', round($experience * 0.5 - 30), round($experience * 0.7)]; } else { $options['where'][] = ['player.experience BETWEEN ? AND ?', round($experience * 0.7 - 30), round($experience * 1.3 + 30)]; } } $options['where'][] = ['player.id != ?', $playerId]; $options['where'][] = 'player.active = 1'; $options['where'][] = 'player.is_in_match = 0'; $options['where'][] = 'player.is_in_tournament = 0'; $options['where'][] = 'player.accept_challenge = 1'; $options['where'][] = 'player.mental >= 750'; $players = self::loadAll($options); if (count($players) == 0) { return null; } $pick = Engine::dice(0, count($players) - 1); return $players[$pick]; }
public function computerMatch() { $created = 0; $options = []; $options['clearSelect'] = true; $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'league_id', 'experience']); $options['where'][] = 'player.is_in_tournament = 0'; $options['where'][] = 'player.is_in_match = 0'; $options['where'][] = 'player.user_id = 0'; $options['where'][] = 'player.active = 1'; $options['where'][] = 'player.mental >= 750'; $players = \Own\Bus\Player\Data::loadAll($options); $count = count($players); if ($count > 0) { $pick = Engine::dice(0, $count - 1); $player = $players[$pick]; unset($players); $player2 = \Own\Bus\Player\Data::searchByLeague($player->getId(), $player->getLeagueId()); if (isset($player2)) { $match = new \Own\Bus\Match\Model(); $playerMatch1 = new \Own\Bus\PlayerMatch\Model(); $playerMatch2 = new \Own\Bus\PlayerMatch\Model(); $match->setSurface($player->getLeague()->getSurface()); $match->setType(MatchType::LEAGUE); $match->setLeagueId($player->getLeagueId()); $match->setBestOfSets($player->getLeague()->getBestOfSets()); $matchTime = (new Util\DateTime())->add(new \DateInterval('PT120S')); $playerMatch1->setPlayerId($player->getId()); $playerMatch1->setLevel($player->calculateLevel()); $playerMatch1->save(); $playerMatch2->setPlayerId($player2->getId()); $playerMatch2->setLevel($player2->calculateLevel()); $playerMatch2->save(); $match->setPlayerMatch1Id($playerMatch1->getId()); $match->setPlayerMatch2Id($playerMatch2->getId()); $match->setScheduled($matchTime); $match->setStatus(MatchStatus::READY); $match->save(); if ($player2->getUserId() != 0) { \Own\Bus\Notification\Service::create($player2->getId(), 0, 'matchStart', [['scheduledMatch', $matchTime->format('datetime')]]); } \Own\Bus\Player\Data::updateIsInMatch($player->getId(), $player2->getId()); $created = 1; } } $this->log('computer match: ' . $created); }
public static function removeAndAddPlayer() { $options = []; $options['clearSelect'] = true; $options['select'][] = \Own\Bus\Player\Data::getList(['id', 'username']); $options['where'][] = 'player.user_id = 0'; $options['where'][] = 'player.active = 1'; $players = \Own\Bus\Player\Data::loadAll($options); if (count($players) > 0) { $db = new Util\Data(); $pick = \Own\Bus\Engine::dice(0, count($players) - 1); $remove = 'UPDATE bus_player SET active = 0 WHERE id = ' . $players[$pick]->getId(); $db->execute($remove); Util\Log::log(Util\Code::CRON, 'player retired: ' . $players[$pick]->getUsername() . ' (' . $players[$pick]->getId() . ')', __FILE__, __LINE__); $leagues = \Own\Bus\League\Data::loadAll(); $player = new \Own\Bus\Player\Model(); $player->setRandom(1); $player->setActive(true); if (count($leagues) > 0) { $player->setLeagueId(\Own\Bus\Engine::findLeague($leagues, 1)); } $player->save(); Util\Log::log(Util\Code::CRON, 'new player: ' . $player->getUsername() . ' (' . $player->getId() . ')', __FILE__, __LINE__); } }
public function selectServer() { $toss = Engine::dice(1, 2); if ($toss == 1) { if ($this->match->getPlayerMatch1()->getPlayer()->getToss() == 1) { $this->match->setServerId($this->match->getPlayerMatch1Id()); } else { $this->match->setServerId($this->match->getPlayerMatch2Id()); } } else { if ($this->match->getPlayerMatch2()->getPlayer()->getToss() == 1) { $this->match->setServerId($this->match->getPlayerMatch2Id()); } else { $this->match->setServerId($this->match->getPlayerMatch1Id()); } } return $toss; }
public function updateMasteries() { $total = $this->getExperienceLeft(); $oldTactic = $this->getTacticValues(); $masteries = Service::getMasteryList(); while (count($masteries) > 0 && $total >= Service::masteryCost(1)) { $pick = Engine::dice(0, count($masteries) - 1); $mastery = $masteries[$pick]; $cost = Service::masteryCost($mastery + 1); if ($total >= $cost) { $total -= $cost; $this->{$mastery}++; unset($masteries[$pick]); $masteries = array_values($masteries); // update tactic $value = $this->{$mastery} + Engine::dice(0, 2); switch ($mastery) { case 'serve': $this->tacticServe1 = $value; $this->tacticServe2 = $value; break; case 'return': $this->tacticReturn1 = $value; $this->tacticReturn2 = $value; break; case 'forehand': case 'backhand': case 'turnAround': $this->tacticTurnAround = 2 + min(3, abs($this->forehand - $this->backhand)); break; case 'volley': case 'netApproach': $this->tacticNet = $value; $this->tacticNetMove = round($value / 2); break; case 'serveVolley': $this->tacticServeNet = round($value / 2); break; case 'dropsthot': $this->tacticDropshot = round($value / 2); break; case 'endurance': $this->tacticIntensity = $value; break; case 'counter': $this->tacticCounter = round($value / 2); break; case 'offense': case 'defense': $this->tacticBaseline = 5 + $this->offense - $this->defense; $this->tacticBaseline = min(10, max(1, $this->tacticBaseline)); break; } } } $this->changeTactic($oldTactic); return true; }
public function calculateServeSpeed() { $speed = 60 + round($this->point / 2) + Engine::dice(-10, 10); if ($this->isSuccess && $speed > $this->playerMatch->getFastestServe()) { $this->playerMatch->setFastestServe($speed); } return $speed; }