patch-dressedcheck #57

Merged
lopar merged 4 commits from patch-dressedcheck into master 2022-06-11 00:18:38 +00:00
6 changed files with 94 additions and 70 deletions
Showing only changes of commit b8f837b6cf - Show all commits

View File

@ -45,8 +45,7 @@ if (isset($_GET['remclan'])) {
# Телеграф. # Телеграф.
if (!empty($_POST['receiver']) && !empty($_POST['tgmsg'])) { if (!empty($_POST['receiver']) && !empty($_POST['tgmsg'])) {
$receiver = Db::getInstance()->ofetch('SELECT id FROM users WHERE login= ?', $_POST['receiver']); Chat::sendTelegraf($_POST['tgmsg'], User::getInstance($_POST['receiver'])->getId());
Chat::sendTelegraf($_POST['tgmsg'], $receiver->id);
echo "Успешно."; echo "Успешно.";
} }
@ -78,26 +77,49 @@ Template::header('ᐰdminка');
<button disabled><img src="../i/magic/check.gif" alt="check"> Проверка</button> <button disabled><img src="../i/magic/check.gif" alt="check"> Проверка</button>
<form method='post'> <form method='post'>
<fieldset>
<legend>Добавить в «дело» игрока заметку о нарушении правил, прокрутке и пр.</legend> <legend>Добавить в «дело» игрока заметку о нарушении правил, прокрутке и пр.</legend>
<input name='ldnick' placeholder='Логин'> <input name='ldtext' size='50' placeholder='Сообщение'> <label>
<input name='ldnick' placeholder='Логин'>
</label>
<label>
<input name='ldtext' size='50' placeholder='Сообщение'>
</label>
<input type='submit' value='Добавить'><br> <input type='submit' value='Добавить'><br>
</fieldset>
</form> </form>
<form method='post'> <form method='post'>
<fieldset>
<legend>Отправить системное сообщение в чат</legend> <legend>Отправить системное сообщение в чат</legend>
<label>
<input name='syschatmsg' size='74' placeholder='Введите сообщение'> <input name='syschatmsg' size='74' placeholder='Введите сообщение'>
</label>
<input type='submit' value='Отправить'> <input type='submit' value='Отправить'>
</fieldset>
</form> </form>
<form method='post'> <form method='post'>
<fieldset>
<legend>Телеграф</legend> <legend>Телеграф</legend>
<label>
<input name='receiver' placeholder='Логин'> <input name='receiver' placeholder='Логин'>
</label>
<label>
<input name='tgmsg' size='50' placeholder='Сообщение'> <input name='tgmsg' size='50' placeholder='Сообщение'>
</label>
<input type='submit' value='Отправить'> <input type='submit' value='Отправить'>
</fieldset>
</form> </form>
<form method='post'> <form method='post'>
<fieldset>
<legend>Поменять статус</legend> <legend>Поменять статус</legend>
<label>
<input name='login' placeholder='Логин'> <input name='login' placeholder='Логин'>
</label>
<label>
<input name='status' placeholder='Статус'> <input name='status' placeholder='Статус'>
</label>
<input type='submit' value='Изменить статус'> <input type='submit' value='Изменить статус'>
</fieldset>
</form> </form>
<span class="legend">Невидимки</span><br> <span class="legend">Невидимки</span><br>

View File

@ -48,7 +48,12 @@ class CureInjury extends Magic
{ {
$this->target = $this->target == $_SESSION['uid'] ? User::getInstance() : User::getInstance($this->target); $this->target = $this->target == $_SESSION['uid'] ? User::getInstance() : User::getInstance($this->target);
$this->login = $this->target->getLogin(); $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 public static function cast($target, $type): self

View File

@ -1,11 +1,26 @@
<?php <?php
# Date: 16.09.2020 (08:45) # Date: 16.09.2020 (08:45)
namespace Battles\Magic; namespace Battles\Magic;
use Battles\Database\Db;
class Magic class Magic
{ {
protected $status; protected string $status;
private Db $db;
private object $magic;
protected function isVisible($caster, $target):bool public function __construct(Db $db, int $id)
{
$this->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) { if ($caster->battle != $target->battle || $caster->room != $target->room) {
$this->status = 'Вы не видите цель!'; $this->status = 'Вы не видите цель!';
@ -15,7 +30,7 @@ class Magic
} }
} }
protected function isNotDead($caster):bool protected function isNotDead($caster): bool
{ {
if ($caster->health < 1) { if ($caster->health < 1) {
$this->status = 'Вы мертвы!'; $this->status = 'Вы мертвы!';
@ -25,7 +40,7 @@ class Magic
} }
} }
protected function enoughMana($caster):bool protected function enoughMana($caster): bool
{ {
if ($caster->mana < 1) { if ($caster->mana < 1) {
$this->status = 'Недостаточно пыли!'; $this->status = 'Недостаточно пыли!';
@ -35,7 +50,7 @@ class Magic
} }
} }
protected function isNotInBattle($caster):bool protected function isNotInBattle($caster): bool
{ {
if ($caster->battle) { if ($caster->battle) {
$this->status = 'Невозможно применить в поединке!'; $this->status = 'Невозможно применить в поединке!';
@ -52,12 +67,12 @@ class Magic
* *
* @return bool * @return bool
*/ */
protected function isSuccess($caster, int $difficulty = 40):bool protected function isSuccess($caster, int $difficulty = 40): bool
{ {
# 40 - потолок стата. # 40 - потолок стата.
if ($difficulty > 40) { if ($difficulty > 40) {
$difficulty = 40; $difficulty = 40;
} }
return mt_rand(1,$difficulty) < $caster->intelligence; return mt_rand(1, $difficulty) < $caster->intelligence;
} }
} }

View File

@ -216,6 +216,11 @@ class User
return $this->experience; return $this->experience;
} }
public function addExperience(int $amount): void
{
$this->experience += max($amount, 0);
}
public function getBattle(): int public function getBattle(): int
{ {
return $this->battle; return $this->battle;

View File

@ -6,9 +6,6 @@
* Project name: Battles-Game * Project name: Battles-Game
*/ */
use Battles\Database\Db;
use Battles\User;
include_once 'classes/Database/db.php'; include_once 'classes/Database/db.php';
include_once 'classes/Database/Mysql.php'; include_once 'classes/Database/Mysql.php';
include_once 'classes/Database/Statement.php'; include_once 'classes/Database/Statement.php';

View File

@ -5,6 +5,7 @@
* Project name: Battles-Game * Project name: Battles-Game
*/ */
use Battles\Chat;
use Battles\Database\Db; use Battles\Database\Db;
use Battles\DressedItems; use Battles\DressedItems;
use Battles\InventoryItem; 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; // 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 = ?'; $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()]); Db::getInstance()->execute($query, [$_GET['goto'], $_GET['goto'], User::getInstance()->getId()]);
User::getInstance()->setRoom(intval($_GET['goto'])); 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 (!User::getInstance($bot)->getId()) {
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 {
return false; 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 = [ $var_map = [
@ -123,7 +124,7 @@ function savecavedata($cavedata, $caveleader, $floor)
function GiveExp($id, $exp) function GiveExp($id, $exp)
{ {
db::c()->query('UPDATE users SET exp = exp + ?i WHERE id = ?i', $exp, $id); User::getInstance($id)->addExperience($exp);
} }
/** /**
@ -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 = new Battles\Magic\Magic(Db::getInstance(), $dress['includemagic']);
$magic = db::c()->query('SELECT * FROM `magic` WHERE `id` = ?i', $dress['includemagic'])->fetch_assoc();
$r = ''; $r = '';
$script = 'main'; $script = User::getInstance()->getBattle() ? 'fbattle' : 'main';
if ($user['battle']) {
$script = 'fbattle';
}
$r .= "<a onclick=\""; $r .= "<a onclick=\"";
if ($magic['targeted'] == 1) { if ($magic->getMagic()->targeted == 1) {
$r .= "okno('Введите название предмета', '{$script}.php?use={$dress['id']}', 'target')"; $r .= "okno('Введите название предмета', '{$script}.php?use={$dress['id']}', 'target')";
} elseif ($magic['targeted'] == 2) { } elseif ($magic->getMagic()->targeted == 2) {
$r .= "findlogin('" . $magic['name'] . "', '{$script}.php?use={$dress['id']}', 'target')"; $r .= "findlogin('" . $magic->getMagic()->name . "', '{$script}.php?use={$dress['id']}', 'target')";
} else { } else {
$r .= "if (confirm('Использовать сейчас?')) window.location='" . $script . ".php?use=" . $dress['id'] . "';"; $r .= "if (confirm('Использовать сейчас?')) window.location='" . $script . ".php?use=" . $dress['id'] . "';";
} }
@ -435,30 +432,13 @@ function usemagic($id, $target)
function addch($text, $room = 0) function addch($text, $room = 0)
{ {
if ($room == 0) { Chat::sendSys($text);
$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); //закрытие
}
} }
function addchp($text, $who, $room = 0) function addchp($text, $who, $room = 0)
{ {
if ($room == 0) { Chat::sendSys($text, $who);
$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); //закрытие
} }
function err($t) function err($t)