Рефакторинг, отказ от $u->testAction('',2) для разрыва зависимости с User::class. Добавлен зачаточный генератор запросов.

This commit is contained in:
2024-05-14 17:24:54 +03:00
parent 7b8ffdfd6a
commit bc136cc030
11 changed files with 802 additions and 742 deletions
+251 -279
View File
@@ -5,6 +5,7 @@ use Core\Db;
use DarksLight2\Training\TrainingManager;
use Helper\Conversion;
use Helper\Math;
use Model\ActionModel;
use Model\Constant\Stat;
use User\Effects;
@@ -1088,276 +1089,248 @@ class Priems
return $rr;
}
public function pruse($id)
public function pruse($id): void
{
global $btl;
$u = $this->u; // Для присоедиянемых файлов.
if ($id == 100500 && $this->u->info['animal'] > 0) {
$use_lst = $this->u->testAction(
'`uid` = "' . $this->u->info['id'] . '" AND `vars` = "animal_use' . $btl->i->id . '" LIMIT 1',
1
);
if (!isset($use_lst['id'])) {
$a = mysql_fetch_assoc(
mysql_query(
'SELECT * FROM `users_animal` WHERE `uid` = "' . $this->u->info['id'] . '" AND `id` = "' . $this->u->info['animal'] . '" AND `pet_in_cage` = "0" AND `delete` = "0" LIMIT 1'
)
);
if ($this->u->stats['hpNow'] < 1) {
echo 'Вы не можете выпустить зверя, вы потеряли все НР';
} elseif (isset($a['id']) && $a['eda'] < 1) {
echo 'Вы не накормили зверя...';
} elseif (isset($a['id'])) {
//Добавляем зверя в бой
$tp = [
1 => 'Кот',
2 => 'Сова',
3 => 'Светляк',
4 => 'Чертяка',
5 => 'Пес',
6 => 'Свин',
7 => 'Дракон',
];
$id = mysql_fetch_assoc(
mysql_query(
'SELECT `id` FROM `test_bot` WHERE `login` = "' . $tp[$a['type']] . ' [' . $a['level'] . ']" LIMIT 1'
)
);
if (isset($id['id']) && $btl->i->type != 500) {
$b = $this->u->addNewbot($id['id'], null, null);
if ($b > 0 && $b) {
$a['eda'] -= 4;
if ($a['eda'] < 0) {
$a['eda'] = 0;
}
$vLog = 'time1=' . time() . '||s1=' . $this->u->info['sex'] . '||t1=' . $this->u->info['team'] . '||login1=' . $this->u->info['login'] . '';
$mas1 = [
'time' => time(),
'battle' => $btl->i->id,
'id_hod' => $btl->hodID,
'vars' => $vLog,
'zona1' => '',
'zonb1' => '',
'zona2' => '',
'zonb2' => '',
'type' => '1',
];
$sex = $this->u->info['sex'] === 1 ? 'a' : '';
$mas1['text'] = "{tm1} {u1} выпустил$sex зверя &quot;<b>" . $a['name'] . '&quot;</b>';
Log::add($mas1);
mysql_query(
'UPDATE `users` SET `login` = "' . $a['name'] . ' (зверь ' . $this->u->info['login'] . ')",`obraz` = "' . $a['obraz'] . '.gif",`battle` = "' . $btl->i->id . '" WHERE `id` = "' . $b['id'] . '" LIMIT 1'
);
mysql_query(
'UPDATE `stats` SET `team` = "' . $this->u->info['team'] . '" WHERE `id` = "' . $b['id'] . '" LIMIT 1'
);
mysql_query(
'UPDATE `users_animal` SET `eda` = "' . $a['eda'] . '" WHERE `id` = "' . $a['id'] . '" LIMIT 1'
);
$this->u->addAction(time(), 'animal_use' . $btl->i->id, $a['level']);
} else {
echo 'Не удалось выпустить зверя...';
}
} else {
//Бот не найден
echo '<br>Не удалось выпустить зверя - он боится...';
}
} else {
//зверь не найден
echo 'У Вас нет зверя ...';
}
} else {
//зверь уже выпущен
echo 'Вы уже выпускали зверя в этом бою ...';
}
$this->processAnimal($btl);
} else {
$p = explode('|', $this->u->info['priems']);
$pz = explode('|', $this->u->info['priems_z']);
if ($p[(int)$id] > 0 && $pz[(int)$id] <= 0 && $this->u->info['hpNow'] >= 1) {
$pl = mysql_fetch_assoc(
mysql_query(
'SELECT * FROM `priems` WHERE `level`<=' . $this->u->info['level'] . ' AND `id` = ' . $p[(int)$id]
)
);
if (isset($pl['id']) && $pl['activ'] != 1) {
if ($pl['activ'] == 0) {
unset($pl);
} elseif ($pl['activ'] > 1) {
//Книжный прием
if ($this->testActiv($pl['activ']) == 0) {
unset($pl);
}
}
}
if (isset($pl['id'])) {
$notr = 0;
$pl['useon_user'] = $this->u->info['enemy'];
if (isset($_POST['useon']) && $_POST['useon'] != '' && $_POST['useon'] != 'none') {
$this->ue = mysql_fetch_assoc(
mysql_query(
'SELECT
`u`.`id`,`u`.`login`,`u`.`login2`,`u`.`online`,`u`.`admin`,`u`.`city`,`u`.`cityreg`,`u`.`align`,`u`.`clan`,
`u`.`level`,`u`.`money`,`u`.`money3`,`u`.`money4`,`u`.`battle`,`u`.`sex`,`u`.`obraz`,`u`.`win`,`u`.`win_t`,
`u`.`lose`,`u`.`lose_t`,`u`.`nich`,`u`.`timeMain`,`u`.`invis`,`u`.`bot_id`,`u`.`animal`,`u`.`type_pers`,
`u`.`notrhod`,`u`.`bot_room`,`u`.`inUser`,`u`.`inTurnir`,`u`.`inTurnirnew`,`u`.`stopexp`,`u`.`real`,
`st`.*
FROM `users` AS `u`
LEFT JOIN `stats` AS `st` ON (`u`.`id`=`st`.`id`)
WHERE (
`u`.`login`="' . mysql_real_escape_string($_POST['useon']) . '" OR
(
`u`.`login2` = "' . mysql_real_escape_string($_POST['useon']) . '" AND
`u`.`login2` != "")
) AND
(
`u`.`inUser` > 0 OR
(
`u`.`battle`="' . $btl->i->id . '" AND
`st`.`hpNow` > 0
)
) ORDER BY `u`.`id` DESC LIMIT 1'
)
);
if (isset($this->ue['id']) && $this->ue['inUser'] > 0) {
$this->ue = mysql_fetch_assoc(
mysql_query(
'SELECT
`u`.`id`,`u`.`login`,`u`.`login2`,`u`.`online`,`u`.`admin`,`u`.`city`,`u`.`cityreg`,`u`.`align`,`u`.`clan`,
`u`.`level`,`u`.`money`,`u`.`money3`,`u`.`money4`,`u`.`battle`,`u`.`sex`,`u`.`obraz`,`u`.`win`,`u`.`win_t`,
`u`.`lose`,`u`.`lose_t`,`u`.`nich`,`u`.`timeMain`,`u`.`invis`,`u`.`bot_id`,`u`.`animal`,`u`.`type_pers`,
`u`.`notrhod`,`u`.`bot_room`,`u`.`inUser`,`u`.`inTurnir`,`u`.`inTurnirnew`,`u`.`stopexp`,`u`.`real`,
`st`.*
FROM `users` AS `u`
LEFT JOIN `stats` AS `st` ON (`u`.`id`=`st`.`id`)
WHERE
`u`.`battle`="' . $btl->i->id . '" AND
`st`.`hpNow` > 0) AND
`u`.`id` = "' . $this->ue['inUser'] . '" ORDER BY `u`.`id` ASC LIMIT 1'
)
);
}
if (!isset($this->ue['id']) && $pl['trUser'] > 0) {
$notr++;
}
if ($pl['team'] == 1) {
//свои
if ($this->u->info['team'] != $this->ue['team']) {
$notr++;
}
} elseif ($pl['team'] == 2) {
//противники
if ($this->u->info['team'] == $this->ue['team']) {
$notr++;
}
}
} else {
$ga = mysql_fetch_assoc(
mysql_query(
'SELECT * FROM `battle_act` WHERE `battle` = "' . $btl->i->id . '" AND `uid1` = "' . $this->u->info['id'] . '" AND `uid2` = "' . $this->u->info['enemy'] . '" LIMIT 1'
)
);
if (($this->u->info['enemy'] == 0 || isset($ga['id'])) && ($pl['tr_hod'] > 0 || $pl['trUser'] > 0)) {
$notr++;
}
}
$notr += $this->testpriem($pl, 1, $this->ue['id']);
if ($this->ue['id'] > 0) {
$notr += $this->testRazmenOldUser($this->ue['id'], $this->u->info['enemy'], $pl['id']);
}
if ($notr == 0) {
mysql_query(
'UPDATE `stats` SET `last_pr` = "' . $pl['id'] . '" WHERE `id` = "' . $this->u->info['id'] . '" LIMIT 1'
);
//Приемы на персонажах
if ($this->ue['id'] > 0) {
$btl->priemsRazmen([$this->u->info['id'], $this->ue['id']], 'fast');
mysql_query(
'UPDATE `eff_users` SET `mark` = 1 WHERE `uid` = "' . $this->ue['id'] . '" AND `delete` = 0'
);
} else {
$btl->priemsRazmen([$this->u->info['id'], $this->u->info['enemy']], 'fast');
mysql_query(
'UPDATE `eff_users` SET `mark` = 1 WHERE `uid` = "' . $this->u->info['enemy'] . '" AND `delete` = 0'
);
}
mysql_query(
'UPDATE `eff_users` SET `mark` = 1 WHERE `uid` = "' . $this->u->info['id'] . '" AND `delete` = 0'
);
if (file_exists('../../_incl_data/class/Priem/' . $pl['id'] . '.php')) {
require('../../_incl_data/class/Priem/' . $pl['id'] . '.php');
$this->testDie($this->ue['id']);
} else {
echo 'useSkill' . $pl['id'];
}
if (!isset($cup)) {
$this->uppz($pl, $id);
//Отнимаем тактики
//$this->mintr($pl);
if ($pl['tr_hod'] > 0) {
$this->trhod($pl);
}
if ($pl['id'] != 258) {
if ($pl['cancel_eff'] == '') {
$pl['cancel_eff'] = '258';
} else {
$pl['cancel_eff'] .= ',258';
}
}
if ($pl['cancel_eff'] != '') {
$i = 0;
$e = explode(',', $pl['cancel_eff']);
while ($i < count($e)) {
if ($e[$i] > 0) {
if ($e[$i] == 258) {
$nem = mysql_fetch_assoc(
mysql_query(
'SELECT * FROM `eff_users` WHERE `uid` = "' . $this->u->info['id'] . '" AND `v1` = "priem" AND `v2` = "' . $e[$i] . '" AND `delete` = "0" AND `mark` = 1 LIMIT 1'
)
);
} else {
$nem = mysql_fetch_assoc(
mysql_query(
'SELECT * FROM `eff_users` WHERE `uid` = "' . $this->ue['id'] . '" AND `v1` = "priem" AND `v2` = "' . $e[$i] . '" AND `delete` = "0" AND `mark` = 1 LIMIT 1'
)
);
}
if (isset($nem['id'])) {
$nem['priem'] = mysql_fetch_assoc(
mysql_query(
'SELECT * FROM `priems` WHERE `id` = "' . $e[$i] . '" LIMIT 1'
)
);
if (isset($nem['id'])) {
$btl->delPriem($nem, $btl->users[$btl->uids[$this->ue['id']]], 500);
}
}
}
$i++;
}
}
}
}
}
}
$this->processPriem($id, $btl);
}
}
//для папки priems
private function processAnimal(Battle $btl): void
{
if ($this->u->stats['hpNow'] < 1) {
echo 'Вы не можете выпустить зверя, вы потеряли все НР';
return;
}
$alreadyReleased = $this->u->testAction(
'`uid` = "' . $this->u->info['id'] . '" AND `vars` = "animal_use' . $btl->i->id . '" LIMIT 1',
1
);
if (!empty($alreadyReleased['id'])) {
echo 'Вы уже выпускали зверя в этом бою ...';
return;
}
$animal = Db::getRow('select * from users_animal where uid = ? and id = ? and pet_in_cage = 0', [$this->u->info['id'], $this->u->info['animal']]);
if (!isset($animal['id'])) {
echo 'У вас нет зверя.';
return;
}
if ($animal['eda'] < 1) {
echo 'Вы не накормили зверя.';
return;
}
$animalTypes = [
1 => 'Кот',
2 => 'Сова',
3 => 'Светляк',
4 => 'Чертяка',
5 => 'Пес',
6 => 'Свин',
7 => 'Дракон',
];
$botLogin = $animalTypes[$animal['type']] . ' [' . $animal['level'] . ']';
$botId = Db::getValue('select id from test_bot where login = ?', [$botLogin]);
if (!$botId) {
echo 'Системная ошибка: Неизвестный зверь!';
return;
}
$b = $this->u->addNewbot($botId);
if (!$b) {
echo 'Не удалось призвать зверя.';
return;
}
if ($b > 0) {
$animal['eda'] -= 4;
if ($animal['eda'] < 0) {
$animal['eda'] = 0;
}
$logData = [
'time' => time(),
'battle' => $btl->i->id,
'id_hod' => $btl->hodID,
'vars' => 'time1=' . time() . '||s1=' . $this->u->info['sex'] . '||t1=' . $this->u->info['team'] . '||login1=' . $this->u->info['login'],
'zona1' => '',
'zonb1' => '',
'zona2' => '',
'zonb2' => '',
'type' => '1',
'text' => '{tm1} {u1} выпустил' . ($this->u->info['sex'] === 1 ? 'a' : '') . " зверя «{$animal['name']}».",
];
Log::add($logData);
Db::sql('update users set login = ?, obraz = ?, battle = ? where id = ?', [$animal['name'], $animal['obraz'] . '.gif', $btl->i->id, $b['id']]);
Db::sql('update stats set team = ? where id = ?', [$this->u->info['team'], $b['id']]);
Db::sql('update users_animal set eda = ? where id = ?', [$animal['eda'], $animal['id']]);
$this->u->addAction(time(), 'animal_use' . $btl->i->id, $animal['level']);
}
}
private function processPriem(int $id, Battle $btl): void
{
$target = '';
$targetNotEmpty = false;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$target = (string)filter_input(INPUT_POST, 'useon');
$targetNotEmpty = $target && $target !== 'none';
}
$cup = false;
$priemsOnPlayer = explode('|', $this->u->info['priems']);
$pz = explode('|', $this->u->info['priems_z']);
if ($priemsOnPlayer[$id] <= 0 || $pz[$id] > 0 || $this->u->info['hpNow'] < 1) {
return;
}
$priem = Db::getRow('select * from priems where level <= ? and id = ?', [$this->u->info['level'], $priemsOnPlayer['id']]);
if (isset($priem['id']) && $priem['activ'] != 1) {
if ($priem['activ'] == 0) {
unset($priem);
} elseif ($priem['activ'] > 1) {
//Книжный прием
if ($this->testActiv($priem['activ']) == 0) {
unset($priem);
}
}
}
if (!isset($priem['id'])) {
return;
}
$notr = 0;
$priem['useon_user'] = $this->u->info['enemy'];
if ($targetNotEmpty) {
$this->ue = Db::getRow('select
users.id, login, login2, online, admin, city, cityreg, align, clan, level, money, money3, money4, battle, sex, obraz, win, win_t, lose, lose_t, nich,
timeMain, invis, bot_id, animal, type_pers, notrhod, bot_room, inUser, inTurnir, inTurnirnew, stopexp, `real`, stats.*
from users inner join stats on users.id = stats.id where (login = ? or login2 = ?) and (inUser > 0 or (battle = ? and hpNow > 0))
order by users.id desc limit 1', [$target, $target, $btl->i->id]);
if (isset($this->ue['id']) && $this->ue['inUser'] > 0) {
$this->ue = Db::getRow('select
users.id, login, login2, online, admin, city, cityreg, align, clan, level, money, money3, money4, battle, sex, obraz, win, win_t, lose, lose_t, nich,
timeMain, invis, bot_id, animal, type_pers, notrhod, bot_room, inUser, inTurnir, inTurnirnew, stopexp, `real`, stats.*
from users inner join stats on users.id = stats.id where battle = ? and hpNow > 0 and users.id = ?
order by users.id limit 1', [$btl->i->id, $this->ue['inUser']]);
}
if (!isset($this->ue['id']) && $priem['trUser'] > 0) {
$notr++;
}
if ($priem['team'] == 1) {
//свои
if ($this->u->info['team'] != $this->ue['team']) {
$notr++;
}
} elseif ($priem['team'] == 2) {
//противники
if ($this->u->info['team'] == $this->ue['team']) {
$notr++;
}
}
} else {
$check = Db::getValue('select count(id) from battle_act where battle = ? and uid1 = ? and uid2 = ?', [$btl->i->id, $this->u->info['id'], $this->u->info['enemy']]) > 0;
if (($this->u->info['enemy'] == 0 || $check) && ($priem['tr_hod'] > 0 || $priem['trUser'] > 0)) {
$notr++;
}
}
$notr += $this->testpriem($priem, 1, $this->ue['id']);
if ($this->ue['id'] > 0) {
$notr += $this->testRazmenOldUser($this->ue['id'], $this->u->info['enemy'], $priem['id']);
}
if ($notr != 0) {
return;
}
Db::sql('update stats set last_pr = ? where id = ?', [$priem['id'], $this->u->info['id']]);
//Приемы на персонажах
$markuids = [];
if ($this->ue['id'] > 0) {
$btl->priemsRazmen([$this->u->info['id'], $this->ue['id']], 'fast');
$markuids[] = $this->ue['id'];
} else {
$btl->priemsRazmen([$this->u->info['id'], $this->u->info['enemy']], 'fast');
$markuids[] = $this->u->info['enemy'];
}
$markuids[] = $this->u->info['id'];
Db::sql('update eff_users set mark = 1 where uid in (?)', [implode(',', $markuids)]);
if (file_exists('../../_incl_data/class/Priem/' . $priem['id'] . '.php')) {
$u = $this->u; // Для присоедиянемых файлов.
require_once '../../_incl_data/class/Priem/' . $priem['id'] . '.php';
$this->testDie($this->ue['id']);
} else {
echo 'useSkill' . $priem['id'];
}
if ($cup) { // Из подключаемых файлов.
return;
}
$this->uppz($priem, $id);
//Отнимаем тактики
//$this->mintr($pl);
if ($priem['tr_hod'] > 0) {
$this->trhod($priem);
}
if ($priem['id'] != 258) {
if ($priem['cancel_eff'] == '') {
$priem['cancel_eff'] = '258';
} else {
$priem['cancel_eff'] .= ',258';
}
}
if ($priem['cancel_eff'] == '') {
return;
}
$i = 0;
$e = explode(',', $priem['cancel_eff']);
while ($i < count($e)) {
if ($e[$i] <= 0) {
$i++;
continue;
}
if ($e[$i] == 258) {
$uid = $this->u->info['id'];
} else {
$uid = $this->ue['id'];
}
$nem = Db::getRow('select * from eff_users where uid = ? and v1 = \'priem\' and v2 = ? and mark = 1 limit 1', [$uid, $e[$i]]);
if (isset($nem['id'])) {
$nem['priem'] = Db::getRow('select * from priems where id = ?', [$e['id']]);
$btl->delPriem($nem, $btl->users[$btl->uids[$this->ue['id']]], 500);
}
$i++;
}
}
private function testActiv($id)
{
@@ -1368,11 +1341,8 @@ class Priems
$this->u->info['id'] > 0) {
$r = 1;
} else {
$tst = $this->u->testAction(
'`uid` = "' . $this->u->info['id'] . '" AND `time` < ' . time() . ' AND `vars` = "read" AND `vals` = "' . $id . '" LIMIT 1',
1
);
if (isset($tst['id'])) {
$test = (bool)Db::getValue("select count(id) from actions where uid = ? and time < unix_timestamp() and vars = 'read' and vals = ?", [$this->u->info['id'], $id]);
if ($test) {
$r = 1;
}
}
@@ -1428,11 +1398,8 @@ class Priems
if ($pl['xuse'] > 0) {
$xu = $this->u->testAction(
'`vars` = "use_priem_' . $btl->i->id . '_' . $this->u->info['id'] . '" AND `vals` = "' . $pl['id'] . '" LIMIT ' . $pl['xuse'],
2
);
if ($xu[0] >= $pl['xuse']) {
$xu = ActionModel::testCount(["vars = use_priem_{$btl->i->id}_{$this->u->info['id']}", "vals = {$pl['id']}"], $pl['xuse']);
if ($xu >= $pl['xuse']) {
$notr++;
}
}
@@ -2046,6 +2013,8 @@ class Priems
}
}
//выводим приемы $id - 1 (вне боя), 2 - в бою
/** Одеть приём в слот?
* @param $id
* @return void
@@ -2099,8 +2068,6 @@ class Priems
}
}
//выводим приемы $id - 1 (вне боя), 2 - в бою
public function getTechniquesInfo(?int $id = null): array
{
# SELECT * FROM `priems` WHERE `level`<="' . $this->u->info['level'] . '" AND `activ` > "0" AND `id` = "' . $id . '" LIMIT 1
@@ -2120,7 +2087,6 @@ class Priems
// );
}
public function seeMyPriems(): void
{
$i = 0;
@@ -2243,6 +2209,8 @@ class Priems
return [0 => $lvar, 1 => $pz];
}
//Мощность / подавление / сопротивление и т.д.
/**
* Генерирует html строку для вставки в JS $("#priems").html(" сюда ");
* @return string
@@ -2337,8 +2305,6 @@ class Priems
return str_replace('"', '\\"', $pr);
}
//Мощность / подавление / сопротивление и т.д.
public function getByCategory(?int $category_id = null)
{
@@ -2437,10 +2403,16 @@ class Priems
);
}
/**
* Что-то для подключаемых файлов приёмов.
*
* @param $uid
* @param $mg
* @return bool|mysqli_result|resource
*/
private function rezadEff($uid, $mg)
{
global $btl;
//$this->rezadEff($this->u->info['id'],'wis_fire_');
$md = '';
$md2 = '';
$ex = explode('|', $btl->users[$btl->uids[$uid]]['priems']);