Замена прямых запросов в БД на метод Effects::addHod.

This commit is contained in:
Ivor Barhansky 2024-02-10 19:31:02 +02:00
parent 66d825bc6e
commit 9843a3a991
3 changed files with 70 additions and 61 deletions

View File

@ -786,8 +786,7 @@ class Priems
$krituet = true,
$heal = 0,
$namenew = null
)
{
) {
$trawm_off = false;
global $btl;
if ($namenew != null) {
@ -966,7 +965,8 @@ class Priems
);
//заносим в лог боя
$vLog = 'time1=' . time() . '||s1=' . $btl->users[$btl->uids[$usu]]['sex'] . '||t1=' . $btl->users[$btl->uids[$usu]]['team'] . '||login1=' . $btl->users[$btl->uids[$usu]]['login'] . '||s2=' . $btl->users[$btl->uids[$uen]]['sex'] . '||t2=' . $btl->users[$btl->uids[$uen]]['team'] . '||login2=' . $btl->users[$btl->uids[$uen]]['login'] . '';
$vLog = 'time1=' . time(
) . '||s1=' . $btl->users[$btl->uids[$usu]]['sex'] . '||t1=' . $btl->users[$btl->uids[$usu]]['team'] . '||login1=' . $btl->users[$btl->uids[$usu]]['login'] . '||s2=' . $btl->users[$btl->uids[$uen]]['sex'] . '||t2=' . $btl->users[$btl->uids[$uen]]['team'] . '||login2=' . $btl->users[$btl->uids[$uen]]['login'] . '';
$mas1 = [
'time' => time(),
'battle' => $btl->i->id,
@ -1614,8 +1614,7 @@ class Priems
$noupdatebtl = 0,
$noplus = 0,
$pname = null
)
{
) {
global $btl;
//$pl = mysql_fetch_assoc(mysql_query('SELECT * FROM `priems` WHERE `id` = ' . (int)$pr));
$pl = Db::getRow('select * from priems where id = ?', [$pr]);
@ -1654,10 +1653,8 @@ class Priems
if (isset($num['id']) && ($num['user_use'] != $this->u->info['id'] && $pl['zmu'] != 2)) {
// удаляем эффект
Db::sql(
'update eff_users set `delete` = unix_timestamp() where id = ?',
[$num['id']]
);
Effects::removeById(0, $num['id']);
$i = 0;
while ($i < count($btl->stats[$btl->uids[$uid]]['effects'])) {
if ($btl->stats[$btl->uids[$uid]]['effects'][$i]['id'] == $num['id']) {
@ -1669,17 +1666,28 @@ class Priems
unset($num);
}
if (!isset($num['id'])) {
$q = 'insert into eff_users (tr_life_user, bj, user_use, hod, v2, img2, id_eff, uid, name, data, overtype, timeuse, v1) values (?,?,?,?,?,?,?,?,?,?,?,?,?)';
$image = !empty($pl['img']) ? $pl['img'] : $pl['id'];
$name = !empty($pname) ? $pname : $pl['name'];
$image .= '.gif';
Db::sql(
$q, [floor($tr_life_user), $bj, $uu, $h, $pl['id'], $image, 22, $uid, $name, $data, 0, $tm, 'priem']
Effects::addCustom(
[
'id_eff' => 22,
'uid' => $uid,
'name' => $name,
'data' => $data,
'timeUse' => $tm,
'user_use' => $uu,
'v1' => 'priem',
'v2' => $pl['id'],
'img2' => $image,
'hod' => $h,
'bj' => $bj,
'tr_life_user' => floor($tr_life_user),
]
);
$lid = Db::lastInsertId();
if ($lid) {
$r = true;
}
/* добавляем данные к $btl->eff */
if ($noupdatebtl == 0) {
@ -1691,15 +1699,9 @@ class Priems
$num['hod'] = $h;
if ($data != -1 && $data != '' && $d2 == 2) {
$num['data'] .= '|' . $data;
Db::sql(
'update eff_users set x = x + 1, hod = ?, data = ? where id = ?',
[$h, $num['data'], $num['id']]
);
Effects::setHod($num['id'], $h, 'x + 1', $num['data']);
} else {
Db::sql(
'update eff_users set x = x + 1, hod = ? where id = ?',
[$h, $num['id']]
);
Effects::setHod($num['id'], $h, 'x + 1');
}
$r = true;
} else {
@ -1707,12 +1709,9 @@ class Priems
$num['hod'] = $h;
if ($data != -1 && $data != '' && $d2 == 2) {
$num['data'] .= '|' . $data;
Db::sql("update eff_users set hod = ?, data = ? where id = ?", [$h, $num['data'], $num['id']]);
Effects::setHod($num['id'], $h, data: $num['data']);
} else {
Db::sql(
'update eff_users set hod = ? where id = ?',
[$h, $num['id']]
);
Effects::setHod($num['id'], $h);
}
$r = true;
}
@ -1982,7 +1981,8 @@ class Priems
} else {
//бьем противника с пропуском хода
mysql_query(
'INSERT INTO `battle_act` (`battle`,`uid1`,`uid2`,`time`,`out1`,`type`,`tpo1`) VALUES ("' . $btl->i->id . '","' . $this->u->info['id'] . '","' . $this->u->info['enemy'] . '","' . time() . '","1","1","2")'
'INSERT INTO `battle_act` (`battle`,`uid1`,`uid2`,`time`,`out1`,`type`,`tpo1`) VALUES ("' . $btl->i->id . '","' . $this->u->info['id'] . '","' . $this->u->info['enemy'] . '","' . time(
) . '","1","1","2")'
);
}
}
@ -2107,17 +2107,17 @@ class Priems
if (isset($id)) {
return Db::getRow('select * from priems where level <= ? and activ > 0 and id = ? order by img,level', [$this->u->info['level'], $id]);
// return Db::getRow(
// 'select * from techniques_categories left join priems on techniques_categories.technique_id = priems.id
// where priems.level <= ? and priems.activ > 0 and priems.id = ? order by priems.img,priems.level', [User::start()->info['level'], $id]
// );
// return Db::getRow(
// 'select * from techniques_categories left join priems on techniques_categories.technique_id = priems.id
// where priems.level <= ? and priems.activ > 0 and priems.id = ? order by priems.img,priems.level', [User::start()->info['level'], $id]
// );
}
return Db::getRows('select * from priems where level <= ? and activ > 0 order by img,level', [$this->u->info['level']]);
// return Db::getRows(
// 'select * from techniques_categories left join priems on techniques_categories.technique_id = priems.id
// where priems.level <= ? and priems.activ > 0 order by priems.img,priems.level', [User::start()->info['level']]
// );
// return Db::getRows(
// 'select * from techniques_categories left join priems on techniques_categories.technique_id = priems.id
// where priems.level <= ? and priems.activ > 0 order by priems.img,priems.level', [User::start()->info['level']]
// );
}
@ -2355,7 +2355,9 @@ class Priems
echo
<<< HTML
<a href="javascript:void(0)" onclick="location.href='main.php?skills=1&rz=4&use_priem=$priem[id]';">
<img class="pwq$priem[category_id] pwqall" onMouseOver="top.popup(this, '(#$priem[id]) <b>$priem[name]</b><Br>{$this->priemInfo($priem)[0]}');" onMouseOut="top.hic();" onMouseDown="top.hic();" style="display:none;margin-top:2px; $cl margin-left:1px;" src="//img.new-combats.tech/i/eff/$priem[img].gif" width="40" height="25" />
<img class="pwq$priem[category_id] pwqall" onMouseOver="top.popup(this, '(#$priem[id]) <b>$priem[name]</b><Br>{$this->priemInfo(
$priem
)[0]}');" onMouseOut="top.hic();" onMouseDown="top.hic();" style="display:none;margin-top:2px; $cl margin-left:1px;" src="//img.new-combats.tech/i/eff/$priem[img].gif" width="40" height="25" />
</a>
HTML;
}

View File

@ -208,6 +208,13 @@ 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]);
}
/**
* @param int $id
* @param int $hod
* @param int|string $x для запроса x = x + 1, вводить 'x + 1'
* @param string $data
* @return void
*/
public static function setHod(int $id, int $hod, int|string $x = 0, string $data = ''): void
{
$args = ['id' => $id, 'hod' => $hod];

View File

@ -227,7 +227,7 @@ class Stats
} elseif (Config::get('effz') > 0 && $e['hod'] == -1) {
$efzz = round(($e['timeUse'] + $e['actionTime'] + $e['timeAce']) - time());
if ($efzz > 0) {
Db::sql('update eff_users set hod = ? where id = ?', [$efzz / Config::get('effz'), $e['id']]);
Effects::setHod($e['id'], $efzz / Config::get('effz'));
}
}
}