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); } } }
function tournamentTable() { global $smarty; global $template_dir; global $db; global $config; $encList = $db->selectList('tournamentencounters', '*', "`tournamentid`=" . $this->tournamentId, "`roundid` ASC, `encounterid` ASC"); foreach ($encList as $encounter) { $y = $encounter['roundid']; $x = $encounter['encounterid']; $curEnc = new EliminationEncounter($this->tournamentId, $y, $x); $finalList[$x][$y]['round'] = $x; $finalList[$x][$y]['encid'] = $y; foreach ($this->participants as $participant) { if ($participant->getId() == $curEnc->getPlayer1id()) { $player1 = $participant; } if ($participant->getId() == $curEnc->getPlayer2id()) { $player2 = $participant; } } // Only player 2 (in the last enc) could be a dummy if ($curEnc->getPlayer2id() == -1) { $player2 = newDummy(); } if ($curEnc->getPlayer1id() == 0) { $player1 = newUnknown(); } if ($curEnc->getPlayer2id() == 0) { $player2 = newUnknown(); } if ($curEnc->getPlayer1id() > 0 && $curEnc->getPlayer2id() > 0) { $finalList[$x][$y]['link'] = makeUrl('tournament', array('tournamentid' => $this->tournamentId, 'encid' => $x, 'roundid' => $y, 'mode' => 'view')); } $finalList[$x][$y]['p1name'] = $player1->getName(); $finalList[$x][$y]['p1url'] = $player1->getUrl(); $finalList[$x][$y]['p2name'] = $player2->getName(); $finalList[$x][$y]['p2url'] = $player2->getUrl(); $finalList[$x][$y]['timestatus'] = $curEnc->getEncTimeState(); if ($curEnc->isFinished()) { $finalList[$x][$y]['p1points'] = $curEnc->getPoints1(); $finalList[$x][$y]['p2points'] = $curEnc->getPoints2(); $finalList[$x][$y]['winner'] = $curEnc->winner(); } } $smarty->assign('roundsandmaps', $this->getRoundsAndMaps($y + 1)); $smarty->assign('table', $finalList); $smarty->assign('encounterWidth', $config->get('tournament', 'tree-encounter-width')); $smarty->assign('encTempl', $template_dir . '/kothencounter.tpl'); $smarty->assign('path', $template_dir . '/koth.tpl'); }
private function setEncPoints($roundId, $encId, $p1points, $p2points) { $enc = new EliminationEncounter($this->tournamentId, $roundId, $encId); 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 ($p2points >= $p1points && $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 global $db; global $notify; global $lang; $db->update('tournamentlist', "`state`=3", "`tournamentid`=" . $this->tournamentId); $notify->add($lang->get('tournament'), $lang->get('ntfy_end_game')); } } // 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()); } } } if (isset($loserNextEnc)) { if ($enc->winner() == 1) { if ($loserFirstAtNext) { $loserNextEnc->setPlayer1id($enc->getPlayer2id()); } else { $loserNextEnc->setPlayer2id($enc->getPlayer2id()); } } else { if ($loserFirstAtNext) { $loserNextEnc->setPlayer1id($enc->getPlayer1id()); } else { $loserNextEnc->setPlayer2id($enc->getPlayer1id()); } } } // Forward looser if he has a bye if (isset($loserNextEnc)) { $p1id = $loserNextEnc->getPlayer1id(); $p2id = $loserNextEnc->getPlayer2id(); if ($p1id == -1 && $p2id > 0 || $p2id == -1 && $p1id > 0 || $p1id == -1 && $p2id == -1) { $loserNextEnc->setPoints(0, 0); $this->setEncPoints($roundId + 1, $loserNextEnc->getId(), 0, 0); } } }