diff --git a/admin/admin.php b/admin/admin.php index 52a277f..fd1d6dd 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -45,8 +45,7 @@ if (isset($_GET['remclan'])) { # Телеграф. if (!empty($_POST['receiver']) && !empty($_POST['tgmsg'])) { - $receiver = Db::getInstance()->ofetch('SELECT id FROM users WHERE login= ?', $_POST['receiver']); - Chat::sendTelegraf($_POST['tgmsg'], $receiver->id); + Chat::sendTelegraf($_POST['tgmsg'], User::getInstance($_POST['receiver'])->getId()); echo "Успешно."; } @@ -78,26 +77,49 @@ Template::header('ᐰdminка');
- Добавить в «дело» игрока заметку о нарушении правил, прокрутке и пр. - -
+
+ Добавить в «дело» игрока заметку о нарушении правил, прокрутке и пр. + + +
+
+
Отправить системное сообщение в чат - - + + +
+
Телеграф - - - + + + +
+
Поменять статус - - - + + + +
Невидимки
diff --git a/classes/Battles/Magic/CureInjury.php b/classes/Battles/Magic/CureInjury.php index 9ef433f..878843a 100644 --- a/classes/Battles/Magic/CureInjury.php +++ b/classes/Battles/Magic/CureInjury.php @@ -48,7 +48,12 @@ class CureInjury extends Magic { $this->target = $this->target == $_SESSION['uid'] ? User::getInstance() : User::getInstance($this->target); $this->login = $this->target->getLogin(); - return ($this->isVisible(User::getInstance(), $this->target) && $this->isNotDead(User::getInstance()) && $this->enoughMana(User::getInstance()) && $this->isNotInBattle(User::getInstance())); + return ( + $this->isVisible(User::getInstance(), $this->target) && + $this->isNotDead(User::getInstance()) && + $this->enoughMana(User::getInstance()) && + $this->isNotInBattle(User::getInstance()) + ); } public static function cast($target, $type): self diff --git a/classes/Battles/Magic/Magic.php b/classes/Battles/Magic/Magic.php index f9135b0..9f357c6 100644 --- a/classes/Battles/Magic/Magic.php +++ b/classes/Battles/Magic/Magic.php @@ -1,11 +1,26 @@ magic = $db->ofetch('select * from magic where id = ?', $id); + } + + public function getMagic(): object + { + return $this->magic; + } + + protected function isVisible($caster, $target): bool { if ($caster->battle != $target->battle || $caster->room != $target->room) { $this->status = 'Вы не видите цель!'; @@ -15,7 +30,7 @@ class Magic } } - protected function isNotDead($caster):bool + protected function isNotDead($caster): bool { if ($caster->health < 1) { $this->status = 'Вы мертвы!'; @@ -25,7 +40,7 @@ class Magic } } - protected function enoughMana($caster):bool + protected function enoughMana($caster): bool { if ($caster->mana < 1) { $this->status = 'Недостаточно пыли!'; @@ -35,7 +50,7 @@ class Magic } } - protected function isNotInBattle($caster):bool + protected function isNotInBattle($caster): bool { if ($caster->battle) { $this->status = 'Невозможно применить в поединке!'; @@ -52,12 +67,12 @@ class Magic * * @return bool */ - protected function isSuccess($caster, int $difficulty = 40):bool + protected function isSuccess($caster, int $difficulty = 40): bool { # 40 - потолок стата. if ($difficulty > 40) { $difficulty = 40; } - return mt_rand(1,$difficulty) < $caster->intelligence; + return mt_rand(1, $difficulty) < $caster->intelligence; } } \ No newline at end of file diff --git a/classes/Battles/User.php b/classes/Battles/User.php index 5440af0..4cce280 100644 --- a/classes/Battles/User.php +++ b/classes/Battles/User.php @@ -216,6 +216,11 @@ class User return $this->experience; } + public function addExperience(int $amount): void + { + $this->experience += max($amount, 0); + } + public function getBattle(): int { return $this->battle; diff --git a/config.php b/config.php index b8acd9b..eff79b9 100644 --- a/config.php +++ b/config.php @@ -6,9 +6,6 @@ * Project name: Battles-Game */ -use Battles\Database\Db; -use Battles\User; - include_once 'classes/Database/db.php'; include_once 'classes/Database/Mysql.php'; include_once 'classes/Database/Statement.php'; diff --git a/functions.php b/functions.php index 33d7ba6..5fa07bc 100644 --- a/functions.php +++ b/functions.php @@ -5,6 +5,7 @@ * Project name: Battles-Game */ +use Battles\Chat; use Battles\Database\Db; use Battles\DressedItems; use Battles\InventoryItem; @@ -24,7 +25,7 @@ if (User::getInstance()->getBlock()) { } //Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам. -Travel::roomRedirects(User::$current->getRoom(), User::$current->getBattle(), User::$current->getInTower()); +Travel::roomRedirects(User::getInstance()->getRoom(), User::getInstance()->getBattle(), User::getInstance()->getInTower()); ///* // * Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам. @@ -78,26 +79,26 @@ Travel::roomRedirects(User::$current->getRoom(), User::$current->getBattle(), Us // exit; //} -if (!empty($_GET['goto']) && !empty($_GET['tStamp']) && !empty($_GET['vcode']) && $_GET['vcode'] == md5(sha1($_GET['goto'] . $_GET['tStamp']))) { +if ( + !empty($_GET['goto']) && + !empty($_GET['tStamp']) && + !empty($_GET['vcode']) && + $_GET['vcode'] == md5(sha1($_GET['goto'] . $_GET['tStamp'])) +) { $query = 'update users u, online o set u.room = ?, o.room = ? where user_id = id and user_id = ?'; Db::getInstance()->execute($query, [$_GET['goto'], $_GET['goto'], User::getInstance()->getId()]); User::getInstance()->setRoom(intval($_GET['goto'])); } -function createbot($bot, $login = "") +function createbot($bot, $login = null) { - $rec = db::c()->query('SELECT `id`, `login`, `maxhp` FROM `users` WHERE `id` = "?s" LIMIT 1', $bot)->fetch_assoc(); - if (isset($rec['id'])) { - if ($login) { - $rec['login'] = $login; - } - $botname = $rec['login']; - db::c()->query('INSERT INTO `bots` (`name`, `prototype`, `hp`) VALUES ("?s", "?s", "?s")', $botname, $bot, $rec['maxhp']); - $nid = db::c()->getLastInsertId(); - return ["id" => $nid, "login" => $botname]; - } else { + if (!User::getInstance($bot)->getId()) { return false; } + $botname = $login ?: User::getInstance($bot)->getLogin(); + Db::getInstance()->execute('insert into bots (name, prototype, hp) values (?, ?, ?)', + [$botname, $bot, (new UserStats($bot))->getMaxHealth()]); + return ["id" => Db::getInstance()->lastInsertId(), "login" => $botname]; } $var_map = [ @@ -123,15 +124,15 @@ function savecavedata($cavedata, $caveleader, $floor) function GiveExp($id, $exp) { - db::c()->query('UPDATE users SET exp = exp + ?i WHERE id = ?i', $exp, $id); + User::getInstance($id)->addExperience($exp); } /** * Генератор прогрессбара. - * @param $current - Текущее значение. - * @param $maximum - Максимальное значение. + * @param $current - Текущее значение. + * @param $maximum - Максимальное значение. * @param string $line_color - Цвет полоски прогрессбара. - * @param string $bg_color - Фон прогрессбара. + * @param string $bg_color - Фон прогрессбара. * @return string */ function showProgressBar($current, $maximum, string $line_color = 'limegreen', string $bg_color = 'silver'): string @@ -199,22 +200,18 @@ EMPTY_SLOT; } // ссылка на магию -function showhrefmagic($dress) +function showhrefmagic(array $dress): string { - $user = db::c()->query('SELECT `battle` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc(); - $magic = db::c()->query('SELECT * FROM `magic` WHERE `id` = ?i', $dress['includemagic'])->fetch_assoc(); + $magic = new Battles\Magic\Magic(Db::getInstance(), $dress['includemagic']); $r = ''; - $script = 'main'; - if ($user['battle']) { - $script = 'fbattle'; - } + $script = User::getInstance()->getBattle() ? 'fbattle' : 'main'; $r .= "getMagic()->targeted == 1) { $r .= "okno('Введите название предмета', '{$script}.php?use={$dress['id']}', 'target')"; - } elseif ($magic['targeted'] == 2) { - $r .= "findlogin('" . $magic['name'] . "', '{$script}.php?use={$dress['id']}', 'target')"; + } elseif ($magic->getMagic()->targeted == 2) { + $r .= "findlogin('" . $magic->getMagic()->name . "', '{$script}.php?use={$dress['id']}', 'target')"; } else { $r .= "if (confirm('Использовать сейчас?')) window.location='" . $script . ".php?use=" . $dress['id'] . "';"; } @@ -435,30 +432,13 @@ function usemagic($id, $target) function addch($text, $room = 0) { - if ($room == 0) { - $room = User::getInstance()->getRoom(); - } - if ($fp = @fopen("tmp/chat.txt", "a")) { //открытие - flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА - fwrite($fp, ":[" . time() . "]:[!sys!!]:[" . ($text) . "]:[" . $room . "]\r\n"); //работа с файлом - fflush($fp); //ОЧИЩЕНИЕ ФАЙЛОВОГО БУФЕРА И ЗАПИСЬ В ФАЙЛ - flock($fp, LOCK_UN); //СНЯТИЕ БЛОКИРОВКИ - fclose($fp); //закрытие - } + Chat::sendSys($text); } function addchp($text, $who, $room = 0) { - if ($room == 0) { - $room = User::getInstance()->getRoom(); - } - $fp = fopen("tmp/chat.txt", "a"); //открытие - flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА - fwrite($fp, ":[" . time() . "]:[{$who}]:[" . ($text) . "]:[" . $room . "]\r\n"); //работа с файлом - fflush($fp); //ОЧИЩЕНИЕ ФАЙЛОВОГО БУФЕРА И ЗАПИСЬ В ФАЙЛ - flock($fp, LOCK_UN); //СНЯТИЕ БЛОКИРОВКИ - fclose($fp); //закрытие + Chat::sendSys($text, $who); } function err($t)