code clean
This commit is contained in:
parent
5e264f837a
commit
9c7fcda600
@ -11,10 +11,10 @@ if ($header) {
|
||||
} elseif ($ch != null) {
|
||||
Template::header('buttons');
|
||||
?>
|
||||
<script language="JavaScript" src="js/ch.js"></script>
|
||||
<script language="JavaScript" src="js/sl2.js"></script>
|
||||
<script language="JavaScript" src="js/chat.js"></script>
|
||||
<style type="text/css">
|
||||
<script src="js/ch.js"></script>
|
||||
<script src="js/sl2.js"></script>
|
||||
<script src="js/chat.js"></script>
|
||||
<style>
|
||||
a.hoversmile:hover {
|
||||
background-color: gray;
|
||||
}
|
||||
|
10
config.php
10
config.php
@ -6,6 +6,8 @@
|
||||
* Project name: Battles-Game
|
||||
*/
|
||||
|
||||
use Battles\Database\DBPDO;
|
||||
|
||||
ini_set('display_errors', 'On');
|
||||
error_reporting(E_ALL);
|
||||
const GAMEDOMAIN = "battles.lan";
|
||||
@ -44,13 +46,11 @@ spl_autoload_register(function ($className) {
|
||||
/**
|
||||
* Глобальные переменные. Промежуточное решение для совместимости.
|
||||
*/
|
||||
if (empty(\Battles\Database\DBPDO::$db)) {
|
||||
\Battles\Database\DBPDO::$db = new \Battles\Database\DBPDO();
|
||||
}
|
||||
if (empty(\Battles\User::$current) && $_SESSION['uid']) {
|
||||
\Battles\User::$current = new \Battles\User($_SESSION['uid']);
|
||||
if (empty(DBPDO::$db)) {
|
||||
DBPDO::$db = new DBPDO();
|
||||
}
|
||||
|
||||
|
||||
// Для нападалок. Сперва комнаты в которых нельзя напасть, потом персонажи на которых нельзя напасть.
|
||||
const UNKILABLE = [
|
||||
'rooms' => [620, 621, 1051, 1052],
|
||||
|
@ -13,13 +13,19 @@ use Battles\User;
|
||||
use Battles\UserInfo;
|
||||
|
||||
require_once 'config.php';
|
||||
|
||||
if (empty($_SESSION['uid'])) {
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
} else {
|
||||
if (empty($user) && $_SESSION['uid']) {
|
||||
$user = new User($_SESSION['uid']);
|
||||
}
|
||||
|
||||
if (empty(User::$current) && $_SESSION['uid']) {
|
||||
User::$current = new User($_SESSION['uid']);
|
||||
}
|
||||
}
|
||||
if (User::$current->getId() && User::$current->getBlock()) {
|
||||
exit('user blocked!');
|
||||
}
|
||||
|
107
main.php
107
main.php
@ -9,6 +9,7 @@ use Battles\Travel;
|
||||
use Battles\UserInfo;
|
||||
use Battles\UserStats;
|
||||
use Battles\User;
|
||||
use Exceptions\GameException;
|
||||
|
||||
$get = filter_input(INPUT_SERVER, 'QUERY_STRING');
|
||||
if ($get == 'exit') {
|
||||
@ -19,47 +20,39 @@ require_once 'functions.php';
|
||||
|
||||
User::$current->setOnline();
|
||||
|
||||
// Инициализируем входящие GET\POST переменные.
|
||||
$goto = $_GET['goto'] ?? null;
|
||||
$obraz = $_GET['obraz'] ?? null;
|
||||
$del = $_GET['del'] ?? 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) {
|
||||
$ups = $_GET['ups'] ?? null;
|
||||
$use = $_GET['use'] ?? null;
|
||||
$useTarget = $_POST['target'] ?? null;
|
||||
$drop = $_GET['drop'] ?? null;
|
||||
$dress = $_GET['dress'] ?? null;
|
||||
$undress = $_GET['undress'] ?? null;
|
||||
$destruct = $_GET['destruct'] ?? null;
|
||||
|
||||
if ($ups) {
|
||||
User::$current->addOnePointToStat($ups);
|
||||
$req = (object)[];
|
||||
$keys = ['ups', 'drop', 'dress', 'destruct', 'use', 'undress', 'edit', 'goto', 'obraz', 'setshadow'];
|
||||
foreach ($keys as $key) {
|
||||
$req->$key = $_REQUEST[$key] ?? null;
|
||||
}
|
||||
if ($drop) {
|
||||
$items = new DressedItems($_SESSION['uid']);
|
||||
$items->undressItem($drop);
|
||||
|
||||
if ($req->edit) {
|
||||
if ($req->ups) {
|
||||
try {
|
||||
$up = new UserInfo(User::$current->getId());
|
||||
$up->addOnePointToStat($req->ups);
|
||||
unset($up);
|
||||
} catch (GameException $e) {
|
||||
echo $e;
|
||||
}
|
||||
}
|
||||
if ($req->drop) {
|
||||
$items = new DressedItems(User::$current->getId());
|
||||
$items->undressItem($req->drop);
|
||||
unset($items);
|
||||
}
|
||||
//Пока что одеваем предмет отсюда.
|
||||
if ($dress) {
|
||||
$dressing = new InventoryItem(DBPDO::$db->ofetch('select * from inventory where item_id = ? ', $dress));
|
||||
if ($req->dress) {
|
||||
$dressing = new InventoryItem(DBPDO::$db->ofetch('select * from inventory where item_id = ? ', $req->dress));
|
||||
$dressing->dressItem();
|
||||
unset($dressing);
|
||||
}
|
||||
if ($destruct) {
|
||||
$q = DBPDO::$db->ofetch('select name,dressed_slot from inventory where owner_id = ? and item_id = ?', [User::$current->getId(), $destruct]);
|
||||
if ($req->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 (empty($q->dressed_slot)) {
|
||||
InventoryItem::destroyItem($destruct);
|
||||
GameLogs::addUserLog(User::$current->getId(), User::$current->getLogin() . ' выбросил предмет ' . $q->name . ' id:(cap' . $destruct . ')');
|
||||
InventoryItem::destroyItem($req->destruct);
|
||||
GameLogs::addUserLog(User::$current->getId(), User::$current->getLogin() . ' выбросил предмет ' . $q->name . ' id:(cap' . $req->destruct . ')');
|
||||
err('Предмет ' . $q->name . ' выброшен.');
|
||||
} else {
|
||||
err('Ошибка: нельзя выбросить одетый предмет!');
|
||||
@ -68,11 +61,11 @@ if ($edit) {
|
||||
err('Ошибка: предмет не найден!');
|
||||
}
|
||||
}
|
||||
if ($use) {
|
||||
usemagic($use, $useTarget);
|
||||
if ($req->use) {
|
||||
usemagic($req->use, $req->useTarget);
|
||||
}
|
||||
if ($undress) {
|
||||
DressedItems::undressAllItems($_SESSION['uid']);
|
||||
if ($req->undress) {
|
||||
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');
|
||||
exit();
|
||||
}
|
||||
if ($_POST['module_quest'] ?? 0) {
|
||||
if ($req->module_quest ?? 0) {
|
||||
header('Location: module_quest.php');
|
||||
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');
|
||||
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');
|
||||
exit();
|
||||
}
|
||||
if ($_POST['main_page'] ?? 0) {
|
||||
if ($req->main_page ?? 0) {
|
||||
header('Location: main.php');
|
||||
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])) {
|
||||
header('Location: city.php');
|
||||
@ -133,44 +126,44 @@ function del_efs($id, $type)
|
||||
}
|
||||
|
||||
// Входим и выходим если можем.
|
||||
if ($goto) {
|
||||
if ($req->goto) {
|
||||
$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();
|
||||
$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
|
||||
|
||||
if ($d['sum_weight'] > $userStats->getStrength() * 4 && $goto) {
|
||||
if ($d['sum_weight'] > $userStats->getStrength() * 4) {
|
||||
err('У вас переполнен рюкзак, вы не можете передвигаться...');
|
||||
$imove = false;
|
||||
}
|
||||
if ($eff->getNumRows() && $goto) {
|
||||
if ($eff->getNumRows()) {
|
||||
err('У вас тяжелая травма, вы не можете передвигатся...');
|
||||
$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());
|
||||
header('Location: city.php');
|
||||
exit("<i>Топ-топ-топ...</i>");
|
||||
} else {
|
||||
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());
|
||||
header('Location: main.php');
|
||||
exit("<i>Топ-топ-топ...</i>");
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($_GET['use'])) {
|
||||
usemagic($_GET['use'], $_POST['target']);
|
||||
if ($req->use) {
|
||||
usemagic($req->use, $req->target);
|
||||
}
|
||||
|
||||
if ($obraz) {
|
||||
User::$current->setShadow($obraz);
|
||||
if ($req->obraz) {
|
||||
User::$current->setShadow($req->obraz);
|
||||
User::$current->saveUser();
|
||||
}
|
||||
|
||||
if ($setShadow) {
|
||||
if ($req->setshadow) {
|
||||
Template::header('Образ персонажа');
|
||||
?>
|
||||
<div style="text-align: right;">
|
||||
@ -307,8 +300,14 @@ Template::header('Игра');
|
||||
<?php endif; ?>
|
||||
<br>
|
||||
<!-- #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()->accuracy ?><br>
|
||||
Шанс крита: <?= $userStats->getFullStats()->criticals ?><br>
|
||||
|
7
shop.php
7
shop.php
@ -5,6 +5,7 @@ use Battles\Database\DBPDO;
|
||||
use Battles\Item;
|
||||
use Battles\ShopItem;
|
||||
use Battles\Template;
|
||||
use Battles\User;
|
||||
|
||||
require_once 'functions.php';
|
||||
$saleItems = false;
|
||||
@ -13,14 +14,14 @@ $shopCategoryTypeNumber = $_GET['otdel'] ?? 0;
|
||||
$status = null;
|
||||
|
||||
if (!empty($_POST['sellshop'])) {
|
||||
$status = ShopItem::sellItem($_POST['itemId'], $user, 1);
|
||||
$status = ShopItem::sellItem($_POST['itemId'], User::$current, 1);
|
||||
}
|
||||
|
||||
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) {
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user