Code smell.

This commit is contained in:
Ivor Barhansky
2022-12-17 01:20:43 +02:00
parent b1f578f4b0
commit 0398425205
45 changed files with 875 additions and 851 deletions
+34 -21
View File
@@ -5,6 +5,7 @@
* Project name: Battles-Game
*/
use Battles\Chat;
use Battles\Database\Db;
use Battles\Travel;
use Battles\User;
@@ -76,17 +77,17 @@ function savecavedata($cavedata, $caveleader, $floor)
*
* @param $current - Текущее значение.
* @param $maximum - Максимальное значение.
* @param string $line_color - Цвет полоски прогрессбара.
* @param string $bg_color - Фон прогрессбара.
* @param string $lineColor - Цвет полоски прогрессбара.
* @param string $bgColor - Фон прогрессбара.
*
* @return string
*/
function showProgressBar($current, $maximum, string $line_color = 'limegreen', string $bg_color = 'silver'): string
function showProgressBar($current, $maximum, string $lineColor = 'limegreen', string $bgColor = 'silver'): string
{
$bar = round($current / $maximum * 100);
return <<<HTML
<div style="width: 100%; height: 16px; background: $bg_color; overflow: hidden; border-radius: 3px;">
<div style="height: 16px; background: $line_color; border-radius: 3px; width: $bar%;"></div>
<div style="width: 100%; height: 16px; background: $bgColor; overflow: hidden; border-radius: 3px;">
<div style="height: 16px; background: $lineColor; border-radius: 3px; width: $bar%;"></div>
</div>
<div style="width: 100%; height: 16px; font-size: 14px; text-align: center; margi
n-top: -16px;">
@@ -105,26 +106,25 @@ HTML;
*/
function echoscroll($slot): string
{
$all_magic = 0;
$allMagic = 0;
if (User::getInstance()->getBattle()) {
$script = 'fbattle';
$all_magic = Db::getInstance()->fetchColumn('select magic from battle where id = ?', User::getInstance()->getBattle());
$all_magic = unserialize($all_magic);
$allMagic = Db::getInstance()->fetchColumn('select magic from battle where id = ?', User::getInstance()->getBattle());
$allMagic = unserialize($allMagic);
} else {
$script = 'main';
}
$dress = Db::getInstance()->fetch('select magic, name, image, durability from inventory where item_id - ?', User::getInstance()->$slot);
$need_charge = Db::getInstance()->fetchColumn('select needcharge from magic where id = ?', $dress['magic']);
$dress = Db::getInstance()->fetch('select magic, name, image, durability from inventory where item_id = ?', User::getInstance()->$slot);
$needCharge = Db::getInstance()->fetchColumn('select needcharge from magic where id = ?', $dress['magic']);
$str = null;
if ((User::getInstance()->$slot > 0) && ($all_magic[User::getInstance()->getId()] < 1 || empty($need_charge))) {
if ((User::getInstance()->$slot > 0) && ($allMagic[User::getInstance()->getId()] < 1 || empty($needCharge))) {
$row['id'] = User::getInstance()->$slot;
if ($dress['magic']) {
$magic_targeted = Db::getInstance()->fetchColumn('select targeted from magic where id = ?', $dress['magic']);
$magicTargeted = Db::getInstance()->fetchColumn('select targeted from magic where id = ?', $dress['magic']);
$str .= "<a onclick=\"";
if ($magic_targeted === 1) {
if ($magicTargeted === 1) {
$str .= "okno('Введите название предмета', '" . $script . ".php?use={$row['id']}', 'target'); ";
} else
if ($magic_targeted === 2) {
} elseif ($magicTargeted === 2) {
$str .= "findlogin('Введите имя персонажа', '" . $script . ".php?use={$row['id']}', 'target'); ";
} else {
$str .= "if(confirm('Использовать сейчас?')) { window.location='" . $script . ".php?use=" . $row['id'] . "';}";
@@ -134,7 +134,7 @@ function echoscroll($slot): string
$str .= <<<ACTIVE_SCROLL
<img class='tooltip' src="i/sh/{$dress['img']}" width='40' title="<b>{$dress['name']}</b><br> Прочность {$dress['duration']} / {$dress['maxdur']} " height='25' alt="Свиток"></a>
ACTIVE_SCROLL;
} elseif ((User::getInstance()->$slot > 0) && ($all_magic[User::getInstance()->getId()] >= 1) && $need_charge['needcharge'] > 0) {
} elseif ((User::getInstance()->$slot > 0) && ($allMagic[User::getInstance()->getId()] >= 1) && $needCharge['needcharge'] > 0) {
$str .= <<<INACTIVE_SCROLL
<img src="i/sh/magicclock.gif" width="40" height="25" title='Произведите размен ударами и магия снова станет доступна' alt="Свиток">
INACTIVE_SCROLL;
@@ -176,12 +176,26 @@ function addActions($time, $vars, $vls, $uid)
* по нескольку раз вызывают эти функции.
*/
function addch($text, $room = 0)
/**
* @param $text
* @param $room
* @param $smth
* @return void
* @deprecated use Chat::sendSys($msg) instead.
*/
function addch($text, $room = 0, $smth = null)
{
Chat::sendSys($text);
}
/**
* @param $text
* @param $who
* @param $room
* @return void
* @deprecated use Chat::sendSys($msg, $receiverId) instead.
*/
function addchp($text, $who, $room = 0)
{
Chat::sendSys($text, $who);
@@ -200,9 +214,8 @@ function err($t)
*/
function telegraph(int $userId, string $text)
{
$userExists = Db::getInstance()->fetchColumn('select count(*) from users where id = ?', $userId) > 0;
if ($userExists) {
Db::getInstance()->execute('INSERT INTO chat (user_id,receiver_id,msg,type) VALUES (-1,?,?,?)', [$userId, $text, 'sms']);
if (User::getInstance($userId)->getId() > 0) {
Chat::sendTelegraf($text, $userId);
}
}
@@ -334,4 +347,4 @@ function SolveExp($at_id, $def_id, $damage): float
}
return round((($baseexp[$defInfo->getLevel()]) * ($defAllPrice / (($atAllPrice + $defAllPrice) / 2)) * ($damage / $defInfo->getMaxHealth()) * $expmf * $mfit * $mfbot * $mfbot2) / 3);
}
}