From b79a0ccf1bb84a8fe9d48db8562cee04a106d9ab Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Sat, 10 Feb 2024 21:33:10 +0200 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B0=20mysql=5F?= =?UTF-8?q?query=20=D0=B8=20=D1=83=D0=BF=D1=80=D0=BE=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _incl_data/class/Battle.php | 643 +++++++++++++++--------------------- 1 file changed, 266 insertions(+), 377 deletions(-) diff --git a/_incl_data/class/Battle.php b/_incl_data/class/Battle.php index 219a9fca..038581dc 100644 --- a/_incl_data/class/Battle.php +++ b/_incl_data/class/Battle.php @@ -920,12 +920,12 @@ JS; $ir = 0; $bi = 0; + $stats = new Stats($u); + if ($this->i->id > 0) { if ($this->i->izlom == 0) { //данные о игроках в бою - $trl = mysql_query( - 'SELECT `u`.`no_ip`,`u`.`id`,`u`.`notrhod`,`u`.`login`,`u`.`login2`,`u`.`sex`,`u`.`online`,`u`.`admin`,`u`.`align`,`u`.`align_lvl`,`u`.`align_exp`,`u`.`clan`,`u`.`level`,`u`.`battle`,`u`.`obraz`,`u`.`win`,`u`.`lose`,`u`.`nich`,`u`.`animal`,`st`.`stats`,`st`.`hpNow`,`st`.`mpNow`,`st`.`exp`,`st`.`dnow`,`st`.`team`,`st`.`battle_yron`,`st`.`battle_exp`,`st`.`enemy`,`st`.`battle_text`,`st`.`upLevel`,`st`.`timeGo`,`st`.`timeGoL`,`st`.`bot`,`st`.`lider`,`st`.`btl_cof`,`st`.`tactic1`,`st`.`tactic2`,`st`.`tactic3`,`st`.`tactic4`,`st`.`tactic5`,`st`.`tactic6`,`st`.`tactic7`,`st`.`x`,`st`.`y`,`st`.`battleEnd`,`st`.`priemslot`,`st`.`priems`,`st`.`priems_z`,`st`.`bet`,`st`.`clone`,`st`.`atack`,`st`.`bbexp`,`st`.`res_x`,`st`.`res_y`,`st`.`res_s`,`st`.`id`,`st`.`last_hp`,`st`.`last_pr`,`u`.`sex`,`u`.`money`,`u`.`money3`,`u`.`money2`,`u`.`bot_id` FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`battle` = "' . $this->i->id . '" ORDER BY `st`.`bot` DESC' - ); + $bu = Db::getRows("select *, if(login2 = '', login, login2) as login2 from users left join stats on users.id = stats.id where battle = ? order by bot desc", [$this->i->id]); $this->users = []; $this->stats = []; @@ -933,40 +933,30 @@ JS; $this->bots = []; $this->iBots = []; - while ($pl = mysql_fetch_array($trl)) { - //записываем данные - if ($pl['login2'] == '') { - $pl['login2'] = $pl['login']; - } - $this->users[$ir] = $pl; - $this->uids[$pl['id']] = $ir; - if ($pl['bot'] > 0) { - $this->bots[$bi] = $pl['id']; - $this->iBots[$pl['id']] = $bi; + foreach ($bu as $user) { + $this->users[$ir] = $user; + $this->uids[$user['id']] = $ir; + if ($user['bot'] > 0) { + $this->bots[$bi] = $user['id']; + $this->iBots[$user['id']] = $bi; $bi++; } - //записываем статы - $this->stats[$ir] = $u->getStats($pl['id'], 0, 0, false, false, true); + $this->stats[$ir] = $stats->getStats($user['id']); $ir++; } + } elseif (!isset($this->uids[$u->info['id']])) { //данные о игроках в бою - $trl = mysql_query( - 'SELECT `u`.`no_ip`,`u`.`id`,`u`.`notrhod`,`u`.`login`,`u`.`login2`,`u`.`sex`,`u`.`online`,`u`.`admin`,`u`.`align`,`u`.`align_lvl`,`u`.`align_exp`,`u`.`clan`,`u`.`level`,`u`.`battle`,`u`.`obraz`,`u`.`win`,`u`.`lose`,`u`.`nich`,`u`.`animal`,`st`.`stats`,`st`.`hpNow`,`st`.`mpNow`,`st`.`exp`,`st`.`dnow`,`st`.`team`,`st`.`battle_yron`,`st`.`battle_exp`,`st`.`enemy`,`st`.`battle_text`,`st`.`upLevel`,`st`.`timeGo`,`st`.`timeGoL`,`st`.`bot`,`st`.`lider`,`st`.`btl_cof`,`st`.`tactic1`,`st`.`tactic2`,`st`.`tactic3`,`st`.`tactic4`,`st`.`tactic5`,`st`.`tactic6`,`st`.`tactic7`,`st`.`x`,`st`.`y`,`st`.`battleEnd`,`st`.`priemslot`,`st`.`priems`,`st`.`priems_z`,`st`.`bet`,`st`.`clone`,`st`.`atack`,`st`.`bbexp`,`st`.`res_x`,`st`.`res_y`,`st`.`res_s`,`st`.`id`,`st`.`last_hp`,`st`.`last_pr`,`u`.`sex`,`u`.`money`,`u`.`bot_id`,`u`.`money3`,`u`.`money2` FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`id` = ' . $this->i->id - ); - $pl = mysql_fetch_array($trl); - //записываем данные - if ($pl['login2'] == '') { - $pl['login2'] = $pl['login']; + $bu = Db::getRows("select *, if(login2 = '', login, login2) as login2 from users left join stats on users.id = stats.id where users.id = ?", [$this->i->id]); + foreach ($bu as $user) { + $this->users[] = $user; + $this->uids[$user['id']] = $ir; + if ($user['bot'] > 0) { + $this->bots[] = $user['id']; + $this->iBots[$user['id']] = $bi; + } + $this->stats[] = $stats->getStats($user['id']); } - $this->users[] = $pl; - $this->uids[$pl['id']] = $ir; - if ($pl['bot'] > 0) { - $this->bots[] = $pl['id']; - $this->iBots[$pl['id']] = $bi; - } - //записываем статы - $this->stats[] = $u->getStats($pl['id'], 0, 0, false, false, true); } } @@ -1034,34 +1024,36 @@ JS; if ($j == 0) { //конец излома $this->finish->finishBattle($tml, $tmv); - mysql_query( - 'INSERT INTO `izlom_rating` (`uid`,`time`,`voln`,`level`,`bots`,`rep`,`obr`,`btl`) VALUES ("' . $u->info['id'] . '","' . time( - ) . '","' . $this->i->izlomroundsee . '","' . $this->i->izlomlvl . '","0","0","' . ($this->i->izlomobr - $this->i->izlomobrnow) . '","' . $this->i->id . '")' + Db::sql( + 'insert into izlom_rating (uid, time, voln, level, obr, btl) values (?,unix_timestamp(),?,?,?,?)', + [$u->info['id'], $this->i->izlomroundsee, $this->i->izlomlvl, $this->i->izlomobr - $this->i->izlomobrnow, $this->i->id] ); + } else { - $this->i->setIzlomround($iz['round']); - mysql_query( - 'UPDATE `battle` SET `izlomObrNow` = ' . $obr . ',`izlomObr` = `izlomObr` + ' . $obr . ',`timeout` = (`timeout`+5),`izlomRound` = "' . ($this->i->getIzlomround( - ) + 1) . '",`izlomRoundSee` = `izlomRoundSee`+1 WHERE `id` = "' . $this->i->id . '" LIMIT 1' + + Db::sql( + 'update battle set izlomobrnow = ?, izlomobr = izlomobr + ?, timeout = timeout + 5, izlomround = izlomround + 1, izlomroundsee = izlomroundsee + 1 where id = ?', + [$obr, $obr, $this->i->id] ); + $this->stats[$this->uids[$u->info['id']]]['hpNow'] += $this->stats[$this->uids[$u->info['id']]]['hpAll'] * 0.25; $this->stats[$this->uids[$u->info['id']]]['mpNow'] += $this->stats[$this->uids[$u->info['id']]]['mpAll'] * 0.25; $this->users[$this->uids[$u->info['id']]]['hpNow'] = $this->stats[$this->uids[$u->info['id']]]['hpAll']; $this->users[$this->uids[$u->info['id']]]['mpNow'] = $this->stats[$this->uids[$u->info['id']]]['mpAll']; //где это брать?? - $vLog = 'at1=00000||at2=00000||zb1=' . $this->stats[$this->uids[$u1]]['zonb'] . - '||zb2=' . $this->stats[$this->uids[$u2]]['zonb'] . - '||bl1=' . $this->atacks[$id]['b' . $a] . - '||bl2=' . $this->atacks[$id]['b' . $b] . - '||time1=' . $this->atacks[$id]['time'] . - '||time2=' . $this->atacks[$id]['time2'] . - '||s2=' . $this->users[$this->uids[$u2]]['sex'] . - '||s1=' . $this->users[$this->uids[$u1]]['sex'] . - '||t2=' . $this->users[$this->uids[$u2]]['team'] . - '||t1=' . $this->users[$this->uids[$u1]]['team'] . - '||login1=' . $this->users[$this->uids[$u1]]['login2'] . - '||login2=' . $this->users[$this->uids[$u2]]['login2']; + $vLog = 'at1=00000||at2=00000||zb1=' . $this->stats[$this->uids[$u->info['id']]]['zonb'] . + '||zb2=' . $this->stats[$this->uids[$u->info['enemy']]]['zonb'] . + '||bl1=' . $this->atacks[$this->i->id]['b1'] . + '||bl2=' . $this->atacks[$this->i->id]['b2'] . + '||time1=' . $this->atacks[$this->i->id]['time'] . + '||time2=' . $this->atacks[$this->i->id]['time2'] . + '||s2=' . $this->users[$this->uids[$u->info['enemy']]]['sex'] . + '||s1=' . $this->users[$this->uids[$u->info['id']]]['sex'] . + '||t2=' . $this->users[$this->uids[$u->info['enemy']]]['team'] . + '||t1=' . $this->users[$this->uids[$u->info['id']]]['team'] . + '||login1=' . $this->users[$this->uids[$u->info['id']]]['login2'] . + '||login2=' . $this->users[$this->uids[$u->info['enemy']]]['login2']; $mas = [ 'battle' => $this->i->id, @@ -1426,7 +1418,6 @@ JS; public function testUserInfoBattle($uid): void { - global $u; if (isset($this->uids[$uid])) { return; } @@ -1435,24 +1426,13 @@ JS; if (!isset($this->uids[$uid])) { $this->uids[$uid] = count($this->users); } - $this->users[$this->uids[$uid]] = mysql_fetch_array( - mysql_query( - 'SELECT - `u`.`id`,`u`.`login`,`u`.`login2`,`u`.`online`,`u`.`admin`,`u`.`city`,`u`.`cityreg`,`u`.`align`,`u`.`align_lvl`,`u`.`align_exp`,`u`.`clan`, - `u`.`level`,`u`.`money`,`u`.`money3`,`u`.`money2`,`u`.`money4`,`u`.`battle`,`u`.`sex`,`u`.`obraz`,`u`.`win`,`u`.`win_t`, - `u`.`lose`,`u`.`lose_t`,`u`.`nich`,`u`.`timeMain`,`u`.`invis`,`u`.`bot_id`,`u`.`animal`,`u`.`type_pers`, - `u`.`notrhod`,`u`.`bot_room`,`u`.`inUser`,`u`.`inTurnir`,`u`.`inTurnirnew`,`u`.`stopexp`,`u`.`real`, - `st`.* - FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`id` = "' . $uid . '" LIMIT 1' - ) - ); - $stats = new Stats($u); - $this->stats[$this->uids[$uid]] = $stats->getStats(); //getStats($this->users[$this->uids[$uid]]) + + $stats = new Stats(User::start()); + $this->users[$this->uids[$uid]] = User::getInfo($uid); + $this->stats[$this->uids[$uid]] = $stats->getStats($uid); //getStats($this->users[$this->uids[$uid]]) //fixme много чего повторно берется } - //Добавляем размены в лог - /** * Расчет опыта * @param $y @@ -1485,216 +1465,136 @@ JS; return (int)round($addExp); } - //Добавляем в лог действия приема - - public function addNewStat($stat): void + public function addNewStat(array $stat): void { + $sql = 'insert into battle_stat (battle, uid1, uid2, time, type, a, b, type_a, type_b, ma, mb, yrn, yrn_krit, tm1, tm2) + values (:battle,:uid1,:uid2,:time,:type,:a,:b,:type_a,:type_b,:ma,:mb,:yrn,:yrn_krit,:tm1,:tm2)'; + if (isset($stat[1])) { - mysql_query( - 'INSERT INTO `battle_stat` - ( `battle`,`uid1`,`uid2`,`time`,`type`,`a`,`b`,`ma`,`mb`,`type_a`,`type_b`,`yrn`,`yrn_krit`,`tm1`,`tm2` ) VALUES ( - "' . $this->i->id . '", - "' . $stat[1]['uid1'] . '", - "' . $stat[1]['uid2'] . '", - "' . $stat[1]['time'] . '", - "' . $stat[1]['type'] . '", - "' . $stat[1]['a'] . '", - "' . $stat[1]['b'] . '", - "' . $stat[1]['ma'] . '", - "' . $stat[1]['mb'] . '", - "' . $stat[1]['type_a'] . '", - "' . $stat[1]['type_b'] . '", - "' . $stat[1]['yrn'] . '", - "' . $stat[1]['yrn_krit'] . '", - "' . $stat[1]['tm1'] . '", - "' . $stat[1]['tm2'] . '" - )' - ); + $stat[1]['battle'] = $this->i->id; + Db::sql($sql, $stat[1]); } + if (isset($stat[2])) { - mysql_query( - 'INSERT INTO `battle_stat` - ( `battle`,`uid1`,`uid2`,`time`,`type`,`a`,`b`,`ma`,`mb`,`type_a`,`type_b`,`yrn`,`yrn_krit`,`tm1`,`tm2` ) VALUES ( - "' . $this->i->id . '", - "' . $stat[2]['uid1'] . '", - "' . $stat[2]['uid2'] . '", - "' . $stat[2]['time'] . '", - "' . $stat[2]['type'] . '", - "' . $stat[2]['a'] . '", - "' . $stat[2]['b'] . '", - "' . $stat[1]['ma'] . '", - "' . $stat[2]['mb'] . '", - "' . $stat[2]['type_a'] . '", - "' . $stat[2]['type_b'] . '", - "' . $stat[2]['yrn'] . '", - "' . $stat[2]['yrn_krit'] . '", - "' . $stat[2]['tm1'] . '", - "' . $stat[2]['tm2'] . '" - )' - ); + $stat[2]['battle'] = $this->i->id; + Db::sql($sql, $stat[2]); } } - //Считаем контру - public function lookLog(): string { - global $u; + $u = User::start(); + $js = ''; + $pll = 0; - $hodID = mysql_fetch_array( - mysql_query( - 'SELECT `id`,`id_hod` FROM `battle_logs` WHERE `battle` = "' . $this->i->id . '" ORDER BY `time` LIMIT 1' - ) - ); - if ($hodID['id_hod'] <= 1) { + $hodID = Db::getValue('select id_hod from battle_logs where battle = ? order by time limit 1', [$this->i->id]) ?? 0; + if ($hodID <= 1) { $u->info['alog'] = 0; } - $js = ''; - $pll = 0; + $sp = Db::getRows('select * from battle_logs where battle = ? and id_hod >= (select alog from stats where id = ?) order by id desc', [$this->i->id, $u->info['id']]) ?? []; - $talog = mysql_fetch_array( - mysql_query('SELECT `alog` FROM `stats` WHERE `id` = "' . $u->info['id'] . '" LIMIT 1') - ); - $sp = mysql_query( - 'SELECT - `id`,`type`,`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zona2`,`zonb1`,`zonb2` - FROM `battle_logs` - WHERE `battle` = "' . $this->i->id . '" AND `id_hod` >= ' . $talog['alog'] . ' ORDER BY `id` DESC' - ); - if (isset($sp) && $this->i->getTeamwin() != -1) { - $sp = mysql_query( - 'SELECT - `id`,`type`,`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zona2`,`zonb1`,`zonb2` - FROM `battle_logs_save` - WHERE `battle` = "' . $this->i->id . '" AND `id_hod` >= ' . $talog['alog'] . ' ORDER BY `id` DESC' - ); + if (!empty($sp) && $this->i->getTeamwin() != -1) { + $sp = Db::getRows('select * from battle_logs_save where battle = ? and id_hod >= (select alog from stats where id = ?) order by id desc', [$this->i->id, $u->info['id']]) ?? []; } - $jin = 0; - $forYou2 = 0; - if (is_array($sp)) { - while ($pl = mysql_fetch_array($sp)) { - if ($jin == 0) { - $u->info['alog'] = $pl['id_hod']; - } - $jin++; - $rt = $pl['text']; - $pl['vars'] = str_replace('^^^^', 'rvnO', $pl['vars']); - $rt = str_replace( - '{tm1}', '' . date('H:i', $pl['time']) . '', - $rt - ); - $rt = str_replace( - '{tm2}', '' . date('H:i', $pl['time']) . '', - $rt - ); - $rt = str_replace( - '{tm3}', - '' . date('d.m.Y H:i', $pl['time']) . '', $rt - ); - $rt = str_replace( - '{tm4}', - '' . date('d.m.Y H:i', $pl['time']) . '', $rt - ); - $pl['text'] = $rt; + $search = ['{tm1}', '{tm2}', '{tm3}', '{tm4}']; - unset($rt); - if ($pll < $pl['id']) { - $pll = $pl['id']; - } - $js = 'add_log(' . $pl['id'] . ',' . $forYou2 . ',"' . $pl['text'] . '",' . $pl['id_hod'] . ',0,0,"' . str_replace( - '"', - '"', $pl['vars'] - ) . '");' . $js; + foreach ($sp as $log) { + if (!isset($firstloop)) { + $u->info['alog'] = $log['id_hod']; + $firstloop = true; } + + $log['vars'] = str_replace('^^^^', 'rvnO', $log['vars']); + + $replace = [ + '' . date('H:i', $log['time']) . '', + '' . date('H:i', $log['time']) . '', + '' . date('d.m.Y H:i', $log['time']) . '', + '' . date('d.m.Y H:i', $log['time']) . '', + ]; + + $log['text'] = str_replace($search, $replace, $log['text']); + + if ($pll < $log['id']) { + $pll = $log['id']; + } + + $jstext = json_encode($log['text']); + $jsvars = json_encode($log['vars']); + + $js = "add_log({$log['id']},0,$jstext,{$log['id_hod']},0,0,$jsvars)" . $js; } - mysql_query( - 'UPDATE `stats` SET `alog`="' . $u->info['alog'] . '" WHERE `id` ="' . $u->info['id'] . '" LIMIT 1' - ); - $js .= 'id_log=' . $pll . ';'; - return $js; + + Db::sql('update stats set alog = ? where id = ?', [$u->info['alog'], $u->info['id']]); + $js .= "id_log=$pll;"; + + return htmlspecialchars($js, ENT_QUOTES); } - //Расчитываем статы для конкретной зоны атаки - public function lookmLog(): string { - global $u; + if ($this->i->type == 9) { + return ''; + } + + $u = User::start(); + $js = ''; $pll = 0; - if ($this->i->type != 9) { - $hodID = mysql_fetch_array( - mysql_query( - 'SELECT `id_hod` FROM `battle_logs` WHERE `battle` = "' . $this->i->id . '" ORDER BY `time` LIMIT 1' - ) - ); - if ($hodID['id_hod'] <= 1) { - $u->info['mlog'] = 0; - } - - $tmlog = mysql_fetch_array( - mysql_query('SELECT `mlog` FROM `stats` WHERE `id` = "' . $u->info['id'] . '" LIMIT 1') - ); - $spm = mysql_query( - 'SELECT - `id`,`type`,`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zona2`,`zonb1`,`zonb2` - FROM `battle_logs` - WHERE `battle` = "' . $this->i->id . '" AND `id_hod` >= ' . $tmlog['mlog'] . ' AND `vars` LIKE "%' . $u->info['login'] . '%" ORDER BY `id` DESC' - ); - - if (isset($spm) && $this->i->getTeamwin() != -1) { - $spm = mysql_query( - 'SELECT - `id`,`type`,`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zona2`,`zonb1`,`zonb2` - FROM `battle_logs_save` - WHERE `battle` = "' . $this->i->id . '" AND `id_hod` >= ' . $tmlog['mlog'] . ' AND `vars` LIKE "%' . $u->info['login'] . '%" ORDER BY `id` DESC' - ); - } - - $jin = 0; - $forYou2 = 0; - if (is_array($spm)) { - while ($plm = mysql_fetch_array($spm)) { - if ($jin == 0) { - $u->info['mlog'] = $plm['id_hod']; - } - $jin++; - $rt = $plm['text']; - $plm['vars'] = str_replace('^^^^', 'rvnO', $plm['vars']); - $rt = str_replace( - '{tm1}', '' . date('H:i', $plm['time']) . '', $rt - ); - $rt = str_replace( - '{tm2}', '' . date('H:i', $plm['time']) . '', $rt - ); - $rt = str_replace( - '{tm3}', '' . date('d.m.Y H:i', $plm['time']) . '', - $rt - ); - $rt = str_replace( - '{tm4}', '' . date('d.m.Y H:i', $plm['time']) . '', - $rt - ); - $plm['text'] = $rt; - unset($rt); - if ($pll < $plm['id']) { - $pll = $plm['id']; - } - $js = 'add_mlog(' . $plm['id'] . ',' . $forYou2 . ',"' . $plm['text'] . '",' . $plm['id_hod'] . ',0,0,"' . str_replace( - '"', - '"', $plm['vars'] - ) . '");' . $js; - } - } - $js .= 'id_mlog=' . $pll . ';'; - mysql_query( - 'UPDATE `stats` SET `mlog`="' . $u->info['mlog'] . '" WHERE `id` ="' . $u->info['id'] . '" LIMIT 1' - ); + $hodID = Db::getValue('select id_hod from battle_logs where battle = ? order by time limit 1', [$this->i->id]) ?? 0; + if ($hodID <= 1) { + $u->info['mlog'] = 0; } - return $js; + + $sp = Db::getRows( + "select * from battle_logs where battle = ? and id_hod >= (select mlog from stats where id = ?) and vars like ? order by id desc", + [$this->i->id, $u->info['id'], "%{$u->info['login']}%"] + ) ?? []; + + if (!empty($sp) && $this->i->getTeamwin() != -1) { + $sp = Db::getRows( + 'select * from battle_logs_save where battle = ? and id_hod >= (select mlog from stats where id = ?) and vars like ? order by id desc', + [$this->i->id, $u->info['id'], "%{$u->info['login']}%"] + ) ?? []; + } + + $search = ['{tm1}', '{tm2}', '{tm3}', '{tm4}']; + + foreach ($sp as $log) { + if (!isset($firstloop)) { + $u->info['mlog'] = $log['id_hod']; + $firstloop = true; + } + + $log['vars'] = str_replace('^^^^', 'rvnO', $log['vars']); + + $replace = [ + '' . date('H:i', $log['time']) . '', + '' . date('H:i', $log['time']) . '', + '' . date('d.m.Y H:i', $log['time']) . '', + '' . date('d.m.Y H:i', $log['time']) . '', + ]; + + $log['text'] = str_replace($search, $replace, $log['text']); + + if ($pll < $log['id']) { + $pll = $log['id']; + } + + $jstext = json_encode($log['text']); + $jsvars = json_encode($log['vars']); + + $js = "add_mlog({$log['id']},0,$jstext,{$log['id_hod']},0,0,$jsvars)" . $js; + } + + Db::sql('update stats set mlog = ? where id = ?', [$u->info['mlog'], $u->info['id']]); + $js .= "id_mlog=$pll;"; + + return htmlspecialchars($js, ENT_QUOTES); } //Считаем урон @@ -1816,22 +1716,17 @@ JS; public function testActions(): void { - global $u; + $u = User::start(); //проверяем удары - $m = mysql_query('SELECT * FROM `battle_act` WHERE `battle` = "' . $this->i->id . '" ORDER BY `id`'); - $i = 0; - while ($pl = mysql_fetch_array($m)) { - $pluids = mysql_fetch_array( - mysql_query( - 'SELECT `hpNow` FROM `stats` WHERE (`id` = "' . $pl['uid1'] . '" AND `hpNow` <= 0) OR (`id` = "' . $pl['uid2'] . '" AND `hpNow` <= 0) LIMIT 1' - ) - ); - $pltest = mysql_fetch_array( - mysql_query('SELECT * FROM `battle_act` WHERE `id` = "' . $pl['id'] . '" LIMIT 1') - ); - if (isset($pltest['id'])) { - if (isset($pluids['hpNow'])) { - mysql_query('DELETE FROM `battle_act` WHERE `id` = "' . $pl['id'] . '" LIMIT 1'); + $ba = Db::getRows('select * from battle_act where battle = ? order by id', [$this->i->id]); + + foreach ($ba as $pl) { + $testhpnow = Db::getValue('select hpnow from stats where hpnow <= 0 and id in (?,?) limit 1', [$pl['uid1'], $pl['uid2']]); + $testid = (bool)Db::getValue('select count(id) from battle_act where id = ?', [$pl['id']]); + + if ($testid) { + if ($testhpnow) { + Db::sql('delete from battle_act where id = ?', [$pl['id']]); } elseif ($pl['time'] + $this->i->timeout > time()) { //удар не пропущен по тайму, просто заносим данные $this->atacks[$pl['id']] = $pl; @@ -1863,7 +1758,7 @@ JS; //наносим удар по пропуску $this->atacks[$pl['id']] = $pl; $this->startAtack($pl['id']); - mysql_query('DELETE FROM `battle_act` WHERE `id` = "' . $pl['id'] . '"'); + Db::sql('delete from battle_act where id = ?', [$pl['id']]); } } @@ -1880,6 +1775,7 @@ JS; } } + $i = 0; //тест, бот делает удары while ($i < count($this->bots)) { $bot = $this->bots[$i]; @@ -1916,9 +1812,7 @@ JS; $this->users[$this->uids[$bot]]['timego'] < time() ) { $this->botAtack($this->users[$j]['id'], $bot, 1); - mysql_query( - 'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1' - ); + Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]); } } elseif ( isset($this->users[$i]) && @@ -1939,18 +1833,14 @@ JS; !isset($this->ag[$bot][$this->users[$i]['id']]) ) { $this->botAtack($this->users[$i]['id'], $bot, 1); - mysql_query( - 'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1' - ); + Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]); } elseif ( !isset($this->ag[$bot][$this->users[$i]['id']]) && isset($this->ga[$bot][$this->users[$i]['id']]) && $this->users[$this->uids[$bot]]['timego'] < time() ) { $this->botAtack($bot, $this->users[$i]['id'], 1); - mysql_query( - 'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1' - ); + Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]); } } } else { @@ -1998,9 +1888,7 @@ JS; } $this->startAtack($this->ga[$bot][$this->users[$j]['id']]); $this->users[$this->uids[$bot]]['timego'] = $tnbot; - mysql_query( - 'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1' - ); + Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]); } } elseif ( isset($this->ag[$bot][$this->users[$j]['id']]) && @@ -2016,9 +1904,7 @@ JS; $tnbot = time() - 1; } $this->users[$this->uids[$bot]]['timego'] = $tnbot; - mysql_query( - 'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1' - ); + Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]); } } } @@ -3072,99 +2958,101 @@ JS; public function testPogB($uid, $yr, $pliid, $test = 0) { - $yr2 = $yr; - $checktuman = mysql_fetch_array( - mysql_query( - 'SELECT * FROM `eff_users` WHERE `uid` = "' . $uid . '" - AND (`v2` = 273 OR `v2` = 286 OR `v2` = 287 OR `v2` = 288) - AND `delete` =0 LIMIT 1' - ) - ); //проверка на туманный образ - if ($yr > 0 && !isset($checktuman['id'])) { - global $priem; - $i = 0; - while ($i < count($this->stats[$this->uids[$uid]]['set_pog2'])) { - $j = $this->stats[$this->uids[$uid]]['set_pog2'][$i]; - if ($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['id'] == $pliid || $test == 1) { - $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] = str_replace( - 'add_pog2=' . $j['y'], - 'add_pog2=$', $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] - ); - $dt3 = Conversion::dataStringToArray($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data']); - $dt30 = floor($j['y'] / $yr2 * 100); - if ($dt30 < $dt3['add_pog2p']) { - $dt3['add_pog2p'] = $dt30; - } - unset($dt30); - if (isset($dt3['add_pog2mp'])) { - if ((round( - round($yr2 / 100 * (100 - $dt3['add_pog2p'])) * $dt3['add_pog2mp'] - )) > $this->stats[$this->uids[$uid]]['mpNow']) { - //не хватило маны, считаем сколько хватит % от поглощенного урона - $j['yhj'] = $this->stats[$this->uids[$uid]]['mpNow'] / (round( - round($yr2 / 100 * (100 - $dt3['add_pog2p'])) * $dt3['add_pog2mp'] - )) * 100; - $j['yhj'] = floor($j['yhj']); //Сколько % мы можем поглотить - $dt3['add_pog2p'] = floor($dt3['add_pog2p'] / 100 * $j['yhj']); - } - if ($test == 1) { - $priem->minMana($uid, round(round($yr2 / 100 * $dt3['add_pog2p']) * $dt3['add_pog2mp'])); - } - } - if (!isset($this->poglast[$uid])) { - $this->poglast[$uid] = 0; - } - $this->poglast[$uid] += $yr2; - if ($test == 1) { - // осталось для поглощения - $j['y'] -= round($this->poglast[$uid] / 100 * $dt3['add_pog2p']); - $priem->minMana( - $uid, - round(round($this->poglast[$uid] / 100 * $dt3['add_pog2p']) * $dt3['add_pog2mp']) - ); - } - if (isset($dt3['add_pog2p'])) { - $yr2 = round($yr2 / 100 * (100 - $dt3['add_pog2p'])); - } - if ($j['y'] < 0 || ($this->stats[$this->uids[$uid]]['mpNow'] <= 0 && $dt3['add_pog2mp'] > 0)) { - $dt2 = Conversion::dataStringToArray($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data']); - if (isset($dt2['endPog']) && $dt2['endPog'] == 1) { - //удаляем прием - //Добавляем в лог - $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['priem'] = mysql_fetch_array( - mysql_query( - 'SELECT * FROM `priems` WHERE `id` = "' . $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['v2'] . '" LIMIT 1' - ) - ); - $this->delPriem( - $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1], - $this->users[$this->uids[$uid]], 4, $uid - ); - $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1] = 'delete'; - } - unset($dt2); - $j['y'] = 0; - } - $this->stats[$this->uids[$uid]]['set_pog'][$i]['y'] = $j['y']; - if (isset($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'])) { - $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] = str_replace( - 'add_pog2=$', - 'add_pog2=' . $j['y'], $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] - ); - mysql_query( - 'UPDATE `eff_users` SET `data` = "' . $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] . '" WHERE `id` = "' . $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['id'] . '" LIMIT 1' - ); - } - if ($j['y'] - $this->poglast[$uid] + $yr2 < 0) { - $yr -= $yr + ($j['y'] - $this->poglast[$uid] + $yr2); - $yr2 = $yr; - $i = count($this->stats[$this->uids[$uid]]['set_pog2']) + 1; - } - } - $i++; - } + $checktuman = Db::getValue('select count(id) from eff_users where uid = ? and v2 in (273,286,287,288)', [$uid]) == 0; //проверка на туманный образ + if ($yr <= 0 || !$checktuman) { + return $yr; } - unset($checktuman); + + global $priem; + + $yr2 = $yr; + $i = 0; + + while ($i < count($this->stats[$this->uids[$uid]]['set_pog2'])) { + $j = $this->stats[$this->uids[$uid]]['set_pog2'][$i]; + if ($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['id'] != $pliid && $test != 1) { + $i++; + continue; + } + + $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] = str_replace( + 'add_pog2=' . $j['y'], + 'add_pog2=$', $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] + ); + $dt3 = Conversion::dataStringToArray($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data']); + $dt30 = floor($j['y'] / $yr2 * 100); + if ($dt30 < $dt3['add_pog2p']) { + $dt3['add_pog2p'] = $dt30; + } + unset($dt30); + + if (isset($dt3['add_pog2mp'])) { + if ((round(round($yr2 / 100 * (100 - $dt3['add_pog2p'])) * $dt3['add_pog2mp'])) > $this->stats[$this->uids[$uid]]['mpNow']) { + //не хватило маны, считаем сколько хватит % от поглощенного урона + $j['yhj'] = $this->stats[$this->uids[$uid]]['mpNow'] / (round(round($yr2 / 100 * (100 - $dt3['add_pog2p'])) * $dt3['add_pog2mp'])) * 100; + $j['yhj'] = floor($j['yhj']); //Сколько % мы можем поглотить + $dt3['add_pog2p'] = floor($dt3['add_pog2p'] / 100 * $j['yhj']); + } + if ($test == 1) { + $priem->minMana($uid, round(round($yr2 / 100 * $dt3['add_pog2p']) * $dt3['add_pog2mp'])); + } + } + + if (!isset($this->poglast[$uid])) { + $this->poglast[$uid] = 0; + } + $this->poglast[$uid] += $yr2; + + if ($test == 1) { + // осталось для поглощения + $j['y'] -= round($this->poglast[$uid] / 100 * $dt3['add_pog2p']); + $priem->minMana($uid, round(round($this->poglast[$uid] / 100 * $dt3['add_pog2p']) * $dt3['add_pog2mp'])); + } + + if (isset($dt3['add_pog2p'])) { + $yr2 = round($yr2 / 100 * (100 - $dt3['add_pog2p'])); + } + + if ($j['y'] < 0 || ($this->stats[$this->uids[$uid]]['mpNow'] <= 0 && $dt3['add_pog2mp'] > 0)) { + $dt2 = Conversion::dataStringToArray($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data']); + if (isset($dt2['endPog']) && $dt2['endPog'] == 1) { + //удаляем прием + //Добавляем в лог + + $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['priem'] = + Db::getRow('select * from priems where id = ?', [$this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['v2']]); + $this->delPriem( + $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1], + $this->users[$this->uids[$uid]], 4, $uid + ); + $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1] = 'delete'; + } + unset($dt2); + $j['y'] = 0; + } + + $this->stats[$this->uids[$uid]]['set_pog'][$i]['y'] = $j['y']; + if (isset($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'])) { + $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] = str_replace( + 'add_pog2=$', + 'add_pog2=' . $j['y'], $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] + ); + Db::sql( + 'update eff_users set data = ? where id = ?', + [$this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'], $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['id']] + ); + + } + + if ($j['y'] - $this->poglast[$uid] + $yr2 < 0) { + $yr -= $yr + ($j['y'] - $this->poglast[$uid] + $yr2); + $yr2 = $yr; + $i = count($this->stats[$this->uids[$uid]]['set_pog2']) + 1; + } + + $i++; + } + return $yr2; } @@ -3311,11 +3199,15 @@ JS; if ($at[$a]['atack'][$j]['yron']['hp'] > $at[$a]['atack'][$j]['yron']['hpAll']) { $at[$a]['atack'][$j]['yron']['hp'] = $at[$a]['atack'][$j]['yron']['hpAll']; } + //Травмирование - if (rand(0, 100) <= 50 && ($at[$a]['atack'][$j][1] == 4 || $at[$a]['atack'][$j][1] == 5) && !isset($at[$a]['atack'][$j]['yron']['travma']) && rand( - 0, - 1000 - ) < 500 && $this->users[$this->uids[$u2]]['level'] > 1 && $this->stats[$this->uids[$u1]] > 1) { + if ( + rand(0, 100) <= 50 && + ($at[$a]['atack'][$j][1] == 4 || $at[$a]['atack'][$j][1] == 5) && + !isset($at[$a]['atack'][$j]['yron']['travma']) && + $this->users[$this->uids[$u2]]['level'] > 1 && + $this->stats[$this->uids[$u1]] > 1 + ) { $trvm_chns = floor(rand(0, 200) / 10); if ($trvm_chns > 3 || $trvm_chns < 1) { $trvm_chns = 0; @@ -4375,8 +4267,6 @@ JS; return; } - var_dump($_POST); - //atack: '3_2_0_0_0' (length=9) //block: '5' (length=1) @@ -4404,7 +4294,6 @@ JS; } $this->uAtc = $na; $js .= 'testClearZone();'; - var_dump($this->uAtc); } public function teamsTake(User $u): void