Code smell

This commit is contained in:
Igor Barkov (iwork) 2019-09-24 12:49:05 +03:00
parent ece44ccb43
commit e4fc6df747
2 changed files with 16 additions and 12 deletions

View File

@ -125,8 +125,8 @@ class fbattle
$this->razmen_init($_POST['enemy'], $_POST['attack'], $_POST['defend']); $this->razmen_init($_POST['enemy'], $_POST['attack'], $_POST['defend']);
} }
if (isset($_GET['smena'], $_POST['smena'])) { if (isset($_POST['smena'])) {
$sm = mysql_fetch_array(mysql_query('SELECT `id`, `login`, `battle`, `bot`, `hp` FROM `users` WHERE `login` = "' . mysql_real_escape_string($_POST['smena']) . '" AND `battle` = "' . $user['battle'] . '" AND `hp` > 0 LIMIT 1')); $sm = db::c()->query('SELECT `id`, `login`, `battle`, `bot`, `hp` FROM `users` WHERE `hp` > 0 AND `login` = "?s" AND `battle` = ?i', $_POST['smena'], $user['battle'])->fetch_assoc();
if (isset($sm['id'])) { if (isset($sm['id'])) {
if ($sm['bot'] > 0) { if ($sm['bot'] > 0) {
$bt = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `bots` WHERE `name` = "' . mysql_real_escape_string($_POST['smena']) . '" LIMIT 1')); $bt = mysql_fetch_array(mysql_query('SELECT `id`, `hp` FROM `bots` WHERE `name` = "' . mysql_real_escape_string($_POST['smena']) . '" LIMIT 1'));
@ -273,7 +273,7 @@ class fbattle
function update_battle() function update_battle()
{ {
return mysql_query('UPDATE `battle` SET `exp` = \'' . serialize($this->exp) . '\', `teams` = \'' . serialize($this->battle) . '\', `damage` = \'' . serialize($this->damage) . '\' WHERE `id` = ' . $this->battle_data['id'] . ' ;'); return db::c()->query('UPDATE `battle` SET `exp` = "?s", `teams` = "?s", `damage` = "?s", WHERE `id` = ?i', serialize($this->exp), serialize($this->battle), serialize($this->damage), $this->battle_data['id']);
} }
/*------------------------------------------------------------------- /*-------------------------------------------------------------------
@ -283,13 +283,16 @@ class fbattle
function razmen_init($enemy, $attack, $defend) function razmen_init($enemy, $attack, $defend)
{ {
// проверяем прафильность // проверяем прафильность
if (($attack == 1 OR $attack == 2 OR $attack == 3 OR $attack == 4 OR $attack == 5) && $defend < 5 && $defend > 0 && $enemy && $this->user['hp'] > 0) { if (in_array($attack,[1,2,3,4,5]) AND in_array($defend,[1,2,3,4]) AND $enemy AND $this->user['hp'] > 0) {
// if (($attack == 1 OR $attack == 2 OR $attack == 3 OR $attack == 4 OR $attack == 5) && $defend < 5 && $defend > 0 && $enemy && $this->user['hp'] > 0) {
if ($this->battle[$enemy][$this->user['id']][0] > 0) { if ($this->battle[$enemy][$this->user['id']][0] > 0) {
// ================================== // ==================================
$this->add_log($this->get_comment()); // комментатор # Реплики комментатора:
// х-ки драчующихся $this->add_log($this->get_comment());
# Подсчёт характеристик бойцов:
$mf = $this->solve_mf($enemy, $attack); $mf = $this->solve_mf($enemy, $attack);
// проверяем кто куда попал // проверяем кто куда попал
// удар по мне // удар по мне
$uvorotme = $this->get_chanse($mf['me']['uvorot']); $uvorotme = $this->get_chanse($mf['me']['uvorot']);
$krithe = $this->get_chanse($mf['he']['krit']); $krithe = $this->get_chanse($mf['he']['krit']);

View File

@ -281,7 +281,7 @@ class zayavka
$range2 = "{$row['t2min']}-{$row['t2max']}"; $range2 = "{$row['t2min']}-{$row['t2max']}";
} }
$rr = "<input type=\"radio\" " . ((in_array($user['id'], $row['team1']) || in_array($user['id'], $row['team2'])) ? "disabled " : "") . " name=\"gocombat\" value=\"{$row['id']}\"><font class=date>{$row['podan']}</font> <b>{$row['t1c']}</b>({$range1}) ("; $rr = "<input type=\"radio\" " . ((in_array($user['id'], $row['team1']) || in_array($user['id'], $row['team2'])) ? "disabled " : "") . " name=\"gocombat\" value=\"{$row['id']}\"><span class=date>{$row['podan']}</span> <b>{$row['t1c']}</b>({$range1}) (";
foreach ($row['team1'] as $k => $v) { foreach ($row['team1'] as $k => $v) {
if ($k != 0) { if ($k != 0) {
$rr .= ", "; $rr .= ", ";
@ -306,7 +306,7 @@ class zayavka
$rr .= "<img src=\"i/fighttype6.gif\" width=\"20\" height=\"20\" />"; $rr .= "<img src=\"i/fighttype6.gif\" width=\"20\" height=\"20\" />";
} }
$a = db::c()->query('SELECT `align`,`admin` FROM `users` WHERE `id` = ?i', $user['id'])->fetch_assoc(); $a = db::c()->query('SELECT `admin` FROM `users` WHERE `id` = ?i', $user['id'])->fetch_assoc();
$rr .= ")&nbsp; тип боя: "; $rr .= ")&nbsp; тип боя: ";
if ($row['blood'] && $row['type'] == 4) { if ($row['blood'] && $row['type'] == 4) {
@ -321,7 +321,7 @@ class zayavka
$rr .= "(таймаут {$row['timeout']} мин.) <span style='color: gray;'><i>бой начнется через " . round(($row['start'] - time()) / 60, 1) . " мин. " . (($row['coment']) ? "(" . $row['coment'] . ")" : "") . "</i></span>"; $rr .= "(таймаут {$row['timeout']} мин.) <span style='color: gray;'><i>бой начнется через " . round(($row['start'] - time()) / 60, 1) . " мин. " . (($row['coment']) ? "(" . $row['coment'] . ")" : "") . "</i></span>";
if (($a['align'] > 1.4 && $a['align'] < 2) || $a['admin'] == 1) { if ($a['admin'] === 1) {
$rr .= "<a href='?zid={$row['id']}&do=clear'><small>Удалить комментарий</small></a><br />"; $rr .= "<a href='?zid={$row['id']}&do=clear'><small>Удалить комментарий</small></a><br />";
} else { } else {
$rr .= "<br />"; $rr .= "<br />";
@ -374,13 +374,13 @@ class zayavka
$rr .= "(таймаут {$row['timeout']} мин.) <span style='color: gray;'><i >бой начнется через " . round(($row['start'] - time()) / 60, 1) . " мин. " . (($row['coment']) ? "(" . $row['coment'] . ")" : "") . "</i></span>"; $rr .= "(таймаут {$row['timeout']} мин.) <span style='color: gray;'><i >бой начнется через " . round(($row['start'] - time()) / 60, 1) . " мин. " . (($row['coment']) ? "(" . $row['coment'] . ")" : "") . "</i></span>";
if ($user['admin'] == 1) { if ($user['admin'] === 1) {
$rsr = ' | <a href=\'?level=haos&zid=' . $row['id'] . '&del=true\'>Удалить заявку</a>'; $rsr = ' | <a href=\'?level=haos&zid=' . $row['id'] . '&del=true\'>Удалить заявку</a>';
} else { } else {
$rsr = ''; $rsr = '';
} }
if (($user['align'] > 1.4 && $user['align'] < 2) || $user['admin'] == 1) { if ($user['admin'] == 1) {
$rr .= "<small><a href='?zid={$row['id']}&do=clear'>Удалить коммнтарий</a>$rsr</small><br />"; $rr .= "<small><a href='?zid={$row['id']}&do=clear'>Удалить коммнтарий</a>$rsr</small><br />";
} else { } else {
$rr .= "<br />"; $rr .= "<br />";
@ -605,7 +605,7 @@ if (!empty($_POST['open'])) {
fclose($f); fclose($f);
} }
?> ?>
<HTML> <HTML lang="ru">
<HEAD> <HEAD>
<link rel=stylesheet href="css/main.css"> <link rel=stylesheet href="css/main.css">
<meta charset=utf-8"> <meta charset=utf-8">
@ -620,6 +620,7 @@ if (!empty($_POST['open'])) {
text-align: center; text-align: center;
} }
</style> </style>
<title></title>
</HEAD> </HEAD>
<body onload="top.setHP(<?= $user['hp'] ?>,<?= $user['maxhp'] ?>,<?php if (!$user['battle']) { <body onload="top.setHP(<?= $user['hp'] ?>,<?= $user['maxhp'] ?>,<?php if (!$user['battle']) {
echo "100"; echo "100";