private function setEncPoints($roundId, $encId, $p1points, $p2points)
 {
     $enc = new EliminationEncounter($this->tournamentId, $roundId, $encId);
     if ($roundId < $this->roundCount() - 1) {
         // not in last round
         $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2);
         if ($this->thirdplayoff && $roundId == $this->roundCount() - 2) {
             $firstAtNext = $enc->getId() % 2 == 0;
         } else {
             $firstAtNext = $enc->getAlias() % 2 == 0;
         }
     }
     // check which player has won and forward this player
     $enc->setPoints($p1points, $p2points);
     if (isset($nextEnc)) {
         if ($enc->winner() == 1) {
             if ($firstAtNext) {
                 $nextEnc->setPlayer1id($enc->getPlayer1id());
             } else {
                 $nextEnc->setPlayer2id($enc->getPlayer1id());
             }
         } else {
             if ($firstAtNext) {
                 $nextEnc->setPlayer1id($enc->getPlayer2id());
             } else {
                 $nextEnc->setPlayer2id($enc->getPlayer2id());
             }
         }
     }
     //  /w 3rd playoff forward loosers as well
     if ($this->thirdplayoff && $roundId == $this->roundCount() - 2) {
         $thirdPlayoffEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 1);
         if ($enc->winner() == 2) {
             if ($firstAtNext) {
                 $thirdPlayoffEnc->setPlayer1id($enc->getPlayer1id());
             } else {
                 $thirdPlayoffEnc->setPlayer2id($enc->getPlayer1id());
             }
         } else {
             if ($firstAtNext) {
                 $thirdPlayoffEnc->setPlayer1id($enc->getPlayer2id());
             } else {
                 $thirdPlayoffEnc->setPlayer2id($enc->getPlayer2id());
             }
         }
         // Check if there is a bye in the 3rd playoff
         if ($thirdPlayoffEnc->getPlayer1id() == -1 or $thirdPlayoffEnc->getPlayer2id() == -1) {
             $thirdPlayoffEnc->setPoints(0, 0);
         }
     }
 }
Пример #2
0
function getAllNextEncounters()
{
    global $db;
    global $lang;
    $tournaments = $db->selectList("tournamentlist", "*", "`state`=2");
    $allNextEncs = array();
    foreach ($tournaments as $tourney) {
        switch ($tourney['mode']) {
            // Single Elimination
            case 1:
                // Double Elimination
            // Double Elimination
            case 2:
                // KotH
            // KotH
            case 6:
                $allEnc = $db->selectList("tournamentencounters", "*", "`tournamentid`=" . $tourney['tournamentid'] . " AND `state`=0 AND (`player1id`>0 OR `player2id`>0)");
                require_once "mod/default/tournament/tournament.eliminationencounter.class.php";
                foreach ($allEnc as $enc) {
                    $curEnc = new EliminationEncounter($enc['tournamentid'], $enc['roundid'], $enc['encounterid']);
                    $allNextEncs[] = array('time' => $curEnc->getEncTimeState(), 'round' => makeRoundNr($curEnc->getRoundId(), $tourney['mode']), 'encounterid' => $curEnc->getId(), 'player1id' => makePlayerUrl($curEnc->getPlayer1Id(), $tourney['playerperteam'] == 1), 'player2id' => makePlayerUrl($curEnc->getPlayer2Id(), $tourney['playerperteam'] == 1), 'title' => $tourney['title']);
                }
                break;
                // Groups
            // Groups
            case 3:
                $allEnc = $db->selectList("tournamentgroupenc", "*", "`tournamentid`=" . $tourney['tournamentid'] . " GROUP BY `round`, `group` HAVING MIN(rank)=0");
                foreach ($allEnc as $enc) {
                    $participants = $db->selectList("tournamentgroupenc", "*", "`tournamentid`=" . $enc['tournamentid'] . " AND `round`=" . $enc['round'] . " AND `group`=" . $enc['group']);
                    $allParticipants = array();
                    foreach ($participants as $participant) {
                        $allParticipants[] = makePlayerUrl($participant['participantid']);
                    }
                    $encounterUrl = makeHTMLUrl($lang->get('group') . " " . chr(65 + $enc['group']), makeURL('tournament', array('mode' => 'table', 'tournamentid' => $enc['tournamentid'], 'action' => 'submit', 'group' => $enc['group'], 'round' => $enc['round'])));
                    $allNextEncs[] = array('time' => '', 'round' => makeRoundNr($enc['round'] - 1, $tourney['mode']), 'encounterid' => $enc['group'], 'player1id' => $encounterUrl, 'player2id' => '', 'title' => $tourney['title'], 'participants' => $allParticipants);
                }
                break;
                // Points
            // Points
            case 4:
                break;
                // Randomize
            // Randomize
            case 5:
                break;
        }
    }
    usort($allNextEncs, "sortNextEncounters");
    return $allNextEncs;
}
 public function undoSetEncounter($roundId, $encId)
 {
     $enc = new EliminationEncounter($this->tournamentId, $roundId, $encId, false);
     // do not allow encounters with byes to be reset
     if ($enc->getPlayer1id() < 0 || $enc->getPlayer2id() < 0) {
         return false;
     }
     if ($roundId < $this->lastRound() - 1) {
         // normal and looser tier not merged yet
         if ($enc->getId() >= $this->lowerEncOffset()) {
             // in looser tier
             if ($roundId == $this->lastRound() - 2) {
                 // winner will get in first final match
                 $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 0);
                 $firstAtNext = false;
             } else {
                 if ($roundId % 2 == 0) {
                     $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, $enc->getId());
                     $firstAtNext = false;
                 } else {
                     $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2 + $this->lowerEncOffset());
                     $firstAtNext = $enc->getAlias() % 2 == 0;
                 }
             }
         } else {
             // in winner tier
             if ($roundId == 1) {
                 $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2);
                 $firstAtNext = $enc->getAlias() % 2 == 0;
                 $loserNextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() / 2 + $this->lowerEncOffset());
                 $loserFirstAtNext = $enc->getAlias() % 2 == 0;
             } else {
                 $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 2, (int) $enc->getAlias() / 2);
                 $firstAtNext = $enc->getAlias() % 2 == 0;
                 $loserNextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, (int) $enc->getAlias() + $this->lowerEncOffset());
                 $loserFirstAtNext = true;
             }
         }
     } else {
         if ($roundId == $this->lastRound() - 1) {
             // create second final match
             $nextEnc = new EliminationEncounter($this->tournamentId, $roundId + 1, 0, false);
             $loserNextEnc = $nextEnc;
             $firstAtNext = true;
             $loserFirstAtNext = false;
         } else {
             // final match
         }
     }
     // Check if the encounters are undoable
     if (isset($nextEnc)) {
         if (!$this->isNextEncUndoable($nextEnc)) {
             return false;
         }
     }
     if (isset($loserNextEnc)) {
         if (!$this->isNextEncUndoable($loserNextEnc)) {
             return false;
         }
     }
     if (isset($nextEnc)) {
         if ($firstAtNext) {
             $nextEnc->setPlayer1id(0);
         } else {
             $nextEnc->setPlayer2id(0);
         }
     }
     if (isset($loserNextEnc)) {
         if ($loserFirstAtNext) {
             $loserNextEnc->setPlayer1id(0);
         } else {
             $loserNextEnc->setPlayer2id(0);
         }
     }
     $enc->unsetPoints();
     return true;
 }