Рассинхрон версий Tournament.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Insallah;
|
||||
use Achievements;
|
||||
use user;
|
||||
|
||||
class TournamentModel
|
||||
{
|
||||
@@ -17,18 +15,60 @@ class TournamentModel
|
||||
*/
|
||||
public static function getUserLevel($uid)
|
||||
{
|
||||
$db = new Db;
|
||||
$db = new Db();
|
||||
$level = $db::getValue('select level from users where id = ? and level between 8 and 12 and battle = 0', [$uid]);
|
||||
if (!$level) {
|
||||
return 0;
|
||||
return $level ? $level : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
* @param int $level
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEkrOverpriced($uid, $level = null)
|
||||
{
|
||||
$db = new Db();
|
||||
if (is_null($level)) {
|
||||
$level = $db::getValue('select level from users where id = ?', [$uid]);
|
||||
}
|
||||
$ekr_total = $db::getValue('select sum(2price) from items_users where inOdet > 0 and uid = ?', [$uid]);
|
||||
$exp = $db::getValue('select exp from stats where id = ?', [$uid]);
|
||||
// Вот правда не знаю проканает или нет.
|
||||
if ($ekr_total > ($level - 7) * 150 || $exp < 250000) {
|
||||
return 0;
|
||||
$wearedItemsEkrPrice = $db::getValue('select sum(2price) from items_users where inOdet > 0 and uid = ?', [$uid]);
|
||||
return $wearedItemsEkrPrice > Tournament::ekrOverpriceFormula($level);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isEnoughExperience($uid)
|
||||
{
|
||||
$db = new Db();
|
||||
return $db::getValue('select exp from stats where id = ?', [$uid]) >= Tournament::MIN_EXP;
|
||||
}
|
||||
return $level;
|
||||
|
||||
/**
|
||||
* @param int $uid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function IsRestrictedToJoin($uid)
|
||||
{
|
||||
$db = new Db();
|
||||
$delayEffect = $db::getValue('select count(*) from eff_users where uid = ? and id_eff = 486 and `delete` = 0', [$uid]);
|
||||
return (bool)$delayEffect;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $tid
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isStarted($tid)
|
||||
{
|
||||
$db = new Db();
|
||||
$status = $db::getValue('select count(*) from tournaments where start_time = -1 and tid = ?', [$tid]);
|
||||
return (bool)$status;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +151,8 @@ class TournamentModel
|
||||
public static function getFightersTeams(array $fighters_list)
|
||||
{
|
||||
$db = new Db();
|
||||
return array_chunk($db::getRows('select id from users where battle = 0 and id in (?)', [implode(', ', $fighters_list)]), 2);
|
||||
$query = sprintf("select id from users where battle = 0 and id in (%s)", implode(', ', $fighters_list));
|
||||
return array_chunk($db::getColumn($query), 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -124,7 +165,7 @@ class TournamentModel
|
||||
public static function getFreeFighters($tid)
|
||||
{
|
||||
$db = new Db();
|
||||
return $db::getRows('select uid from tournaments_users where tid = ? and death_time = 0 order by rand()', [$tid]);
|
||||
return $db::getColumn('select uid from tournaments_users where tid = ? and death_time = 0 order by rand()', [$tid]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,14 +178,12 @@ class TournamentModel
|
||||
public static function getWinners($tid)
|
||||
{
|
||||
$db = new Db();
|
||||
$arr = [];
|
||||
array_unshift($arr, '');
|
||||
unset($arr[0]);
|
||||
$winners = $db::getRows('select uid from tournaments_users where tid = ? order by death_time desc limit 3', [$tid]);
|
||||
foreach ($winners as $winner) {
|
||||
$arr[] = $winner['uid'];
|
||||
}
|
||||
return $arr;
|
||||
$winners = $db::getColumn('select uid from tournaments_users where tid = ? order by death_time desc limit 3', [$tid]);
|
||||
return [
|
||||
1 => $winners[0],
|
||||
2 => $winners[1],
|
||||
3 => $winners[2]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -166,10 +205,10 @@ class TournamentModel
|
||||
limit 1) as last_battle
|
||||
where
|
||||
battle_users.battle = last_battle.id and
|
||||
battle_users.team != last_battle.team_win';
|
||||
battle_users.team != last_battle.team_win and
|
||||
battle_users.uid in (select uid from tournaments_users where death_time = 0)';
|
||||
$db = new Db;
|
||||
$row = $db::getRow($query);
|
||||
$db::sql('delete from battle where id = ?', [$row['battle']]);
|
||||
return $row['uid'];
|
||||
}
|
||||
|
||||
@@ -182,10 +221,13 @@ class TournamentModel
|
||||
*/
|
||||
public static function removeFighter($uid)
|
||||
{
|
||||
if (!$uid) return;
|
||||
$db = new Db();
|
||||
$db::sql('update tournaments_users set death_time = unix_timestamp() where uid = ?', [$uid]);
|
||||
$db::sql('update tournaments_users set death_time = unix_timestamp() where death_time = 0 and uid = ?', [$uid]);
|
||||
self::teleport($uid, 9);
|
||||
(new Achievements(user::start()))->updateCounter('trn');
|
||||
//fixme: Классы не подключаются друг к другу. Нужно менять архитектуру игры. :(
|
||||
Db::sql("update users_achiv set trn = trn + 1 where id = ?", [$uid]);
|
||||
//(new Achievements(\user::start()))->updateCounter('trn');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -252,15 +294,17 @@ class TournamentModel
|
||||
/**
|
||||
* Нет проверок $message потому что оно всегда задаётся в коде и игрок на него не влияет.
|
||||
*
|
||||
* @param string $city
|
||||
* @param string $message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function sysMessage($message, $city = 'capitalcity')
|
||||
public static function sysMessage($message)
|
||||
{
|
||||
if (!empty($message)) {
|
||||
$db = new Db();
|
||||
$db::sql('insert into chat (city, room, time, type, text, new, da) values (?, 0, unix_timestamp(), 6, ?, 1, 1)', [$city, $message]);
|
||||
$message = "<span style='font-weight: bold; color: forestgreen;'>$message</span>";
|
||||
$db::sql('insert into chat (time, type, text, new, da) values (unix_timestamp(), 6, ?, 1, 1)', [$message]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,4 +329,18 @@ class TournamentModel
|
||||
$stmt->execute($args);
|
||||
}
|
||||
}
|
||||
|
||||
/** Эффект-ограничитель на участие в турнире.
|
||||
* @param $uid
|
||||
* @param $unix_time
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function giveDelay($uid, $unix_time)
|
||||
{
|
||||
$db = new Db();
|
||||
$query = 'insert into eff_users (id_eff, uid, name, timeUse) VALUES (?,?,?,?)';
|
||||
$args = [486, $uid, 'Призёр городского турнира!', $unix_time];
|
||||
$db::sql($query, $args);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user