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

This commit is contained in:
Ivor Barhansky 2024-02-10 21:33:10 +02:00
parent 9843a3a991
commit b79a0ccf1b

View File

@ -920,12 +920,12 @@ JS;
$ir = 0; $ir = 0;
$bi = 0; $bi = 0;
$stats = new Stats($u);
if ($this->i->id > 0) { if ($this->i->id > 0) {
if ($this->i->izlom == 0) { if ($this->i->izlom == 0) {
//данные о игроках в бою //данные о игроках в бою
$trl = mysql_query( $bu = Db::getRows("select *, if(login2 = '', login, login2) as login2 from users left join stats on users.id = stats.id where battle = ? order by bot desc", [$this->i->id]);
'SELECT `u`.`no_ip`,`u`.`id`,`u`.`notrhod`,`u`.`login`,`u`.`login2`,`u`.`sex`,`u`.`online`,`u`.`admin`,`u`.`align`,`u`.`align_lvl`,`u`.`align_exp`,`u`.`clan`,`u`.`level`,`u`.`battle`,`u`.`obraz`,`u`.`win`,`u`.`lose`,`u`.`nich`,`u`.`animal`,`st`.`stats`,`st`.`hpNow`,`st`.`mpNow`,`st`.`exp`,`st`.`dnow`,`st`.`team`,`st`.`battle_yron`,`st`.`battle_exp`,`st`.`enemy`,`st`.`battle_text`,`st`.`upLevel`,`st`.`timeGo`,`st`.`timeGoL`,`st`.`bot`,`st`.`lider`,`st`.`btl_cof`,`st`.`tactic1`,`st`.`tactic2`,`st`.`tactic3`,`st`.`tactic4`,`st`.`tactic5`,`st`.`tactic6`,`st`.`tactic7`,`st`.`x`,`st`.`y`,`st`.`battleEnd`,`st`.`priemslot`,`st`.`priems`,`st`.`priems_z`,`st`.`bet`,`st`.`clone`,`st`.`atack`,`st`.`bbexp`,`st`.`res_x`,`st`.`res_y`,`st`.`res_s`,`st`.`id`,`st`.`last_hp`,`st`.`last_pr`,`u`.`sex`,`u`.`money`,`u`.`money3`,`u`.`money2`,`u`.`bot_id` FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`battle` = "' . $this->i->id . '" ORDER BY `st`.`bot` DESC'
);
$this->users = []; $this->users = [];
$this->stats = []; $this->stats = [];
@ -933,40 +933,30 @@ JS;
$this->bots = []; $this->bots = [];
$this->iBots = []; $this->iBots = [];
while ($pl = mysql_fetch_array($trl)) { foreach ($bu as $user) {
//записываем данные $this->users[$ir] = $user;
if ($pl['login2'] == '') { $this->uids[$user['id']] = $ir;
$pl['login2'] = $pl['login']; if ($user['bot'] > 0) {
} $this->bots[$bi] = $user['id'];
$this->users[$ir] = $pl; $this->iBots[$user['id']] = $bi;
$this->uids[$pl['id']] = $ir;
if ($pl['bot'] > 0) {
$this->bots[$bi] = $pl['id'];
$this->iBots[$pl['id']] = $bi;
$bi++; $bi++;
} }
//записываем статы $this->stats[$ir] = $stats->getStats($user['id']);
$this->stats[$ir] = $u->getStats($pl['id'], 0, 0, false, false, true);
$ir++; $ir++;
} }
} elseif (!isset($this->uids[$u->info['id']])) { } elseif (!isset($this->uids[$u->info['id']])) {
//данные о игроках в бою //данные о игроках в бою
$trl = mysql_query( $bu = Db::getRows("select *, if(login2 = '', login, login2) as login2 from users left join stats on users.id = stats.id where users.id = ?", [$this->i->id]);
'SELECT `u`.`no_ip`,`u`.`id`,`u`.`notrhod`,`u`.`login`,`u`.`login2`,`u`.`sex`,`u`.`online`,`u`.`admin`,`u`.`align`,`u`.`align_lvl`,`u`.`align_exp`,`u`.`clan`,`u`.`level`,`u`.`battle`,`u`.`obraz`,`u`.`win`,`u`.`lose`,`u`.`nich`,`u`.`animal`,`st`.`stats`,`st`.`hpNow`,`st`.`mpNow`,`st`.`exp`,`st`.`dnow`,`st`.`team`,`st`.`battle_yron`,`st`.`battle_exp`,`st`.`enemy`,`st`.`battle_text`,`st`.`upLevel`,`st`.`timeGo`,`st`.`timeGoL`,`st`.`bot`,`st`.`lider`,`st`.`btl_cof`,`st`.`tactic1`,`st`.`tactic2`,`st`.`tactic3`,`st`.`tactic4`,`st`.`tactic5`,`st`.`tactic6`,`st`.`tactic7`,`st`.`x`,`st`.`y`,`st`.`battleEnd`,`st`.`priemslot`,`st`.`priems`,`st`.`priems_z`,`st`.`bet`,`st`.`clone`,`st`.`atack`,`st`.`bbexp`,`st`.`res_x`,`st`.`res_y`,`st`.`res_s`,`st`.`id`,`st`.`last_hp`,`st`.`last_pr`,`u`.`sex`,`u`.`money`,`u`.`bot_id`,`u`.`money3`,`u`.`money2` FROM `users` AS `u` LEFT JOIN `stats` AS `st` ON (`u`.`id` = `st`.`id`) WHERE `u`.`id` = ' . $this->i->id foreach ($bu as $user) {
); $this->users[] = $user;
$pl = mysql_fetch_array($trl); $this->uids[$user['id']] = $ir;
//записываем данные if ($user['bot'] > 0) {
if ($pl['login2'] == '') { $this->bots[] = $user['id'];
$pl['login2'] = $pl['login']; $this->iBots[$user['id']] = $bi;
} }
$this->users[] = $pl; $this->stats[] = $stats->getStats($user['id']);
$this->uids[$pl['id']] = $ir;
if ($pl['bot'] > 0) {
$this->bots[] = $pl['id'];
$this->iBots[$pl['id']] = $bi;
} }
//записываем статы
$this->stats[] = $u->getStats($pl['id'], 0, 0, false, false, true);
} }
} }
@ -1034,34 +1024,36 @@ JS;
if ($j == 0) { if ($j == 0) {
//конец излома //конец излома
$this->finish->finishBattle($tml, $tmv); $this->finish->finishBattle($tml, $tmv);
mysql_query( Db::sql(
'INSERT INTO `izlom_rating` (`uid`,`time`,`voln`,`level`,`bots`,`rep`,`obr`,`btl`) VALUES ("' . $u->info['id'] . '","' . time( 'insert into izlom_rating (uid, time, voln, level, obr, btl) values (?,unix_timestamp(),?,?,?,?)',
) . '","' . $this->i->izlomroundsee . '","' . $this->i->izlomlvl . '","0","0","' . ($this->i->izlomobr - $this->i->izlomobrnow) . '","' . $this->i->id . '")' [$u->info['id'], $this->i->izlomroundsee, $this->i->izlomlvl, $this->i->izlomobr - $this->i->izlomobrnow, $this->i->id]
); );
} else { } else {
$this->i->setIzlomround($iz['round']);
mysql_query( Db::sql(
'UPDATE `battle` SET `izlomObrNow` = ' . $obr . ',`izlomObr` = `izlomObr` + ' . $obr . ',`timeout` = (`timeout`+5),`izlomRound` = "' . ($this->i->getIzlomround( 'update battle set izlomobrnow = ?, izlomobr = izlomobr + ?, timeout = timeout + 5, izlomround = izlomround + 1, izlomroundsee = izlomroundsee + 1 where id = ?',
) + 1) . '",`izlomRoundSee` = `izlomRoundSee`+1 WHERE `id` = "' . $this->i->id . '" LIMIT 1' [$obr, $obr, $this->i->id]
); );
$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;
$this->users[$this->uids[$u->info['id']]]['hpNow'] = $this->stats[$this->uids[$u->info['id']]]['hpAll']; $this->users[$this->uids[$u->info['id']]]['hpNow'] = $this->stats[$this->uids[$u->info['id']]]['hpAll'];
$this->users[$this->uids[$u->info['id']]]['mpNow'] = $this->stats[$this->uids[$u->info['id']]]['mpAll']; $this->users[$this->uids[$u->info['id']]]['mpNow'] = $this->stats[$this->uids[$u->info['id']]]['mpAll'];
//где это брать?? //где это брать??
$vLog = 'at1=00000||at2=00000||zb1=' . $this->stats[$this->uids[$u1]]['zonb'] . $vLog = 'at1=00000||at2=00000||zb1=' . $this->stats[$this->uids[$u->info['id']]]['zonb'] .
'||zb2=' . $this->stats[$this->uids[$u2]]['zonb'] . '||zb2=' . $this->stats[$this->uids[$u->info['enemy']]]['zonb'] .
'||bl1=' . $this->atacks[$id]['b' . $a] . '||bl1=' . $this->atacks[$this->i->id]['b1'] .
'||bl2=' . $this->atacks[$id]['b' . $b] . '||bl2=' . $this->atacks[$this->i->id]['b2'] .
'||time1=' . $this->atacks[$id]['time'] . '||time1=' . $this->atacks[$this->i->id]['time'] .
'||time2=' . $this->atacks[$id]['time2'] . '||time2=' . $this->atacks[$this->i->id]['time2'] .
'||s2=' . $this->users[$this->uids[$u2]]['sex'] . '||s2=' . $this->users[$this->uids[$u->info['enemy']]]['sex'] .
'||s1=' . $this->users[$this->uids[$u1]]['sex'] . '||s1=' . $this->users[$this->uids[$u->info['id']]]['sex'] .
'||t2=' . $this->users[$this->uids[$u2]]['team'] . '||t2=' . $this->users[$this->uids[$u->info['enemy']]]['team'] .
'||t1=' . $this->users[$this->uids[$u1]]['team'] . '||t1=' . $this->users[$this->uids[$u->info['id']]]['team'] .
'||login1=' . $this->users[$this->uids[$u1]]['login2'] . '||login1=' . $this->users[$this->uids[$u->info['id']]]['login2'] .
'||login2=' . $this->users[$this->uids[$u2]]['login2']; '||login2=' . $this->users[$this->uids[$u->info['enemy']]]['login2'];
$mas = [ $mas = [
'battle' => $this->i->id, 'battle' => $this->i->id,
@ -1426,7 +1418,6 @@ JS;
public function testUserInfoBattle($uid): void public function testUserInfoBattle($uid): void
{ {
global $u;
if (isset($this->uids[$uid])) { if (isset($this->uids[$uid])) {
return; return;
} }
@ -1435,24 +1426,13 @@ JS;
if (!isset($this->uids[$uid])) { if (!isset($this->uids[$uid])) {
$this->uids[$uid] = count($this->users); $this->uids[$uid] = count($this->users);
} }
$this->users[$this->uids[$uid]] = mysql_fetch_array(
mysql_query( $stats = new Stats(User::start());
'SELECT $this->users[$this->uids[$uid]] = User::getInfo($uid);
`u`.`id`,`u`.`login`,`u`.`login2`,`u`.`online`,`u`.`admin`,`u`.`city`,`u`.`cityreg`,`u`.`align`,`u`.`align_lvl`,`u`.`align_exp`,`u`.`clan`, $this->stats[$this->uids[$uid]] = $stats->getStats($uid); //getStats($this->users[$this->uids[$uid]])
`u`.`level`,`u`.`money`,`u`.`money3`,`u`.`money2`,`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`.`id` = "' . $uid . '" LIMIT 1'
)
);
$stats = new Stats($u);
$this->stats[$this->uids[$uid]] = $stats->getStats(); //getStats($this->users[$this->uids[$uid]])
//fixme много чего повторно берется //fixme много чего повторно берется
} }
//Добавляем размены в лог
/** /**
* Расчет опыта * Расчет опыта
* @param $y * @param $y
@ -1485,216 +1465,136 @@ JS;
return (int)round($addExp); return (int)round($addExp);
} }
//Добавляем в лог действия приема public function addNewStat(array $stat): void
public function addNewStat($stat): void
{ {
$sql = 'insert into battle_stat (battle, uid1, uid2, time, type, a, b, type_a, type_b, ma, mb, yrn, yrn_krit, tm1, tm2)
values (:battle,:uid1,:uid2,:time,:type,:a,:b,:type_a,:type_b,:ma,:mb,:yrn,:yrn_krit,:tm1,:tm2)';
if (isset($stat[1])) { if (isset($stat[1])) {
mysql_query( $stat[1]['battle'] = $this->i->id;
'INSERT INTO `battle_stat` Db::sql($sql, $stat[1]);
( `battle`,`uid1`,`uid2`,`time`,`type`,`a`,`b`,`ma`,`mb`,`type_a`,`type_b`,`yrn`,`yrn_krit`,`tm1`,`tm2` ) VALUES (
"' . $this->i->id . '",
"' . $stat[1]['uid1'] . '",
"' . $stat[1]['uid2'] . '",
"' . $stat[1]['time'] . '",
"' . $stat[1]['type'] . '",
"' . $stat[1]['a'] . '",
"' . $stat[1]['b'] . '",
"' . $stat[1]['ma'] . '",
"' . $stat[1]['mb'] . '",
"' . $stat[1]['type_a'] . '",
"' . $stat[1]['type_b'] . '",
"' . $stat[1]['yrn'] . '",
"' . $stat[1]['yrn_krit'] . '",
"' . $stat[1]['tm1'] . '",
"' . $stat[1]['tm2'] . '"
)'
);
}
if (isset($stat[2])) {
mysql_query(
'INSERT INTO `battle_stat`
( `battle`,`uid1`,`uid2`,`time`,`type`,`a`,`b`,`ma`,`mb`,`type_a`,`type_b`,`yrn`,`yrn_krit`,`tm1`,`tm2` ) VALUES (
"' . $this->i->id . '",
"' . $stat[2]['uid1'] . '",
"' . $stat[2]['uid2'] . '",
"' . $stat[2]['time'] . '",
"' . $stat[2]['type'] . '",
"' . $stat[2]['a'] . '",
"' . $stat[2]['b'] . '",
"' . $stat[1]['ma'] . '",
"' . $stat[2]['mb'] . '",
"' . $stat[2]['type_a'] . '",
"' . $stat[2]['type_b'] . '",
"' . $stat[2]['yrn'] . '",
"' . $stat[2]['yrn_krit'] . '",
"' . $stat[2]['tm1'] . '",
"' . $stat[2]['tm2'] . '"
)'
);
}
} }
//Считаем контру if (isset($stat[2])) {
$stat[2]['battle'] = $this->i->id;
Db::sql($sql, $stat[2]);
}
}
public function lookLog(): string public function lookLog(): string
{ {
global $u; $u = User::start();
$js = '';
$pll = 0;
$hodID = mysql_fetch_array( $hodID = Db::getValue('select id_hod from battle_logs where battle = ? order by time limit 1', [$this->i->id]) ?? 0;
mysql_query( if ($hodID <= 1) {
'SELECT `id`,`id_hod` FROM `battle_logs` WHERE `battle` = "' . $this->i->id . '" ORDER BY `time` LIMIT 1'
)
);
if ($hodID['id_hod'] <= 1) {
$u->info['alog'] = 0; $u->info['alog'] = 0;
} }
$js = ''; $sp = Db::getRows('select * from battle_logs where battle = ? and id_hod >= (select alog from stats where id = ?) order by id desc', [$this->i->id, $u->info['id']]) ?? [];
$pll = 0;
$talog = mysql_fetch_array( if (!empty($sp) && $this->i->getTeamwin() != -1) {
mysql_query('SELECT `alog` FROM `stats` WHERE `id` = "' . $u->info['id'] . '" LIMIT 1') $sp = Db::getRows('select * from battle_logs_save where battle = ? and id_hod >= (select alog from stats where id = ?) order by id desc', [$this->i->id, $u->info['id']]) ?? [];
);
$sp = mysql_query(
'SELECT
`id`,`type`,`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zona2`,`zonb1`,`zonb2`
FROM `battle_logs`
WHERE `battle` = "' . $this->i->id . '" AND `id_hod` >= ' . $talog['alog'] . ' ORDER BY `id` DESC'
);
if (isset($sp) && $this->i->getTeamwin() != -1) {
$sp = mysql_query(
'SELECT
`id`,`type`,`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zona2`,`zonb1`,`zonb2`
FROM `battle_logs_save`
WHERE `battle` = "' . $this->i->id . '" AND `id_hod` >= ' . $talog['alog'] . ' ORDER BY `id` DESC'
);
}
$jin = 0;
$forYou2 = 0;
if (is_array($sp)) {
while ($pl = mysql_fetch_array($sp)) {
if ($jin == 0) {
$u->info['alog'] = $pl['id_hod'];
}
$jin++;
$rt = $pl['text'];
$pl['vars'] = str_replace('^^^^', 'rvnO', $pl['vars']);
$rt = str_replace(
'{tm1}', '<span class=\"date {fru}\">' . date('H:i', $pl['time']) . '</span>',
$rt
);
$rt = str_replace(
'{tm2}', '<span class=\"date {fru}\">' . date('H:i', $pl['time']) . '</span>',
$rt
);
$rt = str_replace(
'{tm3}',
'<span class=\"date {fru}\">' . date('d.m.Y H:i', $pl['time']) . '</span>', $rt
);
$rt = str_replace(
'{tm4}',
'<span class=\"date {fru}\">' . date('d.m.Y H:i', $pl['time']) . '</span>', $rt
);
$pl['text'] = $rt;
unset($rt);
if ($pll < $pl['id']) {
$pll = $pl['id'];
}
$js = 'add_log(' . $pl['id'] . ',' . $forYou2 . ',"' . $pl['text'] . '",' . $pl['id_hod'] . ',0,0,"' . str_replace(
'"',
'&quot;', $pl['vars']
) . '");' . $js;
}
}
mysql_query(
'UPDATE `stats` SET `alog`="' . $u->info['alog'] . '" WHERE `id` ="' . $u->info['id'] . '" LIMIT 1'
);
$js .= 'id_log=' . $pll . ';';
return $js;
} }
$search = ['{tm1}', '{tm2}', '{tm3}', '{tm4}'];
foreach ($sp as $log) {
if (!isset($firstloop)) {
$u->info['alog'] = $log['id_hod'];
$firstloop = true;
}
$log['vars'] = str_replace('^^^^', 'rvnO', $log['vars']);
$replace = [
'<span class=\"date {fru}\">' . date('H:i', $log['time']) . '</span>',
'<span class=\"date {fru}\">' . date('H:i', $log['time']) . '</span>',
'<span class=\"date {fru}\">' . date('d.m.Y H:i', $log['time']) . '</span>',
'<span class=\"date {fru}\">' . date('d.m.Y H:i', $log['time']) . '</span>',
];
$log['text'] = str_replace($search, $replace, $log['text']);
if ($pll < $log['id']) {
$pll = $log['id'];
}
$jstext = json_encode($log['text']);
$jsvars = json_encode($log['vars']);
$js = "add_log({$log['id']},0,$jstext,{$log['id_hod']},0,0,$jsvars)" . $js;
}
Db::sql('update stats set alog = ? where id = ?', [$u->info['alog'], $u->info['id']]);
$js .= "id_log=$pll;";
return htmlspecialchars($js, ENT_QUOTES);
}
//Расчитываем статы для конкретной зоны атаки
public function lookmLog(): string public function lookmLog(): string
{ {
global $u; if ($this->i->type == 9) {
return '';
}
$u = User::start();
$js = ''; $js = '';
$pll = 0; $pll = 0;
if ($this->i->type != 9) { $hodID = Db::getValue('select id_hod from battle_logs where battle = ? order by time limit 1', [$this->i->id]) ?? 0;
$hodID = mysql_fetch_array( if ($hodID <= 1) {
mysql_query(
'SELECT `id_hod` FROM `battle_logs` WHERE `battle` = "' . $this->i->id . '" ORDER BY `time` LIMIT 1'
)
);
if ($hodID['id_hod'] <= 1) {
$u->info['mlog'] = 0; $u->info['mlog'] = 0;
} }
$tmlog = mysql_fetch_array( $sp = Db::getRows(
mysql_query('SELECT `mlog` FROM `stats` WHERE `id` = "' . $u->info['id'] . '" LIMIT 1') "select * from battle_logs where battle = ? and id_hod >= (select mlog from stats where id = ?) and vars like ? order by id desc",
); [$this->i->id, $u->info['id'], "%{$u->info['login']}%"]
$spm = mysql_query( ) ?? [];
'SELECT
`id`,`type`,`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zona2`,`zonb1`,`zonb2`
FROM `battle_logs`
WHERE `battle` = "' . $this->i->id . '" AND `id_hod` >= ' . $tmlog['mlog'] . ' AND `vars` LIKE "%' . $u->info['login'] . '%" ORDER BY `id` DESC'
);
if (isset($spm) && $this->i->getTeamwin() != -1) { if (!empty($sp) && $this->i->getTeamwin() != -1) {
$spm = mysql_query( $sp = Db::getRows(
'SELECT 'select * from battle_logs_save where battle = ? and id_hod >= (select mlog from stats where id = ?) and vars like ? order by id desc',
`id`,`type`,`time`,`battle`,`id_hod`,`text`,`vars`,`zona1`,`zona2`,`zonb1`,`zonb2` [$this->i->id, $u->info['id'], "%{$u->info['login']}%"]
FROM `battle_logs_save` ) ?? [];
WHERE `battle` = "' . $this->i->id . '" AND `id_hod` >= ' . $tmlog['mlog'] . ' AND `vars` LIKE "%' . $u->info['login'] . '%" ORDER BY `id` DESC'
);
} }
$jin = 0; $search = ['{tm1}', '{tm2}', '{tm3}', '{tm4}'];
$forYou2 = 0;
if (is_array($spm)) { foreach ($sp as $log) {
while ($plm = mysql_fetch_array($spm)) { if (!isset($firstloop)) {
if ($jin == 0) { $u->info['mlog'] = $log['id_hod'];
$u->info['mlog'] = $plm['id_hod']; $firstloop = true;
} }
$jin++;
$rt = $plm['text']; $log['vars'] = str_replace('^^^^', 'rvnO', $log['vars']);
$plm['vars'] = str_replace('^^^^', 'rvnO', $plm['vars']);
$rt = str_replace( $replace = [
'{tm1}', '<span class=\"date {fru}\">' . date('H:i', $plm['time']) . '</span>', $rt '<span class=\"date {fru}\">' . date('H:i', $log['time']) . '</span>',
); '<span class=\"date {fru}\">' . date('H:i', $log['time']) . '</span>',
$rt = str_replace( '<span class=\"date {fru}\">' . date('d.m.Y H:i', $log['time']) . '</span>',
'{tm2}', '<span class=\"date {fru}\">' . date('H:i', $plm['time']) . '</span>', $rt '<span class=\"date {fru}\">' . date('d.m.Y H:i', $log['time']) . '</span>',
); ];
$rt = str_replace(
'{tm3}', '<span class=\"date {fru}\">' . date('d.m.Y H:i', $plm['time']) . '</span>', $log['text'] = str_replace($search, $replace, $log['text']);
$rt
); if ($pll < $log['id']) {
$rt = str_replace( $pll = $log['id'];
'{tm4}', '<span class=\"date {fru}\">' . date('d.m.Y H:i', $plm['time']) . '</span>',
$rt
);
$plm['text'] = $rt;
unset($rt);
if ($pll < $plm['id']) {
$pll = $plm['id'];
} }
$js = 'add_mlog(' . $plm['id'] . ',' . $forYou2 . ',"' . $plm['text'] . '",' . $plm['id_hod'] . ',0,0,"' . str_replace(
'"', $jstext = json_encode($log['text']);
'&quot;', $plm['vars'] $jsvars = json_encode($log['vars']);
) . '");' . $js;
$js = "add_mlog({$log['id']},0,$jstext,{$log['id_hod']},0,0,$jsvars)" . $js;
} }
}
$js .= 'id_mlog=' . $pll . ';'; Db::sql('update stats set mlog = ? where id = ?', [$u->info['mlog'], $u->info['id']]);
mysql_query( $js .= "id_mlog=$pll;";
'UPDATE `stats` SET `mlog`="' . $u->info['mlog'] . '" WHERE `id` ="' . $u->info['id'] . '" LIMIT 1'
); return htmlspecialchars($js, ENT_QUOTES);
}
return $js;
} }
//Считаем урон //Считаем урон
@ -1816,22 +1716,17 @@ JS;
public function testActions(): void public function testActions(): void
{ {
global $u; $u = User::start();
//проверяем удары //проверяем удары
$m = mysql_query('SELECT * FROM `battle_act` WHERE `battle` = "' . $this->i->id . '" ORDER BY `id`'); $ba = Db::getRows('select * from battle_act where battle = ? order by id', [$this->i->id]);
$i = 0;
while ($pl = mysql_fetch_array($m)) { foreach ($ba as $pl) {
$pluids = mysql_fetch_array( $testhpnow = Db::getValue('select hpnow from stats where hpnow <= 0 and id in (?,?) limit 1', [$pl['uid1'], $pl['uid2']]);
mysql_query( $testid = (bool)Db::getValue('select count(id) from battle_act where id = ?', [$pl['id']]);
'SELECT `hpNow` FROM `stats` WHERE (`id` = "' . $pl['uid1'] . '" AND `hpNow` <= 0) OR (`id` = "' . $pl['uid2'] . '" AND `hpNow` <= 0) LIMIT 1'
) if ($testid) {
); if ($testhpnow) {
$pltest = mysql_fetch_array( Db::sql('delete from battle_act where id = ?', [$pl['id']]);
mysql_query('SELECT * FROM `battle_act` WHERE `id` = "' . $pl['id'] . '" LIMIT 1')
);
if (isset($pltest['id'])) {
if (isset($pluids['hpNow'])) {
mysql_query('DELETE FROM `battle_act` WHERE `id` = "' . $pl['id'] . '" LIMIT 1');
} elseif ($pl['time'] + $this->i->timeout > time()) { } elseif ($pl['time'] + $this->i->timeout > time()) {
//удар не пропущен по тайму, просто заносим данные //удар не пропущен по тайму, просто заносим данные
$this->atacks[$pl['id']] = $pl; $this->atacks[$pl['id']] = $pl;
@ -1863,7 +1758,7 @@ JS;
//наносим удар по пропуску //наносим удар по пропуску
$this->atacks[$pl['id']] = $pl; $this->atacks[$pl['id']] = $pl;
$this->startAtack($pl['id']); $this->startAtack($pl['id']);
mysql_query('DELETE FROM `battle_act` WHERE `id` = "' . $pl['id'] . '"'); Db::sql('delete from battle_act where id = ?', [$pl['id']]);
} }
} }
@ -1880,6 +1775,7 @@ JS;
} }
} }
$i = 0;
//тест, бот делает удары //тест, бот делает удары
while ($i < count($this->bots)) { while ($i < count($this->bots)) {
$bot = $this->bots[$i]; $bot = $this->bots[$i];
@ -1916,9 +1812,7 @@ JS;
$this->users[$this->uids[$bot]]['timego'] < time() $this->users[$this->uids[$bot]]['timego'] < time()
) { ) {
$this->botAtack($this->users[$j]['id'], $bot, 1); $this->botAtack($this->users[$j]['id'], $bot, 1);
mysql_query( Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]);
'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1'
);
} }
} elseif ( } elseif (
isset($this->users[$i]) && isset($this->users[$i]) &&
@ -1939,18 +1833,14 @@ JS;
!isset($this->ag[$bot][$this->users[$i]['id']]) !isset($this->ag[$bot][$this->users[$i]['id']])
) { ) {
$this->botAtack($this->users[$i]['id'], $bot, 1); $this->botAtack($this->users[$i]['id'], $bot, 1);
mysql_query( Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]);
'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1'
);
} elseif ( } elseif (
!isset($this->ag[$bot][$this->users[$i]['id']]) && !isset($this->ag[$bot][$this->users[$i]['id']]) &&
isset($this->ga[$bot][$this->users[$i]['id']]) && isset($this->ga[$bot][$this->users[$i]['id']]) &&
$this->users[$this->uids[$bot]]['timego'] < time() $this->users[$this->uids[$bot]]['timego'] < time()
) { ) {
$this->botAtack($bot, $this->users[$i]['id'], 1); $this->botAtack($bot, $this->users[$i]['id'], 1);
mysql_query( Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]);
'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1'
);
} }
} }
} else { } else {
@ -1998,9 +1888,7 @@ JS;
} }
$this->startAtack($this->ga[$bot][$this->users[$j]['id']]); $this->startAtack($this->ga[$bot][$this->users[$j]['id']]);
$this->users[$this->uids[$bot]]['timego'] = $tnbot; $this->users[$this->uids[$bot]]['timego'] = $tnbot;
mysql_query( Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]);
'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1'
);
} }
} elseif ( } elseif (
isset($this->ag[$bot][$this->users[$j]['id']]) && isset($this->ag[$bot][$this->users[$j]['id']]) &&
@ -2016,9 +1904,7 @@ JS;
$tnbot = time() - 1; $tnbot = time() - 1;
} }
$this->users[$this->uids[$bot]]['timego'] = $tnbot; $this->users[$this->uids[$bot]]['timego'] = $tnbot;
mysql_query( Db::sql('update stats set timego = ? where id = ?', [$tnbot, $this->users[$this->uids[$bot]]['id']]);
'UPDATE `stats` SET `timeGo` = "' . $tnbot . '" WHERE `id` = "' . $this->users[$this->uids[$bot]]['id'] . '" LIMIT 1'
);
} }
} }
} }
@ -3072,20 +2958,23 @@ JS;
public function testPogB($uid, $yr, $pliid, $test = 0) public function testPogB($uid, $yr, $pliid, $test = 0)
{ {
$yr2 = $yr; $checktuman = Db::getValue('select count(id) from eff_users where uid = ? and v2 in (273,286,287,288)', [$uid]) == 0; //проверка на туманный образ
$checktuman = mysql_fetch_array( if ($yr <= 0 || !$checktuman) {
mysql_query( return $yr;
'SELECT * FROM `eff_users` WHERE `uid` = "' . $uid . '" }
AND (`v2` = 273 OR `v2` = 286 OR `v2` = 287 OR `v2` = 288)
AND `delete` =0 LIMIT 1'
)
); //проверка на туманный образ
if ($yr > 0 && !isset($checktuman['id'])) {
global $priem; global $priem;
$yr2 = $yr;
$i = 0; $i = 0;
while ($i < count($this->stats[$this->uids[$uid]]['set_pog2'])) { while ($i < count($this->stats[$this->uids[$uid]]['set_pog2'])) {
$j = $this->stats[$this->uids[$uid]]['set_pog2'][$i]; $j = $this->stats[$this->uids[$uid]]['set_pog2'][$i];
if ($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['id'] == $pliid || $test == 1) { if ($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['id'] != $pliid && $test != 1) {
$i++;
continue;
}
$this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] = str_replace( $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] = str_replace(
'add_pog2=' . $j['y'], 'add_pog2=' . $j['y'],
'add_pog2=$', $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] 'add_pog2=$', $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data']
@ -3096,14 +2985,11 @@ JS;
$dt3['add_pog2p'] = $dt30; $dt3['add_pog2p'] = $dt30;
} }
unset($dt30); unset($dt30);
if (isset($dt3['add_pog2mp'])) { if (isset($dt3['add_pog2mp'])) {
if ((round( if ((round(round($yr2 / 100 * (100 - $dt3['add_pog2p'])) * $dt3['add_pog2mp'])) > $this->stats[$this->uids[$uid]]['mpNow']) {
round($yr2 / 100 * (100 - $dt3['add_pog2p'])) * $dt3['add_pog2mp']
)) > $this->stats[$this->uids[$uid]]['mpNow']) {
//не хватило маны, считаем сколько хватит % от поглощенного урона //не хватило маны, считаем сколько хватит % от поглощенного урона
$j['yhj'] = $this->stats[$this->uids[$uid]]['mpNow'] / (round( $j['yhj'] = $this->stats[$this->uids[$uid]]['mpNow'] / (round(round($yr2 / 100 * (100 - $dt3['add_pog2p'])) * $dt3['add_pog2mp'])) * 100;
round($yr2 / 100 * (100 - $dt3['add_pog2p'])) * $dt3['add_pog2mp']
)) * 100;
$j['yhj'] = floor($j['yhj']); //Сколько % мы можем поглотить $j['yhj'] = floor($j['yhj']); //Сколько % мы можем поглотить
$dt3['add_pog2p'] = floor($dt3['add_pog2p'] / 100 * $j['yhj']); $dt3['add_pog2p'] = floor($dt3['add_pog2p'] / 100 * $j['yhj']);
} }
@ -3111,31 +2997,30 @@ JS;
$priem->minMana($uid, round(round($yr2 / 100 * $dt3['add_pog2p']) * $dt3['add_pog2mp'])); $priem->minMana($uid, round(round($yr2 / 100 * $dt3['add_pog2p']) * $dt3['add_pog2mp']));
} }
} }
if (!isset($this->poglast[$uid])) { if (!isset($this->poglast[$uid])) {
$this->poglast[$uid] = 0; $this->poglast[$uid] = 0;
} }
$this->poglast[$uid] += $yr2; $this->poglast[$uid] += $yr2;
if ($test == 1) { if ($test == 1) {
// осталось для поглощения // осталось для поглощения
$j['y'] -= round($this->poglast[$uid] / 100 * $dt3['add_pog2p']); $j['y'] -= round($this->poglast[$uid] / 100 * $dt3['add_pog2p']);
$priem->minMana( $priem->minMana($uid, round(round($this->poglast[$uid] / 100 * $dt3['add_pog2p']) * $dt3['add_pog2mp']));
$uid,
round(round($this->poglast[$uid] / 100 * $dt3['add_pog2p']) * $dt3['add_pog2mp'])
);
} }
if (isset($dt3['add_pog2p'])) { if (isset($dt3['add_pog2p'])) {
$yr2 = round($yr2 / 100 * (100 - $dt3['add_pog2p'])); $yr2 = round($yr2 / 100 * (100 - $dt3['add_pog2p']));
} }
if ($j['y'] < 0 || ($this->stats[$this->uids[$uid]]['mpNow'] <= 0 && $dt3['add_pog2mp'] > 0)) { if ($j['y'] < 0 || ($this->stats[$this->uids[$uid]]['mpNow'] <= 0 && $dt3['add_pog2mp'] > 0)) {
$dt2 = Conversion::dataStringToArray($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data']); $dt2 = Conversion::dataStringToArray($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data']);
if (isset($dt2['endPog']) && $dt2['endPog'] == 1) { if (isset($dt2['endPog']) && $dt2['endPog'] == 1) {
//удаляем прием //удаляем прием
//Добавляем в лог //Добавляем в лог
$this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['priem'] = mysql_fetch_array(
mysql_query( $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['priem'] =
'SELECT * FROM `priems` WHERE `id` = "' . $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['v2'] . '" LIMIT 1' Db::getRow('select * from priems where id = ?', [$this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['v2']]);
)
);
$this->delPriem( $this->delPriem(
$this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1], $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1],
$this->users[$this->uids[$uid]], 4, $uid $this->users[$this->uids[$uid]], 4, $uid
@ -3145,26 +3030,29 @@ JS;
unset($dt2); unset($dt2);
$j['y'] = 0; $j['y'] = 0;
} }
$this->stats[$this->uids[$uid]]['set_pog'][$i]['y'] = $j['y']; $this->stats[$this->uids[$uid]]['set_pog'][$i]['y'] = $j['y'];
if (isset($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'])) { if (isset($this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'])) {
$this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] = str_replace( $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] = str_replace(
'add_pog2=$', 'add_pog2=$',
'add_pog2=' . $j['y'], $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] 'add_pog2=' . $j['y'], $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data']
); );
mysql_query( Db::sql(
'UPDATE `eff_users` SET `data` = "' . $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'] . '" WHERE `id` = "' . $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['id'] . '" LIMIT 1' 'update eff_users set data = ? where id = ?',
[$this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['data'], $this->stats[$this->uids[$uid]]['effects'][$j['id'] - 1]['id']]
); );
} }
if ($j['y'] - $this->poglast[$uid] + $yr2 < 0) { if ($j['y'] - $this->poglast[$uid] + $yr2 < 0) {
$yr -= $yr + ($j['y'] - $this->poglast[$uid] + $yr2); $yr -= $yr + ($j['y'] - $this->poglast[$uid] + $yr2);
$yr2 = $yr; $yr2 = $yr;
$i = count($this->stats[$this->uids[$uid]]['set_pog2']) + 1; $i = count($this->stats[$this->uids[$uid]]['set_pog2']) + 1;
} }
}
$i++; $i++;
} }
}
unset($checktuman);
return $yr2; return $yr2;
} }
@ -3311,11 +3199,15 @@ JS;
if ($at[$a]['atack'][$j]['yron']['hp'] > $at[$a]['atack'][$j]['yron']['hpAll']) { if ($at[$a]['atack'][$j]['yron']['hp'] > $at[$a]['atack'][$j]['yron']['hpAll']) {
$at[$a]['atack'][$j]['yron']['hp'] = $at[$a]['atack'][$j]['yron']['hpAll']; $at[$a]['atack'][$j]['yron']['hp'] = $at[$a]['atack'][$j]['yron']['hpAll'];
} }
//Травмирование //Травмирование
if (rand(0, 100) <= 50 && ($at[$a]['atack'][$j][1] == 4 || $at[$a]['atack'][$j][1] == 5) && !isset($at[$a]['atack'][$j]['yron']['travma']) && rand( if (
0, rand(0, 100) <= 50 &&
1000 ($at[$a]['atack'][$j][1] == 4 || $at[$a]['atack'][$j][1] == 5) &&
) < 500 && $this->users[$this->uids[$u2]]['level'] > 1 && $this->stats[$this->uids[$u1]] > 1) { !isset($at[$a]['atack'][$j]['yron']['travma']) &&
$this->users[$this->uids[$u2]]['level'] > 1 &&
$this->stats[$this->uids[$u1]] > 1
) {
$trvm_chns = floor(rand(0, 200) / 10); $trvm_chns = floor(rand(0, 200) / 10);
if ($trvm_chns > 3 || $trvm_chns < 1) { if ($trvm_chns > 3 || $trvm_chns < 1) {
$trvm_chns = 0; $trvm_chns = 0;
@ -4375,8 +4267,6 @@ JS;
return; return;
} }
var_dump($_POST);
//atack: '3_2_0_0_0' (length=9) //atack: '3_2_0_0_0' (length=9)
//block: '5' (length=1) //block: '5' (length=1)
@ -4404,7 +4294,6 @@ JS;
} }
$this->uAtc = $na; $this->uAtc = $na;
$js .= 'testClearZone();'; $js .= 'testClearZone();';
var_dump($this->uAtc);
} }
public function teamsTake(User $u): void public function teamsTake(User $u): void