game/_incl_data/class/Insallah/Tournament/Tournament.php

135 lines
4.3 KiB
PHP
Raw Normal View History

2022-06-06 21:30:34 +00:00
<?php
namespace Insallah;
class Tournament
{
2022-07-01 12:45:43 +00:00
const IS_ENABLED = true;
const SEND_CHAT_MESSAGE = 3;
const START_TOURNAMENT = 5;
const PRIZE1 = 25;
const PRIZE2 = 10;
const PRIZE3 = 5;
const MIN_EXP = 175000;
const CHAT_MESSAGE = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!';
const VICTORY_MESSAGE = '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> %d <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>! <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: %s. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: %s. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>: %s.';
const DELAY1 = '+12hour';
const DELAY2 = '+6hour';
const DELAY3 = '+3hour';
/** <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 $int
*
* @return float|int
*/
public static function ekrOverpriceFormula($int)
{
return ($int - 7) * 151;
}
2022-06-06 21:30:34 +00:00
/**
2022-07-01 12:45:43 +00:00
* <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>.
2022-06-06 21:30:34 +00:00
*
* @param int $user_id
*
* @return void
*/
public function join($user_id)
{
2022-07-01 12:45:43 +00:00
/** <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>. */
2022-06-06 21:30:34 +00:00
$userLevel = TournamentModel::getUserLevel($user_id);
2022-07-01 12:45:43 +00:00
if (
$userLevel === 0 ||
TournamentModel::isEkrOverpriced($user_id, $userLevel) ||
!TournamentModel::isEnoughExperience($user_id) ||
TournamentModel::IsRestrictedToJoin($user_id) ||
TournamentModel::isStarted($user_id)
) {
2022-06-06 21:30:34 +00:00
return;
}
$mq = TournamentModel::getWaitingMembersQuantity($userLevel);
if (empty($mq)) {
TournamentModel::createTournament($userLevel);
}
TournamentModel::joinTournament($user_id, $userLevel);
2022-07-01 12:45:43 +00:00
$mq++;
2022-06-06 21:30:34 +00:00
2022-07-01 12:45:43 +00:00
if ($mq == self::SEND_CHAT_MESSAGE) {
TournamentModel::sysMessage(sprintf(self::CHAT_MESSAGE, $userLevel));
2022-06-06 21:30:34 +00:00
}
2022-07-01 12:45:43 +00:00
if ($mq == self::START_TOURNAMENT) {
2022-06-06 21:30:34 +00:00
TournamentModel::startTournament($userLevel);
}
}
/**
2022-07-01 12:45:43 +00:00
* <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>.
2022-06-06 21:30:34 +00:00
* @return void
*/
2022-07-01 12:45:43 +00:00
public function startAllBattles()
2022-06-06 21:30:34 +00:00
{
2022-07-01 12:45:43 +00:00
$db = new Db();
$db::sql('delete from tournaments where start_time + date_add(start_time,interval 30 minute) < unix_timestamp()');
TournamentModel::removeFighter(TournamentModel::getLooser());
$tournament_levels = $db::getColumn('select tid from tournaments where start_time = -1');
foreach ($tournament_levels as $level) {
$alive_fighters = TournamentModel::getFreeFighters($level);
if (count($alive_fighters) > 1) {
shuffle($alive_fighters);
$this->start_battle($alive_fighters);
} elseif (count($alive_fighters) === 1) {
TournamentModel::removeFighter($alive_fighters[0], true);
$this->victory($level);
}
2022-06-06 21:30:34 +00:00
}
}
/**
2022-07-01 12:45:43 +00:00
* <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>.
2022-06-06 21:30:34 +00:00
*
* @param array $fighters_list
*
* @return void
*/
private function start_battle(array $fighters_list)
{
$teams = TournamentModel::getFightersTeams($fighters_list);
foreach ($teams as $team) {
if (count($team) === 2) {
TournamentModel::startBattle($team[0], $team[1]);
}
}
}
/**
2022-07-01 12:45:43 +00:00
* <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>.
2022-06-06 21:30:34 +00:00
*
* @param int $tournament_id
*
* @return void
*/
private function victory($tournament_id)
{
$winners = TournamentModel::getWinners($tournament_id);
2022-07-01 12:45:43 +00:00
sleep(1);
TournamentModel::givePrizeItems($winners[1], self::PRIZE1);
TournamentModel::givePrizeItems($winners[2], self::PRIZE2);
TournamentModel::givePrizeItems($winners[3], self::PRIZE3);
sleep(1);
TournamentModel::giveDelay($winners[1], strtotime(self::DELAY1));
TournamentModel::giveDelay($winners[2], strtotime(self::DELAY2));
TournamentModel::giveDelay($winners[3], strtotime(self::DELAY3));
sleep(1);
TournamentModel::sysMessage(sprintf(self::VICTORY_MESSAGE,
$tournament_id,
TournamentModel::uidToLogin($winners[1]),
TournamentModel::uidToLogin($winners[2]),
TournamentModel::uidToLogin($winners[3])));
sleep(3);
2022-06-06 21:30:34 +00:00
TournamentModel::destroyTournament($tournament_id);
}
}