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

This commit is contained in:
Ivor Barhansky 2024-02-10 18:18:11 +02:00
parent 98882e156e
commit 8c49088f27
3 changed files with 90 additions and 97 deletions

View File

@ -9,6 +9,7 @@ use Clan\ClanInfo;
use Core\Config; use Core\Config;
use Core\Db; use Core\Db;
use DTO\BattlePriem; use DTO\BattlePriem;
use Helper\Comparsion;
use Helper\Conversion; use Helper\Conversion;
use Model\Constant\Stat; use Model\Constant\Stat;
use User\Effects; use User\Effects;
@ -1034,12 +1035,14 @@ JS;
//конец излома //конец излома
$this->finish->finishBattle($tml, $tmv); $this->finish->finishBattle($tml, $tmv);
mysql_query( 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 . '")' '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 . '")'
); );
} else { } else {
$this->i->setIzlomround($iz['round']); $this->i->setIzlomround($iz['round']);
mysql_query( 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' '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'
); );
$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']]]['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->stats[$this->uids[$u->info['id']]]['mpNow'] += $this->stats[$this->uids[$u->info['id']]]['mpAll'] * 0.25;
@ -1255,8 +1258,7 @@ JS;
bool $stabil, bool $stabil,
bool $test = false, bool $test = false,
int $inlog = 0 int $inlog = 0
): mixed ): mixed {
{
/** /**
* profil = { * profil = {
@ -2081,35 +2083,21 @@ JS;
if (!isset($this->atacks[$id]) || $this->atacks[$id]['lock'] != 0) { if (!isset($this->atacks[$id]) || $this->atacks[$id]['lock'] != 0) {
return; return;
} }
//Прием разгадать тактику //Прием разгадать тактику
$i = 1; $i = 1;
$j = 2; $j = 2;
while ($i <= 2) { while ($i <= 2) {
$untac = mysql_fetch_array( $hasResolveTacticPriem = Db::getValue("select count(id) from eff_users where v1 = 'priem' and v2 = 217 and uid = ?", [$this->atacks[$id]['uid' . $i]]) > 0;
mysql_query( $hasNoAgressiveShield = Db::getValue("select count(id) from eff_users where v1 = 'priem' and v2 = 211 and uid = ?", [$this->atacks[$id]['uid' . $j]]) == 0;
'SELECT `id` FROM `eff_users` WHERE `v1` = "priem" AND `v2` = 217 AND `uid` = "' . $this->atacks[$id]['uid' . $i] . '" AND `delete` = 0 LIMIT 1'
) if ($hasResolveTacticPriem && $hasNoAgressiveShield) {
); $activePriems = Db::getRows("select eff_users.* from eff_users inner join priems on eff_users.v2 = priems.id where uid = ? and v1 = 'priem' and
$agrs = mysql_fetch_array( v2 not in (29, 30, 31, 32, 36, 49, 85, 86, 87, 88, 89, 90, 139, 174, 175, 176, 177, 178, 179, 187, 188, 191, 201, 206, 207, 208, 209, 210, 211, 217, 220, 222, 226,
mysql_query( 227, 228, 229, 233, 236, 238, 245, 248, 249, 256, 258, 261, 262, 263, 269, 270, 276, 277, 284, 285, 324, 332, 333, 334, 335) and
'SELECT `id` FROM `eff_users` WHERE `v1` = "priem" AND `v2` = 211 AND `uid` = "' . $this->atacks[$id]['uid' . $j] . '" AND `delete` = 0 LIMIT 1' eff_users.name not like '%Иммунитет%' and neg = 0", [$this->atacks[$id]['uid' . $j]]);
) foreach ($activePriems as $ap) {
); $this->delPriem($ap, $this->users[$this->uids[$this->atacks[$id]['uid' . $j]]], 100);
if (isset($untac['id']) && !isset($agrs['id'])) {
$pvr['sp'] = mysql_query(
'SELECT `a`.* FROM `eff_users` AS `a` WHERE `a`.`uid` = "' . $this->atacks[$id]['uid' . $j] . '" AND `a`.`delete` = 0 AND `a`.`v1` = "priem"
and v2 not in (29, 30, 31, 32, 36, 49, 85, 86, 87, 88, 89, 90, 139, 174, 175, 176, 177, 178, 179, 187, 188, 191, 201, 206, 207, 208, 209, 210, 211, 217, 220, 222, 226,
227, 228, 229, 233, 236, 238, 245, 248, 249, 256, 258, 261, 262, 263, 269, 270, 276, 277, 284, 285, 324, 332, 333, 334, 335)
AND `name` NOT LIKE "%Иммунитет%"
LIMIT 30'
);
while ($pvr['pl'] = mysql_fetch_array($pvr['sp'])) {
$pvr['pl']['priem'] = mysql_fetch_array(
mysql_query('SELECT * FROM `priems` WHERE `id` = "' . $pvr['pl']['v2'] . '" LIMIT 1')
);
if (isset($pvr['pl']['priem']['id']) && $pvr['pl']['priem']['neg'] == 0) {
$this->delPriem($pvr['pl'], $this->users[$this->uids[$this->atacks[$id]['uid' . $j]]], 100);
}
} }
} }
$j--; $j--;
@ -2186,6 +2174,7 @@ JS;
// Проверяем приемы // Проверяем приемы
// Получаем приемы игроков // Получаем приемы игроков
$at = $this->priemsTestRazmen($id, $at); $at = $this->priemsTestRazmen($id, $at);
// Собираем размен (пересчитываем и расчитываем урон и т.д) // Собираем размен (пересчитываем и расчитываем урон и т.д)
$at = $this->priemsRestartRazmen($id, $at); //Повторная проверка приемов (если требуется) $at = $this->priemsRestartRazmen($id, $at); //Повторная проверка приемов (если требуется)
@ -2211,12 +2200,12 @@ JS;
//Возращаем зоны блока //Возращаем зоны блока
$this->restZonb($this->atacks[$id]['uid1'], $this->atacks[$id]['uid2']); $this->restZonb($this->atacks[$id]['uid1'], $this->atacks[$id]['uid2']);
//обновляем задержки приемов //обновляем задержки приемов
$zd1 = explode('|', $this->users[$this->uids[$this->atacks[$id]['uid1']]]['priems_z']); $zd1 = explode('|', $this->users[$this->uids[$this->atacks[$id]['uid1']]]['priems_z']);
$zd2 = explode('|', $this->users[$this->uids[$this->atacks[$id]['uid2']]]['priems_z']); $zd2 = explode('|', $this->users[$this->uids[$this->atacks[$id]['uid2']]]['priems_z']);
$prmos = [];
$i5 = 0;
$i5 = 0;
while ($i5 < 51) { while ($i5 < 51) {
if (isset($zd1[$i5]) && $zd1[$i5] > 0) { if (isset($zd1[$i5]) && $zd1[$i5] > 0) {
//Если приемы не требуют ход //Если приемы не требуют ход
@ -2232,7 +2221,7 @@ JS;
} }
$i5++; $i5++;
} }
unset($prmos);
if ($this->users[$this->uids[$this->atacks[$id]['uid1']]]['enemy'] == $this->users[$this->uids[$this->atacks[$id]['uid2']]]['id']) { if ($this->users[$this->uids[$this->atacks[$id]['uid1']]]['enemy'] == $this->users[$this->uids[$this->atacks[$id]['uid2']]]['id']) {
$this->users[$this->uids[$this->atacks[$id]['uid1']]]['enemy'] = -$this->users[$this->uids[$this->atacks[$id]['uid1']]]['enemy']; $this->users[$this->uids[$this->atacks[$id]['uid1']]]['enemy'] = -$this->users[$this->uids[$this->atacks[$id]['uid1']]]['enemy'];
@ -2249,23 +2238,18 @@ JS;
} elseif ($this->atacks[$id]['uid2'] == $u->info['id']) { } elseif ($this->atacks[$id]['uid2'] == $u->info['id']) {
$u->info['priems_z'] = implode('|', $zd2); $u->info['priems_z'] = implode('|', $zd2);
} }
//Проверяем тактики //Проверяем тактики
$i = 1; $i = 1;
while ($i <= 6) { while ($i <= 6) {
if ($this->users[$this->uids[$this->atacks[$id]['uid1']]]['tactic' . $i] > 25) { $this->users[$this->uids[$this->atacks[$id]['uid1']]]['tactic' . $i] = Comparsion::minimax($this->users[$this->uids[$this->atacks[$id]['uid1']]]['tactic' . $i], 0, 25);
$this->users[$this->uids[$this->atacks[$id]['uid1']]]['tactic' . $i] = 25; $this->users[$this->uids[$this->atacks[$id]['uid2']]]['tactic' . $i] = Comparsion::minimax($this->users[$this->uids[$this->atacks[$id]['uid2']]]['tactic' . $i], 0, 25);
} elseif ($this->users[$this->uids[$this->atacks[$id]['uid1']]]['tactic' . $i] <= 0) {
$this->users[$this->uids[$this->atacks[$id]['uid1']]]['tactic' . $i] = 0;
}
if ($this->users[$this->uids[$this->atacks[$id]['uid2']]]['tactic' . $i] > 25) {
$this->users[$this->uids[$this->atacks[$id]['uid2']]]['tactic' . $i] = 25;
} elseif ($this->users[$this->uids[$this->atacks[$id]['uid2']]]['tactic' . $i] <= 0) {
$this->users[$this->uids[$this->atacks[$id]['uid2']]]['tactic' . $i] = 0;
}
$i++; $i++;
} }
//Обновляем задержки предметов //Обновляем задержки предметов
Db::sql('update items_users set btl_zd = btl_zd - 1 where (uid = ? or uid = ?) and btl_zd > 0 and inOdet > 0', [$this->atacks[$id]['uid1'], $this->atacks[$id]['uid2']]); Db::sql('update items_users set btl_zd = btl_zd - 1 where (uid = ? or uid = ?) and btl_zd > 0 and inodet > 0', [$this->atacks[$id]['uid1'], $this->atacks[$id]['uid2']]);
Db::sql('update users set notrhod = -1 where id = ? or id = ?', [$this->atacks[$id]['uid1'], $this->atacks[$id]['uid2']]); Db::sql('update users set notrhod = -1 where id = ? or id = ?', [$this->atacks[$id]['uid1'], $this->atacks[$id]['uid2']]);
//Обновляем задержки заклинаний, пирогов, тактик //Обновляем задержки заклинаний, пирогов, тактик
@ -2355,9 +2339,8 @@ JS;
if (isset($eff[$i])) { if (isset($eff[$i])) {
if ($eff[$i]['timeUse'] == 77 && $eff[$i]['hod'] > -1) { if ($eff[$i]['timeUse'] == 77 && $eff[$i]['hod'] > -1) {
$eff[$i]['hod']--; $eff[$i]['hod']--;
$eff[$i]['priem'] = mysql_fetch_array(
mysql_query('SELECT * FROM `priems` WHERE `id` = "' . $eff[$i]['v2'] . '" LIMIT 1') $eff[$i]['priem'] = Db::getValue('select * from priems where id = ?', [$eff[$i]['v2']]) ?? 0;
);
if (round($eff[$i]['priem']['minmana'] * $eff[$i]['x']) != 0) { if (round($eff[$i]['priem']['minmana'] * $eff[$i]['x']) != 0) {
//Отнимаем ману у того кто кастовал //Отнимаем ману у того кто кастовал
$priem->minMana( $priem->minMana(
@ -2411,20 +2394,17 @@ JS;
$pvr['mpSee'] = '+' . $pvr['mp']; $pvr['mpSee'] = '+' . $pvr['mp'];
$pvr['mpNow'] += $pvr['mp']; $pvr['mpNow'] += $pvr['mp'];
} }
if ($pvr['mpNow'] > $pvr['mpAll']) {
$pvr['mpNow'] = $pvr['mpAll']; $pvr['mpNow'] = Comparsion::minimax($pvr['mpNow'], 0, $pvr['mpAll']);
} elseif ($pvr['mpNow'] < 0) {
$pvr['mpNow'] = 0;
}
if ($pvr['mpSee'] == 0) { if ($pvr['mpSee'] == 0) {
$pvr['mpSee'] = '--'; $pvr['mpSee'] = '--';
} }
$this->stats[$this->uids[$pvr['uid']]]['mpNow'] = $pvr['mpNow']; $this->stats[$this->uids[$pvr['uid']]]['mpNow'] = $pvr['mpNow'];
$this->users[$this->uids[$pvr['uid']]]['mpNow'] = $pvr['mpNow']; $this->users[$this->uids[$pvr['uid']]]['mpNow'] = $pvr['mpNow'];
mysql_query(
'UPDATE `stats` SET `mpNow` = "' . $this->stats[$this->uids[$pvr['uid']]]['mpNow'] . '" WHERE `id` = "' . $pvr['uid'] . '" LIMIT 1' Db::sql('update stats set mpnow = ? where id = ?', [$this->stats[$this->uids[$pvr['uid']]]['mpNow'], $pvr['uid']]);
);
$pvr['text'] = $this->addlt(1, 21, $this->users[$this->uids[$pvr['uid']]]['sex']); $pvr['text'] = $this->addlt(1, 21, $this->users[$this->uids[$pvr['uid']]]['sex']);
$pvr['text2'] = '{tm1} ' . $pvr['text'] . ' на <strong style="color: #006699;">' . $pvr['mpSee'] . '</strong> [' . $pvr['mpNow'] . '/' . $pvr['mpAll'] . '] (Мана)'; $pvr['text2'] = '{tm1} ' . $pvr['text'] . ' на <strong style="color: #006699;">' . $pvr['mpSee'] . '</strong> [' . $pvr['mpNow'] . '/' . $pvr['mpAll'] . '] (Мана)';
@ -2442,9 +2422,8 @@ JS;
} }
if ($eff[$i]['hod'] > 0) { if ($eff[$i]['hod'] > 0) {
$this->stats[$this->uids[$this->atacks[$id]['uid' . $j]]]['effects']['hod'] = $eff[$i]['hod']; $this->stats[$this->uids[$this->atacks[$id]['uid' . $j]]]['effects']['hod'] = $eff[$i]['hod'];
mysql_query( Effects::setHod($eff[$i]['id'], $eff[$i]['hod']);
'UPDATE `eff_users` SET `hod` = "' . $eff[$i]['hod'] . '" WHERE `id` = "' . $eff[$i]['id'] . '" LIMIT 1'
);
} else { } else {
//удаляем прием //удаляем прием
if ($eff[$i]['v2'] > 0) { if ($eff[$i]['v2'] > 0) {
@ -2460,14 +2439,10 @@ JS;
} }
} }
} elseif ($eff[$i]['timeUse'] == 77 && $eff[$i]['hod'] == -2) { } elseif ($eff[$i]['timeUse'] == 77 && $eff[$i]['hod'] == -2) {
$eff[$i]['priem'] = mysql_fetch_array( $eff[$i]['priem'] = Db::getRow('select * from priems where id = ?', [$eff[$i]['v2']]);
mysql_query('SELECT * FROM `priems` WHERE `id` = "' . $eff[$i]['v2'] . '" LIMIT 1') $priem->hodUsePriem($this, $eff[$i]);
);
$priem->hodUsePriem($eff[$i], $eff[$i]['priem']);
} else { } else {
$eff[$i]['priem'] = mysql_fetch_array( $eff[$i]['priem'] = Db::getRow('select * from priems where id = ?', [$eff[$i]['v2']]);
mysql_query('SELECT * FROM `priems` WHERE `id` = "' . $eff[$i]['v2'] . '" LIMIT 1')
);
if (isset($eff[$i]['priem']['minmana']) && round( if (isset($eff[$i]['priem']['minmana']) && round(
$eff[$i]['priem']['minmana'] * $eff[$i]['x'] $eff[$i]['priem']['minmana'] * $eff[$i]['x']
) != 0) { ) != 0) {
@ -2501,9 +2476,7 @@ JS;
} }
if ($eff[$i]['hod'] > 0) { if ($eff[$i]['hod'] > 0) {
$this->stats[$this->uids[$this->atacks[$id]['uid' . $j]]]['effects']['hod'] = $eff[$i]['hod']; $this->stats[$this->uids[$this->atacks[$id]['uid' . $j]]]['effects']['hod'] = $eff[$i]['hod'];
mysql_query( Effects::setHod($eff[$i]['id'], $eff[$i]['hod']);
'UPDATE `eff_users` SET `hod` = "' . $eff[$i]['hod'] . '" WHERE `id` = "' . $eff[$i]['id'] . '" LIMIT 1'
);
} else { } else {
//удаляем прием //удаляем прием
if ($eff[$i]['v2'] > 0) { if ($eff[$i]['v2'] > 0) {
@ -2549,7 +2522,7 @@ JS;
} }
/** Осторожно! Подключаются файлы!!! /** Осторожно! Подключаются файлы!!!
* @param $pl * @param array $pl
* @param $u1 * @param $u1
* @param int $t * @param int $t
* @param int|array $u2 * @param int|array $u2
@ -2557,13 +2530,12 @@ JS;
* @return void * @return void
*/ */
public function delPriem( public function delPriem(
$pl, array $pl,
$u1, $u1,
int $t = 1, int $t = 1,
int|array $u2 = 0, int|array $u2 = 0,
string $rznm = 'Очиститься Кровью' string $rznm = 'Очиститься Кровью'
): void ): void {
{
global $u, $priem; global $u, $priem;
if (!isset($pl['priem']['id']) || isset($this->del_val['eff'][$pl['priem']['id']])) { if (!isset($pl['priem']['id']) || isset($this->del_val['eff'][$pl['priem']['id']])) {
return; return;
@ -4128,8 +4100,7 @@ JS;
$hodID, $hodID,
$tm1 = 0, $tm1 = 0,
$tm2 = 0 $tm2 = 0
): void ): void {
{
$time = time(); $time = time();
if ($tm1 == 0) { if ($tm1 == 0) {
$tm1 = isset($this->atacks[$id]) ? $this->atacks[$id]['time'] : $time; $tm1 = isset($this->atacks[$id]) ? $this->atacks[$id]['time'] : $time;
@ -4273,7 +4244,7 @@ JS;
'{tm1} Персонаж {u1} был убит из-за большого количества пропусков хода.', '{tm1} Персонаж {u1} был убит из-за большого количества пропусков хода.',
$this->hodID $this->hodID
); );
Db::sql('update stats set hpNow = 0 where id = ?', [$this->atacks[$id]['uid1']]); Db::sql('update stats set hpnow = 0 where id = ?', [$this->atacks[$id]['uid1']]);
} }
if ($cn2 > Config::get('propsk_die')) { if ($cn2 > Config::get('propsk_die')) {
$this->priemAddLog( $this->priemAddLog(
@ -4281,7 +4252,7 @@ JS;
'{tm1} Персонаж {u1} был убит из-за большого количества пропусков хода.', '{tm1} Персонаж {u1} был убит из-за большого количества пропусков хода.',
$this->hodID $this->hodID
); );
Db::sql('update stats set hpNow = 0 where id = ?', [$this->atacks[$id]['uid2']]); Db::sql('update stats set hpnow = 0 where id = ?', [$this->atacks[$id]['uid2']]);
} }
} }

View File

@ -107,14 +107,14 @@ class Priems
} }
/** используем прием каждый ход /** используем прием каждый ход
* @param $eff * @param Battle $btl
* @param $pr * @param array $eff
* @return bool * @return bool
*/ */
public function hodUsePriem($eff, $pr) public function hodUsePriem(Battle $btl, array $eff): bool
{ {
global $btl;
$u = $this->u; // Для присоедиянемых файлов. $u = $this->u; // Для присоедиянемых файлов.
$pr = $eff['priem'];
$return_main = true; $return_main = true;
$ue = Db::getRow( $ue = Db::getRow(
'select * from users left join stats on (users.id = stats.id) where users.id = ? and battle = ? and hpnow > 0', 'select * from users left join stats on (users.id = stats.id) where users.id = ? and battle = ? and hpnow > 0',

View File

@ -199,6 +199,28 @@ insert into eff_users
Db::sql("insert into eff_users (no_Ace, id_eff, overType, uid, name, data, timeUse) values (1,479,112,?,'Защита от нападения','zashitatk=1',unix_timestamp())", [$userId]); Db::sql("insert into eff_users (no_Ace, id_eff, overType, uid, name, data, timeUse) values (1,479,112,?,'Защита от нападения','zashitatk=1',unix_timestamp())", [$userId]);
} }
public static function setHod(int $id, int $hod, int|string $x = 0, string $data = ''): void
{
$args = ['id' => $id, 'hod' => $hod];
$xsql = '';
$datasql = '';
if ($x === 'x + 1') {
$xsql = ', x = x + 1';
} elseif (is_numeric($x)) {
$xsql = ', x = :x';
$args['x'] = $x;
}
if (!empty($data)) {
$datasql = ', data = :data';
$args['data'] = $data;
}
$sql = "update eff_users set hod = :hod$xsql$datasql where id = :id";
Db::sql($sql, $args);
}
/** /**
* Духовность. Спасение. * Духовность. Спасение.
* Из свитка нападения. * Из свитка нападения.