From 92318be8377ee02f0fdd51b5b9ada83470164dd9 Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Wed, 12 Apr 2023 03:05:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=BF=D1=82=D0=B8=D0=BC=D0=B8=D0=B7?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D0=B8=20=D1=82=D0=B5=D0=BA?= =?UTF-8?q?=D1=83=D1=89=D0=B8=D1=85=20=D0=B1=D0=BE=D1=91=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _incl_data/class/Core/ArraySorter.php | 71 +++++++++++ _incl_data/class/FightRequest.php | 166 +++++++++++--------------- 2 files changed, 144 insertions(+), 93 deletions(-) create mode 100644 _incl_data/class/Core/ArraySorter.php diff --git a/_incl_data/class/Core/ArraySorter.php b/_incl_data/class/Core/ArraySorter.php new file mode 100644 index 00000000..ab59288d --- /dev/null +++ b/_incl_data/class/Core/ArraySorter.php @@ -0,0 +1,71 @@ +{$key2}; + } elseif (isset($value[$key2])) { + $key = $value[$key2]; + } + + if ($key === null) { + continue; + } + + $grouped[$key][] = $value; + } + + // Recursively build a nested grouping if more parameters are supplied + // Each grouped array value is grouped according to the next sequential key + if (func_num_args() > 2) { + $args = func_get_args(); + + foreach ($grouped as $key => $value) { + $params = array_merge([$value], array_slice($args, 2, func_num_args())); + $grouped[$key] = call_user_func_array('array_group_by', $params); + } + } + + return $grouped; + } +} diff --git a/_incl_data/class/FightRequest.php b/_incl_data/class/FightRequest.php index 7d3dc277..e773f2a8 100644 --- a/_incl_data/class/FightRequest.php +++ b/_incl_data/class/FightRequest.php @@ -1,5 +1,6 @@ 1) { //Начало турнира - Db::sql('update turnirs set time = unix_timestamp() + ?, status = 1 where id = ?', [$pl['time3'], $pl['id']]); + Db::sql( + 'update turnirs set time = unix_timestamp() + ?, status = 1 where id = ?', [$pl['time3'], $pl['id']] + ); $usp = mysql_query( 'SELECT * FROM `users` WHERE `inTurnirnew` = "' . $pl['id'] . '" LIMIT ' . $pl['users_in'] @@ -336,7 +339,9 @@ class FightRequest if (!$zayavka['nobot']) { // Если нет запрета на ботов. $getRealPlayersQuery = 'select * from stats left join users on stats.id = users.id where exp >= ? and exp < ? and bot = 0 order by btl_cof desc limit 50'; $getBotsQuery = 'select * from stats left join users on stats.id = users.id where bot = 2 and exp >= ? and exp < ?'; - $botUsers = Db::getRows($getBotsQuery, [$levelToExp[$zayavka['min_lvl_1']], $levelToExp[$zayavka['max_lvl_1'] + 1]]); + $botUsers = Db::getRows( + $getBotsQuery, [$levelToExp[$zayavka['min_lvl_1']], $levelToExp[$zayavka['max_lvl_1'] + 1]] + ); } if (empty($botUsers)) { @@ -403,7 +408,9 @@ class FightRequest $tm2 = []; $i = []; $toChat = $toWhere = ''; - $users = Db::getRows('select * from stats left join users on stats.id = users.id where zv = ?', [$zv['id']]); + $users = Db::getRows( + 'select * from stats left join users on stats.id = users.id where zv = ?', [$zv['id']] + ); foreach ($users as $user) { !empty(${'tm' . $user['team']}) ?: ${'tm' . $user['team']} = []; !empty($i[$user['team']]) ?: $i[$user['team']] = 0; @@ -1018,8 +1025,8 @@ class FightRequest /** * Звуковой пинг в чат? - * @todo убрать колхоз с условиями когда станет ясно как оно работает. * @return void + * @todo убрать колхоз с условиями когда станет ясно как оно работает. */ private function sendSysChatSound(string $to = '', int $room = 0) { @@ -1514,7 +1521,9 @@ class FightRequest $sa = 'а'; } - $cmsg->setText(' [login:' . $this->u->info['login'] . '] отозвал' . $sa . ' свой запрос на бой.'); + $cmsg->setText( + ' [login:' . $this->u->info['login'] . '] отозвал' . $sa . ' свой запрос на бой.' + ); $cmsg->setCity($uz['city']); $cmsg->setTo($uz['login']); $chat->sendMsg($cmsg); @@ -2092,8 +2101,8 @@ function MM_jumpMenu(targ,selObj,restore){ //v3.0

- Бой без правил (проигравшая сторона получает инвалидность)
- Закрытый поединок (бой будет изолирован от нападений)
+ Бой без правил (проигравшая сторона получает инвалидность)
+ Закрытый поединок (бой будет изолирован от нападений)
Запрет на использование свитков восстановления НР и Маны
'; @@ -2110,87 +2119,54 @@ function MM_jumpMenu(targ,selObj,restore){ //v3.0 } } } elseif ($r == 6) { - //текущие - $x = 1; - $html = ''; - $p = 0; - $_GET['from'] = round((int)$_GET['from']); - if ($_GET['from'] > 1 && $_GET['from'] < 50) { - $p = $_GET['from'] - 1; - } - $xx = mysql_num_rows( - mysql_query( - 'SELECT `id` FROM `battle` WHERE `type` != 329 AND `team_win` = "-1" AND `time_over` = "0" AND `start1` > 0' - ) - ); - $px = $p * 15; - if ($p > ceil($xx / 15)) { - $p = ceil($xx / 15); - } - $sp = mysql_query( - 'SELECT * FROM `battle` WHERE `type` != 329 AND `team_win` = "-1" AND `time_over` = "0" AND `start1` > 0 ORDER BY `time_start` DESC LIMIT ' . ((int)$px) . ',15' - ); - while ($pl = mysql_fetch_array($sp)) { - $tm = ''; - $tmu = []; - $tms = []; - $spi = mysql_query( - 'SELECT `u`.`login`,`st`.`id`,`st`.`team`,`u`.`id` FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`battle` = "' . $pl['id'] . '"' - ); - while ($pli = mysql_fetch_array($spi)) { - if (!isset($tmu[$pli['team']])) { - $tms[count($tms)] = $pli['team']; - } - $tmu[$pli['team']][count($tmu[$pli['team']])] = $pli['id']; - } - $i = 0; - while ($i < count($tms)) { - $tmsu = ''; - $j = 0; - while ($j < count($tmu[$tms[$j]])) { - if ($tmu[$tms[$i]][$j] > 0) { - $tmsu .= $this->u->microLogin($tmu[$tms[$i]][$j], 1) . ', '; - } - $j++; - } - $tmsu = rtrim($tmsu, ', '); - $tm .= $tmsu; - if ($i + 1 != count($tms)) { - $tm .= ' против '; - } - $i++; - } - if ($tm != '') { - $html .= ($p + $x) . '. ' . date( - 'd.m.y H:i', $pl['time_start'] - ) . ' ' . $tm . ' Физический бой »»
'; - } - $x++; - } ?> - - - - - -

Записи текущих боев на - (всего )

- К сожалению сейчас боев нет...'; - } else { - echo '
' . $html . '
'; - } ?> - - - - - -
0 && $xx > 15) { ?>«« - предыдущая страница  - 0) { ?> - следующая страница »»  -
+

Записи текущих боев на

0 order by time_start) order by battle desc'; + $currentBattles = Db::getRows($query); + + if (empty($currentBattles)) { + echo '
К сожалению сейчас боев нет...
'; + } else { + // Надеялся на вывод вида: + // [battle -> [team -> [uid, uid, uid], team -> [uid, uid, uid],]], + // [battle -> [team -> [uid, uid, uid], team -> [uid, uid, uid],]], + // но глубоко наломался, где-то перемудрил с ArraySorter::groupBy() + // и на выходе там сортировка, но с сохранением всех вложенностей, + // что усложнило последющий вывод. Но вышло как вышло. Ins. + $currentBattlesArray = ArraySorter::groupBy($currentBattles, 'battle'); + echo '
    '; + foreach ($currentBattlesArray as $battleId => $cb) { + $players = ''; + $typeBattle = 0; + $timeStart = 0; + $teams = ArraySorter::groupBy($cb, 'team'); + foreach ($teams as $teamId => $team) { + foreach ($team as $key => $player) { + $players .= $this->u->microLogin($player['id']); + if ($key !== array_key_last($team)) { + $players .= ', '; + } else { + $typeBattle = $player['typeBattle']; + $timeStart = $player['time_start']; + } + } + if ($teamId === array_key_first($teams)) { + $players .= ' против '; + } + } + echo '
  1. ' . date('d.m.y H:i', $timeStart) . ''; + echo " $players "; + echo ''; + echo '▶▶'; + } + echo '
'; + } + ///new + + } elseif ($r == 7) { //завершенные $btl = ''; @@ -2663,7 +2639,9 @@ function MM_jumpMenu(targ,selObj,restore){ //v3.0 ) ); $d1 = ''; - if ($uz['id'] == $this->u->info['id'] || $uze['id'] == $this->u->info['id'] || $this->u->info['level'] <= Config::get('bot_level')) { + if ($uz['id'] == $this->u->info['id'] || $uze['id'] == $this->u->info['id'] || $this->u->info['level'] <= Config::get( + 'bot_level' + )) { $d1 = 'disabled="disabled"'; } if (!isset($uze['id']) || $this->u->info['zv'] == $pl['id']) { @@ -2813,7 +2791,9 @@ function MM_jumpMenu(targ,selObj,restore){ //v3.0 } $cmsg = new ChatMessage(); - $cmsg->setText(' [login:' . $this->u->info['login'] . '] принял' . $sa . ' вашу заявку на бой.[reflesh_main_zv_priem:' . $this->u->info['id'] . ']'); + $cmsg->setText( + ' [login:' . $this->u->info['login'] . '] принял' . $sa . ' вашу заявку на бой.[reflesh_main_zv_priem:' . $this->u->info['id'] . ']' + ); $cmsg->setCity($uz1['city']); $cmsg->setTo($uz1['login']); $cmsg->setType(6);