Замена mysql_query и упрощение.

This commit is contained in:
Ivor Barhansky 2024-02-10 16:35:56 +02:00
parent 7c15294688
commit 98882e156e

View File

@ -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']);
}
}