Рефакторинг заявок на поединок.

This commit is contained in:
2023-04-15 22:17:40 +03:00
parent 92318be837
commit f92aa003ac
17 changed files with 1733 additions and 4491 deletions
@@ -0,0 +1,17 @@
<?php
namespace Core;
class ComparsionHelper
{
public static function minimax($value, $minimum, $maximum)
{
if ($value < $minimum) {
$value = $minimum;
}
if ($value > $maximum) {
$value = $maximum;
}
return $value;
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,61 @@
<?php
namespace FightRequest;
class FRHelper
{
/** Ń÷čňŕĺň đŕçđĺřĺííűĺ óđîâíč čăđîęîâ â ăđóďďîâűő çŕ˙âęŕő.
* @param int $type ňčď ôčëüňđŕ.
* @param int $userLevel óđîâĺíü čăđîęŕ ďîäŕţůĺăî çŕ˙âęó.
* @return object
*/
public static function getTeammatesLevel(int $type, int $userLevel): object
{
$min = 0;
$max = 21;
switch ($type) {
default:
break;
case 1: // ňîëüęî ěîĺăî č íčćĺ
$max = $userLevel;
break;
case 2: // ňîëüęî íčćĺ ěîĺăî
$max = $userLevel - 1;
break;
case 3: // ňîëüęî ěîĺăî
$min = $userLevel;
$max = $userLevel;
break;
case 4: // íĺ âűřĺ ěĺí˙ íŕ 1 óđîâĺíü
$min = $userLevel;
$max = $userLevel + 1;
break;
case 5: // íĺ íčćĺ ěĺí˙ íŕ 1 óđîâĺíü
$min = $userLevel - 1;
$max = $userLevel;
break;
case 6: // ěîé óđîâĺíü +- 1
$min = $userLevel - 1;
$max = $userLevel + 1;
break;
}
return (object)[
'min'=> $min,
'max'=> $max,
];
}
/** Ń÷čňŕĺň đŕçđĺřĺííűĺ óđîâíč čăđîęîâ â őŕîňč÷ĺńęčő çŕ˙âęŕő.
* @param int $type ňčď ôčëüňđŕ.
* @param int $userLevel óđîâĺíü čăđîęŕ ďîäŕţůĺăî çŕ˙âęó.
* @return object
*/
public static function getChaoticTeammatesLevel(int $type, int $userLevel): object
{
if (!in_array($type, [3, 6])) {
$type = 0;
}
return self::getTeammatesLevel($type, $userLevel);
}
}
@@ -1,12 +1,14 @@
<?php
namespace Insallah;
namespace Tournament;
use Core\Db;
class Tournament
{
const IS_ENABLED = true;
const IS_ENABLED = false;
private const SEND_CHAT_MESSAGE = 3;
private const START_TOURNAMENT = 5;
public const START_TOURNAMENT = 5;
private const PRIZE1 = 25;
private const PRIZE2 = 10;
private const PRIZE3 = 5;
@@ -72,12 +74,11 @@ class Tournament
*/
public function startAllBattles(): void
{
$db = new Db();
$db::sql(
Db::sql(
'delete from tournaments where start_time + date_add(start_time,interval 30 minute) < unix_timestamp()'
);
TournamentModel::removeFighter(TournamentModel::getLooser());
$tournamentLevels = $db::getColumn('select tid from tournaments where start_time = -1');
$tournamentLevels = Db::getColumn('select tid from tournaments where start_time = -1');
foreach ($tournamentLevels as $level) {
$aliveFighters = TournamentModel::getFreeFighters($level);
if (count($aliveFighters) > 1) {
@@ -1,6 +1,10 @@
<?php
namespace Insallah;
namespace Tournament;
use Chat;
use ChatMessage;
use Core\Db;
class TournamentModel
{
@@ -15,8 +19,7 @@ class TournamentModel
*/
public static function getUserLevel(int $uid): int
{
$db = new Db();
$level = $db::getValue('select level from users where id = ? and level between 8 and 12 and battle = 0', [$uid]);
$level = Db::getValue('select level from users where id = ? and level between 8 and 12 and battle = 0', [$uid]);
return $level ?: 0;
}
@@ -28,11 +31,10 @@ class TournamentModel
*/
public static function isEkrOverpriced(int $uid, ?int $level = null): bool
{
$db = new Db();
if (is_null($level)) {
$level = $db::getValue('select level from users where id = ?', [$uid]);
$level = Db::getValue('select level from users where id = ?', [$uid]);
}
$wearedItemsEkrPrice = $db::getValue('select sum(2price) from items_users where inOdet > 0 and uid = ?', [$uid]);
$wearedItemsEkrPrice = Db::getValue('select sum(2price) from items_users where inOdet > 0 and uid = ?', [$uid]);
return $wearedItemsEkrPrice > Tournament::ekrOverpriceFormula($level);
}
@@ -43,9 +45,8 @@ class TournamentModel
*/
public static function isEnoughExperience(int $uid): bool
{
$db = new Db();
return $db::getValue('select exp from stats where id = ?', [$uid]) >= Tournament::MIN_EXP;
}
return Db::getValue('select exp from stats where id = ?', [$uid]) >= Tournament::MIN_EXP;
}
/**
* @param int $uid
@@ -54,8 +55,7 @@ class TournamentModel
*/
public static function isRestrictedToJoin(int $uid): bool
{
$db = new Db();
return $db::getValue('select count(*) from eff_users where uid = ? and id_eff = 486 and `delete` = 0', [$uid]);
return Db::getValue('select count(*) from eff_users where uid = ? and id_eff = 486 and `delete` = 0', [$uid]);
}
/**
@@ -65,8 +65,7 @@ class TournamentModel
*/
public static function isStarted(int $tid): bool
{
$db = new Db();
return $db::getValue('select count(*) from tournaments where start_time = -1 and tid = ?', [$tid]);
return Db::getValue('select count(*) from tournaments where start_time = -1 and tid = ?', [$tid]);
}
/**
@@ -78,8 +77,7 @@ class TournamentModel
*/
public static function getWaitingMembersQuantity(int $tid): int
{
$db = new Db();
return $db::getValue('select count(*) from tournaments_users where tid = ?', [$tid]);
return Db::getValue('select count(*) from tournaments_users where tid = ?', [$tid]);
}
/**
@@ -91,8 +89,7 @@ class TournamentModel
*/
public static function createTournament(int $tid): void
{
$db = new Db();
$db::sql('insert into tournaments (tid) values (?)', [$tid]);
Db::sql('insert into tournaments (tid) values (?)', [$tid]);
}
/**
@@ -107,8 +104,7 @@ class TournamentModel
{
/** Кастомные комнаты 25008 - 25012. */
$roomId = 25000 + $tid;
$db = new Db();
$db::sql('insert into tournaments_users (tid, uid) values (?, ?)', [$tid, $uid]);
Db::sql('insert into tournaments_users (tid, uid) values (?, ?)', [$tid, $uid]);
self::teleport($uid, $roomId);
}
@@ -121,8 +117,7 @@ class TournamentModel
*/
public static function startTournament(int $tid): void
{
$db = new Db();
$db::sql('update tournaments set start_time = -1 where tid = ?', [$tid]);
Db::sql('update tournaments set start_time = -1 where tid = ?', [$tid]);
}
/**
@@ -134,9 +129,8 @@ class TournamentModel
*/
public static function destroyTournament(int $tid): void
{
$db = new Db();
//Убедиться что в базе настроен foreign_keys и последует автоочистка tournaments_users !!!
$db::sql('delete from tournaments where tid = ?', [$tid]);
Db::sql('delete from tournaments where tid = ?', [$tid]);
}
/**
@@ -148,9 +142,8 @@ class TournamentModel
*/
public static function getFightersTeams(array $fightersList): array
{
$db = new Db();
$query = sprintf("select id from users where battle = 0 and id in (%s)", implode(', ', $fightersList));
return array_chunk($db::getColumn($query), 2);
return array_chunk(Db::getColumn($query), 2);
}
/**
@@ -162,8 +155,9 @@ class TournamentModel
*/
public static function getFreeFighters(int $tid): array
{
$db = new Db();
return $db::getColumn('select uid from tournaments_users where tid = ? and death_time = 0 order by uid', [$tid]);
return Db::getColumn(
'select uid from tournaments_users where tid = ? and death_time = 0 order by uid', [$tid]
);
}
/**
@@ -175,12 +169,13 @@ class TournamentModel
*/
public static function getWinners(int $tid): array
{
$db = new Db();
$winners = $db::getColumn('select uid from tournaments_users where tid = ? order by death_time desc limit 3', [$tid]);
$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]
3 => $winners[2],
];
}
@@ -210,8 +205,8 @@ class TournamentModel
inner join battle_users bu on b.team_win != bu.team and b.id = bu.battle
inner join tournaments_users tu on bu.uid = tu.uid
where typeBattle = 25000 and death_time = 0 order by b.time_start desc limit 1';
$db = new Db;
$row = $db::getRow($query);
$row = Db::getRow($query);
return $row['uid'] ?? 0;
}
@@ -228,8 +223,9 @@ class TournamentModel
return;
}
//$winner_timer_add = $winner? 500 : 0; # Последный ДОЛЖЕН быть последним.
$db = new Db();
$db::sql('update tournaments_users set death_time = unix_timestamp() + 500 where death_time = 0 and uid = ?', [$uid]);
Db::sql(
'update tournaments_users set death_time = unix_timestamp() + 500 where death_time = 0 and uid = ?', [$uid]
);
self::teleport($uid, 9);
//fixme: Классы не подключаются друг к другу. Нужно менять архитектуру игры. :(
Db::sql("update users_achiv set trn = trn + 1 where id = ?", [$uid]);
@@ -245,8 +241,7 @@ class TournamentModel
*/
public static function getTournamentIdByUserId(int $uid)
{
$db = new Db();
return $db::getValue('select tid from tournaments_users where uid = ?', [$uid]);
return Db::getValue('select tid from tournaments_users where uid = ?', [$uid]);
}
/**
@@ -262,18 +257,19 @@ class TournamentModel
*/
public static function startBattle(int $uid1, int $uid2): void
{
$db = new Db();
$check = Db::getValue('select count(*) from users where id in (?, ?) and battle = 0', [$uid1, $uid2]);
if ($check !== 2) {
return;
}
$db::exec('insert into battle (city, time_start, timeout, type, invis, noinc, travmChance, typeBattle)
values (\'capitalcity\', unix_timestamp(), 60, 0, 1, 1, 0, 25000)');
$bid = $db::lastInsertId(); // ВАЖНО!
$db::sql('update stats set team = 1, hpNow = hpAll, mpNow = mpAll where id = ?', [$uid1]);
$db::sql('update stats set team = 2, hpNow = hpAll, mpNow = mpAll where id = ?', [$uid2]);
$db::sql('update users set battle = ? where id in (?, ?)', [$bid, $uid1, $uid2]);
Db::exec(
'insert into battle (city, time_start, timeout, type, invis, noinc, travmChance, typeBattle)
values (\'capitalcity\', unix_timestamp(), 60, 0, 1, 1, 0, 25000)'
);
$bid = Db::lastInsertId(); // ВАЖНО!
Db::sql('update stats set team = 1, hpNow = hpAll, mpNow = mpAll where id = ?', [$uid1]);
Db::sql('update stats set team = 2, hpNow = hpAll, mpNow = mpAll where id = ?', [$uid2]);
Db::sql('update users set battle = ? where id in (?, ?)', [$bid, $uid1, $uid2]);
}
/**
@@ -285,8 +281,7 @@ class TournamentModel
*/
public static function uidToLogin(int $uid)
{
$db = new Db();
return $db::getValue('select login from users where id = ?', [$uid]);
return Db::getValue('select login from users where id = ?', [$uid]);
}
/**
@@ -299,8 +294,7 @@ class TournamentModel
*/
private static function teleport(int $uid, int $roomId): void
{
$db = new Db();
$db::sql('update users set room = ? where id = ?', [$roomId, $uid]);
Db::sql('update users set room = ? where id = ?', [$roomId, $uid]);
}
/**
@@ -315,12 +309,12 @@ class TournamentModel
if (empty($message)) {
return;
}
$cmsg = new \ChatMessage();
$cmsg = new ChatMessage();
$cmsg->setDa(1);
$cmsg->setType(6);
$cmsg->setText($message);
$cmsg->setColor('forestgreen');
(new \Chat())->sendMsg($cmsg);
(new Chat())->sendMsg($cmsg);
}
/**
@@ -337,10 +331,9 @@ class TournamentModel
values (4754, :uid, :data, 1, unix_timestamp(), unix_timestamp())';
$args = [
'uid' => $uid,
'data' => 'nosale=1|musor=1|sudba=' . self::uidToLogin($uid) . '|lvl=8|tr_s1=0|tr_s2=0|tr_s3=0|tr_s4=0'
'data' => 'nosale=1|musor=1|sudba=' . self::uidToLogin($uid) . '|lvl=8|tr_s1=0|tr_s2=0|tr_s3=0|tr_s4=0',
];
$db = new Db();
$stmt = $db::prepare($query);
$stmt = Db::prepare($query);
for ($i = 0; $i < $quantity; $i++) {
$stmt->execute($args);
}
@@ -354,9 +347,8 @@ class TournamentModel
*/
public static function giveDelay(int $uid, int $unixtime): void
{
$db = new Db();
$query = 'insert into eff_users (id_eff, uid, name, timeUse) VALUES (?,?,?,?)';
$args = [486, $uid, 'Призёр городского турнира!', $unixtime];
$db::sql($query, $args);
Db::sql($query, $args);
}
}
-559
View File
@@ -1,559 +0,0 @@
<?php
use Core\Db;
class Tournir
{
private User $u;
private array $info;
private array $user;
private array $name = [0 => 'Выжить любой ценой', 1 => 'Каждый сам за себя', 2 => 'Захват ключа',];
public function __construct()
{
$this->u = User::start();
$this->start();
$this->locationSee();
}
private function start()
{
$this->info = Db::getRow('select * from turnirs where id = ?', [$this->u->info['inTurnirnew']]);
$this->user = Db::getRow(
'select * from users_turnirs where turnir = ? and bot = ?',
[$this->u->info['inTurnirnew'], $this->u->info['id']]
);
}
private function startTurnir()
{
$row = Db::getValue('select count(*) from users where win = 0 and lose = 0 and nich = 0');
if (!$row || $this->info['status'] == 3) {
if ($this->info['status'] == 3) {
$this->finishTurnir();
}
} else {
Db::sql('update turnirs set status = 3 where id = ?', [$this->info['id']]);
//Создание поединка
Db::sql(
'insert into battle (city, time_start, timeout, type, turnir) values (?,unix_timestamp(),60,1,?)',
[$this->u->info['city'], $this->info['id']]
);
$uri = Db::lastInsertId();
//Закидываем персонажей в поединок
Db::sql('update users set battle = ? where inUser = 0 and inTurnirnew = ?', [$uri, $this->info['id']]);
//Обозначаем завершение турнира при выходе
die('Перейтиде в раздел "поединки"...');
}
}
private function finishTurnir()
{
$chat = new Chat();
$cmsg = new ChatMessage();
$cmsg->setType(6);
$this->info = mysql_fetch_array(
mysql_query('SELECT * FROM `turnirs` WHERE `id` = ' . $this->u->info['inTurnirnew'])
);
if ($this->info['status'] != 3) {
return;
}
$win = '';
$lose = '';
$sp = mysql_query(
'SELECT * FROM `users_turnirs` WHERE `turnir` = "' . $this->info['id'] . '" ORDER BY `points` DESC'
);
while ($pl = mysql_fetch_array($sp)) {
mysql_query('DELETE FROM `users_turnirs` WHERE `turnir` = "' . $this->info['id'] . '"');
$inf = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "' . $pl['uid'] . '" LIMIT 1'));
$bot = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "' . $pl['bot'] . '" LIMIT 1'));
if (isset($inf['id'], $bot['id'])) {
//выдаем призы и т.д
mysql_query('DELETE FROM `users` WHERE `id` = "' . $bot['id'] . '" LIMIT 1');
mysql_query('DELETE FROM `stats` WHERE `id` = "' . $bot['id'] . '" LIMIT 1');
mysql_query('DELETE FROM `items_users` WHERE `uid` = "' . $bot['id'] . '" LIMIT 1000');
mysql_query('DELETE FROM `eff_users` WHERE `uid` = "' . $bot['id'] . '" LIMIT 1000');
}
if ($pl['team'] == $this->info['winner'] && $this->info['winner'] != 0) {
$inf['add_expp'] = [0, 1, 5, 10, 15, 25, 35, 70, 100, 150, 200, 300, 500, 700, 1000];
//получаем опыт (с 0 по 12 лвл)
$inf['add_expn'] = [10, 30, 55, 62, 92, 180, 350, 1350, 4500, 7000, 21000, 30000, 35000];
$inf['add_expn'] = $inf['add_expn'][$inf['level']];
mysql_query(
'UPDATE `users` SET `win` = `win` + 1,`win_t` = `win_t` + 1 WHERE `id` = "' . $inf['id'] . '" LIMIT 1'
);
mysql_query(
'UPDATE `stats` SET `exp` = `exp` + ' . $inf['add_expn'] . ' WHERE `id` = "' . $inf['id'] . '" LIMIT 1'
);
$win .= '<b>' . $inf['login'] . '</b>, ';
$cmsg->setRoom($inf['room']);
$cmsg->setTo($inf['login']);
$cmsg->setText("Турнир завершен. Вы являетесь победителем турнира, получено опыта: <b>{$inf['add_expn']}</b>.");
$chat->sendMsg($cmsg);
} elseif ($pl['team'] != $this->info['winner'] && $this->info['winner'] != 0) {
mysql_query(
'UPDATE `users` SET `lose` = `lose` + 1,`lose_t` = `lose_t` + 1 WHERE `id` = "' . $inf['id'] . '" LIMIT 1'
);
$lose .= '<b>' . $inf['login'] . '</b>, ';
} else {
mysql_query('UPDATE `users` SET `nich` = `nich` + 1 WHERE `id` = "' . $inf['id'] . '" LIMIT 1');
}
mysql_query('DELETE FROM `users_turnirs` WHERE `uid` = "' . $inf['id'] . '" LIMIT 1');
}
mysql_query(
'UPDATE `users` SET `inUser` = 0,`inTurnirnew` = 0 WHERE `inTurnirnew` = "' . $this->info['id'] . '" LIMIT ' . $this->info['users_in']
);
mysql_query(
'UPDATE `turnirs` SET `chat` = 4 , `winner` = -1,`users_in` = 0,`status` = 0,`winner` = -1,`step` = 0,`time` = "' . (time(
) + $this->info['time2']) . '",`count` = `count` + 1 WHERE `id` = ' . $this->info['id'] . ' LIMIT 1'
);
if ($win != '') {
$win = rtrim($win, ', ');
$lose = rtrim($lose, ', ');
$win = 'Победители турнира: ' . $win . '. Проигравшая сторона: ' . $lose . '. Следующий турнир начнется через ' . $this->u->timeOut(
$this->info['time2']
) . ' (' . date('d.m.Y H:i', (time() + $this->info['time2'])) . ').';
} else {
$win = 'Победители турнира отсутствует. Следующий турнир начнется через ' . $this->u->timeOut(
$this->info['time2']
) . ' (' . date('d.m.Y H:i', (time() + $this->info['time2'])) . ').';
}
$cmsg->setText('<b>Турнир завершен.</b> ' . $win);
$chat->sendMsg($cmsg);
}
private function locationSee()
{
$r = '';
$tm1 = '';
$tm2 = '';
$noitm = [869 => 1, 1246 => 1, 155 => 1, 1245 => 1, 678 => 1];
//получение комплекта
if ($this->info['step'] != 3 && $this->info['step'] != 0 && isset($_GET['gocomplect']) && $this->user['points'] < 2) {
$aso = explode(',', $this->user['items']);
$ast = explode('-', $_GET['gocomplect']);
$asg = [];
$asj = [];
$asgp = [];
$i = 0;
while ($i < count($aso)) {
if ($aso[$i] > 0) {
$asg[$aso[$i]] = true;
}
$i++;
}
$i = 0;
$j = 0;
$noitm = 0;
$addi = 1;
while ($i < count($ast)) {
if ($ast[$i] > 0) {
if (!$asg[$ast[$i]]) {
$noitm++;
}
$itm = mysql_fetch_array(
mysql_query(
'SELECT `id`,`inSlot`,`price1` FROM `items_main` WHERE `id` = "' . mysql_real_escape_string(
$ast[$i]
) . '" LIMIT 1'
)
);
if (isset($itm['id'])) {
$itm2 = mysql_fetch_array(
mysql_query(
'SELECT `iid`,`price_1` FROM `items_shop` WHERE `item_id` = "' . mysql_real_escape_string(
$ast[$i]
) . '" AND `kolvo` > 0 LIMIT 1'
)
);
if ($itm2['price_1'] > $itm['price1']) {
$itm['price1'] = $itm2['price_1'];
}
if ($itm['inSlot'] == 3 || $itm['inSlot'] == 10) {
$asg[$itm['inSlot']][count($asg[$itm['inSlot']])] = $itm['id'];
$asgp[$itm['inSlot']][count($asgp[$itm['inSlot']])] = $itm['price1'];
} else {
$asg[$itm['inSlot']] = $itm['id'];
$asp[$itm['inSlot']] = $itm['price1'];
}
$j++;
}
}
$i++;
}
if ($noitm > 0) {
echo 'Использование багов карается законом!';
$addi = 0;
} elseif (count($asg[3]) > 2) {
echo 'Вы выбрали слишком много предметов, выберите только два оружия и один щит';
$addi = 0;
} elseif (count($asg[10]) > 3) {
echo 'Вы выбрали слишком много предметов, выберите только три кольца';
$addi = 0;
} elseif ($j > 16) {
echo 'Вы выбрали слишком много предметов';
$addi = 0;
} elseif ($j < 1) {
echo 'Выберите хотя бы один предмет';
$addi = 0;
}
if ($addi == 1) {
$i = 0;
while ($i <= 17) {
if ($i == 10) {
if ($asg[$i][0] > 0) {
$this->u->addItem($asg[$i][0], $this->u->info['id']);
$this->user['points'] += 1 + round($asgp[$i][0]);
}
if ($asg[$i][1] > 0) {
$this->u->addItem($asg[$i][1], $this->u->info['id']);
$this->user['points'] += 1 + round($asgp[$i][1]);
}
if ($asg[$i][2] > 0) {
$this->u->addItem($asg[$i][2], $this->u->info['id']);
$this->user['points'] += 1 + round($asgp[$i][2]);
}
} elseif ($i == 3) {
if ($asg[$i][0] > 0) {
$this->u->addItem($asg[$i][0], $this->u->info['id']);
$this->user['points'] += 1 + round($asgp[$i][0]);
}
if ($asg[$i][1] > 0) {
$this->u->addItem($asg[$i][1], $this->u->info['id']);
$this->user['points'] += 1 + round($asgp[$i][1]);
}
} elseif ($asg[$i] > 0) {
$this->u->addItem($asg[$i], $this->u->info['id']);
$this->user['points'] += 1 + round($asgp[$i]);
}
$i++;
}
mysql_query(
'UPDATE `users_turnirs` SET `points` = "' . $this->user['points'] . '",`items` = "0" WHERE `bot` = "' . $this->u->info['id'] . '" LIMIT 1'
);
mysql_query(
'UPDATE `stats` SET `ability` = "100",`skills` = "10" WHERE `id` = "' . $this->u->info['id'] . '" LIMIT 1'
);
mysql_query('UPDATE `users` SET `level` = "12" WHERE `id` = "' . $this->u->info['id'] . '" LIMIT 1');
mysql_query('UPDATE `turnirs` SET `step` = "0" WHERE `id` = "' . $this->info['id'] . '" LIMIT 1');
$this->info['step'] = 0;
$this->info['items'] = '0';
}
}
if ($this->info['step'] == 3) {
$this->finishTurnir();
} elseif ($this->info['step'] == 0) {
//распределяем команды
$po = [0, 0];
$sp = mysql_query(
'SELECT * FROM `users_turnirs` WHERE `turnir` = "' . $this->info['id'] . '" AND `points` > 3 ORDER BY `points` DESC LIMIT ' . $this->info['users_in']
);
$tmr = rand(1, 2);
if ($tmr == 1) {
$tmr = [2, 1];
} else {
$tmr = [1, 2];
}
while ($pl = mysql_fetch_array($sp)) {
$inf = mysql_fetch_array(
mysql_query('SELECT * FROM `users` WHERE `id` = "' . $pl['uid'] . '" LIMIT 1')
);
$bot = mysql_fetch_array(
mysql_query('SELECT * FROM `users` WHERE `id` = "' . $pl['bot'] . '" LIMIT 1')
);
if (isset($inf['id'], $bot['id'])) {
if ($po[1] == $po[2]) {
$tm = rand(1, 2);
} elseif ($po[1] > $po[2]) {
$tm = 2;
} else {
$tm = 1;
}
//$tm = $tmr[$tm];
$bot['team'] = $tm;
$po[$bot['team']] += $pl['points'];
mysql_query(
'UPDATE `stats` SET `team` = "' . $bot['team'] . '" WHERE `id` = "' . $bot['id'] . '" LIMIT 1'
);
mysql_query(
'UPDATE `users_turnirs` SET `team` = "' . $bot['team'] . '" WHERE `id` = "' . $pl['id'] . '" LIMIT 1'
);
}
}
mysql_query('UPDATE `turnirs` SET `step` = "1" WHERE `id` = "' . $this->info['id'] . '" LIMIT 1');
}
$sp = mysql_query(
'SELECT * FROM `users_turnirs` WHERE `turnir` = "' . $this->info['id'] . '" LIMIT ' . $this->info['users_in']
);
$po = [0, 0];
while ($pl = mysql_fetch_array($sp)) {
$inf = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "' . $pl['uid'] . '" LIMIT 1'));
$bot = mysql_fetch_array(
mysql_query(
'SELECT `u`.*,`st`.* FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON `u`.`id` = `st`.`id` WHERE `u`.`id` = "' . $pl['bot'] . '" LIMIT 1'
)
);
if (isset($inf['id'], $bot['id'])) {
$po[$bot['team']] += $pl['points'];
//${'tm'.$bot['team']} .= '<b>'.$bot['login'].'</b> ['.$bot['level'].']<br>';
${'tm' . $bot['team']} .= $this->u->microLogin($bot, 2) . '<br>';
}
}
$r .= '<style>/* цвета команд */
.CSSteam0 { font-weight: bold; cursor:pointer; }
.CSSteam1 { font-weight: bold; color: #6666CC; cursor:pointer; }
.CSSteam2 { font-weight: bold; color: #B06A00; cursor:pointer; }
.CSSteam3 { font-weight: bold; color: #269088; cursor:pointer; }
.CSSteam4 { font-weight: bold; color: #A0AF20; cursor:pointer; }
.CSSteam5 { font-weight: bold; color: #0F79D3; cursor:pointer; }
.CSSteam6 { font-weight: bold; color: #D85E23; cursor:pointer; }
.CSSteam7 { font-weight: bold; color: #5C832F; cursor:pointer; }
.CSSteam8 { font-weight: bold; color: #842B61; cursor:pointer; }
.CSSteam9 { font-weight: bold; color: navy; cursor:pointer; }
.CSSvs { font-weight: bold; }</style>';
$r .= '<h3>&laquo;' . $this->name[$this->info['type']] . '&raquo;</h3><br>Начало турнира через ' . $this->u->timeOut(
$this->info['time'] - time()
) . '! ';
if (isset($_GET['hpregenNowTurnir']) && ($this->u->stats['hpNow'] < $this->u->stats['hpAll'] || $this->u->stats['mpNow'] < $this->u->stats['mpAll'])) {
mysql_query(
'UPDATE `stats` SET `hpNow` = "' . $this->u->stats['hpAll'] . '",`mpNow` = "' . $this->u->stats['mpAll'] . '" WHERE `id` = "' . $this->u->info['id'] . '" LIMIT 1'
);
}
if ($this->user['points'] < 3) {
//Еще не получили обмундирование
if ($this->user['points'] < 2) {
$r .= '<INPUT class=\'btn_grey\' onClick="selectItmSave()" TYPE=button name=tmp value="Получить обмундирование">';
} else {
$r .= ' <INPUT class=\'btn_grey\' onClick="location=\'main.php\';" TYPE=button name=tmp value="Я готов';
if ($this->u->info['sex'] == 1) {
$r .= 'а';
}
$r .= '!">';
}
} else {
$r .= '<small><b>Вы участвуете в турнире!</b></small>';
$r .= ' &nbsp; <INPUT class=\'btn_grey\' onClick="location.href=\'main.php?hpregenNowTurnir=1\'" TYPE=button name=tmp value="Восстановить HP и MP">';
}
$r .= '<div style="float:right"><INPUT onClick="location=\'main.php\';" TYPE=button name=tmp value="Обновить"></div>';
if ($this->user['points'] < 3 && $this->user['items'] != '0') {
$r .= '<div align="left" style="height:1px; width:100%; margin:10px 0 10px 0; border-top:1px solid #999999;"></div>';
if ($this->user['items'] == '') {
//Выдаем предметы для выбора
$ai = '';
$sp = mysql_query(
'SELECT `a`.*,`b`.* FROM `items_shop` AS `a` LEFT JOIN `items_main` AS `b` ON (`a`.`item_id` = `b`.`id`) WHERE `a`.`sid` = 1 AND
(`a`.`r` != 5 AND `a`.`r` != 9 AND `a`.`r` <= 18 AND `a`.`kolvo` > 0 AND `cantBuy` = 0 AND `a`.`level` < 9 AND `b`.`level` < 9) AND
`b`.`class` != 6'
);
while ($pl = mysql_fetch_array($sp)) {
if (!isset($noitm[$pl['item_id']])) {
$aso[$pl['inslot']][count($aso[$pl['inslot']])] = $pl;
}
}
$j = 1;
$com = [];
while ($j <= 5) {
$i = 0;
while ($i <= 17) {
if ($i == 3) {
//
$com[$i] = $aso[$i][rand(0, count($aso[$i]) - 1)];
} elseif ($i == 14) {
//правая рука
$com[$i] = $aso[$i][rand(0, count($aso[$i]) - 1)];
} else {
//обмундирование
$com[$i] = $aso[$i][rand(0, count($aso[$i]) - 1)];
if ($i == 10) {
$ai .= $com[$i]['id'] . ',';
$com[$i] = $aso[$i][rand(0, count($aso[$i]) - 1)];
$ai .= $com[$i]['id'] . ',';
}
}
if ($com[$i]['id'] > 0 && $i != 10) {
$ai .= $com[$i]['id'] . ',';
}
$i++;
}
$j++;
}
unset($com);
$ai .= '0';
$this->user['items'] = $ai;
mysql_query(
'UPDATE `users_turnirs` SET `items` = "' . $ai . '" WHERE `id` = "' . $this->user['id'] . '" LIMIT 1'
);
}
//Выводим предметы чтобы надеть их
$ai = explode(',', $this->user['items']);
$i = 0;
$ia = [];
while ($i < count($ai)) {
if ($ai[$i] > 0) {
$pli = mysql_fetch_array(
mysql_query(
'SELECT `id`,`inSlot`,`name`,`type`,`img`,`level` FROM `items_main` WHERE `id` = "' . $ai[$i] . '" LIMIT 1'
)
);
$ia[$pli['inSlot']][count($ia[$pli['inSlot']])] = $pli;
unset($pli);
}
$i++;
}
unset($ai);
$r .= '<b>Выберите предметы для турнира:</b><br>';
?>
<style>
.its0 {
margin: 2px;
cursor: pointer;
filter: DXImageTransform.Microsoft.BasicImage(grayscale=1);
-ms-filter: DXImageTransform.Microsoft.BasicImage(grayscale=1);
-webkit-filter: grayscale(100%);
}
.its1 {
background-color: #ee9898;
margin: 1px;
border: 1px solid #b16060;
}
</style>
<script>
var set = [];
set[3] = [0, 0, 0];
set[10] = [0, 0, 0, 0];
function selectItmAdd(x, y, id, s) {
if (s != 10 && s != 3) {
if (set[s] != undefined && set[s] != 0) {
$('#it_' + set[s][1] + '_' + set[s][2]).attr('class', 'its0');
set[s] = 0;
}
set[s] = [id, x, y];
$('#it_' + x + '_' + y).attr('class', 'its1');
} else if (s == 10) {
if (set[s][0] > 2) {
$('#it_' + set[s][1][1] + '_' + set[s][1][2]).attr('class', 'its0');
$('#it_' + set[s][2][1] + '_' + set[s][2][2]).attr('class', 'its0');
$('#it_' + set[s][3][1] + '_' + set[s][3][2]).attr('class', 'its0');
set[s] = [0, 0, 0, 0];
}
if (set[s][1] == 0) {
set[s][1] = [id, x, y];
} else if (set[s][2] == 0) {
set[s][2] = [id, x, y];
} else if (set[s][3] == 0) {
set[s][3] = [id, x, y];
}
set[s][0]++;
$('#it_' + x + '_' + y).attr('class', 'its1');
} else if (s == 3) {
if (set[s][0] > 1) {
$('#it_' + set[s][1][1] + '_' + set[s][1][2]).attr('class', 'its0');
$('#it_' + set[s][2][1] + '_' + set[s][2][2]).attr('class', 'its0');
set[s] = [0, 0, 0];
}
if (set[s][1] == 0) {
set[s][1] = [id, x, y];
} else if (set[s][2] == 0) {
set[s][2] = [id, x, y];
}
set[s][0]++;
$('#it_' + x + '_' + y).attr('class', 'its1');
}
}
function selectItmSave() {
var i = 0;
var r = '';
while (i <= 17) {
if (set[i] != undefined) {
if (i == 10) {
if (set[i][1][0] != undefined) {
r += set[i][1][0] + '-';
}
if (set[i][2][0] != undefined) {
r += set[i][2][0] + '-';
}
if (set[i][3][0] != undefined) {
r += set[i][3][0] + '-';
}
} else if (i == 3) {
if (set[i][1][0] != undefined) {
r += set[i][1][0] + '-';
}
if (set[i][2][0] != undefined) {
r += set[i][2][0] + '-';
}
} else {
if (set[i][0] != undefined) {
r += set[i][0] + '-';
}
}
}
i++;
}
location = "main.php?gocomplect=" + r;
}
</script>
<?php
$i = 0;
while ($i <= 17) {
if (count($ia[$i]) > 0) {
$j = 0;
while ($j < count($ia[$i])) {
$r .= '<img id="it_' . $i . '_' . $j . '" onclick="selectItmAdd(' . $i . ',' . $j . ',' . $ia[$i][$j]['id'] . ',' . $ia[$i][$j]['inSlot'] . ');" class="its0" title="' . $ia[$i][$j]['name'] . '" src="//img.new-combats.tech/i/items/' . $ia[$i][$j]['img'] . '">';
$j++;
}
$r .= '<br>';
}
$i++;
}
}
$r .= '<div align="left" style="height:1px; width:100%; margin:10px 0 10px 0; border-top:1px solid #999999;"></div>';
$r .= '<table style="border:1px solid #99cccc" width="700" bgcolor="#bbdddd" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td width="350" align="center" bgcolor="#99cccc"><b class="CSSteam1">Команда 1</b></td>
<td align="center" bgcolor="#99cccc"><b class="CSSteam2">Команда 2</b></td>
</tr>
<tr>
<td align="center" style="border-right:1px solid #99cccc">' . rtrim($tm1, ', ') . '</td>
<td align="center">' . rtrim($tm2, ', ') . '</td>
</tr>
</table>';
if (($this->info['time'] - time() < 0) && $this->info['step'] == 1) {
//начинаем турнир
$this->startTurnir();
}
echo $r;
}
}
+19 -1
View File
@@ -2599,7 +2599,7 @@ FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON (`im`.`id` = `iu`.`
public function addNewbot($id, $botDate, $clon, $logins_bot = null, $luser = null, $round = null)
{
if ($clon != null) {
$r = false;
$r = 0;
if (!is_array($clon)) {
$clon = $this->getUserInfoById((int)$clon);
}
@@ -11887,4 +11887,22 @@ LIMIT 1'
Db::sql('update users set online = unix_timestamp() where id = ?', [$uid]);
}
public function isModerator(): bool
{
return $this->isAdmin() || $this->info['align'] > 3 && $this->info['align'] < 4;
}
public function isAdmin(): bool
{
return $this->info['admin'] > 0;
}
/** Игрок имеет меньше 30% хп.
* @return bool
*/
public function isWeakened(): bool
{
return $this->stats['hpNow'] < ceil($this->stats['hpMax'] / 100 * 30);
}
}
+25
View File
@@ -0,0 +1,25 @@
<?php
use Core\Db;
class UserEffects
{
/** Äàòü èãðîêó ýôôåêò.
* @param int $uid id èãðîêà
* @param int $id id ýôôåêòà
* @return void
*/
public static function addById(int $uid, int $id)
{
$eff = Db::getRow('select mname, mdata, oneType, id2 from eff_main where id2 = ?', [$id]);
if (!$eff['id2']) {
return;
}
Db::sql(
'insert into eff_users (overType, id_eff, uid, name, timeUse, data) values (?,?,?,?,unix_timestamp(),?)',
[$eff['oneType'], $eff['id2'], $uid, $eff['mname'], $eff['mdata']]
);
}
}
+27
View File
@@ -31,4 +31,31 @@ union all select data from eff_users where uid = ? and `delete` = 0';
}
return $params;
}
/** Данные для отрисовки логина и полосок жизни\маны.
* @param User $u
* @return object
*/
public static function getLoginHpManaBars(User $u): object
{
$hpNow = floor($u->stats['hpNow']);
$hpAll = $u->stats['hpAll'];
$mpNow = floor($u->stats['mpNow']);
$mpAll = $u->stats['mpAll'];
//floor(120 / 100 * ($hpNow / $hpAll * 100)); // ??????
$ph = ($hpAll > 0 && $hpNow > 0) ? floor(120 / $hpNow / $hpAll) : 0;
$pm = ($mpAll > 0 && $mpNow > 0) ? floor(120 / $mpNow / $mpAll) : 0;
return (object)[
'uid' => $u->info['id'],
'login' => $u->microLogin($u->info['id']),
'hpbarwidth' => $ph,
'mpbarwidth' => $pm,
'hpbartext' => ' ' . $hpNow . '/' . $hpAll,
'mpbartext' => ' ' . $mpNow . '/' . $mpAll,
'divstyle' => $pm === 0 ? ' margin-top:13px;' : '',
'hasmana' => $mpAll > 0,
];
}
}