105 lines
3.3 KiB
PHP
105 lines
3.3 KiB
PHP
|
<?php
|
|||
|
|
|||
|
namespace Insallah\Tournaments;
|
|||
|
|
|||
|
class Tournament
|
|||
|
{
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
*
|
|||
|
* @param int $uid
|
|||
|
*
|
|||
|
* @return void
|
|||
|
*/
|
|||
|
public function join(int $uid)
|
|||
|
{
|
|||
|
/** <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> level, <20><><EFBFBD> 0 <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. */
|
|||
|
$checks = new Model\GameConnector();
|
|||
|
$tournament = new Model\Tournament();
|
|||
|
$userLevel = $checks->setUser($uid)->getAllowedLevel();
|
|||
|
|
|||
|
if (
|
|||
|
$userLevel === 0 ||
|
|||
|
$checks->isEkrOverpriced() ||
|
|||
|
!$checks->isEnoughExperience() ||
|
|||
|
$checks->isRestrictedToJoin() ||
|
|||
|
$tournament->isStarted($uid)
|
|||
|
) {
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
$user = new Model\User();
|
|||
|
|
|||
|
if (empty($user->getWaitingQuantity($userLevel))) {
|
|||
|
Model\Tournament::create($userLevel);
|
|||
|
}
|
|||
|
|
|||
|
$user->joinTournament($uid, $userLevel);
|
|||
|
$user->addWaitingUser();
|
|||
|
|
|||
|
if ($user->getWaitingQuantity($userLevel) == Config::SEND_CHAT_MESSAGE) {
|
|||
|
Model\GameConnector::sysMessage(sprintf(Config::CHAT_MESSAGE, $userLevel));
|
|||
|
}
|
|||
|
|
|||
|
if ($user->getWaitingQuantity($userLevel) == Config::START_TOURNAMENT) {
|
|||
|
Model\Tournament::start($userLevel);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\<5C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
* @return void
|
|||
|
*/
|
|||
|
public static function startAllBattles()
|
|||
|
{
|
|||
|
if (!Config::IS_ENABLED) {
|
|||
|
return;
|
|||
|
}
|
|||
|
$tournamentlevels = new Model\Tournament();
|
|||
|
$alivefighters = new Model\User();
|
|||
|
Model\User::remove(Model\GameConnector::getLooser());
|
|||
|
foreach ($tournamentlevels->getAllStarted() as $level) {
|
|||
|
$count = count($alivefighters->getAlive($level, true));
|
|||
|
if ($count > 1) {
|
|||
|
Model\GameConnector::startBattle($alivefighters->getAlive($level, true));
|
|||
|
} elseif ($count === 1) {
|
|||
|
Model\User::remove($alivefighters->getAlive($level, true)[0]);
|
|||
|
self::victory($level);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**
|
|||
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
|
|||
|
*
|
|||
|
* @param int $tid
|
|||
|
*
|
|||
|
* @return void
|
|||
|
*/
|
|||
|
private static function victory(int $tid)
|
|||
|
{
|
|||
|
$u = new Model\User();
|
|||
|
$uid = new Model\GameConnector();
|
|||
|
sleep(1);
|
|||
|
$uid->setUser($u->getWinners($tid)[1])->givePrizeItems(Config::PRIZE1);
|
|||
|
$uid->setUser($u->getWinners($tid)[2])->givePrizeItems(Config::PRIZE2);
|
|||
|
$uid->setUser($u->getWinners($tid)[3])->givePrizeItems(Config::PRIZE3);
|
|||
|
sleep(1);
|
|||
|
$uid->setUser($u->getWinners($tid)[1])->giveDelay(Config::DELAY1);
|
|||
|
$uid->setUser($u->getWinners($tid)[2])->giveDelay(Config::DELAY2);
|
|||
|
$uid->setUser($u->getWinners($tid)[3])->giveDelay(Config::DELAY3);
|
|||
|
sleep(1);
|
|||
|
Model\GameConnector::sysMessage(
|
|||
|
sprintf(
|
|||
|
Config::VICTORY_MESSAGE,
|
|||
|
$tid,
|
|||
|
$uid->setUser($u->getWinners($tid)[1])->uidToLogin(),
|
|||
|
$uid->setUser($u->getWinners($tid)[2])->uidToLogin(),
|
|||
|
$uid->setUser($u->getWinners($tid)[3])->uidToLogin()
|
|||
|
)
|
|||
|
);
|
|||
|
sleep(3);
|
|||
|
Model\Tournament::destroy($tid);
|
|||
|
}
|
|||
|
}
|