Замена 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\Db;
use DTO\BattlePriem;
use Helper\Comparsion;
use Helper\Conversion;
use Model\Constant\Stat;
use User\Effects;
@ -246,7 +247,7 @@ class Battle
/**
* @param int|null $experience
* @param bool $hardcore поединок с гарантированной травмой
* @param bool $hardcore поединок с гарантированной травмой
* @return array|int[]
*/
public static function getType(?int $experience, bool $hardcore = false): array
@ -364,10 +365,10 @@ class Battle
Db::sql(
'update stats set last_hp = ?, tactic7 = ? where id = ?', [
$this->users[$this->uids[$uid]]['last_hp'],
$this->users[$this->uids[$uid]]['tactic7'],
$uid,
]
$this->users[$this->uids[$uid]]['last_hp'],
$this->users[$this->uids[$uid]]['tactic7'],
$uid,
]
);
return (int)$hp;
@ -1034,12 +1035,14 @@ JS;
//конец излома
$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 . '")'
'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 {
$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'
'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']]]['mpNow'] += $this->stats[$this->uids[$u->info['id']]]['mpAll'] * 0.25;
@ -1144,9 +1147,9 @@ JS;
/**
* @param array $botLogins
* @param int $counter
* @param int $obr
* @param int $unique для совместимости с непонятным вызовом User->addAction
* @param int $counter
* @param int $obr
* @param int $unique для совместимости с непонятным вызовом User->addAction
* при вызове уникального монстра.
* @return void
*/
@ -1236,14 +1239,14 @@ JS;
/** Осторожно! Подключаются файлы!!!
* Трогать очень осторожно. Этот шайтан как-то проверяет приёмы на враге
* и рассчитывает урон учитывая и эти приёмы тоже.
* @param int $uid1
* @param int $uid2
* @param int $priem
* @param int $uid1
* @param int $uid2
* @param int $priem
* @param $yron
* @param int $profil
* @param int $profil
* @param bool $stabil
* @param bool $test
* @param int $inlog
* @param int $inlog
* @return float|int|mixed
*/
public function testYronPriem(
@ -1255,8 +1258,7 @@ JS;
bool $stabil,
bool $test = false,
int $inlog = 0
): mixed
{
): mixed {
/**
* profil = {
@ -2081,35 +2083,21 @@ JS;
if (!isset($this->atacks[$id]) || $this->atacks[$id]['lock'] != 0) {
return;
}
//Прием разгадать тактику
$i = 1;
$j = 2;
while ($i <= 2) {
$untac = mysql_fetch_array(
mysql_query(
'SELECT `id` FROM `eff_users` WHERE `v1` = "priem" AND `v2` = 217 AND `uid` = "' . $this->atacks[$id]['uid' . $i] . '" AND `delete` = 0 LIMIT 1'
)
);
$agrs = mysql_fetch_array(
mysql_query(
'SELECT `id` FROM `eff_users` WHERE `v1` = "priem" AND `v2` = 211 AND `uid` = "' . $this->atacks[$id]['uid' . $j] . '" AND `delete` = 0 LIMIT 1'
)
);
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);
}
$hasResolveTacticPriem = Db::getValue("select count(id) from eff_users where v1 = 'priem' and v2 = 217 and uid = ?", [$this->atacks[$id]['uid' . $i]]) > 0;
$hasNoAgressiveShield = Db::getValue("select count(id) from eff_users where v1 = 'priem' and v2 = 211 and uid = ?", [$this->atacks[$id]['uid' . $j]]) == 0;
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
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
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);
}
}
$j--;
@ -2186,6 +2174,7 @@ JS;
// Проверяем приемы
// Получаем приемы игроков
$at = $this->priemsTestRazmen($id, $at);
// Собираем размен (пересчитываем и расчитываем урон и т.д)
$at = $this->priemsRestartRazmen($id, $at); //Повторная проверка приемов (если требуется)
@ -2211,12 +2200,12 @@ JS;
//Возращаем зоны блока
$this->restZonb($this->atacks[$id]['uid1'], $this->atacks[$id]['uid2']);
//обновляем задержки приемов
$zd1 = explode('|', $this->users[$this->uids[$this->atacks[$id]['uid1']]]['priems_z']);
$zd2 = explode('|', $this->users[$this->uids[$this->atacks[$id]['uid2']]]['priems_z']);
$prmos = [];
$i5 = 0;
$i5 = 0;
while ($i5 < 51) {
if (isset($zd1[$i5]) && $zd1[$i5] > 0) {
//Если приемы не требуют ход
@ -2232,7 +2221,7 @@ JS;
}
$i5++;
}
unset($prmos);
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'];
@ -2249,23 +2238,18 @@ JS;
} elseif ($this->atacks[$id]['uid2'] == $u->info['id']) {
$u->info['priems_z'] = implode('|', $zd2);
}
//Проверяем тактики
$i = 1;
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] = 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;
}
$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]['uid2']]]['tactic' . $i] = Comparsion::minimax($this->users[$this->uids[$this->atacks[$id]['uid2']]]['tactic' . $i], 0, 25);
$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']]);
//Обновляем задержки заклинаний, пирогов, тактик
@ -2355,9 +2339,8 @@ JS;
if (isset($eff[$i])) {
if ($eff[$i]['timeUse'] == 77 && $eff[$i]['hod'] > -1) {
$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) {
//Отнимаем ману у того кто кастовал
$priem->minMana(
@ -2411,20 +2394,17 @@ JS;
$pvr['mpSee'] = '+' . $pvr['mp'];
$pvr['mpNow'] += $pvr['mp'];
}
if ($pvr['mpNow'] > $pvr['mpAll']) {
$pvr['mpNow'] = $pvr['mpAll'];
} elseif ($pvr['mpNow'] < 0) {
$pvr['mpNow'] = 0;
}
$pvr['mpNow'] = Comparsion::minimax($pvr['mpNow'], 0, $pvr['mpAll']);
if ($pvr['mpSee'] == 0) {
$pvr['mpSee'] = '--';
}
$this->stats[$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['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) {
$this->stats[$this->uids[$this->atacks[$id]['uid' . $j]]]['effects']['hod'] = $eff[$i]['hod'];
mysql_query(
'UPDATE `eff_users` SET `hod` = "' . $eff[$i]['hod'] . '" WHERE `id` = "' . $eff[$i]['id'] . '" LIMIT 1'
);
Effects::setHod($eff[$i]['id'], $eff[$i]['hod']);
} else {
//удаляем прием
if ($eff[$i]['v2'] > 0) {
@ -2460,14 +2439,10 @@ JS;
}
}
} elseif ($eff[$i]['timeUse'] == 77 && $eff[$i]['hod'] == -2) {
$eff[$i]['priem'] = mysql_fetch_array(
mysql_query('SELECT * FROM `priems` WHERE `id` = "' . $eff[$i]['v2'] . '" LIMIT 1')
);
$priem->hodUsePriem($eff[$i], $eff[$i]['priem']);
$eff[$i]['priem'] = Db::getRow('select * from priems where id = ?', [$eff[$i]['v2']]);
$priem->hodUsePriem($this, $eff[$i]);
} else {
$eff[$i]['priem'] = mysql_fetch_array(
mysql_query('SELECT * FROM `priems` WHERE `id` = "' . $eff[$i]['v2'] . '" LIMIT 1')
);
$eff[$i]['priem'] = Db::getRow('select * from priems where id = ?', [$eff[$i]['v2']]);
if (isset($eff[$i]['priem']['minmana']) && round(
$eff[$i]['priem']['minmana'] * $eff[$i]['x']
) != 0) {
@ -2501,9 +2476,7 @@ JS;
}
if ($eff[$i]['hod'] > 0) {
$this->stats[$this->uids[$this->atacks[$id]['uid' . $j]]]['effects']['hod'] = $eff[$i]['hod'];
mysql_query(
'UPDATE `eff_users` SET `hod` = "' . $eff[$i]['hod'] . '" WHERE `id` = "' . $eff[$i]['id'] . '" LIMIT 1'
);
Effects::setHod($eff[$i]['id'], $eff[$i]['hod']);
} else {
//удаляем прием
if ($eff[$i]['v2'] > 0) {
@ -2549,21 +2522,20 @@ JS;
}
/** Осторожно! Подключаются файлы!!!
* @param $pl
* @param array $pl
* @param $u1
* @param int $t
* @param int $t
* @param int|array $u2
* @param string $rznm
* @param string $rznm
* @return void
*/
public function delPriem(
$pl,
$u1,
int $t = 1,
array $pl,
$u1,
int $t = 1,
int|array $u2 = 0,
string $rznm = 'Очиститься Кровью'
): void
{
string $rznm = 'Очиститься Кровью'
): void {
global $u, $priem;
if (!isset($pl['priem']['id']) || isset($this->del_val['eff'][$pl['priem']['id']])) {
return;
@ -4128,8 +4100,7 @@ JS;
$hodID,
$tm1 = 0,
$tm2 = 0
): void
{
): void {
$time = time();
if ($tm1 == 0) {
$tm1 = isset($this->atacks[$id]) ? $this->atacks[$id]['time'] : $time;
@ -4273,7 +4244,7 @@ JS;
'{tm1} Персонаж {u1} был убит из-за большого количества пропусков хода.',
$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')) {
$this->priemAddLog(
@ -4281,7 +4252,7 @@ JS;
'{tm1} Персонаж {u1} был убит из-за большого количества пропусков хода.',
$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 $pr
* @param Battle $btl
* @param array $eff
* @return bool
*/
public function hodUsePriem($eff, $pr)
public function hodUsePriem(Battle $btl, array $eff): bool
{
global $btl;
$u = $this->u; // Для присоедиянемых файлов.
$pr = $eff['priem'];
$return_main = true;
$ue = Db::getRow(
'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]);
}
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);
}
/**
* Духовность. Спасение.
* Из свитка нападения.