From 98882e156e9e41b4c0cb9a3482a5c16b8f1bda4c Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Sat, 10 Feb 2024 16:35:56 +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 | 59 ++++++++++--------------------------- 1 file changed, 15 insertions(+), 44 deletions(-) diff --git a/_incl_data/class/Battle.php b/_incl_data/class/Battle.php index e7d1a92e..3c780c79 100644 --- a/_incl_data/class/Battle.php +++ b/_incl_data/class/Battle.php @@ -2042,25 +2042,16 @@ JS; private function botAtack($uid, $pl, $tp): void { - $test_atack = mysql_fetch_array( - mysql_query( - 'SELECT `id` FROM `battle_act` WHERE `battle` = "' . $this->i->id . '" AND (( - `uid1` = "' . $pl . '" AND `uid2` = "' . $uid . '" - ) OR ( - `uid2` = "' . $pl . '" AND `uid1` = "' . $uid . '" - )) LIMIT 1' - ) - ); + $testAttack = Db::getValue('select count(id) from battle_act where battle = ? and uid1 in (?,?) and uid2 in(?,?) and uid1 != uid2', [$this->i->id, $pl, $uid, $pl, $uid]) === 0; + $testuid = Db::getValue('select id from stats where id = ? and hpnow >= 1', [$uid]); - if ($tp == 1 && !isset($test_atack['id'])) { - $test_uid = mysql_fetch_array( - mysql_query('SELECT * FROM `stats` WHERE `id` = "' . $uid . '" AND `hpNow` >= 1 LIMIT 1') - ); - $test_pl = mysql_fetch_array( - mysql_query('SELECT * FROM `stats` WHERE `id` = "' . $pl . '" AND `hpNow` >= 1 LIMIT 1') - ); - if (isset($test_uid['id']) && isset($test_pl['id']) && $test_uid['id'] != $test_pl['id']) { - $a = rand(1, 5) . '' . rand(1, 5) . rand(1, 5) . rand(1, 5) . rand(1, 5); + if ($tp == 1 && $testAttack) { + + $testpl = Db::getValue('select id from stats where id = ? and hpnow >= 1', [$pl]); + $check = $testuid && $testpl && $testuid !== $testpl; + + if ($check) { + $a = rand(1, 5) . rand(1, 5) . rand(1, 5) . rand(1, 5) . rand(1, 5); $b = rand(1, 5); Db::sql( "insert into battle_act (battle,time,uid1,uid2,a1,b1,a2,b2,invis1,invis2) values (?,unix_timestamp(),?,?,?,?,'',0,0,0)", @@ -2069,33 +2060,13 @@ JS; } } elseif ($tp == 2) { //бот отвечает на удар - $test_uid = mysql_fetch_array( - mysql_query('SELECT * FROM `stats` WHERE `id` = "' . $uid . '" AND `hpNow` >= 1 LIMIT 1') - ); - $test_pl = mysql_fetch_array( - mysql_query('SELECT * FROM `stats` WHERE `id` = "' . $pl['uid2'] . '" AND `hpNow` >= 1 LIMIT 1') - ); - if (isset($test_uid['id']) && isset($test_pl['id']) && $test_uid['id'] != $test_pl['id']) { - $na = []; - $a222 = rand(1, 5) . '_' . rand(1, 5) . '_' . rand(1, 5) . '_' . rand(1, 5) . '_' . rand(1, 5); - $a = explode('_', $a222); - $i = 1; - while ($i <= 5) { - if (isset($a[$i - 1])) { - $a[$i - 1] = intval(round($a[$i - 1])); - if ($a[$i - 1] >= 1 && $a[$i - 1] <= 5) { - $na['a'][$i] = $a[$i - 1]; - } else { - $na['a'][$i] = 0; - } - } - $i++; - } - $na['b'] = rand(1, 5); - //Проводим удар + $testpl = Db::getValue('select id from stats where id = ? and hpnow >= 1', [$pl['uid2']]); + $check = $testuid && $testpl && $testuid !== $testpl; - $this->atacks[$pl['id']]['a2'] = $a222; - $this->atacks[$pl['id']]['b2'] = $na['b']; + if ($check) { + //Проводим удар + $this->atacks[$pl['id']]['a2'] = rand(1, 5) . '_' . rand(1, 5) . '_' . rand(1, 5) . '_' . rand(1, 5) . '_' . rand(1, 5); + $this->atacks[$pl['id']]['b2'] = rand(1, 5); $this->startAtack($pl['id']); } }