code clean

This commit is contained in:
Igor Barkov (iwork) 2021-08-26 19:15:47 +03:00
parent 5e264f837a
commit 9c7fcda600
5 changed files with 74 additions and 68 deletions

View File

@ -11,10 +11,10 @@ if ($header) {
} elseif ($ch != null) { } elseif ($ch != null) {
Template::header('buttons'); Template::header('buttons');
?> ?>
<script language="JavaScript" src="js/ch.js"></script> <script src="js/ch.js"></script>
<script language="JavaScript" src="js/sl2.js"></script> <script src="js/sl2.js"></script>
<script language="JavaScript" src="js/chat.js"></script> <script src="js/chat.js"></script>
<style type="text/css"> <style>
a.hoversmile:hover { a.hoversmile:hover {
background-color: gray; background-color: gray;
} }

View File

@ -6,6 +6,8 @@
* Project name: Battles-Game * Project name: Battles-Game
*/ */
use Battles\Database\DBPDO;
ini_set('display_errors', 'On'); ini_set('display_errors', 'On');
error_reporting(E_ALL); error_reporting(E_ALL);
const GAMEDOMAIN = "battles.lan"; const GAMEDOMAIN = "battles.lan";
@ -44,13 +46,11 @@ spl_autoload_register(function ($className) {
/** /**
* Глобальные переменные. Промежуточное решение для совместимости. * Глобальные переменные. Промежуточное решение для совместимости.
*/ */
if (empty(\Battles\Database\DBPDO::$db)) { if (empty(DBPDO::$db)) {
\Battles\Database\DBPDO::$db = new \Battles\Database\DBPDO(); DBPDO::$db = new DBPDO();
}
if (empty(\Battles\User::$current) && $_SESSION['uid']) {
\Battles\User::$current = new \Battles\User($_SESSION['uid']);
} }
// Для нападалок. Сперва комнаты в которых нельзя напасть, потом персонажи на которых нельзя напасть. // Для нападалок. Сперва комнаты в которых нельзя напасть, потом персонажи на которых нельзя напасть.
const UNKILABLE = [ const UNKILABLE = [
'rooms' => [620, 621, 1051, 1052], 'rooms' => [620, 621, 1051, 1052],

View File

@ -13,12 +13,18 @@ use Battles\User;
use Battles\UserInfo; use Battles\UserInfo;
require_once 'config.php'; require_once 'config.php';
if (empty($_SESSION['uid'])) { if (empty($_SESSION['uid'])) {
header("Location: index.php"); header("Location: index.php");
exit; exit;
} else { } else {
if (empty($user) && $_SESSION['uid']) {
$user = new User($_SESSION['uid']); $user = new User($_SESSION['uid']);
}
if (empty(User::$current) && $_SESSION['uid']) {
User::$current = new User($_SESSION['uid']); User::$current = new User($_SESSION['uid']);
}
} }
if (User::$current->getId() && User::$current->getBlock()) { if (User::$current->getId() && User::$current->getBlock()) {
exit('user blocked!'); exit('user blocked!');

107
main.php
View File

@ -9,6 +9,7 @@ use Battles\Travel;
use Battles\UserInfo; use Battles\UserInfo;
use Battles\UserStats; use Battles\UserStats;
use Battles\User; use Battles\User;
use Exceptions\GameException;
$get = filter_input(INPUT_SERVER, 'QUERY_STRING'); $get = filter_input(INPUT_SERVER, 'QUERY_STRING');
if ($get == 'exit') { if ($get == 'exit') {
@ -19,47 +20,39 @@ require_once 'functions.php';
User::$current->setOnline(); User::$current->setOnline();
// Инициализируем входящие GET\POST переменные. $req = (object)[];
$goto = $_GET['goto'] ?? null; $keys = ['ups', 'drop', 'dress', 'destruct', 'use', 'undress', 'edit', 'goto', 'obraz', 'setshadow'];
$obraz = $_GET['obraz'] ?? null; foreach ($keys as $key) {
$del = $_GET['del'] ?? null; $req->$key = $_REQUEST[$key] ?? null;
$effectId = $_GET['efid'] ?? null; }
$brons = $_GET['modif_bron'] ?? null;
$stats = $_GET['modif_stat'] ?? null;
$mfs = $_GET['modif_mf'] ?? null;
$ids = $_GET['ids'] ?? null;
$setShadow = $_POST['setshadow'] ?? null;
$edit = $_GET['edit'] ?? null;
if ($edit) { if ($req->edit) {
$ups = $_GET['ups'] ?? null; if ($req->ups) {
$use = $_GET['use'] ?? null; try {
$useTarget = $_POST['target'] ?? null; $up = new UserInfo(User::$current->getId());
$drop = $_GET['drop'] ?? null; $up->addOnePointToStat($req->ups);
$dress = $_GET['dress'] ?? null; unset($up);
$undress = $_GET['undress'] ?? null; } catch (GameException $e) {
$destruct = $_GET['destruct'] ?? null; echo $e;
if ($ups) {
User::$current->addOnePointToStat($ups);
} }
if ($drop) { }
$items = new DressedItems($_SESSION['uid']); if ($req->drop) {
$items->undressItem($drop); $items = new DressedItems(User::$current->getId());
$items->undressItem($req->drop);
unset($items); unset($items);
} }
//Пока что одеваем предмет отсюда. //Пока что одеваем предмет отсюда.
if ($dress) { if ($req->dress) {
$dressing = new InventoryItem(DBPDO::$db->ofetch('select * from inventory where item_id = ? ', $dress)); $dressing = new InventoryItem(DBPDO::$db->ofetch('select * from inventory where item_id = ? ', $req->dress));
$dressing->dressItem(); $dressing->dressItem();
unset($dressing); unset($dressing);
} }
if ($destruct) { if ($req->destruct) {
$q = DBPDO::$db->ofetch('select name,dressed_slot from inventory where owner_id = ? and item_id = ?', [User::$current->getId(), $destruct]); $q = DBPDO::$db->ofetch('select name,dressed_slot from inventory where owner_id = ? and item_id = ?', [User::$current->getId(), $req->destruct]);
if ($q) { if ($q) {
if (empty($q->dressed_slot)) { if (empty($q->dressed_slot)) {
InventoryItem::destroyItem($destruct); InventoryItem::destroyItem($req->destruct);
GameLogs::addUserLog(User::$current->getId(), User::$current->getLogin() . ' выбросил предмет ' . $q->name . ' id:(cap' . $destruct . ')'); GameLogs::addUserLog(User::$current->getId(), User::$current->getLogin() . ' выбросил предмет ' . $q->name . ' id:(cap' . $req->destruct . ')');
err('Предмет ' . $q->name . ' выброшен.'); err('Предмет ' . $q->name . ' выброшен.');
} else { } else {
err('Ошибка: нельзя выбросить одетый предмет!'); err('Ошибка: нельзя выбросить одетый предмет!');
@ -68,11 +61,11 @@ if ($edit) {
err('Ошибка: предмет не найден!'); err('Ошибка: предмет не найден!');
} }
} }
if ($use) { if ($req->use) {
usemagic($use, $useTarget); usemagic($req->use, $req->useTarget);
} }
if ($undress) { if ($req->undress) {
DressedItems::undressAllItems($_SESSION['uid']); DressedItems::undressAllItems(User::$current->getId());
} }
} }
@ -87,28 +80,28 @@ foreach ($data as $row) {
} }
//Обработчики нажатий на кнопки. //Обработчики нажатий на кнопки.
if ($_POST['battlefield'] ?? 0 && User::$current->getRoom() == 1) { if ($req->battlefield ?? 0 && User::$current->getRoom() == 1) {
header('Location: zayavka.php'); header('Location: zayavka.php');
exit(); exit();
} }
if ($_POST['module_quest'] ?? 0) { if ($req->module_quest ?? 0) {
header('Location: module_quest.php'); header('Location: module_quest.php');
exit(); exit();
} }
if ($_POST['move_inside'] ?? 0 && User::$current->getRoom() == 20) { if ($req->move_inside ?? 0 && User::$current->getRoom() == 20) {
header('Location: main.php?goto=arena'); header('Location: main.php?goto=arena');
exit(); exit();
} }
if ($_POST['move_outside'] ?? 0 && User::$current->getRoom() == 1) { if ($req->move_outside ?? 0 && User::$current->getRoom() == 1) {
header('Location: main.php?goto=plo'); header('Location: main.php?goto=plo');
exit(); exit();
} }
if ($_POST['main_page'] ?? 0) { if ($req->main_page ?? 0) {
header('Location: main.php'); header('Location: main.php');
exit(); exit();
} }
if ($edit === null) { if (!$req->edit) {
/* === проверяем соответствие комнаты и скрипта === */ /* === проверяем соответствие комнаты и скрипта === */
if (in_array(User::$current->getRoom(), [20, 21, 26, 48, 51, 52, 651, 2655, 2601, 2701, 2702, 2111])) { if (in_array(User::$current->getRoom(), [20, 21, 26, 48, 51, 52, 651, 2655, 2601, 2701, 2702, 2111])) {
header('Location: city.php'); header('Location: city.php');
@ -133,44 +126,44 @@ function del_efs($id, $type)
} }
// Входим и выходим если можем. // Входим и выходим если можем.
if ($goto) { if ($req->goto) {
$imove = true; $imove = true;
$d = db::c()->query('SELECT SUM(weight) AS sum_weight FROM inventory WHERE owner_id = ?i AND on_sale = 0', User::$current->getId())->fetch_assoc(); $d = db::c()->query('SELECT SUM(weight) AS sum_weight FROM inventory WHERE owner_id = ?i AND on_sale = 0', User::$current->getId())->fetch_assoc();
$eff = db::c()->query('SELECT 1 FROM `users_effects` WHERE `owner_id` = ?i AND (`type` = 14 OR `type` = 13)', User::$current->getId()); $eff = db::c()->query('SELECT 1 FROM `users_effects` WHERE `owner_id` = ?i AND (`type` = 14 OR `type` = 13)', User::$current->getId());
//(масса: <?= $getItemsBonuses->getItemsWeight() . '/' . User::$current->strength * 4 //(масса: <?= $getItemsBonuses->getItemsWeight() . '/' . User::$current->strength * 4
if ($d['sum_weight'] > $userStats->getStrength() * 4 && $goto) { if ($d['sum_weight'] > $userStats->getStrength() * 4) {
err('У вас переполнен рюкзак, вы не можете передвигаться...'); err('У вас переполнен рюкзак, вы не можете передвигаться...');
$imove = false; $imove = false;
} }
if ($eff->getNumRows() && $goto) { if ($eff->getNumRows()) {
err('У вас тяжелая травма, вы не можете передвигатся...'); err('У вас тяжелая травма, вы не можете передвигатся...');
$imove = false; $imove = false;
} }
if ($goto == 'plo' && !User::$current->getZayavka() && $imove && User::$current->getRoom() != 20) { if ($req->goto == 'plo' && !User::$current->getZayavka() && $imove && User::$current->getRoom() != 20) {
db::c()->query('UPDATE users, online SET users.room = 20, online.room = 20 WHERE online.user_id = users.id AND online.user_id = ?i', User::$current->getId()); db::c()->query('UPDATE users, online SET users.room = 20, online.room = 20 WHERE online.user_id = users.id AND online.user_id = ?i', User::$current->getId());
header('Location: city.php'); header('Location: city.php');
exit("<i>Топ-топ-топ...</i>"); exit("<i>Топ-топ-топ...</i>");
} else { } else {
err('Подали заявку на бой и убегаете из клуба? Нехорошо...'); err('Подали заявку на бой и убегаете из клуба? Нехорошо...');
} }
if ($goto == 'arena' && User::$current->getRoom() == 20 && $imove) { if ($req->goto == 'arena' && User::$current->getRoom() == 20 && $imove) {
db::c()->query('UPDATE users, online SET users.room = 1, online.room = 1 WHERE online.user_id = users.id AND online.user_id = ?i', User::$current->getId()); db::c()->query('UPDATE users, online SET users.room = 1, online.room = 1 WHERE online.user_id = users.id AND online.user_id = ?i', User::$current->getId());
header('Location: main.php'); header('Location: main.php');
exit("<i>Топ-топ-топ...</i>"); exit("<i>Топ-топ-топ...</i>");
} }
} }
if (isset($_GET['use'])) { if ($req->use) {
usemagic($_GET['use'], $_POST['target']); usemagic($req->use, $req->target);
} }
if ($obraz) { if ($req->obraz) {
User::$current->setShadow($obraz); User::$current->setShadow($req->obraz);
User::$current->saveUser(); User::$current->saveUser();
} }
if ($setShadow) { if ($req->setshadow) {
Template::header('Образ персонажа'); Template::header('Образ персонажа');
?> ?>
<div style="text-align: right;"> <div style="text-align: right;">
@ -263,7 +256,7 @@ Template::header('Игра');
</script> </script>
<div id=hint3 class=ahint></div> <div id=hint3 class=ahint></div>
<div id="chpassbank" style="display:none; position:absolute; top:50px; left:250px;"></div> <div id="chpassbank" style="display:none; position:absolute; top:50px; left:250px;"></div>
<?php $userInfo->showUserInfoMain()?> <?php $userInfo->showUserInfoMain() ?>
<table style="width: 100%;filter: sepia(1);background: white;"> <table style="width: 100%;filter: sepia(1);background: white;">
<TR> <TR>
<td style="vertical-align: top; width: 350px"> <td style="vertical-align: top; width: 350px">
@ -307,8 +300,14 @@ Template::header('Игра');
<?php endif; ?> <?php endif; ?>
<br> <br>
<!-- #18 Разобраться в прогрессбарах --> <!-- #18 Разобраться в прогрессбарах -->
Здоровье: <progress max="<?= $userStats->getMaxHealth() ?>" value="<?= $userStats->getHealth() ?>"><?= $userStats->getHealth() ?></progress><br> Здоровье:
Пыль: <progress max="<?= $userStats->getMaxMana() ?>" value="<?= $userStats->getMana() ?>"><?= $userStats->getMana() ?></progress><br> <progress max="<?= $userStats->getMaxHealth() ?>"
value="<?= $userStats->getHealth() ?>"><?= $userStats->getHealth() ?></progress>
<br>
Пыль:
<progress max="<?= $userStats->getMaxMana() ?>"
value="<?= $userStats->getMana() ?>"><?= $userStats->getMana() ?></progress>
<br>
Уворот: <?= $userStats->getFullStats()->evasion ?><br> Уворот: <?= $userStats->getFullStats()->evasion ?><br>
Точность: <?= $userStats->getFullStats()->accuracy ?><br> Точность: <?= $userStats->getFullStats()->accuracy ?><br>
Шанс крита: <?= $userStats->getFullStats()->criticals ?><br> Шанс крита: <?= $userStats->getFullStats()->criticals ?><br>

View File

@ -5,6 +5,7 @@ use Battles\Database\DBPDO;
use Battles\Item; use Battles\Item;
use Battles\ShopItem; use Battles\ShopItem;
use Battles\Template; use Battles\Template;
use Battles\User;
require_once 'functions.php'; require_once 'functions.php';
$saleItems = false; $saleItems = false;
@ -13,14 +14,14 @@ $shopCategoryTypeNumber = $_GET['otdel'] ?? 0;
$status = null; $status = null;
if (!empty($_POST['sellshop'])) { if (!empty($_POST['sellshop'])) {
$status = ShopItem::sellItem($_POST['itemId'], $user, 1); $status = ShopItem::sellItem($_POST['itemId'], User::$current, 1);
} }
if (!empty($_POST['buyshop'])) { if (!empty($_POST['buyshop'])) {
$status = ShopItem::buyItem($_POST['itemId'], $user); $status = ShopItem::buyItem($_POST['itemId'], User::$current);
} }
$bank = new Bank($user->getId()); $bank = new Bank(User::$current->getId());
switch ($shopCategoryTypeNumber) { switch ($shopCategoryTypeNumber) {
default: default: