From 4bd6a08e8aa377468137ae3cc2fea9fbd5e609af Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Sat, 11 Jun 2022 02:17:24 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=90=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D0=B0:?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B5=D0=B2=D0=B8=D0=B4=D0=B8=D0=BC=D0=BE=D0=BA?= =?UTF-8?q?=20=D1=83=D0=B5=D1=85=D0=B0=D0=BB=D0=BE=20=D0=B2=20=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81.=20=D0=9E?= =?UTF-8?q?=D1=82=D0=B2=D1=8F=D0=B7=D0=BA=D0=B0=20=D0=BE=D1=82=20functions?= =?UTF-8?q?.php.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/admin.php | 12 +++--------- classes/Battles/Admin/User.php | 20 ++++++++++++++++++++ functions.php | 2 +- 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 classes/Battles/Admin/User.php diff --git a/admin/admin.php b/admin/admin.php index 4e4a270..52a277f 100644 --- a/admin/admin.php +++ b/admin/admin.php @@ -4,11 +4,11 @@ * Author: Igor Barkov * Project name: Battles-Game */ -require_once '../functions.php'; +require_once '../config.php'; use Battles\Admin\Clan; +use Battles\Admin\User as AUser; use Battles\Chat; -use Battles\Database\Db; use Battles\Moderation; use Battles\Template; use Battles\User; @@ -49,12 +49,6 @@ if (!empty($_POST['receiver']) && !empty($_POST['tgmsg'])) { Chat::sendTelegraf($_POST['tgmsg'], $receiver->id); echo "Успешно."; } -# Показывает невидимок. -$row = Db::getInstance()->ofetchAll('SELECT id,login FROM users LEFT JOIN users_effects ue on users.id = ue.owner_id WHERE type = 1022 ORDER BY `id` DESC'); -foreach ($row as $r) { - $invisList .= '[id] = ' .$r->id. ', ' .$r->login. '
'; -} - Template::header('ᐰdminка'); ?> @@ -107,4 +101,4 @@ Template::header('ᐰdminка'); Невидимки
-
\ No newline at end of file +
\ No newline at end of file diff --git a/classes/Battles/Admin/User.php b/classes/Battles/Admin/User.php new file mode 100644 index 0000000..71138ab --- /dev/null +++ b/classes/Battles/Admin/User.php @@ -0,0 +1,20 @@ +ofetchAll('select id, login from users left join users_effects ue on users.id = ue.owner_id where type = ' . self::INVISIBILITY_EFFECT); + foreach ($row as $item) { + $list .= '[id] = ' . $item->id . ', ' . $item->login . '
'; + } + return $list; + } +} \ No newline at end of file diff --git a/functions.php b/functions.php index 60ca77b..33d7ba6 100644 --- a/functions.php +++ b/functions.php @@ -473,7 +473,7 @@ function SolveExp($at_id, $def_id, $damage): float 'btl_1' => 1, 'btl_2' => 0.5, 'btl_3' => 0.05, - ]; + ]; $baseexp = [ "0" => "2", "1" => "5", -- 2.45.2 From b8f837b6cf04c84a93b4eee65cf2fb62485f20a4 Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Sat, 11 Jun 2022 02:18:04 +0300 Subject: [PATCH 2/3] fixes --- admin/admin.php | 48 ++++++++++++++----- classes/Battles/Magic/CureInjury.php | 7 ++- classes/Battles/Magic/Magic.php | 29 ++++++++--- classes/Battles/User.php | 5 ++ config.php | 3 -- functions.php | 72 ++++++++++------------------ 6 files changed, 94 insertions(+), 70 deletions(-) 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) -- 2.45.2 From 4b65e0d3721b3e802ec5653fc58a0af23d3e792b Mon Sep 17 00:00:00 2001 From: Ivor Barhansky Date: Sat, 11 Jun 2022 02:57:27 +0300 Subject: [PATCH 3/3] fixes #15 --- classes/Battles/DressedItems.php | 40 ++++++++++++++++++++---- fbattle.php | 13 +++++--- functions.php | 53 -------------------------------- 3 files changed, 43 insertions(+), 63 deletions(-) diff --git a/classes/Battles/DressedItems.php b/classes/Battles/DressedItems.php index c1ce5b8..5d7ad32 100644 --- a/classes/Battles/DressedItems.php +++ b/classes/Battles/DressedItems.php @@ -12,18 +12,20 @@ use stdClass; class DressedItems { - private $USERID; - private $dressedItem; - private static $db; + private int $USERID; + private stdClass $dressedItem; + private static Db $db; + private object $dressed; /** * DressedItems constructor. - * @param int $user_id ID игрока. + * @param int $user_id ID игрока. */ public function __construct(int $user_id) { self::$db = Db::getInstance(); $this->USERID = $user_id; + $this->dressed = self::$db->ofetchAll('select * from inventory where dressed_slot > 0 and owner_id = ?', $this->USERID); } public static function getDressedItemBySlot($itemSlot, $ownerId) @@ -33,9 +35,8 @@ class DressedItems public function getItemsInSlots(): stdClass { - $items = self::$db->ofetchALL('SELECT * FROM inventory WHERE owner_id = ? AND dressed_slot > 0', $this->USERID); $this->dressedItem = new stdClass(); - foreach ($items as $item) { + foreach ($this->dressed as $item) { $i = $item->dressed_slot; $this->dressedItem->$i = $item; } @@ -54,8 +55,35 @@ class DressedItems self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$slot_id, $this->USERID]); } } + public static function undressAllItems($user_id) { return self::$db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot BETWEEN 1 AND 12 AND owner_id = ?', $user_id); } + + public function checkRequirements() + { + $stats = (new UserStats($this->USERID))->getFullStats(); + $q = 'select count(*) from inventory where + dressed_slot > 0 and + need_strength > ? and + need_dexterity > ? and + need_intuition > ? and + need_endurance > ? and + need_intelligence > ? and + need_wisdom > ? and + owner_id = ?'; + $args = [ + $stats->strength, + $stats->dexterity, + $stats->intuition, + $stats->endurance, + $stats->intelligence, + $stats->wisdom, + $this->USERID + ]; + if (self::$db->fetchColumn($q, $args) > 0) { + self::undressAllItems($this->USERID); + } + } } \ No newline at end of file diff --git a/fbattle.php b/fbattle.php index 0a821f1..c65c37d 100644 --- a/fbattle.php +++ b/fbattle.php @@ -1,4 +1,9 @@ @@ -133,7 +138,7 @@ $fbattle = new fbattle($user['battle']); showUserDoll(1); ?> @@ -290,7 +295,7 @@ $fbattle = new fbattle($user['battle']); if (($user['hp'] > 0) && $fbattle->battle) { echo '
Ожидаем хода противника...
0) ? "battle" : "end") . '>
'; } elseif ($user['hp'] <= 0 && $fbattle->battle) { - ref_drop(); + (new DressedItems(User::getInstance()->getId()))->checkRequirements(); echo '
Ожидаем, пока бой закончат другие игроки...
0) ? "battle" : "end") . '>
'; } break; @@ -468,7 +473,7 @@ $fbattle = new fbattle($user['battle']); return == 1) { - $enemyInfo = new \Battles\User($fbattle->enemy); + $enemyInfo = new User($fbattle->enemy); $enemyInfo->showUserDoll(1); } else { if ($fbattle->battle_data['type'] == 4 || $fbattle->battle_data['type'] == 5) { diff --git a/functions.php b/functions.php index 5fa07bc..ae965e2 100644 --- a/functions.php +++ b/functions.php @@ -281,59 +281,6 @@ function addActions($time, $vars, $vls, $uid) return $ins; } -#15 -function ref_drop() -{ - //сможет держать - function derj($id) - { - $user = db::c()->query('SELECT `id`, `align` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc(); - $ts = db::c()->query('SELECT `id`, `nalign` FROM `inventory` WHERE `id` = ?i', $id)->fetch_assoc(); - $al = '(1 = 1)'; - if ($ts['nalign'] == 1.1) { - $al = '(1 = 2)'; - } - $dd = db::c()->query('SELECT `i`.`id` FROM `users` AS `u`, `inventory` AS `i` - WHERE - `i`.`needident` = 0 AND - `i`.`id` = ?i AND - `i`.`duration` < `i`.`maxdur` AND - `i`.`owner` = ?i AND - `u`.`sila` >= `i`.`nsila` AND - `u`.`lovk` >= `i`.`nlovk` AND - `u`.`inta` >= `i`.`ninta` AND - `u`.`vinos` >= `i`.`nvinos` AND - `u`.`intel` >= `i`.`nintel` AND - `u`.`mudra` >= `i`.`nmudra` AND - `u`.`level` >= `i`.`nlevel` AND - ("?s" OR (?i = `i`.`nalign`) or (`i`.`nalign` = 0)) AND - `u`.`noj` >= `i`.`nnoj` AND - `u`.`topor` >= `i`.`ntopor` AND - `u`.`dubina` >= `i`.`ndubina` AND - `u`.`mec` >= `i`.`nmech` AND - `u`.`mfire` >= `i`.`nfire` AND - `u`.`mwater` >= `i`.`nwater` AND - `u`.`mair` >= `i`.`nair` AND - `u`.`mearth` >= `i`.`nearth` AND - `u`.`mlight` >= `i`.`nlight` AND - `u`.`mgray` >= `i`.`ngray` AND - `u`.`mdark` >= `i`.`ndark` AND - `i`.`setsale` = 0 AND - `u`.`id` = ?i', $id, $user['id'], $al, $user['align'], $user['id']); - return $dd->getNumRows() > 0; - } - - $slot = ['sergi', 'kulon', 'weap', 'bron', 'r1', 'r2', 'r3', 'helm', 'perchi', 'shit', 'boots', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm10']; - $user = db::c()->query('SELECT `sergi`,`kulon`,`weap`,`bron`,`r1`,`r2`,`r3`,`helm`,`perchi`,`shit`,`boots`,`m1`,`m2`,`m3`,`m4`,`m5`,`m6`,`m7`,`m8`,`m9`,`m10` FROM `users` WHERE id = ?i', $_SESSION['uid'])->fetch_assoc(); - for ($i = 0; $i <= 20; $i++) { - if ($user[$slot[$i]] && !derj($user[$slot[$i]])) { - $item = new DressedItems($_SESSION['uid']); - $item->undressItem($i + 1); - $user[$slot[$i]] = null; - } - } -} - // использовать магию function usemagic($id, $target) { -- 2.45.2