Merge pull request 'dev-shop' (#51) from dev-shop into master

Reviewed-on: #51
This commit is contained in:
Ivor Barhansky 2022-01-21 15:11:53 +00:00
commit 8e3a14eb2c
2876 changed files with 4155 additions and 7741 deletions

View File

@ -4,7 +4,6 @@
* Author: Igor Barkov <lopar.4ever@gmail.com> * Author: Igor Barkov <lopar.4ever@gmail.com>
* Project name: Battles-Game * Project name: Battles-Game
*/ */
session_start();
require_once '../functions.php'; require_once '../functions.php';
use Battles\Bank; use Battles\Bank;
@ -15,17 +14,17 @@ use Battles\Nick;
use Battles\Template; use Battles\Template;
use Battles\User; use Battles\User;
if (!$user->getAdmin()) { if (!User::$current->getAdmin()) {
header("HTTP/1.0 404 Not Found"); header("HTTP/1.0 404 Not Found");
exit; exit;
} }
if (isset($_GET['sleep'])) { if (isset($_GET['sleep'])) {
Moderation::muteChat($user->getId(), strtotime('15min')); Moderation::muteChat(User::$current->getId(), strtotime('15min'));
} }
if (isset($_POST['ldnick']) && isset($_POST['ldtext'])) { if (isset($_POST['ldnick']) && isset($_POST['ldtext'])) {
$u = new User($_POST['ldnick']); $u = new User($_POST['ldnick']);
Moderation::addToUserLog($u->getId(), $_POST['ldtext'], $user->getId()); Moderation::addToUserLog($u->getId(), $_POST['ldtext'], User::$current->getId());
unset($u); unset($u);
} }
@ -35,11 +34,10 @@ if (isset($_POST['syschatmsg'])) {
//clans to reg //clans to reg
$unregisteredClans = new class { $unregisteredClans = new class {
public $db;
public function getList() public function getList()
{ {
$row = $this->db->ofetchAll('SELECT * FROM clans WHERE status = 0'); $row = DBPDO::$db->ofetchAll('SELECT * FROM clans WHERE status = 0');
$i = 0; $i = 0;
while ($i < count($row)) { while ($i < count($row)) {
$id = $row[$i]->owner_id; $id = $row[$i]->owner_id;
@ -66,17 +64,16 @@ UNREGCLANLIST;
public function allowRegister($id) public function allowRegister($id)
{ {
$this->db->execute('UPDATE clans SET status = 1 WHERE status = 0 AND owner_id = ?', $id); DBPDO::$db->execute('UPDATE clans SET status = 1 WHERE status = 0 AND owner_id = ?', $id);
} }
public function disallowRegister($id) public function disallowRegister($id)
{ {
$bank = new Bank($id); $bank = new Bank($id);
$this->db->execute('DELETE FROM clans WHERE status = 0 AND owner_id = ?', $id); DBPDO::$db->execute('DELETE FROM clans WHERE status = 0 AND owner_id = ?', $id);
$bank::setBankMoney($bank->getMoney() + GameConfigs::CLAN_REGISTER_COST, $id); $bank::setBankMoney($bank->getMoney() + GameConfigs::CLAN['clan_register_cost'], $id);
} }
}; };
$unregisteredClans->db = new DBPDO();
$unregisteredClans->getList(); $unregisteredClans->getList();
if (isset($_GET['regclan'])) { if (isset($_GET['regclan'])) {
@ -92,19 +89,15 @@ if (isset($_GET['remclan'])) {
# Телеграф. # Телеграф.
if (!empty($_POST['receiver']) && !empty($_POST['tgmsg'])) { if (!empty($_POST['receiver']) && !empty($_POST['tgmsg'])) {
$receiver = DBPDO::INIT()->ofetch('SELECT id FROM users WHERE login= ?', $_POST['receiver']); $receiver = DBPDO::$db->ofetch('SELECT id FROM users WHERE login= ?', $_POST['receiver']);
telegraph($receiver->id, $_POST['tgmsg']); telegraph($receiver->id, $_POST['tgmsg']);
echo "Успешно."; echo "Успешно.";
} }
# Показывает невидимок. # Показывает невидимок.
$row = DBPDO::INIT()->ofetchAll('SELECT id,login FROM users LEFT JOIN users_effects ue on users.id = ue.owner_id WHERE type = 1022 ORDER BY `id` DESC'); $row = DBPDO::$db->ofetchAll('SELECT id,login FROM users LEFT JOIN users_effects ue on users.id = ue.owner_id WHERE type = 1022 ORDER BY `id` DESC');
$i = 0; foreach ($row as $r) {
$invisList = ''; $invisList .= '<b>[id] = ' .$r->id. ', ' .$r->login. '</b><br>';
while ($i < count($row)) {
$invisList .= '<b>[id] = ' . $row[$i]->id . ', ' . $row[$i]->login . ' </b><br>';
$i++;
} }
unset($i);
Template::header('ᐰdminка'); Template::header('ᐰdminка');

View File

@ -5,9 +5,11 @@
* Project name: Battles-Game * Project name: Battles-Game
*/ */
session_start(); use Battles\Database\DBPDO;
use Battles\DressedItems;
use Battles\Template;
require_once "../functions.php"; require_once "../functions.php";
$user = $user ?? new User($_SESSION['uid']);
if (!$user->getAdmin()) { if (!$user->getAdmin()) {
header("HTTP/1.0 404 Not Found"); header("HTTP/1.0 404 Not Found");
exit; exit;
@ -19,13 +21,13 @@ $end = $_POST['end'] ?? null;
$del = $_POST['del'] ?? null; $del = $_POST['del'] ?? null;
if ($player) { if ($player) {
$row = db::c()->query('SELECT id, login FROM users WHERE id = "?s" OR login = "?s"', $player, $player)->fetch_assoc(); $row = DBPDO::$db->ofetch('select id, login from users where id = ? or login = ?', [$player, $player]);
$_SESSION['player_id'] = $row['id']; $_SESSION['player_id'] = $row->id;
$_SESSION['player_name'] = $row['login']; $_SESSION['player_name'] = $row->login;
unset($row); unset($row);
} }
if ($undress_char) { if ($undress_char) {
\Battles\DressedItems::undressAllItems($_SESSION['player_id']); DressedItems::undressAllItems($_SESSION['player_id']);
} }
if ($end) { if ($end) {
unset($_SESSION['player_id']); unset($_SESSION['player_id']);
@ -37,16 +39,16 @@ if (isset($_SESSION['player_id'])) {
if ($del) { if ($del) {
$itemdel = db::c()->query('SELECT item_type, dressed_slot FROM inventory WHERE id=?i', $del)->fetch_assoc(); $itemdel = db::c()->query('SELECT item_type, dressed_slot FROM inventory WHERE id=?i', $del)->fetch_assoc();
if ($itemdel['dressed_slot'] == 1) { if ($itemdel['dressed_slot'] == 1) {
$item = new \Battles\DressedItems($del); $item = new DressedItems($del);
$item->undressItem($itemdel['item_type']); $item->undressItem($itemdel['item_type']);
if ($itemdel['item_type'] == 5) { if ($itemdel['item_type'] == 5) {
$item->undressItem(6); $item->undressItem(6);
$item->undressItem(7); $item->undressItem(7);
} }
} }
db::c()->query('DELETE FROM `inventory` WHERE `id` = ?i', $del); DBPDO::$db->execute('delete from inventory where id = ?', $del);
} }
\Battles\Template::header('ᐰdminка инвентаря'); Template::header('ᐰdminка инвентаря');
?> ?>
<h1>Администрирование инвентаря <?php if (isset($_SESSION['player_name'])) echo $_SESSION['player_name']; ?></h1> <h1>Администрирование инвентаря <?php if (isset($_SESSION['player_name'])) echo $_SESSION['player_name']; ?></h1>
<table class='adm'> <table class='adm'>

View File

@ -1,6 +1,5 @@
<?php <?php
session_start();
include "config.php"; include "config.php";
//$user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '2106' LIMIT 1;")); //$user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '2106' LIMIT 1;"));
//include "functions.php"; //include "functions.php";

View File

@ -3,11 +3,8 @@
use Battles\Bank; use Battles\Bank;
use Battles\GameLogs; use Battles\GameLogs;
use Battles\Template; use Battles\Template;
use Battles\User;
session_start();
require_once 'functions.php'; require_once 'functions.php';
$user = $user ?? new User($_SESSION['uid']);
const SMITH = 'оружейник'; const SMITH = 'оружейник';
const MERCENARY = 'наёмник'; const MERCENARY = 'наёмник';
const MEDIC = 'лекарь'; const MEDIC = 'лекарь';

View File

@ -1,5 +1,8 @@
<?php <?php
session_start();
use Battles\GameLogs;
use Battles\Template;
require_once "functions.php"; require_once "functions.php";
$start = db::c()->query('SELECT `value` FROM `variables` WHERE `var` = "arena_of_gods"')->fetch_assoc(); $start = db::c()->query('SELECT `value` FROM `variables` WHERE `var` = "arena_of_gods"')->fetch_assoc();
@ -23,7 +26,7 @@ function join_arena($u, $btl, $team, $at)
} else { } else {
$adtxt = 'За сторону <b>Света</b>.'; $adtxt = 'За сторону <b>Света</b>.';
} }
addlog($btl, '<span class=date>' . date("H:i") . '</span> ' . Nick::id($u)->short() . ' вмешался в поединок! ' . $adtxt . '<br />'); GameLogs::addBattleLog($btl, '<span class=date>' . date("H:i") . '</span> ' . Nick::id($u)->short() . ' вмешался в поединок! ' . $adtxt . '<br />');
mysql_query('UPDATE `battle` SET `teams` = \'' . serialize($battle) . '\', `t' . $team . '` = CONCAT(`t' . $team . '`,\';' . $u . '\') WHERE `id` = "' . $btl . '" LIMIT 1'); mysql_query('UPDATE `battle` SET `teams` = \'' . serialize($battle) . '\', `t' . $team . '` = CONCAT(`t' . $team . '`,\';' . $u . '\') WHERE `id` = "' . $btl . '" LIMIT 1');
mysql_query("UPDATE users SET `battle` = '" . $btl . "', `zayavka` = 0 WHERE `id` = '" . $u . "' LIMIT 1"); mysql_query("UPDATE users SET `battle` = '" . $btl . "', `zayavka` = 0 WHERE `id` = '" . $u . "' LIMIT 1");
header("Location: fbattle.php"); header("Location: fbattle.php");
@ -121,7 +124,7 @@ if (isset($_GET['append'])) {
} }
} }
} }
\Battles\Template::header('Арена Ангелов'); Template::header('Арена Ангелов');
?> ?>
<link href="css/fight.css" rel="stylesheet"/> <link href="css/fight.css" rel="stylesheet"/>
<style> <style>

View File

@ -4,13 +4,9 @@ use Battles\Bank;
use Battles\GameConfigs; use Battles\GameConfigs;
use Battles\Rooms; use Battles\Rooms;
use Battles\Template; use Battles\Template;
use Battles\User;
use Exceptions\GameException; use Exceptions\GameException;
ob_start("ob_gzhandler");
session_start();
require_once "functions.php"; require_once "functions.php";
$user = $user ?? new User($_SESSION['uid']);
const SUCCESS = "Успешная операция!"; const SUCCESS = "Успешная операция!";
$bank = new Bank($user->getId()); $bank = new Bank($user->getId());

View File

@ -1,5 +1,7 @@
<?php <?php
session_start();
use Battles\Template;
require_once "functions.php"; require_once "functions.php";
$header = $_GET['header'] ?? null; $header = $_GET['header'] ?? null;
$ch = $_GET['ch'] ?? null; $ch = $_GET['ch'] ?? null;
@ -7,12 +9,12 @@ $ch = $_GET['ch'] ?? null;
if ($header) { if ($header) {
exit; exit;
} elseif ($ch != null) { } elseif ($ch != null) {
\Battles\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;
} }
@ -231,7 +233,7 @@ if ($header) {
<div id="oMenu" style="position: absolute; border:1px solid #666; background-color:#CCC; display:none; "></div> <div id="oMenu" style="position: absolute; border:1px solid #666; background-color:#CCC; display:none; "></div>
<div id="ClearMenu" style="position: absolute; border:1px solid #666; background-color: #e2e0e0; display: none;"></div> <div id="ClearMenu" style="position: absolute; border:1px solid #666; background-color: #e2e0e0; display: none;"></div>
<? } else { \Battles\Template::header('buttons'); ?> <? } else { Template::header('buttons'); ?>
<script language="JavaScript" src="js/chat.js"></script> <script language="JavaScript" src="js/chat.js"></script>
<script language="JavaScript"> <script language="JavaScript">

92
buy.php
View File

@ -1,56 +1,48 @@
<?php <?php
//Покупка абилок? Тут?!
session_start();
if (empty($_SESSION['uid'])) {
header('Location: Index.php');
exit;
}
include('config.php');
$is_now = db::c()->query('SELECT `id`, `uid` FROM `abils_user` WHERE `uid` = ?i', $user['id'])->fetch_assoc();
function add_user_abil($ab, $cost) use Battles\Bank;
use Battles\Database\DBPDO;
use Battles\User;
require_once "functions.php";
if (User::$current->getBattle()) {
exit();
}
const PRICES = [
'sleep15' => 20,
'sleep30' => 20,
'closebattle' => 100,
'heal20' => 10,
'heal35' => 25,
'heal50' => 50,
'travmoff' => 10,
'attack' => 10,
'bloodattack' => 25,
'death' => 100,
'comment' => 5,
'openbattle' => 100,
'reamdeath' => 50,
'clone' => 25,
'unclone' => 25,
];
$check_bonuses = DBPDO::$db->ofetch('select 1 from users_bonuses where user_id = ?', User::$current->getId());
if (!$check_bonuses) {
exit('Запрещено: Вам нельзя покупать бонусы.');
}
function buy_bonus($name): bool
{ {
global $user, $banks; global $prices;
if (isset($ab) && $banks['ekr'] >= $cost) { $bank = new Bank(User::$current->getId());
$isset = mysql_fetch_array(mysql_query('SELECT `id`, `' . $ab . '` FROM `abils_user` WHERE `uid` = "' . $user['id'] . '" LIMIT 1')); if ($bank->getMoney() <= PRICES[$name]) {
$isset[$ab] += 1; return false;
mysql_query('UPDATE `abils_user` SET `' . $ab . '` = "' . $isset[$ab] . '" WHERE `uid` = "' . $user['id'] . '"');
$banks['ekr'] -= $cost;
mysql_query('UPDATE `bank` SET `ekr` = "' . $banks['ekr'] . '" WHERE `id` = "' . $user['id'] . '"');
return true;
} }
return false; $query = sprintf('update users_bonuses set %s = %s + 1 where user_id = ?', $name, $name);
DBPDO::$db->execute($query, User::$current->getId());
$bank->setMoney($bank->getMoney() - $prices[$name]);
return true;
} }
$cost = [1, 2, 10, 0.50, 0.80, 1, 1, 0.10, 0.20, 4, 0.02, 20, 10, 1, 1]; echo !empty($_POST['type']) && buy_bonus($_POST['type']) ? 'success' : 'error';
$mag = ['sleep15', 'sleep30', 'closebattle', 'heal20', 'heal35', 'heal50', 'travmoff', 'attack', 'bloodattack', 'death', 'comment', 'openbattle', 'reamdeath', 'clone', 'unclone'];
if (isset($_POST['type'], $_POST['user'])) {
if (isset($user['id'])) {
$price = $cost[$_POST['type'] - 1];
$abil = $mag[$_POST['type'] - 1];
if (isset($banks['id'])) {
if ($banks['ekr'] >= $price) {
if (isset($is_now['id'])) {
if ($user['battle'] == 0) {
if (add_user_abil($abil, $price)) {
echo 'success';
} else {
echo 'Error';
}
} else {
echo 'Не в бою ...';
}
} else {
echo 1;
}
} else {
echo 'Не хватает средств';
}
} else {
echo '<small>Выберите счёт в банке</small>';
}
} else {
echo "Вы не авторизированы";
}
}

View File

@ -1,61 +1,52 @@
<?php <?php
session_start();
if (empty($_SESSION['uid'])) { use Battles\Bank;
exit; use Battles\Database\DBPDO;
} use Battles\User;
require_once "functions.php"; require_once "functions.php";
if (!User::$current->getClan() || User::$current->getBattle()) {
if (empty($user->getClan())) { exit();
exit;
} }
$is_now = db::c()->query('SELECT `id` FROM `abils_klan` WHERE `klan` = ?i', $user['klan'])->fetch_assoc(); const PRICES = [
$clan = db::c()->query('SELECT `glava` FROM `clans` WHERE `id` = ?i', $user['klan'])->fetch_assoc(); 'sleep15' => 20,
$cost = [1, 2, 10, 0.50, 0.80, 1, 1, 0.10, 0.20, 4, 0.02, 20, 10, 1, 1]; 'sleep30' => 20,
$mag = ['sleep15', 'sleep30', 'closebattle', 'heal20', 'heal35', 'heal50', 'travmoff', 'attack', 'bloodattack', 'death', 'comment', 'openbattle', 'reamdeath', 'clone', 'unclone']; 'closebattle' => 100,
'heal20' => 10,
'heal35' => 25,
'heal50' => 50,
'travmoff' => 10,
'attack' => 10,
'bloodattack' => 25,
'death' => 100,
'comment' => 5,
'openbattle' => 100,
'reamdeath' => 50,
'clone' => 25,
'unclone' => 25,
];
function add_klan_abil($ab, $cost) $check_owner = DBPDO::$db->ofetch('select short_name from clans where owner_id = ?', User::$current->getId());
$check_bonuses = DBPDO::$db->ofetch('select 1 from clan_bonuses where short_name = ?', User::$current->getClan());
if (User::$current->getClan() !== $check_owner->short_name) {
exit('Запрещено: Вы не глава клана.');
}
if (!$check_bonuses) {
exit('Запрещено: Вашему клану нельзя покупать бонусы.');
}
function buy_bonus($name): bool
{ {
global $user, $banks; global $prices;
$clan = mysql_fetch_array(mysql_query('SELECT `id`, `glava` FROM `clans` WHERE `id` = "' . $user['klan'] . '"')); $bank = new Bank(User::$current->getId());
if (isset($ab) && $banks['ekr'] >= $cost && $clan['glava'] == $user['id']) { if ($bank->getMoney() <= PRICES[$name]) {
$isset = mysql_fetch_array(mysql_query('SELECT `id`, `' . $ab . '` FROM `abils_klan` WHERE `klan` = "' . $user['klan'] . '"')); return false;
$isset[$ab] += 1;
mysql_query('UPDATE `abils_klan` SET `' . $ab . '` = "' . $isset[$ab] . '" WHERE `klan` = "' . $user['klan'] . '"');
$banks['ekr'] -= $cost;
mysql_query('UPDATE `bank` SET `ekr` = "' . $banks['ekr'] . '" WHERE `id` = "' . $user['id'] . '"');
return true;
} }
return false; $query = sprintf('update clan_bonuses set %s = %s + 1 where short_name = ?', $name, $name);
DBPDO::$db->execute($query, User::$current->getClan());
$bank->setMoney($bank->getMoney() - $prices[$name]);
return true;
} }
if (isset($_POST['type'], $_POST['user'])) { echo !empty($_POST['type']) && buy_bonus($_POST['type']) ? 'success' : 'error';
if (isset($user['id'])) {
$price = $cost[$_POST['type'] - 21];
$abil = $mag[$_POST['type'] - 21];
if (isset($banks['id'])) {
if ($banks['ekr'] >= $price && $user['id'] == $clan['glava']) {
if (isset($is_now['id'])) {
if ($user['battle'] == 0) {
if (add_klan_abil($abil, $price)) {
echo 'success';
} else {
echo 'Error';
}
} else {
echo 'Не в бою ...';
}
} else {
echo 'NULL';
}
} elseif ($user['id'] != $clan['glava']) {
echo 'Вы не глава клана';
} else {
echo 'Не хватает средств';
}
} else {
echo '<small>Выберите счёт в банке</small>';
}
} else {
echo "Вы не авторизированы ...";
}
}

View File

@ -1,5 +1,7 @@
<?php <?php
session_start();
use Battles\Template;
require_once('functions.php'); require_once('functions.php');
if ($user->getRoom() == 51) { if ($user->getRoom() == 51) {
header('location: city.php'); header('location: city.php');
@ -100,7 +102,7 @@ if ($map_user['Up'] == 1) {
onclick="location.href='?move=true&Dir=Up';" alt="Вверх"> onclick="location.href='?move=true&Dir=Up';" alt="Вверх">
MAP; MAP;
} }
\Battles\Template::header('forest'); Template::header('forest');
?> ?>
<link rel="stylesheet" type="text/css" href="css/hostel.css"/> <link rel="stylesheet" type="text/css" href="css/hostel.css"/>
<style> <style>

View File

@ -1,5 +1,8 @@
<?php <?php
session_start();
use Battles\Chat;
use Battles\Template;
require_once "functions.php"; require_once "functions.php";
$in_haos = mysql_fetch_array(mysql_query("SELECT * FROM `cit_haos_status` WHERE `id` = '{$user['id']}';")); $in_haos = mysql_fetch_array(mysql_query("SELECT * FROM `cit_haos_status` WHERE `id` = '{$user['id']}';"));
$owntravma = mysql_fetch_array(mysql_query("SELECT * FROM `effects` WHERE `owner` = " . $user['id'] . " AND (type=13 OR type=12 OR type=14) limit 1;")); $owntravma = mysql_fetch_array(mysql_query("SELECT * FROM `effects` WHERE `owner` = " . $user['id'] . " AND (type=13 OR type=12 OR type=14) limit 1;"));
@ -64,7 +67,7 @@ if ($_POST['pay']) {
if ($_POST['adm_start_raid'] && $user['id'] == 1256) { if ($_POST['adm_start_raid'] && $user['id'] == 1256) {
mysql_query("DELETE FROM `cit_haos_status`;"); mysql_query("DELETE FROM `cit_haos_status`;");
mysql_query("DELETE FROM `cit_haos_var`;"); mysql_query("DELETE FROM `cit_haos_var`;");
AddChatSystem('<font color=red>Начинается прием заявок в рейд на Цитадель Хаоса! Начало рейда через 15 минут.</font>'); Chat::addSYSMessage('Начинается прием заявок в рейд на Цитадель Хаоса! Начало рейда через 15 минут.');
$ch_time = time(); $ch_time = time();
mysql_query("UPDATE variables SET value='{$ch_time}' where var='cit_haos_time';"); mysql_query("UPDATE variables SET value='{$ch_time}' where var='cit_haos_time';");
} }
@ -90,7 +93,7 @@ if ($in_haos['status'] == 2) {
} }
} }
$in_haos = mysql_fetch_array(mysql_query("SELECT * FROM `cit_haos_status` WHERE `id` = '{$user['id']}' LIMIT 1;")); $in_haos = mysql_fetch_array(mysql_query("SELECT * FROM `cit_haos_status` WHERE `id` = '{$user['id']}' LIMIT 1;"));
\Battles\Template::header('Цитадель Хаоса'); Template::header('Цитадель Хаоса');
?> ?>
<!-- JS --> <!-- JS -->
<script> <script>

View File

@ -1,5 +1,7 @@
<?php <?php
session_start();
use Battles\Template;
require_once "functions.php"; require_once "functions.php";
$in_park = mysql_fetch_array(mysql_query("SELECT * FROM `cit_park` WHERE `id` = '{$user['id']}' LIMIT 1;")); $in_park = mysql_fetch_array(mysql_query("SELECT * FROM `cit_park` WHERE `id` = '{$user['id']}' LIMIT 1;"));
$owntravma = mysql_fetch_array(mysql_query("SELECT * FROM `effects` WHERE `owner` = " . $user['id'] . " AND (type=13 OR type=12 OR type=14) limit 1;")); $owntravma = mysql_fetch_array(mysql_query("SELECT * FROM `effects` WHERE `owner` = " . $user['id'] . " AND (type=13 OR type=12 OR type=14) limit 1;"));
@ -106,7 +108,7 @@ if ($_POST['attack']) {
//старт боя - конец //старт боя - конец
\Battles\Template::header('Городской Парк'); Template::header('Городской Парк');
?> ?>
<script> <script>
function refreshPeriodic() { function refreshPeriodic() {

View File

@ -1,11 +1,8 @@
<?php <?php
use Battles\Template; use Battles\Template;
use Battles\User;
session_start();
require_once "functions.php"; require_once "functions.php";
$user = $user ?? new User($_SESSION['uid']);
if ($user->getRoom() == 403) { if ($user->getRoom() == 403) {
include "startpodzemel.php"; include "startpodzemel.php";
if ($_GET['act'] == "cexit") { if ($_GET['act'] == "cexit") {

View File

@ -1,8 +1,11 @@
<?php <?php
use Battles\DressedItems;
use Battles\GameLogs;
use Battles\ShopItem;
use Battles\Template; use Battles\Template;
use Battles\User;
session_start();
require_once 'functions.php'; require_once 'functions.php';
//require_once 'cave/cave_bots.php'; //require_once 'cave/cave_bots.php';
$userslots = ['sergi', 'kulon', 'perchi', 'weap', 'bron', 'r1', 'r2', 'r3', 'helm', 'shit', 'boots', 'rybax', 'plaw', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm10']; $userslots = ['sergi', 'kulon', 'perchi', 'weap', 'bron', 'r1', 'r2', 'r3', 'helm', 'shit', 'boots', 'rybax', 'plaw', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm10'];
@ -129,9 +132,9 @@ function battlewithbot($b, $name = '', $time = 3, $blood = 1, $group = 1, $battl
} }
if ($user1['invis'] == 1) { if ($user1['invis'] == 1) {
addlog($battleid, '<span class=date>' . date("H:i") . '</span> <b>невидимка</b> вмешался в поединок!<BR>'); GameLogs::addBattleLog($battleid, '<span class=date>' . date("H:i") . '</span> <b>невидимка</b> вмешался в поединок!<BR>');
} else { } else {
addlog($battleid, '<span class=date>' . date("H:i") . '</span> ' . Nick::id($user['id'])->short() . ' вмешался в поединок!<BR>'); GameLogs::addBattleLog($battleid, '<span class=date>' . date("H:i") . '</span> ' . Nick::id($user['id'])->short() . ' вмешался в поединок!<BR>');
} }
mysql_query('UPDATE `battle` SET `teams` = \'' . serialize($battle) . '\', `t' . $ttt . '` = CONCAT(`t' . $ttt . '`,\';' . $user1['id'] . '\') WHERE `id` = ' . $battleid . ' LIMIT 1'); mysql_query('UPDATE `battle` SET `teams` = \'' . serialize($battle) . '\', `t' . $ttt . '` = CONCAT(`t' . $ttt . '`,\';' . $user1['id'] . '\') WHERE `id` = ' . $battleid . ' LIMIT 1');
@ -186,7 +189,7 @@ function battlewithbot($b, $name = '', $time = 3, $blood = 1, $group = 1, $battl
} else { } else {
$rr = "<b>" . Nick::id($user1['id'])->full(1) . "</b> и <b>" . Nick::id($botid1)->full(1) . "</b>"; $rr = "<b>" . Nick::id($user1['id'])->full(1) . "</b> и <b>" . Nick::id($botid1)->full(1) . "</b>";
} }
addlog($battleid, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>" . ($others ? "$others<BR>" : "")); GameLogs::addBattleLog($battleid, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>" . ($others ? "$others<BR>" : ""));
if (!$noredir) { if (!$noredir) {
header("Location: fbattle.php"); header("Location: fbattle.php");
} }
@ -300,23 +303,6 @@ function makedeath()
$loses++; $loses++;
} }
function pickupitem($item, $foronetrip, $notmore1, $incave = 0, $podzem = 1, $destiny = 0)
{
global $user;
if ($notmore1) {
$i = mysql_fetch_assoc(mysql_query("SELECT `id` FROM `inventory` WHERE `prototype` = '$item' AND `owner` = '$user[id]' LIMIT 1"));
if (isset($i['id'])) {
return "Вы уже получили здесь всё необходимое.";
}
}
$flds = ['podzem' => 1, 'podzem' => $podzem];
if ($incave) {
$flds['incave'] = 1;
}
$taken = takeshopitem($item, 'shop', '', $foronetrip, $destiny, $flds);
return "Вы получили <b>$taken[name]</b>";
}
function itemtofloor($item, $foronetrip, $incave = 0, $podzem = 1, $from = 'shop', $small = 0) function itemtofloor($item, $foronetrip, $incave = 0, $podzem = 1, $from = 'shop', $small = 0)
{ {
global $user, $x, $y, $floor; global $user, $x, $y, $floor;
@ -325,14 +311,6 @@ function itemtofloor($item, $foronetrip, $incave = 0, $podzem = 1, $from = 'shop
return "Вы нашли <b>$rec[name]</b>."; return "Вы нашли <b>$rec[name]</b>.";
} }
function makeinjury()
{
global $user, $floor, $noautoexit, $loses, $x, $y, $dir;
settravma($user['id'], 20, rand(1, 600), 1, 1);
makedeath();
$noautoexit = 1;
}
function cavewall($w) function cavewall($w)
{ {
if ($w < 100) { if ($w < 100) {
@ -487,7 +465,7 @@ if (@$_GET['kill'] && $user['id'] == $user['caveleader'] && $_GET['kill'] != $us
while ($rec = mysql_fetch_assoc($r)) { while ($rec = mysql_fetch_assoc($r)) {
$slot = getslot($rec['id'], $usr); $slot = getslot($rec['id'], $usr);
if ($slot) { if ($slot) {
$item = new \Battles\DressedItems($v['user']); $item = new DressedItems($v['user']);
$item->undressItem($slot); $item->undressItem($slot);
} }
} }
@ -768,7 +746,7 @@ if (!$_SESSION['movetime']) {
$_SESSION['movetime'] = time(); $_SESSION['movetime'] = time();
} }
if (@$_GET['takeitem']) { if ($_GET['takeitem']) {
$_GET['takeitem'] = (int)$_GET['takeitem']; $_GET['takeitem'] = (int)$_GET['takeitem'];
$it = mysql_fetch_array(mysql_query("SELECT `item`, `foronetrip`, `incave`, `podzem` FROM `caveitems` WHERE `leader` = '$user[caveleader]' AND `x` = '" . ($x * 2) . "' AND `y` = '" . ($y * 2) . "' AND `floor` = '$floor' AND `id` = '$_GET[takeitem]' LIMIT 1")); $it = mysql_fetch_array(mysql_query("SELECT `item`, `foronetrip`, `incave`, `podzem` FROM `caveitems` WHERE `leader` = '$user[caveleader]' AND `x` = '" . ($x * 2) . "' AND `y` = '" . ($y * 2) . "' AND `floor` = '$floor' AND `id` = '$_GET[takeitem]' LIMIT 1"));
@ -781,7 +759,7 @@ if (@$_GET['takeitem']) {
$report = "Ваш рюкзак перегружен."; $report = "Ваш рюкзак перегружен.";
} else { } else {
$destiny = 0; $destiny = 0;
$taken = takeshopitem($it['item'], "$shop", "", $it['foronetrip'], $destiny, ["podzem" => $it["podzem"], "incave" => $it['incave']], 0, 1, "Нашёл в пещере"); $taken = ShopItem::giveNewItem($it['item'], User::$current->getId());
if (@$taken['error']) { if (@$taken['error']) {
$report = $taken['error']; $report = $taken['error'];
} else { } else {
@ -899,7 +877,7 @@ if (@$_GET['exit']) {
while ($rec = mysql_fetch_assoc($r)) { while ($rec = mysql_fetch_assoc($r)) {
$slot = getslot($rec['id']); $slot = getslot($rec['id']);
if ($slot) { if ($slot) {
$item = new \Battles\DressedItems($user['id']); $item = new DressedItems($user['id']);
$item->undressItem($slot); $item->undressItem($slot);
} }
} }

20
ch.php
View File

@ -1,11 +1,11 @@
<?php <?php
use Battles\Database\DBPDO;
use Battles\Template; use Battles\Template;
use Battles\User;
session_start();
require_once 'functions.php'; require_once 'functions.php';
$user = $user ?? new User($_SESSION['uid']); DBPDO::$db->execute('update online set real_time = ? where user_id = ?', [time(), User::$current->getId()]);
db::c()->query('UPDATE `online` SET `real_time` = ?i WHERE `id` = ?i', time(), $u->i()['id']);
if (isset($_GET['online']) && $_GET['online'] != null) { if (isset($_GET['online']) && $_GET['online'] != null) {
if ($_GET['room'] && (int)$_GET['room'] < 500) { if ($_GET['room'] && (int)$_GET['room'] < 500) {
@ -20,7 +20,7 @@ if (isset($_GET['online']) && $_GET['online'] != null) {
`level`, `level`,
`login`, `login`,
`u`.`battle` AS `in_battle`, `u`.`battle` AS `in_battle`,
`o`.`date`, `o`.login_time,
`u`.`invis`, `u`.`invis`,
(SELECT `id` FROM `effects` WHERE `type` = 2 AND `owner` = `u`.`id` LIMIT 1) AS `slp`, (SELECT `id` FROM `effects` WHERE `type` = 2 AND `owner` = `u`.`id` LIMIT 1) AS `slp`,
(SELECT `id` FROM `effects` WHERE (`type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14) AND `owner` = `u`.`id` LIMIT 1) AS `trv` (SELECT `id` FROM `effects` WHERE (`type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14) AND `owner` = `u`.`id` LIMIT 1) AS `trv`
@ -29,7 +29,7 @@ if (isset($_GET['online']) && $_GET['online'] != null) {
`users` AS `u` `users` AS `u`
WHERE WHERE
`o`.`id` = `u`.`id` AND `o`.`id` = `u`.`id` AND
(`o`.`date` >= ' . (time() - 90) . ' OR `u`.`in_tower` = 1) AND (`o`.login_time >= ' . (time() - 90) . ' OR `u`.`in_tower` = 1) AND
`o`.`room` = "' . $u->i()['room'] . '" AND `o`.`room` = "' . $u->i()['room'] . '" AND
`u`.`caveleader` = "' . $u->i()['caveleader'] . '" `u`.`caveleader` = "' . $u->i()['caveleader'] . '"
ORDER BY ORDER BY
@ -60,7 +60,7 @@ if (isset($_GET['online']) && $_GET['online'] != null) {
`level`, `level`,
`login`, `login`,
`u`.`battle` AS `in_battle`, `u`.`battle` AS `in_battle`,
`o`.`date`, `o`.login_time,
`u`.`invis`, `u`.`invis`,
(SELECT `id` FROM `effects` WHERE `type` = 2 AND `owner` = `u`.`id` LIMIT 1) AS `slp`, (SELECT `id` FROM `effects` WHERE `type` = 2 AND `owner` = `u`.`id` LIMIT 1) AS `slp`,
(SELECT `id` FROM `effects` WHERE (`type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14) AND `owner` = `u`.`id` LIMIT 1) AS `trv` (SELECT `id` FROM `effects` WHERE (`type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14) AND `owner` = `u`.`id` LIMIT 1) AS `trv`
@ -69,7 +69,7 @@ if (isset($_GET['online']) && $_GET['online'] != null) {
`users` AS `u` `users` AS `u`
WHERE WHERE
`o`.`id` = `u`.`id` AND `o`.`id` = `u`.`id` AND
(`o`.`date` >= ' . (time() - 90) . ' OR `u`.`in_tower` = 1) AND (`o`.login_time >= ' . (time() - 90) . ' OR `u`.`in_tower` = 1) AND
`u`.`id` IN (' . $uss . ') `u`.`id` IN (' . $uss . ')
ORDER BY ORDER BY
`u`.`login` `u`.`login`
@ -90,7 +90,7 @@ if (isset($_GET['online']) && $_GET['online'] != null) {
`level`, `level`,
`login`, `login`,
`u`.`battle` AS `in_battle`, `u`.`battle` AS `in_battle`,
`o`.`date`, `o`.login_time,
`u`.`invis`, `u`.`invis`,
(SELECT `id` FROM `effects` WHERE `type` = 2 AND `owner` = `u`.`id` LIMIT 1) AS `slp`, (SELECT `id` FROM `effects` WHERE `type` = 2 AND `owner` = `u`.`id` LIMIT 1) AS `slp`,
(SELECT `id` FROM `effects` WHERE (`type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14) AND `owner` = `u`.`id` LIMIT 1) AS `trv` (SELECT `id` FROM `effects` WHERE (`type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14) AND `owner` = `u`.`id` LIMIT 1) AS `trv`
@ -99,7 +99,7 @@ if (isset($_GET['online']) && $_GET['online'] != null) {
`users` AS `u` `users` AS `u`
WHERE WHERE
`o`.`id` = `u`.`id` AND `o`.`id` = `u`.`id` AND
(`o`.`date` >= ' . (time() - 90) . ' OR `u`.`in_tower` = 1) AND (`o`.login_time >= ' . (time() - 90) . ' OR `u`.`in_tower` = 1) AND
`o`.`room` = "' . $user->getRoom() . '" `o`.`room` = "' . $user->getRoom() . '"
ORDER BY ORDER BY
`u`.`login` `u`.`login`
@ -389,7 +389,7 @@ if (isset($_GET['online']) && $_GET['online'] != null) {
db::c()->query("UPDATE `users` SET `chattime` = '" . ($lastpost + 1) . "' WHERE `id` = {$user['id']} LIMIT 1"); db::c()->query("UPDATE `users` SET `chattime` = '" . ($lastpost + 1) . "' WHERE `id` = {$user['id']} LIMIT 1");
} }
echo "</script><script>top.srld();</script>"; echo "</script><script>top.srld();</script>";
db::c()->query("UPDATE `online` SET `date` = " . time() . " WHERE `id` = {$user['id']} LIMIT 1"); db::c()->query("UPDATE `online` SET login_time = " . time() . " WHERE `id` = {$user['id']} LIMIT 1");
exit; exit;
} else { } else {
if (strpos($_GET['text'], "private") !== FALSE && $user['level'] < 1) { if (strpos($_GET['text'], "private") !== FALSE && $user['level'] < 1) {

View File

@ -5,52 +5,18 @@
* Project name: Battles-Game * Project name: Battles-Game
*/ */
use Battles\Chat;
use Battles\Database\DBPDO; use Battles\Database\DBPDO;
use Battles\Template; use Battles\Template;
session_start();
require_once "config.php"; require_once "config.php";
$chat = new Chat(new DBPDO());
$msg = $_POST['msg'] ?? null; if (!empty($_POST['msg'])) {
$uid = $_SESSION['uid'] ?? null; $chat->addMessage($_POST['msg']);
if ($msg) {
$db = new DBPDO();
$db->execute('INSERT INTO chat (user_id,msg) VALUES (?,?)', [$uid, $msg]);
} }
function show_messages()
{
$db = new DBPDO();
$chat = $db->ofetchALL('SELECT msg,msgdate,type,s.login AS sender, r.login AS receiver, s.id AS sid, r.id AS rid FROM chat
LEFT JOIN users s on s.id = chat.user_id
LEFT JOIN users r on r.id = chat.receiver_id
WHERE r.id = ? OR r.id IS NULL OR s.id = ? ORDER BY chat.id', [$_SESSION['uid'], $_SESSION['uid']]);
$i = 0;
while ($i < count($chat)) {
$d = new DateTime($chat[$i]->msgdate);
$m = htmlspecialchars($chat[$i]->msg);
if ($chat[$i]->type == 'sys') { /* Системка */
echo sprintf('<span style="color:maroon;background:#faa;">%s %s</span><br>', $d->format('H:i'), $m);
} elseif ($chat[$i]->rid == $_SESSION['uid']) { /* С указанным получателем */
if ($chat[$i]->type == 'sms') { /* Телеграмма */
echo sprintf('<span style="color:darkgreen;background:#afa;">%s Телеграмма от [%s]: %s</span><br>', $d->format('d.m.Y H:i'), $chat[$i]->sender, $m);
} elseif ($chat[$i]->type == 'private') { /* Приват */
echo sprintf('<span style="background:#efe;">%s [%s] → [%s]: %s</span><br>', $d->format('H:i'), $chat[$i]->sender, $chat[$i]->receiver, $m);
} else { /* Общак */
echo sprintf('%s [%s] → [%s]: %s<br>', $d->format('H:i'), $chat[$i]->sender, $chat[$i]->receiver, $m);
}
} else { /* Без указанного получателя */
echo sprintf('%s [%s]: %s<br>', $d->format('H:i'), $chat[$i]->sender, $m);
}
$i++;
}
unset($i, $chat, $db);
}
Template::header('chat'); Template::header('chat');
show_messages(); echo $chat->getMessages();
?> ?>
<style> <style>
form { form {
@ -72,6 +38,18 @@ show_messages();
border: none; border: none;
padding: 10px; padding: 10px;
} }
span.chatsys {
color:maroon;
background:#faa;
}
span.chatsms {
color:darkgreen;
background:#afa;
}
span.chatprivate {
background:#efe;
}
</style> </style>
<div> <div>
<?php ?> <?php ?>

View File

@ -2,9 +2,10 @@
/** /**
* Центральная площадь * Центральная площадь
*/ */
session_start();
use Battles\Template;
require_once "functions.php"; require_once "functions.php";
$user = $user ?? new \Battles\User($_SESSION['uid']);
if ($user->getZayavka()) { if ($user->getZayavka()) {
exit; exit;
@ -196,7 +197,7 @@ switch ($location[0]) {
} }
} }
\Battles\Template::header('city'); Template::header('city');
echo sprintf('<div style="text-align: right;">Сейчас в игре: %s игроков.></div>', $online->getNumRows()); echo sprintf('<div style="text-align: right;">Сейчас в игре: %s игроков.></div>', $online->getNumRows());
if (in_array($user->getRoom(), [20, 21, 26, 2601, 2655, 2111, 2701, 2702])) { if (in_array($user->getRoom(), [20, 21, 26, 2601, 2655, 2111, 2701, 2702])) {
/* Улицы: /* Улицы:

277
clan.php
View File

@ -1,227 +1,114 @@
<?php <?php
use Battles\Bank; use Battles\Clan;
use Battles\Database\DBPDO; use Battles\GameConfigs;
use Battles\Nick; use Battles\Nick;
use Battles\Rooms; use Battles\Rooms;
use Battles\Template; use Battles\Template;
use Battles\User; use Battles\User;
ob_start("ob_gzhandler");
session_start();
require_once 'functions.php'; require_once 'functions.php';
$user = $user ?? new User($_SESSION['uid']); if (!User::$current->getClan()) {
$db = new DBPDO(); exit('Ошибка! Вы не состоите в клане!');
$clanRow = [];
if (!$user->getClan()) {
exit(err('Вы не состоите в клане!'));
}
try {
$clanRow = $db->fetch('SELECT * FROM `clans` WHERE short_name = ?', $user->getClan());
} catch (Exception $e) {
echo "<div>MYSQL_ERROR: Таблица clans сломана!</div>";
}
define('COST_ADD_MEMBER', 100);
define('COST_REMOVE_MEMBER', 30);
define('CASTLE_REPUTATION_NEEDED', 1000000);
define('CASTLE_COST', 25000);
$status = null;
$action = $_POST['action'] ?? 0;
$login = $_POST['login'] ?? 0;
$zamok = $_POST['zamok'] ?? null;
$kr = $_POST['kr'] ?? null;
$kolv = $_POST['kolv'] ?? null;
$newClanStatus = $_POST['new_status'] ?? null;
$vin = $_POST['vin'] ?? null;
$tus = $_POST['tus'] ?? null;
$lock = true; // блокировка функций
if ($zamok && !$lock) {
$db->execute('UPDATE `clans` SET `zamok` = 1 WHERE `glava` = ?', $user->getId());
$status = "Начат сбор средств на строительство Кланового Замка.";
header("Location: clan.php");
}
if ($kr && $kolv > 0 && !$lock) {
if ($user->getMoney() >= $kolv) {
$db->execute('UPDATE clans SET zbor = zbor + ? WHERE id = ?', [$kolv, $user->getClan()]);
Bank::setWalletMoney($user->setMoney($user->getMoney() - $kolv), $user->getId());
header("Location: clan.php");
} else {
$status = 'Не хватает денег!';
}
}
if ($login && $action == 'add_member') {
$sok = $db->fetch('SELECT id, level, clan FROM users WHERE align = 0 AND login = ?', $login);
$proverka = $db->fetch('SELECT 1 FROM users_effects WHERE type = 20 AND owner_id = ?', $sok['id']);
if (!$proverka) {
echo "Нет проверки!";
} elseif ($sok['clan']) {
echo 'Персонаж уже состоит в клане!';
} elseif ($sok['level'] > 0 && $user->getMoney() >= COST_ADD_MEMBER) {
Bank::setWalletMoney($user->setMoney($user->getMoney() - COST_ADD_MEMBER), $user->getId());
$db->execute('UPDATE users SET clan = ?, align = ? WHERE id = ?', [$clanRow['id'], $clanRow['align'], $sok['id']]);
$status = "Персонаж «{$login}» успешно принят в клан.";
} else {
$status = 'Не хватает денег, или персонажа не существует.';
}
} }
if ($login) { Clan::$current = new Clan();
$sok = $db->fetch('SELECT id FROM users WHERE clan = ? AND login = ?', [$clanRow['id'], $login]); if (User::$current->getClan() != Clan::$current->getClanShortName()) {
if ($action == 'remove_member' && $sok['id'] != $clanRow['owner_id'] && $user->getMoney() >= COST_REMOVE_MEMBER) { exit('Ошибка! Клана ' . User::$current->getClan() . ' не существует!');
Bank::setWalletMoney($user->setMoney($user->getMoney() - COST_REMOVE_MEMBER), $user->getId());
$db->execute('UPDATE users SET clan = null, align = 0 WHERE id = ?', $sok['id']);
$status = "Персонаж «{$login}» покинул клан.";
}
if ($action == 'change_owner' && $clanRow['owner_id'] == $user->getId()) {
$db->execute('UPDATE clans SET owner_id = ? WHERE id = ?', [$sok['id'], $clanRow['id']]);
$clanRow['owner_id'] = $sok['id'];
}
if ($action == 'edit_status' && !$lock) {
if ($sok['id'] != $clanRow['owner_id']) {
if ($newClanStatus) {
$st = strip_tags(str_replace("&lt;", "<", str_replace("&gt;", ">", $newClanStatus)), "<B><I><U>");
$db->execute('UPDATE users SET status = ? WHERE id = ?', [$st, $sok['id']]);
$sok['status'] = $st;
}
} else {
$status = 'Главу клана редактировать запрещено!';
}
}
} }
$clan_memberlist = $db->fetchAll('SELECT id, login, level, align, (SELECT id FROM online WHERE date >= ? AND id = users.id) AS online FROM users WHERE clan = ? ORDER BY online DESC, login', [time() - 60, $clanRow['short_name']]);
Template::header('clan'); Template::header('clan');
$clanRow['zamok'] = null; //Замков нет!
$clanRow['rating'] = null; //рейтов тоже!
$clanRow['zbor'] = null; // И копилки.
?> ?>
<style>
.row {
cursor: default;
}
.column {
padding: 10px;
}
.left {
width: 60%;
float: left;
}
.right {
width: 30%;
float: right;
}
.row:after {
content: "";
display: table;
clear: both;
}
</style>
<div> <div>
<button onclick="location.href='main.php'">Вернуться</button> <button onclick="location.href='main.php'">Вернуться</button>
<?php if (!empty($status)) { <?php if (!empty($_POST['login']) && !empty($_POST['action'])): ?>
err($status); <span class="error">
} ?> <?php if ($_POST['action'] == 'add_member'): ?>
<?= Clan::$current->addMember($_POST['login']) ?>
<?php endif; ?>
<?php if ($_POST['action'] == 'remove_member'): ?>
<?= Clan::$current->removeMember($_POST['login']) ?>
<?php endif; ?>
<?php if ($_POST['action'] == 'change_owner'): ?>
<?= Clan::$current->changeOwner($_POST['login']) ?>
<?php endif; ?>
</span>
<?php endif; ?>
</div> </div>
<table style="width: 100%"> <div class="row">
<tr> <div class="column left">
<td> <h3><img src="./i/clan/<?= Clan::$current->getClanShortName() ?>.png"
<p style="width: 50%; vertical-align: top;" rowspan=2> alt="<?= Clan::$current->getClanShortName() ?>"><?= Clan::$current->getClanName() ?></h3>
<h3><img src="./i/clan/<?= $clanRow['short_name'] ?>.png"><?= $clanRow['full_name'] ?></h3>
<?php if ($clanRow['owner_id'] == $user->getId()): ?> <?php if (Clan::$current->getClanOwnerId() === User::$current->getId()): ?>
<div> <div>
<span id="add_member"> <span id="add_member">
<input type="submit" onclick="use('add_member')" value="Принять в клан"> <input type="submit" onclick="use('add_member')" value="Принять в клан">
</span> </span>
(стоимость услуги: <B><?= COST_ADD_MEMBER ?></B> кр.) [стоимость: <?= GameConfigs::CLAN['add_member_cost'] ?>]
</div> </div>
<div> <div>
<span id="remove_member"> <span id="remove_member">
<input type="submit" onclick="use('remove_member')" value="Выгнать из клана"> <input type="submit" onclick="use('remove_member')" value="Выгнать из клана">
</span> </span>
(стоимость услуги: <B><?= COST_REMOVE_MEMBER ?></B> кр.) [стоимость: <?= GameConfigs::CLAN['remove_member_cost'] ?>]
</div> </div>
<?php endif; ?> <div>
<?php if ($clanRow['owner_id'] == $user->getId()): ?>
<?php if ($login && $action == 'edit_status' && $sok['id'] != $clanRow['owner_id']): ?>
<form method='post'>
<input placeholder='Статус' name='new_status'>
<input type="hidden" name="login" value="<?= $login ?>">
<?php if ($clanRow['glava'] == $user->getId()): ?>
<?php if ($clanRow['owner_id'] == $user->getId()): ?>
<br><input type=checkbox name=vin checked> Может принимать/выгонять членов клана
<?php else: ?>
<br><input type=checkbox name=vin> Может принимать/выгонять членов клана
<?php endif; ?>
<?php if ($clanRow['owner_id'] == $user->getId()): ?>
<br><input type=checkbox name=tus checked> Может менять статус членов клана
<?php else: ?>
<br><input type=checkbox name=tus> Может менять статус членов клана
<?php endif; ?>
<?php endif; ?>
<button name='action' value='edit_status' type='submit'>Ок</button>
<button>×</button>
</form>
<?php else: ?>
<div>
<span id="edit_status">
<input type="submit" onclick="use('edit_status')" value="Редактировать статус">
</span>
</div>
<?php endif; ?>
<?php endif; ?>
<?php if ($clanRow['owner_id'] == $user->getId()): ?>
<div>
<span id="change_owner"> <span id="change_owner">
<input type="submit" onclick="use('change_owner')" value="Сменить главу клана"> <input type="submit" onclick="use('change_owner')" value="Сменить главу клана">
</span> </span>
(сложить с себя полномочия, назначив <b style="color: teal;">Главой Клана</b> другого персонажа) (сложить с себя полномочия, назначив <strong style="color: teal;">Главой Клана</strong> другого
</div> персонажа)
<?php if (empty($clanRow['zamok'])): ?> </div>
<?php if ($clanRow['rating'] < CASTLE_REPUTATION_NEEDED): ?> <?php endif; ?>
Недостаточно рейтинга для постройки замка. <?= showProgressBar($clanRow['rating'], CASTLE_REPUTATION_NEEDED) ?> </div>
<?php else: ?> <div class="column right">
<form method="post"> <table class='zebra' style='width: 100%;'>
<button type="submit" name="zamok" value="zamok">Построить Замок</button> <caption><h3>Соклановцы</h3></caption>
(собрать силами всего клана <?= CASTLE_COST ?> кр.)<BR> <tr>
</form> <th id='c1'>Имя</th>
<?php endif; ?> <th id='c2'>Местонахождение</th>
<?php endif; ?> </tr>
<?php endif; ?> <?php foreach (Clan::$current->getMemberlist() as $member): ?>
<?php if ($clanRow['zamok'] == 1): ?>
<p>
<?php if ($clanRow['zbor'] < CASTLE_COST): ?>
Сбор средств на постройку кланового замка:
<?= showProgressBar($clanRow['zbor'], CASTLE_COST) ?>
<form method="post">
<input name="kolv" size="10">
<button type="submit" name="kr" value="kr">Пожертвовать</button>
</form>
<?php else: ?>
Средства на постройку кланового замка собраны!
<?= showProgressBar(CASTLE_COST, CASTLE_COST) ?>
<?php endif; ?>
<?php endif; ?>
</td>
<td style="vertical-align: top;">
<h3>Соклановцы</h3>
<table class="zebra" style="width: 100%;">
<tr> <tr>
<th>Имя</th> <td>
<th>Статус</th> <?php if ($member->clan_owner): ?>
<th>Местонахождение</th> 👑
<?php endif; ?>
<?= Nick::id($member->id)->full() ?>
</td>
<td>
<em style='font-size: smaller;'><?= $member->room ? Rooms::$roomNames[$member->room] : 'Персонаж не в игре' ?></em>
</td>
</tr> </tr>
<?php <?php endforeach; ?>
$i = 0; </table>
while ($i < count($clan_memberlist)): </div>
if ($clan_memberlist[$i]['id'] == $clanRow['owner_id']) { </div>
$clan_memberlist[$i]['status'] = '<b style="color: #008080;">Глава клана</b>';
}
if (empty($clan_memberlist[$i]['status'])) {
$clan_memberlist[$i]['status'] = 'Боец';
}
if (empty($clan_memberlist[$i]['online'])) {
$rrm = 'Персонаж не в игре';
} elseif ($clan_memberlist[$i]['room'] > 500 && $clan_memberlist[$i]['room'] < 561) {
$rrm = 'Башня смерти';
} else {
$rrm = Rooms::$roomNames[$clan_memberlist[$i]['room']];
}
?>
<tr>
<td><?= Nick::id($clan_memberlist[$i]['id'])->full() ?></td>
<td><?= $clan_memberlist[$i]['status'] ?></td>
<td><i style="font-size: smaller;"><?= $rrm ?></i></td>
</tr>
<?php $i++; ?>
<?php endwhile; ?>
</table>
</td>
</tr>
</table>
<script type="text/javascript"> <script type="text/javascript">
function use(option) { function use(option) {
document.getElementById(option).innerHTML = "<form method='post'><input placeholder='Имя персонажа' name='login'><button name='action' value='" + option + "' type='submit'>Ок</button><button>×</button></form>"; document.getElementById(option).innerHTML = "<form method='post'><input placeholder='Имя персонажа' name='login'><button name='action' value='" + option + "' type='submit'>Ок</button><button>×</button></form>";

View File

@ -1,5 +1,9 @@
<?php <?php
session_start();
use Battles\Chat;
use Battles\GameLogs;
use Battles\Template;
require_once "functions.php"; require_once "functions.php";
$owntravma = mysql_fetch_array(mysql_query("SELECT * FROM `effects` WHERE `owner` = " . $user['id'] . " AND (type=13 OR type=12 OR type=14) limit 1;")); $owntravma = mysql_fetch_array(mysql_query("SELECT * FROM `effects` WHERE `owner` = " . $user['id'] . " AND (type=13 OR type=12 OR type=14) limit 1;"));
$klan = mysql_fetch_array(mysql_query("SELECT * FROM `clans` WHERE `id` = '{$user['klan']}' LIMIT 1;")); $klan = mysql_fetch_array(mysql_query("SELECT * FROM `clans` WHERE `id` = '{$user['klan']}' LIMIT 1;"));
@ -21,7 +25,7 @@ if ($_POST['add_zay']) {
mysql_query("INSERT INTO `clan_castle` VALUES ('{$user['id']}','{$user['klan']}');"); mysql_query("INSERT INTO `clan_castle` VALUES ('{$user['id']}','{$user['klan']}');");
exit("<script>location.href='clan_castle.php';</script>"); exit("<script>location.href='clan_castle.php';</script>");
} }
\Battles\Template::header('Замок Мэра'); Template::header('Замок Мэра');
?> ?>
<script> <script>
function refreshPeriodic() { function refreshPeriodic() {
@ -129,7 +133,7 @@ if ($_POST['add_zay']) {
if ($att['value'] > 0) { if ($att['value'] > 0) {
$att_r = mysql_query("SELECT `id` FROM `users` WHERE `klan`='{$att['value']}' AND `room`='45';"); $att_r = mysql_query("SELECT `id` FROM `users` WHERE `klan`='{$att['value']}' AND `room`='45';");
while ($a = mysql_fetch_array($att_r)) { while ($a = mysql_fetch_array($att_r)) {
$at_on = mysql_fetch_array(mysql_query("select `id` from `online` WHERE `date` >= " . (time() - 60) . " AND `id` = '{$a['id']}' LIMIT 1;")); $at_on = mysql_fetch_array(mysql_query("select `id` from `online` WHERE login_time >= " . (time() - 60) . " AND `id` = '{$a['id']}' LIMIT 1;"));
if ($at_on[0]) { if ($at_on[0]) {
$at_t[] = $a['id']; $at_t[] = $a['id'];
} }
@ -139,7 +143,7 @@ if ($_POST['add_zay']) {
if ($own['value'] > 0) { if ($own['value'] > 0) {
$def_r = mysql_query("SELECT `id` FROM `users` WHERE `klan`='{$own['value']}' AND `room`='45';"); $def_r = mysql_query("SELECT `id` FROM `users` WHERE `klan`='{$own['value']}' AND `room`='45';");
while ($o = mysql_fetch_array($def_r)) { while ($o = mysql_fetch_array($def_r)) {
$df_on = mysql_fetch_array(mysql_query("select `id` from `online` WHERE `date` >= " . (time() - 60) . " AND `id` = '{$o['id']}' LIMIT 1;")); $df_on = mysql_fetch_array(mysql_query("select `id` from `online` WHERE login_time >= " . (time() - 60) . " AND `id` = '{$o['id']}' LIMIT 1;"));
if ($df_on[0]) { if ($df_on[0]) {
$ow_t[] = $o['id']; $ow_t[] = $o['id'];
} }
@ -155,7 +159,7 @@ if ($_POST['add_zay']) {
$cc_att = mysql_fetch_array(mysql_query("SELECT `value` FROM variables WHERE var='castle_att' LIMIT 1;")); $cc_att = mysql_fetch_array(mysql_query("SELECT `value` FROM variables WHERE var='castle_att' LIMIT 1;"));
$cc_a = mysql_fetch_array(mysql_query("SELECT `name` FROM `clans` WHERE `id` = '{$cc_att['value']}' LIMIT 1;")); $cc_a = mysql_fetch_array(mysql_query("SELECT `name` FROM `clans` WHERE `id` = '{$cc_att['value']}' LIMIT 1;"));
AddChatSystem('<font color=red><strong>Клан <img title="' . $cc_a['name'] . '" src="i/clan/' . $cc_a['name'] . '.png">' . $cc_a['name'] . '</strong> без боя забрал у <strong>клана <img title="' . $cc_k['name'] . '" src="i/clan/' . $cc_k['name'] . '.gif">' . $cc_k['name'] . '</strong> Замок Мэра</font>'); Chat::addSYSMessage('Клан <img title="' . $cc_a['name'] . '" src="i/clan/' . $cc_a['name'] . '.png">' . $cc_a['name'] . ' без боя забрал у <strong>клана <img title="' . $cc_k['name'] . '" src="i/clan/' . $cc_k['name'] . '.gif">' . $cc_k['name'] . '</strong> Замок Мэра');
$c_prev = mysql_fetch_array(mysql_query("SELECT `glava`,`align` FROM `clans` WHERE `id`='{$own['value']}' LIMIT 1;")); $c_prev = mysql_fetch_array(mysql_query("SELECT `glava`,`align` FROM `clans` WHERE `id`='{$own['value']}' LIMIT 1;"));
@ -232,7 +236,7 @@ if ($_POST['add_zay']) {
addch("<a href=logs.php?log=" . $id . " target=_blank>Поединок</a> между <B>" . $rrc . "</B> начался. ", $user->getRoom()); addch("<a href=logs.php?log=" . $id . " target=_blank>Поединок</a> между <B>" . $rrc . "</B> начался. ", $user->getRoom());
mysql_query("INSERT INTO `logs` (`id`,`log`) VALUES('{$id}','Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>');"); mysql_query("INSERT INTO `logs` (`id`,`log`) VALUES('{$id}','Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>');");
addlog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>"); GameLogs::addBattleLog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>");
$add_time = time(); $add_time = time();
// всех в БОЙ!!! // всех в БОЙ!!!
foreach ($at_t as $k => $v) { foreach ($at_t as $k => $v) {
@ -290,7 +294,7 @@ if ($_POST['add_zay']) {
addch("<a href=logs.php?log=" . $id . " target=_blank>Поединок</a> между <B>" . $rrc . "</B> начался. ", $user->getRoom()); addch("<a href=logs.php?log=" . $id . " target=_blank>Поединок</a> между <B>" . $rrc . "</B> начался. ", $user->getRoom());
mysql_query("INSERT INTO `logs` (`id`,`log`) VALUES('{$id}','Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>');"); mysql_query("INSERT INTO `logs` (`id`,`log`) VALUES('{$id}','Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>');");
addlog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>"); GameLogs::addBattleLog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <BR>");
$add_time = time(); $add_time = time();
// всех в БОЙ!!! // всех в БОЙ!!!
foreach ($at_t as $k => $v) { foreach ($at_t as $k => $v) {

View File

@ -4,11 +4,8 @@ use Battles\Bank;
use Battles\GameConfigs; use Battles\GameConfigs;
use Battles\Rooms; use Battles\Rooms;
use Battles\Template; use Battles\Template;
use Battles\User;
session_start();
require_once 'functions.php'; require_once 'functions.php';
$user = $user ?? new User($_SESSION['uid']);
$userClan = db::c()->query('SELECT short_name, full_name, info FROM clans where owner_id = ?i', $user->getId())->fetch_object(); $userClan = db::c()->query('SELECT short_name, full_name, info FROM clans where owner_id = ?i', $user->getId())->fetch_object();
$clanFullName = $_POST['clan_full_name'] ?? ''; $clanFullName = $_POST['clan_full_name'] ?? '';
$clanShortName = $_POST['clan_short_name'] ?? ''; $clanShortName = $_POST['clan_short_name'] ?? '';
@ -19,7 +16,7 @@ if ($clanFullName && $clanShortName && $clanInfo && !$userClan) {
$eff = db::c()->query('SELECT 1 FROM users_effects WHERE type = 20 AND owner_id = ?i', $user->getId()); $eff = db::c()->query('SELECT 1 FROM users_effects WHERE type = 20 AND owner_id = ?i', $user->getId());
$name_check = db::c()->query('SELECT owner_id FROM clans WHERE full_name = "?s" OR short_name = "?s"', $clanFullName, $clanShortName); $name_check = db::c()->query('SELECT owner_id FROM clans WHERE full_name = "?s" OR short_name = "?s"', $clanFullName, $clanShortName);
$errorMessage = []; $errorMessage = [];
if (GameConfigs::CLAN_REGISTER_LOCK) { if (GameConfigs::CLAN['clan_register_lock']) {
$errorMessage[10] = 'Регистрация кланов закрыта! <BR>'; $errorMessage[10] = 'Регистрация кланов закрыта! <BR>';
} }
if ($user->getAlign()) { if ($user->getAlign()) {
@ -28,7 +25,7 @@ if ($clanFullName && $clanShortName && $clanInfo && !$userClan) {
if ($user->getClan()) { if ($user->getClan()) {
$errorMessage[1] = 'Вы уже состоите в клане!. <BR>'; $errorMessage[1] = 'Вы уже состоите в клане!. <BR>';
} }
if (GameConfigs::CLAN_REGISTER_COST >= $userBank->getMoney()) { if (GameConfigs::CLAN['clan_register_cost'] >= $userBank->getMoney()) {
$errorMessage[2] = 'Не хватает денег на регистрацию клана. <BR>'; $errorMessage[2] = 'Не хватает денег на регистрацию клана. <BR>';
} }
if (!$eff) { if (!$eff) {
@ -40,7 +37,7 @@ if ($clanFullName && $clanShortName && $clanInfo && !$userClan) {
if (!$errorMessage || $user->getAdmin()) { if (!$errorMessage || $user->getAdmin()) {
try { try {
db::c()->query('INSERT INTO clans (owner_id, full_name, short_name, info) VALUES (?i,"?s","?s","?s")', $user->getId(), $clanFullName, $clanShortName, $clanInfo); db::c()->query('INSERT INTO clans (owner_id, full_name, short_name, info) VALUES (?i,"?s","?s","?s")', $user->getId(), $clanFullName, $clanShortName, $clanInfo);
$userBank->setMoney($userBank->getMoney() - GameConfigs::CLAN_REGISTER_COST); $userBank->setMoney($userBank->getMoney() - GameConfigs::CLAN['clan_register_cost']);
Battles\Bank::setBankMoney($userBank->getMoney(), $user->getId(), 'clanRegister'); Battles\Bank::setBankMoney($userBank->getMoney(), $user->getId(), 'clanRegister');
// Заглушка для отображения данных по только что зарегистрированному клану, когда запрос в базу в начале файла ещё не проходит. // Заглушка для отображения данных по только что зарегистрированному клану, когда запрос в базу в начале файла ещё не проходит.
$userClan = new stdClass(); $userClan = new stdClass();

View File

@ -7,17 +7,16 @@
namespace Battles; namespace Battles;
use Config;
use Exceptions\GameException; use Exceptions\GameException;
use Battles\Database\DBPDO; use Battles\Database\DBPDO;
use Throwable; use Throwable;
class Bank class Bank
{ {
public $user_id; public int $user_id = 0;
private $money; private int $money = 0;
private $user; private $user;
private static $db; private static DBPDO $db;
const ERROR_NO_MONEY_IN_WALLET = "Ошибка! Нет денег в кошельке!"; const ERROR_NO_MONEY_IN_WALLET = "Ошибка! Нет денег в кошельке!";
const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!"; const ERROR_NO_BANK_ACCOUNT = "Ошибка! Счёта не существует!";
@ -29,6 +28,7 @@ class Bank
'depositMoney' => 'Пополнение счёта.', 'depositMoney' => 'Пополнение счёта.',
'withdrawMoney' => 'Снятие денег со счёта.', 'withdrawMoney' => 'Снятие денег со счёта.',
'clanRegister' => 'Оплата стоимости регистрации клана.', 'clanRegister' => 'Оплата стоимости регистрации клана.',
'sellShop' => 'Продажа товара в магазине.'
]; ];
public function __construct(int $user_id) public function __construct(int $user_id)
@ -174,11 +174,11 @@ class Bank
self::setBankMoney($this->money, $this->user_id); self::setBankMoney($this->money, $this->user_id);
$this->bankLogs(0, $this->money, "withdrawMoney"); $this->bankLogs(0, $this->money, "withdrawMoney");
// Отдаём сумму в кошелёк получателя // Отдаём сумму в кошелёк получателя
$this->user->money += $amount; $this->user['money'] += $amount;
self::setWalletMoney($this->user->money, $this->user_id); self::setWalletMoney($this->user['money'], $this->user_id);
// Возвращаем изменившиеся значения // Возвращаем изменившиеся значения
return [ return [
'walletMoney' => $this->user->money, 'walletMoney' => $this->user['money'],
'bankMoney' => $this->money 'bankMoney' => $this->money
]; ];
} }
@ -215,15 +215,12 @@ class Bank
*/ */
public static function setWalletMoney(int $amount, int $user_id): void public static function setWalletMoney(int $amount, int $user_id): void
{ {
try { $u = new User($user_id);
self::$db->execute('UPDATE users SET money = ? WHERE id = ?', [$amount, $user_id]); $u->setMoney($amount);
} catch (Throwable $e) { $u->saveMoney();
echo "Не отработал запрос в БД в файле {$e->getFile()}({$e->getLine()})";
}
} }
public function getMoney() public function getMoney(): int
{ {
return $this->money; return $this->money;
} }

75
classes/Battles/Chat.php Normal file
View File

@ -0,0 +1,75 @@
<?php
namespace Battles;
use Battles\Database\DBPDO;
use DateTime;
use Exception;
class Chat
{
private DateTime $d;
private DBPDO $db;
public function __construct(DBPDO $db)
{
$this->db = $db;
}
public function getMessages(): ?string
{
$query = 'select
msg,
msgdate,
type,
s.login as sender,
r.login as receiver,
s.id as sid,
r.id as rid
from chat
left join users s on s.id = chat.user_id
left join users r on r.id = chat.receiver_id
where
r.id = ?
or r.id is null
or s.id = ?
order by chat.id';
$chatrows = $this->db->ofetchALL($query, [User::$current->getId(), User::$current->getId()]);
$wrappedMessage = null;
foreach ($chatrows as $row) {
try {
$this->d = new DateTime($row->msgdate);
} catch (Exception $e) {
echo 'Chat Datetime Whoops!';
}
$m = htmlspecialchars($row->msg);
if ($row->type === 'sys' && empty($row->rid)) {
$wrappedMessage .= sprintf('<span class="chatsys">%s %s</span><br>', $this->d->format('H:i'), $m);
} elseif ($row->rid === User::$current->getId()) {
if ($row->type === 'sys') {
$wrappedMessage .= sprintf('<span class="chatsys">%s [Система] → %s</span><br>', $this->d->format('H:i'), $m);
} elseif ($row->type == 'sms') {
$wrappedMessage .= sprintf('<span class="chatsms">%s Телеграмма от [%s]: %s</span><br>', $this->d->format('d.m.Y H:i'), $row->sender, $m);
} elseif ($row->type == 'private') {
$wrappedMessage .= sprintf('<span class="chatprivate">%s [%s] → [%s]: %s</span><br>', $this->d->format('H:i'), $row->sender, $row->receiver, $m);
} else {
$wrappedMessage .= sprintf('%s [%s] → [%s]: %s<br>', $this->d->format('H:i'), $row->sender, $row->receiver, $m);
}
} else {
$wrappedMessage .= sprintf('%s [%s]: %s<br>', $this->d->format('H:i'), $row->sender, $m);
}
}
return $wrappedMessage;
}
public function addMessage(string $msg)
{
$this->db->execute('insert into chat (user_id, msg) values (?,?)', [User::$current->getId(), $msg]);
}
public static function addSYSMessage( string $msg, ?int $receiver_id = null)
{
DBPDO::$db->execute('insert into chat (user_id, msg, receiver_id, type) values (?,?,?,?)', [User::$current->getId(), $msg, $receiver_id, 'sys']);
}
}

28
classes/Battles/Check.php Normal file
View File

@ -0,0 +1,28 @@
<?php
# Date: 15.03.2021 (21:53)
namespace Battles;
use Battles\Database\DBPDO;
class Check
{
private User $user;
private DBPDO $db;
/**
* Check constructor.
*
* @param User $user
*/
public function __construct(User $user, DBPDO $db)
{
$this->user = $user;
$this->db = $db;
}
public function Effects()
{
return $this->db->execute('delete from users_effects where remaining_time <= ?', strtotime('now'));
}
}

119
classes/Battles/Clan.php Normal file
View File

@ -0,0 +1,119 @@
<?php
# Date: 23.08.2021 (23:05)
namespace Battles;
use Battles\Database\DBPDO;
class Clan
{
private DBPDO $db;
private User $user;
private $clan;
public static Clan $current;
public function __construct()
{
$this->db = DBPDO::$db;
$this->user = User::$current;
$this->clan = $this->db->ofetch('select * from clans where owner_id = ?', $this->user->getId());
}
public function addMember(string $login): string
{
$target = new User($login);
$error = null;
if (!$this->getProverka($target->getId())) {
$error .= '<br>Нет проверки!';
}
if ($target->getClan()) {
$error .= '<br>Персонаж уже состоит в клане!';
}
if ($target->getLevel() < 1) {
$error .= '<br>Персонаж 0 уровня не может быть принят!';
}
if ($this->user->getMoney() < GameConfigs::CLAN['add_member_cost']) {
$error .= '<br>Недостаточно денег!';
}
if ($error) {
return $error;
}
$this->user->setMoney($this->user->getMoney() - GameConfigs::CLAN['add_member_cost']);
$this->user->saveMoney();
$target->setClan($this->user->getClan());
return "Персонаж «{$login}» успешно принят в клан.";
}
public function removeMember(string $login): string
{
$target = new User($login);
$error = null;
if ($this->user->getMoney() < GameConfigs::CLAN['remove_member_cost']) {
$error .= '<br>Недостаточно денег!';
}
if ($target->getId() === $this->user->getId()) {
$error .= '<br>Себя выгонять нельзя!';
}
if ($target->getClan() !== $this->user->getClan()) {
$error .= '<br>Персонаж не состоит в этом клане!';
}
if ($error) {
return $error;
}
$this->user->setMoney($this->user->getMoney() - GameConfigs::CLAN['remove_member_cost']);
$this->user->saveMoney();
$target->setClan(null);
return "Персонаж «{$login}» покинул клан.";
}
public function changeOwner(string $login): string
{
$target = new User($login);
$error = null;
if ($target->getId() === $this->user->getId()) {
$error .= '<br>Самоудовлетворяетесь? ;)';
}
if ($target->getClan() !== $this->user->getClan()) {
$error .= '<br>Персонаж не состоит в этом клане!';
}
if ($error) {
return $error;
}
$this->db->execute('update clans set owner_id = ? where owner_id = ?', [$target->getId(), $this->user->getId()]);
return 'Вы передали управление кланом персонажу «' . $login . '».';
}
public function setClanInfo(string $text): string
{
$check = $this->db->ofetch('select id from users where clan = (select short_name from clans where owner_id = ?)', $this->user->getId());
if ($check->id !== $this->user->getId()) {
return 'Ошибка доступа!';
}
$this->db->execute('update clans set info = ? where owner_id = ?', [$text, $check->id]);
return 'Описание клана изменено!';
}
public function getMemberlist(): array
{
return $this->db->ofetchAll('select id, (select 1 from clans where short_name = clan and owner_id = id) as clan_owner, room from users where clan = ? order by clan_owner desc, room, login', $this->user->getClan());
}
private function getProverka($user_id)
{
return $this->db->fetch('select 1 from users_effects where type = 20 and owner_id = ?', $user_id);
}
public function getClanOwnerId(): ?int
{
return $this->clan->owner_id;
}
public function getClanName(): ?string
{
return $this->clan->full_name;
}
public function getClanShortName(): ?string
{
return $this->clan->short_name;
}
}

View File

@ -9,6 +9,7 @@ class DBPDO
public $pdo; public $pdo;
private static $_instance = null; private static $_instance = null;
public static DBPDO $db;
function __construct() function __construct()
{ {

View File

@ -157,7 +157,7 @@ CREATE TABLE `online` (
-- Дамп данных таблицы `online` -- Дамп данных таблицы `online`
-- --
INSERT INTO `online` (`user_id`, `date`, `real_time`, `room`) VALUES INSERT INTO `online` (`user_id`, login_time, `real_time`, `room`) VALUES
(2, 1601412403, 1601651536, 1); (2, 1601412403, 1601651536, 1);
-- -------------------------------------------------------- -- --------------------------------------------------------

View File

@ -12,9 +12,14 @@ class GameConfigs
const DATABASE_PASS = 'bottle-neck-horse'; const DATABASE_PASS = 'bottle-neck-horse';
const DATABASE_PORT = '32101'; const DATABASE_PORT = '32101';
const DATABASE_CHARSET = 'utf8'; const DATABASE_CHARSET = 'utf8';
const CLAN = [
const CLAN_REGISTER_COST = 10000; 'add_member_cost' => 100,
const CLAN_REGISTER_LOCK = true; // Запрет на регистрацию кланов. 'remove_member_cost' => 30,
'create_castle_cost' => 25000,
'create_castle_reputation_cost' => 1000000,
'clan_register_cost' => 10000,
'clan_register_lock' => true, // Запрет на регистрацию кланов.
];
const BANK_COMISSION = 0.05; // 5% const BANK_COMISSION = 0.05; // 5%
const DB_SQLITE = '/volume2/web/battles/databases/logs.sqlite'; const DB_SQLITE = '/volume2/web/battles/databases/logs.sqlite';

View File

@ -3,7 +3,6 @@
namespace Battles; namespace Battles;
use Config;
use SQLite3; use SQLite3;
use SQLite3Result; use SQLite3Result;
@ -58,7 +57,7 @@ class GameLogs
public static function getUserLogs($userId = null, $type = null): SQLite3Result public static function getUserLogs($userId = null, $type = null): SQLite3Result
{ {
$db = new SQLite3(GameConfigs::DB_SQLITE); $db = new SQLite3(GameConfigs::DB_SQLITE);
$row = false;
if ($userId && $type) { if ($userId && $type) {
$query = "SELECT * FROM users_logs WHERE user_id = ? AND type = ?"; $query = "SELECT * FROM users_logs WHERE user_id = ? AND type = ?";
$row = $db->prepare($query); $row = $db->prepare($query);
@ -79,4 +78,14 @@ class GameLogs
return $row->execute(); return $row->execute();
} }
public static function addBattleLog(int $battle_id, string $text)
{
$db = new SQLite3(__DIR__ . '../../Database/battle.logs.db');
$row = $db->prepare('insert into newbattles (battle_id, text) values (?,?)');
$row->bindParam(1, $battle_id, SQLITE3_INTEGER);
$row->bindParam(2, $text, SQLITE3_TEXT);
$row->execute();
$row->close();
}
} }

View File

@ -21,14 +21,15 @@ class InventoryItem extends Item
{ {
parent::__construct($row); parent::__construct($row);
$this->owner_id = $row->owner_id; $this->owner_id = $row->owner_id;
$this->present = $row->present;
$this->db = DBPDO::INIT(); $this->db = DBPDO::INIT();
} }
public function printInfo() public function printInfo()
{ {
parent::printAllInfo(); echo $this->getAllInfo();
if ($this->present) { if ($this->present) {
echo "<p style='color: maroon; font-style: italic'>Это подарок от {$this->present}. Вы не можете передать его кому-либо ещё.</p>"; echo "<p style='color: maroon; font-style: italic'>Это подарок от $this->present. Вы не можете передать его кому-либо ещё.</p>";
} }
} }
@ -47,9 +48,8 @@ IMG;
} }
} }
public function printControls() public function printControls(){
{ // Для кнопок управления под картинкой.
/* Тут будут кнопки под картинкой. */
} }
private function dressStatsChecks(): ?string private function dressStatsChecks(): ?string
@ -71,7 +71,6 @@ IMG;
*/ */
public function dressItem() public function dressItem()
{ {
$db = new DBPDO();
$itemInSlot = []; $itemInSlot = [];
if ($this->dressStatsChecks()) { if ($this->dressStatsChecks()) {
return self::REQUIREMENTS_NOT_MET; return self::REQUIREMENTS_NOT_MET;
@ -79,8 +78,8 @@ IMG;
// считаем сколько ОДЕТЫХ предметов в слоте в который мы хотим одеть предмет. 1=просто вещь 1-3=шашни с кольцами // считаем сколько ОДЕТЫХ предметов в слоте в который мы хотим одеть предмет. 1=просто вещь 1-3=шашни с кольцами
// Count добавленный в первый запрос возвращает одну строку в любом случае. // Count добавленный в первый запрос возвращает одну строку в любом случае.
// fetch возвращает одну строку в любом случае. // fetch возвращает одну строку в любом случае.
$weared = $db->ofetchAll('SELECT dressed_slot FROM inventory WHERE dressed_slot != 0 AND item_type = ? AND owner_id = ?', [$this->item_type, $this->owner_id]); $weared = $this->db->ofetchAll('SELECT dressed_slot FROM inventory WHERE dressed_slot != 0 AND item_type = ? AND owner_id = ?', [$this->item_type, $this->owner_id]);
$wearedCount = $db->ofetch('select count(dressed_slot) as c from inventory where dressed_slot !=0 and item_type = ? and owner_id = ?', [$this->item_type, $this->owner_id]); $wearedCount = $this->db->ofetch('select count(dressed_slot) as c from inventory where dressed_slot !=0 and item_type = ? and owner_id = ?', [$this->item_type, $this->owner_id]);
// Если в слоте есть предмет(ы), забиваем их массив одетых в слот предметов. // Если в слоте есть предмет(ы), забиваем их массив одетых в слот предметов.
if ($wearedCount) { if ($wearedCount) {
foreach ($weared as $item) { foreach ($weared as $item) {
@ -95,11 +94,11 @@ IMG;
//работаем с нормальными слотами //работаем с нормальными слотами
if ($wearedCount->c == 1) { if ($wearedCount->c == 1) {
//если слот занят, снимаем старый предмет и одеваем новый предмет //если слот занят, снимаем старый предмет и одеваем новый предмет
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$itemInSlot[0], $this->owner_id]); $this->db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = ? AND owner_id = ?', [$itemInSlot[0], $this->owner_id]);
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]); $this->db->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]);
} elseif (!$wearedCount->c) { } elseif (!$wearedCount->c) {
//если слот пуст, одеваем новый предмет //если слот пуст, одеваем новый предмет
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]); $this->db->execute('UPDATE inventory SET dressed_slot = item_type WHERE item_id = ? AND owner_id = ?', [$this->item_id, $this->owner_id]);
} else { } else {
/* проверка на переполнение слотов */ /* проверка на переполнение слотов */
$error = self::TOO_MANY_ITEMS_IN_SLOTS; $error = self::TOO_MANY_ITEMS_IN_SLOTS;
@ -113,11 +112,11 @@ IMG;
// Сортируем массив свободных слотов по возрастанию. // Сортируем массив свободных слотов по возрастанию.
sort($emptyRingSlots); sort($emptyRingSlots);
// Одеваем предмет в первый свободный слот. // Одеваем предмет в первый свободный слот.
DBPDO::INIT()->execute('update inventory set dressed_slot = ? where item_id = ?', [$emptyRingSlots[0], $this->item_id]); $this->db->execute('update inventory set dressed_slot = ? where item_id = ?', [$emptyRingSlots[0], $this->item_id]);
} elseif ($wearedCount->c == 3) { } elseif ($wearedCount->c == 3) {
// Cнимаем предмет из последнего слота 11 и одеваем новый предмет // Cнимаем предмет из последнего слота 11 и одеваем новый предмет
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = 11'); $this->db->execute('UPDATE inventory SET dressed_slot = 0 WHERE dressed_slot = 11');
DBPDO::INIT()->execute('UPDATE inventory SET dressed_slot = 11 WHERE item_id = ?', $this->item_id); $this->db->execute('UPDATE inventory SET dressed_slot = 11 WHERE item_id = ?', $this->item_id);
} else { } else {
/* проверка на переполнение слотов */ /* проверка на переполнение слотов */
$error = self::TOO_MANY_ITEMS_IN_SLOTS; $error = self::TOO_MANY_ITEMS_IN_SLOTS;
@ -127,17 +126,22 @@ IMG;
$error = self::UNKNOWN_ITEM_TYPE; $error = self::UNKNOWN_ITEM_TYPE;
} }
return isset($error) ? $error : true; return $error ?? true;
} }
/** public static function destroyItem($itemId)
* @param $itemId
*
* @return bool
*/
public static function destroyItem($itemId): bool
{ {
$db = new DBPDO(); DBPDO::INIT()->execute('delete from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?', [$_SESSION['uid'], $itemId]);
return $db->execute('delete from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?', [$_SESSION['uid'], $itemId]); }
/** Надеюсь, временная заглушка, которая объединяет get_meshok() и другую выдачу одной строкой.
* @return string
*/
public static function getWeightData(): string
{
$query = 'select sum(weight) as `all`, strength * 4 as max from inventory left join users u on owner_id = id where owner_id = ?';
$weight = DBPDO::$db->ofetch($query, User::$current->getId());
$css = $weight->all > $weight->max ? ' style="color:maroon;"' : '';
return "<span$css>$weight->all / $weight->max</span>";
} }
} }

View File

@ -1,32 +1,35 @@
<?php <?php
namespace Battles; namespace Battles;
use Battles\Database\DBPDO;
class Item class Item
{ {
protected $item_id; protected int $item_id;
protected $name; protected string $name = '';
protected $item_type; protected int $item_type = self::ITEM_TYPE_TRASH;
protected $durability; protected int $durability = 0;
protected $price; protected int $need_strength = 0;
protected $need_strength; protected int $need_dexterity = 0;
protected $need_dexterity; protected int $need_intuition = 0;
protected $need_intuition; protected int $need_endurance = 0;
protected $need_endurance; protected int $need_intelligence = 0;
protected $need_intelligence; protected int $need_wisdom = 0;
protected $need_wisdom; protected int $add_strength = 0;
protected $add_strength; protected int $add_dexterity = 0;
protected $add_dexterity; protected int $add_intuition = 0;
protected $add_intuition; protected int $add_endurance = 0;
protected $add_endurance; protected int $add_intelligence = 0;
protected $add_intelligence; protected int $add_wisdom = 0;
protected $add_wisdom; protected int $add_accuracy = 0;
protected $add_accuracy; protected int $add_evasion = 0;
protected $add_evasion; protected int $add_criticals = 0;
protected $add_criticals; protected int $add_min_physical_damage = 0;
protected $add_min_physical_damage; protected int $add_max_physical_damage = 0;
protected $add_max_physical_damage; protected int $weight = 0;
protected $weight; protected string $image = '';
protected $image; protected int $item_cost = 0;
public const ITEM_TYPES_ALLOWED_IN_SLOTS = [1,2,3,4,5,6,7,8,9,10,11,12]; public const ITEM_TYPES_ALLOWED_IN_SLOTS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
public const ITEM_TYPE_HELMET = 1; public const ITEM_TYPE_HELMET = 1;
public const ITEM_TYPE_ARMOR = 2; public const ITEM_TYPE_ARMOR = 2;
public const ITEM_TYPE_LEGS = 3; public const ITEM_TYPE_LEGS = 3;
@ -40,7 +43,7 @@ class Item
public const ITEM_TYPE_CONSUMABLE = 20; public const ITEM_TYPE_CONSUMABLE = 20;
public const ITEM_TYPE_OTHER = 50; public const ITEM_TYPE_OTHER = 50;
public const ITEM_TYPE_TRASH = 100; public const ITEM_TYPE_TRASH = 100;
private $typename; private string $typename;
/** /**
* Item constructor. * Item constructor.
@ -100,11 +103,38 @@ class Item
default: default:
$this->typename = 'Хлам'; $this->typename = 'Хлам';
} }
$this->item_cost = $this->calculateItemCost();
} }
/** Рассчёт стоимости предмета в зависимости от его характеристик.
* @return int
*/
protected function calculateItemCost(): int
{
$sum_stats =
$this->add_strength +
$this->add_dexterity +
$this->add_intuition +
$this->add_endurance +
$this->add_intelligence +
$this->add_wisdom;
$sum_mods =
$this->add_accuracy +
$this->add_evasion +
$this->add_criticals;
$sum_damage =
$this->add_min_physical_damage +
$this->add_max_physical_damage;
// За каждые N параметров повышаем множитель на 1 чтобы цена пропрорционально росла.
$stats_cost_modifier = 5 + floor($sum_stats / 10);
$mods_cost_modifier = 2 + floor($sum_mods / 50);
$damage_cost_modifier = 1 + floor($sum_damage / 100);
$result = intval($sum_stats * $stats_cost_modifier + $sum_mods * $mods_cost_modifier + $sum_damage * $damage_cost_modifier);
return $result < 1 ? 1 : $result;
}
protected function wrap(int $number): string
protected function wrap(int $number):string
{ {
if ($number > 0) { if ($number > 0) {
return ": <b>" . $number . "</b>"; return ": <b>" . $number . "</b>";
@ -113,50 +143,56 @@ class Item
} }
} }
protected function printAllInfo() public function getAllInfo(): string
{ {
$needsLines = [ $needsLines = [
"сила" => $this->need_strength, 'сила' => $this->need_strength,
"ловкость" =>$this->need_dexterity, 'ловкость' => $this->need_dexterity,
"интуиция" =>$this->need_intuition, 'интуиция' => $this->need_intuition,
"выносливость" =>$this->need_endurance, 'выносливость' => $this->need_endurance,
"интеллект" =>$this->need_intelligence, 'интеллект' => $this->need_intelligence,
"мудрость" =>$this->need_wisdom, 'мудрость' => $this->need_wisdom,
]; ];
$addsLines = [ $addsLines = [
"Сила" => $this->add_strength, 'Сила' => $this->add_strength,
"Ловкость" => $this->add_dexterity, 'Ловкость' => $this->add_dexterity,
"Интуиция" => $this->add_intuition, 'Интуиция' => $this->add_intuition,
"Выносливость" => $this->add_endurance, 'Выносливость' => $this->add_endurance,
"Интеллект" => $this->add_intelligence, 'Интеллект' => $this->add_intelligence,
"Мудрость" => $this->add_wisdom, 'Мудрость' => $this->add_wisdom,
"Точность" => $this->add_accuracy, 'Точность' => $this->add_accuracy,
"Увёртливость" => $this->add_evasion, 'Увёртливость' => $this->add_evasion,
"Шанс крита" => $this->add_criticals, 'Шанс крита' => $this->add_criticals,
]; ];
echo "<b>" . $this->name . "</b> (Масса: " . $this->weight . ")"; $str = "<b>$this->name</b> (Масса: $this->weight)";
echo "<br> Долговечность: " . $this->durability; $str .= '<br> Стоимость: ' . $this->item_cost;
$str .= '<br> Долговечность: ' . $this->durability;
echo "<br><em>{$this->typename}</em><br>"; $str .= "<br><em>$this->typename</em><br>";
foreach ($needsLines as $stat => $value) { foreach ($needsLines as $stat => $value) {
if ($value > 0) { if ($value > 0) {
echo "<br>Требуется $stat" . $this->wrap($value); $str .= "<br>Требуется $stat" . $this->wrap($value);
} }
} }
foreach ($addsLines as $stat => $value) { foreach ($addsLines as $stat => $value) {
if ($value) { if ($value) {
echo "<br>$stat" . $this->wrap($value); $str .= "<br>$stat" . $this->wrap($value);
} }
} }
if ($this->add_min_physical_damage && !$this->add_max_physical_damage) { if ($this->add_min_physical_damage && !$this->add_max_physical_damage) {
$damage = $this->add_min_physical_damage . " - " . $this->add_min_physical_damage; $damage = $this->add_min_physical_damage . ' - ' . $this->add_min_physical_damage;
} elseif (!$this->add_min_physical_damage && $this->add_max_physical_damage) { } elseif (!$this->add_min_physical_damage && $this->add_max_physical_damage) {
$damage = $this->add_max_physical_damage . " - " . $this->add_max_physical_damage; $damage = $this->add_max_physical_damage . ' - ' . $this->add_max_physical_damage;
} elseif ($this->add_min_physical_damage && $this->add_max_physical_damage) { } elseif ($this->add_min_physical_damage && $this->add_max_physical_damage) {
$damage = $this->add_min_physical_damage . " - " . $this->add_max_physical_damage; $damage = $this->add_min_physical_damage . ' - ' . $this->add_max_physical_damage;
} }
if (isset($damage)) { if (isset($damage)) {
echo "<br>Урон: " . $damage; $str .= '<br>Урон: ' . $damage;
} }
return $str;
}
public static function getItemById($item_id): Item
{
return new Item(DBPDO::$db->ofetch('select * from items where id = ?', $item_id));
} }
} }

View File

@ -10,7 +10,7 @@ use Battles\User;
class Sharpen extends Magic class Sharpen extends Magic
{ {
private $magicDifficulty; private int $magicDifficulty;
/** /**
* Sharpen constructor. * Sharpen constructor.

View File

@ -15,72 +15,72 @@ class Moderation
GameLogs::addUserLog($userId, $message, "moderation"); GameLogs::addUserLog($userId, $message, "moderation");
} }
public static function muteChat(int $target, int $time): bool public static function muteChat(int $target, int $time)
{ {
self::addEffectStatusToUserLog($target, UserEffects::$effectName[2]); self::addEffectStatusToUserLog($target, UserEffects::$effectName[2]);
return User::setUserEffect($target, 2, UserEffects::$effectName[2], $time); User::addUserEffect($target, 2, UserEffects::$effectName[2], $time);
} }
public static function unmuteChat(int $target): bool public static function unmuteChat(int $target)
{ {
self::addEffectStatusToUserLog($target, UserEffects::$effectName[2] . self::STATUS_OFF); self::addEffectStatusToUserLog($target, UserEffects::$effectName[2] . self::STATUS_OFF);
return User::removeUserEffect($target, 2); User::removeUserEffect($target, 2);
} }
public static function muteForum(int $target, int $time): bool public static function muteForum(int $target, int $time)
{ {
self::addEffectStatusToUserLog($target, UserEffects::$effectName[3]); self::addEffectStatusToUserLog($target, UserEffects::$effectName[3]);
return User::setUserEffect($target, 3, UserEffects::$effectName[3], $time); User::addUserEffect($target, 3, UserEffects::$effectName[3], $time);
} }
public static function unmuteForum(int $target): bool public static function unmuteForum(int $target)
{ {
self::addEffectStatusToUserLog($target, UserEffects::$effectName[3] . self::STATUS_OFF); self::addEffectStatusToUserLog($target, UserEffects::$effectName[3] . self::STATUS_OFF);
return User::removeUserEffect($target, 3); User::removeUserEffect($target, 3);
} }
public static function hideUserInfo(int $target, int $time): bool public static function hideUserInfo(int $target, int $time)
{ {
self::addEffectStatusToUserLog($target, UserEffects::$effectName[5]); self::addEffectStatusToUserLog($target, UserEffects::$effectName[5]);
return User::setUserEffect($target, 5, UserEffects::$effectName[5], $time); User::addUserEffect($target, 5, UserEffects::$effectName[5], $time);
} }
public static function unHideUserInfo(int $target): bool public static function unHideUserInfo(int $target)
{ {
self::addEffectStatusToUserLog($target, UserEffects::$effectName[5] . self::STATUS_OFF); self::addEffectStatusToUserLog($target, UserEffects::$effectName[5] . self::STATUS_OFF);
return User::removeUserEffect($target, 5); User::removeUserEffect($target, 5);
} }
public static function blockUser(int $target): void public static function blockUser(int $target)
{ {
self::addEffectStatusToUserLog($target, "Блокировка"); self::addEffectStatusToUserLog($target, "Блокировка");
DBPDO::INIT()->execute('UPDATE battles.users SET block = 1 WHERE id = ?', $target); DBPDO::INIT()->execute('UPDATE battles.users SET block = 1 WHERE id = ?', $target);
} }
public static function unBlockUser(int $target): void public static function unBlockUser(int $target)
{ {
self::addEffectStatusToUserLog($target, "Блокировка" . self::STATUS_OFF); self::addEffectStatusToUserLog($target, "Блокировка" . self::STATUS_OFF);
DBPDO::INIT()->execute('UPDATE battles.users SET block = 0 WHERE block = 1 AND id = ?', $target); DBPDO::INIT()->execute('UPDATE battles.users SET block = 0 WHERE block = 1 AND id = ?', $target);
} }
public static function addToUserLog(int $target, string $message, int $senderId): void public static function addToUserLog(int $target, string $message, int $senderId)
{ {
GameLogs::addUserLog($target, $message, "moderation", $senderId); GameLogs::addUserLog($target, $message, "moderation", $senderId);
} }
public static function setAlign(int $target, int $align): void public static function setAlign(int $target, int $align)
{ {
DBPDO::INIT()->execute('UPDATE users SET align = ? WHERE id = ?', [$align, $target]); DBPDO::INIT()->execute('UPDATE users SET align = ? WHERE id = ?', [$align, $target]);
} }
public static function addChatSysMsg(string $message): void public static function addChatSysMsg(string $message)
{ {
DBPDO::INIT()->execute('INSERT INTO chat (user_id,msg,type) VALUES (-1,?,?)', [$message, 'sys']); DBPDO::INIT()->execute('INSERT INTO chat (user_id,msg,type) VALUES (-1,?,?)', [$message, 'sys']);
} }
public static function addUserCheck(int $target): bool public static function addUserCheck(int $target)
{ {
self::addEffectStatusToUserLog($target, UserEffects::$effectName[20]); self::addEffectStatusToUserLog($target, UserEffects::$effectName[20]);
return User::setUserEffect($target, 20, UserEffects::$effectName[20], strtotime('3days')); User::addUserEffect($target, 20, UserEffects::$effectName[20], strtotime('3days'));
} }
} }

View File

@ -57,7 +57,7 @@ class Nick extends User
*/ */
public function full($showInvisibility = 0):string public function full($showInvisibility = 0):string
{ {
if ($showInvisibility && $this->getInvisibilityStatus()) { if (!$showInvisibility && $this->getInvisibilityStatus()) {
return INVIS; return INVIS;
} }
return $this->getAlignToNickname().$this->getClanToNickname().sprintf('<b>%s</b> [%s] <a href="inf.php?%s" target="_blank"><img src="i/inf.gif" style="width:12px;height:11px"></a>', $this->login, $this->level, $this->login); return $this->getAlignToNickname().$this->getClanToNickname().sprintf('<b>%s</b> [%s] <a href="inf.php?%s" target="_blank"><img src="i/inf.gif" style="width:12px;height:11px"></a>', $this->login, $this->level, $this->login);

86
classes/Battles/Shop.php Normal file
View File

@ -0,0 +1,86 @@
<?php
# Date: 29.08.2021 (21:34)
namespace Battles;
use Battles\Database\DBPDO;
class Shop
{
public const GENERAL_SHOP = 1;
public const BARTER_SHOP = 2;
public const CATEGORY_SALE_ITEMS = -1;
public static Shop $current;
public int $categoryType = 0;
private int $shopId;
public function __construct($shop_id) {
$this->shopId = $shop_id;
}
private function showGoods(): string
{
if ($this->categoryType) {
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0 and item_type = ?', [$this->shopId, $this->categoryType]);
$stmt2 = DBPDO::$db->ofetchAll('select * from inventory where on_sale != 0 and present is null and item_type = ?', $this->categoryType);
} else {
$stmt = DBPDO::$db->ofetchAll('select * from items inner join trade_offers on id = shop_item_id where shop_id = ? and shop_item_quantity !=0', $this->shopId);
$stmt2 = DBPDO::$db->ofetchAll('select * from inventory where on_sale != 0 and present is null');
}
$iteminfo = [];
foreach ($stmt as $item) {
$iteminfo[] = new ShopItem($item, 'buyshop');
}
foreach ($stmt2 as $item) {
$iteminfo[] = new ShopItem($item, 'buymarket');
}
return $this->strFromArr($iteminfo);
}
private function showUserSellItems(): string
{
$stmt = DBPDO::$db->ofetchall('select * from inventory where on_sale = 0 and dressed_slot = 0 and durability > 0 and owner_id = ?', User::$current->getId());
$iteminfo = [];
foreach ($stmt as $item) {
$iteminfo[] = new ShopItem($item, 'sellshop');
}
return $this->strFromArr($iteminfo);
}
private function strFromArr(array $array): string
{
$str = '';
$format = '<div class="row item"><div class="left column">%s%s</div><div class="right column">%s</div></div>';
foreach ($array as $a) {
$str .= sprintf($format, $a->printImage(), $a->printControls(), $a->printInfo());
}
return $str;
}
public function getCategoryName(): string
{
$names = [
Item::ITEM_TYPE_HELMET => 'Шлемы',
Item::ITEM_TYPE_ARMOR => 'Броня',
Item::ITEM_TYPE_LEGS => 'Поножи',
Item::ITEM_TYPE_BOOTS => 'Сапоги',
Item::ITEM_TYPE_GLOVES => 'Перчатки',
Item::ITEM_TYPE_WEAPON => 'Оружие',
Item::ITEM_TYPE_SHIELD => 'Щиты',
Item::ITEM_TYPE_BELT => 'Пояса',
Item::ITEM_TYPE_RING => 'Кольца',
Item::ITEM_TYPE_AMULET => 'Амулеты',
Item::ITEM_TYPE_CONSUMABLE => 'Расходники',
Item::ITEM_TYPE_OTHER => 'Разное',
self::CATEGORY_SALE_ITEMS => 'Предметы в инвентаре',
0 => 'Все товары',
];
return $names[$this->categoryType];
}
public function getItemsList(): string
{
return $this->categoryType !== self::CATEGORY_SALE_ITEMS ? $this->showGoods() : $this->showUserSellItems();
}
}

View File

@ -1,79 +1,296 @@
<?php <?php
namespace Battles; namespace Battles;
use Battles\Database\DBPDO; use Battles\Database\DBPDO;
use Battles\Models\PresentsModel;
use Exceptions\GameException;
class ShopItem extends Item class ShopItem extends Item
{ {
public function printInfo() private const NO_ITEMS_IN_STOCK = "Товара нет в наличии!";
private const NO_MONEY = "У вас нет денег!";
private const NO_BARTER_ITEMS = 'У вас нет требуемых предметов!';
private const BUTTON = [
'setmarket' => 'Сдать в магазин',
'buymarket' => 'Купить с рук',
'sellshop' => 'Продать',
'buyshop' => 'Купить',
];
private const BUY_QUERY = <<<SQL
insert into inventory (
owner_id, name, item_type, durability,
need_strength, need_dexterity, need_intuition, need_endurance, need_intelligence, need_wisdom,
add_strength, add_dexterity, add_intuition, add_endurance, add_intelligence, add_wisdom,
add_accuracy, add_evasion, add_criticals, add_min_physical_damage, add_max_physical_damage,
image, weight, price)
select
?, name, item_type, durability,
need_strength, need_dexterity, need_intuition, need_endurance, need_intelligence, need_wisdom,
add_strength, add_dexterity, add_intuition, add_endurance, add_intelligence, add_wisdom,
add_accuracy, add_evasion, add_criticals, add_min_physical_damage, add_max_physical_damage,
image, weight, greatest(
(
(add_strength + add_dexterity + add_intuition + add_endurance + add_intelligence + add_wisdom) *
(5 + floor((add_strength + add_dexterity + add_intuition + add_endurance + add_intelligence + add_wisdom) / 10))
) +
(
(add_accuracy + add_criticals + add_evasion) *
(2 + floor((add_accuracy + add_criticals + add_evasion) / 50))
) +
(
(add_min_physical_damage + add_max_physical_damage) *
(1 + floor((add_min_physical_damage + add_max_physical_damage) / 100))
)
,1)
from items where id = ?
SQL;
// Тип операции в магазине. Для отображения разных блоков в разных случаях.
private $optype;
private ?int $shop_item_quantity;
private ?int $price;
public static string $status = '';
private ?string $jsonBarterList;
private int $offerId;
private int $ownerId = 0;
public function __construct($row, $operationType = null)
{ {
parent::printAllInfo(); parent::__construct($row);
if ($operationType) {
$this->optype = $operationType;
}
$this->price = $row->price ?? null;
$this->shop_item_quantity = $row->shop_item_quantity ?? null;
$this->item_id = $row->item_id ?? $row->id;
if ($operationType === 'buyshop' || $operationType === 'buymarket') {
$this->offerId = $row->offer_id ?? 0; // Ид позиции в магазине.
$this->jsonBarterList = $row->barter_items_list_json ?? null;
}
if ($operationType === 'buymarket') {
$this->ownerId = $row->owner_id;
}
} }
public function buyItem($owner) public function printInfo(): string
{ {
if ($owner) { $str = $this->getAllInfo();
$db = new DBPDO(); if ($this->optype === 'buyshop') {
$query = "INSERT INTO inventory ( $str .= $this->getLowItemQuantityNote();
owner_id, name, item_type, durability, price, $str .= $this->getBarterList();
need_strength, need_dexterity, need_intuition, }
need_endurance, need_intelligence, need_wisdom, if ($this->optype === 'sellshop') {
add_strength, add_dexterity, add_intuition, $str .= $this->getTextBasedOnPrice();
add_endurance, add_intelligence, add_wisdom, }
add_accuracy, add_evasion, add_criticals, if ($this->optype === 'buymarket') {
add_min_physical_damage, add_max_physical_damage, $str .= $this->getBarterList();
image, weight) $str .= '<br><br>Продавец: ' . Nick::id($this->ownerId)->full(1);
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; }
$values = [ return $str;
$owner, $this->name, $this->item_type, $this->durability, $this->price, }
$this->need_strength, $this->need_dexterity, $this->need_intuition,
$this->need_endurance, $this->need_intelligence, $this->need_wisdom, private function getBarterList(): string
$this->add_strength, $this->add_dexterity, $this->add_intuition, {
$this->add_endurance, $this->add_intelligence, $this->add_wisdom, if (!$this->jsonBarterList) {
$this->add_accuracy, $this->add_evasion, $this->add_criticals, return '';
$this->add_min_physical_damage, $this->add_max_physical_damage, }
$this->image, $this->weight $str = '<div><br>Помимо денег требуются следующие товары:';
]; foreach (json_decode($this->jsonBarterList) as $item) {
$db->execute($query, $values); $str .= '<br>↣ ' . Item::getItemById($item->item_id)->name . ', ' . $item->quantity . ' шт.';
}
$str .= '</div>';
return $str;
}
private function getLowItemQuantityNote(): string
{
if ($this->shop_item_quantity < 1 || $this->shop_item_quantity > 19) {
return '';
}
return "<div style='margin-top: 9px; font-style: italic;'>На складе осталось $this->shop_item_quantity единиц товара!</div>";
}
private function getTextBasedOnPrice(): string
{
if ($this->getSellPriceMean() < 50) {
$goods = 'этот хлам';
} elseif ($this->getSellPriceMean() < 100) {
$goods = 'этот посредственный товар';
} elseif ($this->getSellPriceMean() < 500) {
$goods = 'этот неплохой предмет';
} elseif ($this->getSellPriceMean() < 1000) {
$goods = 'эту отличную штуку';
} else {
$goods = 'это превосходное изделие';
}
return "<div style='margin-top: 9px; font-style: italic;'>В среднем за $goods можно выручить <span class='success'>{$this->getSellPriceMean()}</span> кр.</div>";
}
public function printImage(): string
{
if (!$this->image) {
$this->image = 'noitem.png';
}
return "<img src='/i/sh/$this->image' class='item-wrap-normal' alt=''>";
}
public static function buyItem($id, User $buyer)
{
$check = DBPDO::$db->ofetch("select * from trade_offers where offer_id = ?", $id);
$item = new Item(DBPDO::$db->fetch('select * from items where id = ?', $check->shop_item_id));
$price = $item->calculateItemCost();
if (
!self::checkAndRemoveBarteredItems($check->barter_items_list_json, $buyer->getId()) ||
!self::checkAndPayTheBills($price, $buyer) ||
!self::checkAndChangeRemainingItems($check->shop_item_quantity, $check->shop_item_id)
) {
return;
}
DBPDO::$db->execute(self::BUY_QUERY, [$buyer->getId(), $check->shop_item_id]);
$deloText = $buyer->getLogin() . " купил товар «" . $item->name . "» id:(" . $check->shop_item_id . ") в магазине за " . $price . ".";
GameLogs::addUserLog($buyer->getId(), $deloText);
self::$status = "Предмет " . $item->name . " куплен за " . $price . ".";
}
private static function checkAndRemoveBarteredItems(?string $json_list, int $user_id): bool
{
if (empty($json_list)) {
return true;
}
$allowItemRemove = true;
foreach (json_decode($json_list) as $item) {
$row = DBPDO::$db->ofetch('select sum(1) as s from inventory where name = ? and owner_id = ?', [Item::getItemById($item->item_id)->name, $user_id]);
if ($row->s < $item->quantity) {
$allowItemRemove = false;
}
}
if (!$allowItemRemove) {
self::$status = self::NO_BARTER_ITEMS;
return false;
}
foreach (json_decode($json_list) as $item) {
$query = 'delete from inventory where name = ? and owner_id = ? limit ' . (int)$item->quantity;
// У-у-у, сука! https://phpdelusions.net/pdo#limit
DBPDO::$db->execute($query, [Item::getItemById($item->item_id)->name, $user_id]);
}
return true;
}
private static function checkAndPayTheBills(int $price, User $user): bool
{
if ($user->getMoney() > $price) {
$user->setMoney($user->getMoney() - $price);
$user->saveMoney();
return true;
}
try {
$bank = new Bank($user->getId());
$bank->withdrawMoney($price);
return true;
} catch (GameException $e) {
self::$status = 'Банковская ошибка! ' . self::NO_MONEY;
return false;
}
}
private static function checkAndChangeRemainingItems(int $current_quantity, $item_id): bool
{
if (empty($current_quantity)) {
self::$status = self::NO_ITEMS_IN_STOCK;
return false;
}
if ($current_quantity === -1) {
return true;
}
DBPDO::$db->execute("update trade_offers set shop_item_quantity = shop_item_quantity -1 where shop_item_quantity != -1 and shop_item_id = ? ", $item_id);
return true;
}
public static function sellItem($id, User $seller, $bankTrade = 0)
{
$db = new DBPDO();
$item = $db->ofetch('select * from inventory where item_id = ?', $id);
$sellingItemName = $item->name;
// Продажа за цену от нуля до половины стоимости.
$sellingPrice = $item->price > 1 ? mt_rand(0, $item->price / 2) : mt_rand(0, 1);
$db->execute('delete from inventory where item_id = ?', $id);
if ($bankTrade) {
$bank = new Bank($seller->getId());
$bank->setMoney($bank->getMoney() + $sellingPrice);
Bank::setBankMoney($bank->getMoney(), $seller->getId(), 'sellShop');
} else {
$db->execute('update users set money = money - ? where id = ?', [$sellingPrice, $_SESSION['uid']]);
}
$deloText = "{$seller->getLogin()} продал товар «{$sellingItemName}» id:($id) в магазине за $sellingPrice кр.";
GameLogs::addUserLog($seller->getId(), $deloText);
if ($sellingPrice == 0) {
self::$status = "После длительных и изнурительных торгов вы плюнули на всё и просто подарили ваш «{$sellingItemName}» торговцу.";
} else {
self::$status = "Вы продали «{$sellingItemName}» за $sellingPrice кр.";
}
}
/** Подчсчёт средней суммы продажи.
* @return int
*/
private function getSellPriceMean(): ?int
{
if ($this->price > 1) {
$arr = range(0, $this->price / 2);
return array_sum($arr) / count($arr);
} else {
return $this->price == 1 ? 1 : null;
} }
} }
/** /**
* Для кнопок управления под картинкой предмета в зависимости от ситуации. * Для кнопок управления под картинкой предмета в зависимости от ситуации.
*/ */
public function printControls($shopType = false) public function printControls(): string
{ {
if ($shopType === 'marketput') { if (!in_array($this->optype, ['setmarket', 'buymarket', 'sellshop', 'buyshop',])) {
echo <<<BTN return '';
<form method="post">
<input placeholder="{$this->price}" name="cost">
<input type="hidden" name="putId" value="{$this->item_id}">
<br><input type="submit" name="putToMarket" value="ать в магазин">
</form>
BTN;
} else {
switch ($shopType) {
default:
$btnValue = "Купить за " . intval($this->price) . " кр.";
$btnLink = "/shop.php?buy={$this->item_id}&rnd=" . mt_rand();
break;
case 'sell':
$btnValue = "Продать";
$btnLink = "/shop.php?sell={$this->item_id}&rnd=" . mt_rand();
break;
case 'marketgetback':
$btnValue = "Снять с продажи";
$btnLink = "?back={$this->item_id}&rnd=" . mt_rand();
break;
case 'marketbuy':
$btnValue = "Купить за " . intval($this->setsale) . " кр.";
$btnLink = "?otdel={$this->item_type}&set={$this->item_id}&rnd=" . mt_rand();
break;
}
echo <<<BTN
<p><input type="button" style="background: darkgrey; border: 1px solid grey; border-radius: 2px;" value="{$btnValue}"
onclick="location='{$btnLink}'">
BTN;
} }
$str = $this->optype == 'setmarket' ? '<input placeholder=" ' . $this->price . ' " name="cost">' : '';
$hiddenValue = $this->optype === 'buyshop' ? $this->offerId : $this->item_id;
$button_name = self::BUTTON[$this->optype];
return <<<FORM
<form method="post">$str
<input type="hidden" name="itemId" value="$hiddenValue">
<br><input type="submit" name="$this->optype" value="$button_name">
</form>
FORM;
} }
/**
* @return int
*/
public function getItemType(): int
{
return $this->item_type;
}
/** Выдача магазинных предметов по запросу.
* Ввелась чтобы перебить takeshopitem() в functions с идентичным функционалом.
* @param int $item_id ИД предмета.
* @param int $to ИД пперсонажа-получателя.
*/
public static function giveNewItem(int $item_id, int $to): array
{
$check = DBPDO::$db->ofetch('select 1 from items where id = ?', $item_id);
if (!$check) {
return [];
}
DBPDO::$db->execute(self::BUY_QUERY, [$to, $item_id]);
$return = DBPDO::$db->ofetch('select image, name from inventory where item_id = ?', DBPDO::$db->lastInsertId());
return [
'img' => $return->image,
'name' => $return->name,
'id' => $item_id,
];
}
} }

View File

@ -6,38 +6,49 @@ use Battles\Database\DBPDO;
class User class User
{ {
protected $id = 0; protected int $id = 0;
protected $login = '<em>Некто</em>'; protected string $login = '';
protected $pass; protected ?string $pass = null;
protected $email = '<em>неизвестно</em>'; protected ?string $email = null;
protected $realname; protected ?string $realname = null;
protected $borndate; protected ?string $borndate = null;
protected $info; protected ?string $info = null;
protected $level; protected int $level = 0;
protected $align; protected ?int $align = null;
protected $clan; protected ?string $clan = null;
protected $money; protected ?int $money = null;
protected $ip = 0; protected ?string $ip = null;
protected $admin = 0; protected ?int $admin = null;
protected $enter_game; protected int $room = 0;
protected $room; protected int $block = 0;
protected $block; protected string $shadow = '';
protected $shadow;
// Пока несуществующие, для совместимости. // Пока несуществующие, для совместимости.
protected $experience = 200; protected int $experience = 0;
protected $battle = 0; protected int $battle = 0;
protected $in_tower = 0; // Скорее башню похороним чем запустим... protected int $in_tower = 0; // Скорее башню похороним чем запустим...
protected $zayavka = 0; protected int $zayavka = 0;
protected static $db; protected static DBPDO $db;
public const INFO_CHAR_LIMIT = 1500; public const INFO_CHAR_LIMIT = 1500;
/**
* @var User Переменная инициализируемая при запуске, хранящая объект текущего пользователя.
*/
public static User $current;
/**
* @param int|string $user
*/
public function __construct($user) public function __construct($user)
{ {
self::$db = DBPDO::INIT(); self::$db = DBPDO::INIT();
$user_query = self::$db->fetch('SELECT * FROM users WHERE id = ? OR login = ?', [$user, $user]); $query = 'select * from users where login = ?';
if (is_numeric($user)) {
$query = 'select * from users where id = ?';
$user = (int)$user;
}
$user_query = self::$db->fetch($query, $user);
foreach ($this as $key => $value) { foreach ($this as $key => $value) {
if (isset($user_query[$key])) { if (isset($user_query[$key])) {
$this->$key = $user_query[$key]; $this->$key = $user_query[$key];
@ -45,64 +56,17 @@ class User
} }
} }
protected function showStarSign(): ?string
{
/*
* 1 aries
* 2 taurus
* 3 gemini
* 4 cancer
* 5 leo
* 6 virgo
* 7 libra
* 8 scorpio
* 9 sagittarios
* 10 capricorn
* 11 aquarius
* 12 pisches
*/
$zodiac = [
356 => "10",
326 => "09",
296 => "08",
266 => "07",
235 => "06",
203 => "05",
172 => "04",
140 => "03",
111 => "02",
78 => "01",
51 => "12",
20 => "11",
0 => "10",
];
$dayOfYear = date("z", strtotime($this->borndate));
$isLeapYear = date("L", strtotime($this->borndate)); //Высокосный?
if ($isLeapYear && $dayOfYear > 59) {
--$dayOfYear;
}
foreach ($zodiac as $day => $sign) {
if ($dayOfYear > $day) {
break;
}
}
return $sign ?? null;
}
/** /**
* @param int $userId * @param int $userId
* @param int $type * @param int $type
* @param string $name * @param string $name
* @param int $time * @param int $time
* @param string|null $json_modifiers_list (str, dex, int, end, intel, wis). * @param string|null $json_modifiers_list (str, dex, int, end, intel, wis).
* @return bool
*/ */
public static function setUserEffect(int $userId, int $type, string $name, int $time, string $json_modifiers_list = null): bool public static function addUserEffect(int $userId, int $type, string $name, int $time, string $json_modifiers_list = null)
{ {
$mods = json_decode($json_modifiers_list); $mods = json_decode($json_modifiers_list);
return self::$db->execute('INSERT INTO users_effects (owner_id, type, name, remaining_time, mod_strength, mod_dexterity, mod_intuition, mod_endurance, mod_intelligence, mod_wisdom) VALUES (?,?,?,?,?,?,?,?,?,?)', [$userId, $type, $name, $time, $mods->str ?? null, $mods->dex ?? null, $mods->int ?? null, $mods->end ?? null, $mods->intel ?? null, $mods->wis ?? null]); self::$db->execute('INSERT INTO users_effects (owner_id, type, name, remaining_time, mod_strength, mod_dexterity, mod_intuition, mod_endurance, mod_intelligence, mod_wisdom) VALUES (?,?,?,?,?,?,?,?,?,?)', [$userId, $type, $name, $time, $mods->str ?? null, $mods->dex ?? null, $mods->int ?? null, $mods->end ?? null, $mods->intel ?? null, $mods->wis ?? null]);
} }
public static function removeUserEffect(int $userId, int $type): bool public static function removeUserEffect(int $userId, int $type): bool
@ -113,34 +77,17 @@ class User
return false; return false;
} }
/**
* @return int
*/
public function getId(): int public function getId(): int
{ {
return $this->id; return $this->id;
} }
/**
* @return string
*/
public function getLogin(): string public function getLogin(): string
{ {
return $this->login; return $this->login;
} }
/** public function getPass(): string
* @param string $login
*/
public function setLogin(string $login): void
{
$this->login = $login;
}
/**
* @return mixed
*/
public function getPass()
{ {
return $this->pass; return $this->pass;
} }
@ -153,31 +100,7 @@ class User
$this->pass = $pass; $this->pass = $pass;
} }
public function savePass() public function getRealname(): string
{
self::$db->execute('UPDATE users SET pass = ? WHERE id = ?', [$this->pass, $this->id]);
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* @param string $email
*/
public function setEmail(string $email): void
{
$this->email = $email;
}
/**
* @return mixed
*/
public function getRealname()
{ {
return $this->realname; return $this->realname;
} }
@ -190,26 +113,7 @@ class User
$this->realname = $realname; $this->realname = $realname;
} }
/** public function getInfo(): string
* @return mixed
*/
public function getBorndate()
{
return $this->borndate;
}
/**
* @param mixed $borndate
*/
public function setBorndate($borndate): void
{
$this->borndate = $borndate;
}
/**
* @return mixed
*/
public function getInfo()
{ {
return $this->info; return $this->info;
} }
@ -217,121 +121,56 @@ class User
/** /**
* @param mixed $info * @param mixed $info
*/ */
public function setInfo($info): void public function setInfo($info)
{ {
$this->info = $info; $this->info = $info;
} }
/**
* @return int
*/
public function getLevel(): int public function getLevel(): int
{ {
return $this->level; return $this->level;
} }
/**
* @param int $level
*/
public function setLevel(int $level): void
{
$this->level = $level;
}
/**
* @return int
*/
public function getAlign(): int public function getAlign(): int
{ {
return $this->align; return $this->align;
} }
/** public function getClan(): ?string
* @param int $align
*/
public function setAlign(int $align): void
{
$this->align = $align;
}
/**
* @return string
*/
public function getClan(): string
{ {
return $this->clan; return $this->clan;
} }
/** /**
* @param int $clan * @param string|null $short_name Короткое название клана. Передать null для очистки.
*/ */
public function setClan(string $clan): void public function setClan(?string $short_name)
{ {
$this->clan = $clan; $this->clan = is_null($short_name) ? null : $short_name;
$this->saveUser();
} }
/**
* @return int
*/
public function getMoney(): int public function getMoney(): int
{ {
return $this->money; return $this->money;
} }
/** public function setMoney(int $money)
* @param int $money
*/
public function setMoney(int $money): void
{ {
$this->money = $money; $this->money = $money < 0 ? 0 : $money;
} }
public function saveMoney()
/**
* @return mixed
*/
public function getIp()
{ {
return $this->ip; self::$db->execute('update users set money = ? where id = ?', [$this->money, $this->id]);
} }
/**
* @param mixed $ip
*/
public function setIp($ip): void
{
$this->ip = $ip;
}
/**
* @return int
*/
public function getAdmin(): int public function getAdmin(): int
{ {
return $this->admin; return $this->admin;
} }
/** public function getRoom(): int
* @return mixed
*/
public function getEnterGame()
{
return $this->enter_game;
}
/**
* @param mixed $enter_game
*/
public function setEnterGame($enter_game): void
{
$this->enter_game = $enter_game;
}
/**
* @return mixed
*/
public function getRoom()
{ {
return $this->room; return $this->room;
} }
@ -339,31 +178,17 @@ class User
/** /**
* @param mixed $room * @param mixed $room
*/ */
public function setRoom($room): void public function setRoom($room)
{ {
$this->room = $room; $this->room = $room;
} }
/** public function getBlock(): int
* @return mixed
*/
public function getBlock()
{ {
return $this->block; return $this->block;
} }
/** public function getShadow(): string
* @param mixed $block
*/
public function setBlock($block): void
{
$this->block = $block;
}
/**
* @return mixed
*/
public function getShadow()
{ {
return $this->shadow; return $this->shadow;
} }
@ -382,80 +207,26 @@ class User
} }
} }
public function saveShadow()
{
self::$db->execute('UPDATE users SET shadow = ? WHERE id = ?', [$this->getShadow(), $this->getId()]);
}
/**
* @return int
*/
public function getExperience(): int public function getExperience(): int
{ {
return $this->experience; return $this->experience;
} }
/**
* @param int $experience
*/
public function setExperience(int $experience): void
{
$this->experience = $experience;
}
/**
* @return int
*/
public function getBattle(): int public function getBattle(): int
{ {
return $this->battle; return $this->battle;
} }
/**
* @param int $battle
*/
public function setBattle(int $battle): void
{
$this->battle = $battle;
}
/**
* @return int
*/
public function getInTower(): int public function getInTower(): int
{ {
return $this->in_tower; return $this->in_tower;
} }
/**
* @param int $in_tower
*/
public function setInTower(int $in_tower): void
{
$this->in_tower = $in_tower;
}
/**
* @return int
*/
public function getZayavka(): int public function getZayavka(): int
{ {
return $this->zayavka; return $this->zayavka;
} }
/**
* @param int $zayavka
*/
public function setZayavka(int $zayavka): void
{
$this->zayavka = $zayavka;
}
public function saveAnketa()
{
self::$db->execute('UPDATE users SET realname = ?, info = ? WHERE id = ?', [$this->realname, $this->info, $this->id]);
}
public function setOnline() public function setOnline()
{ {
self::$db->execute('update online set real_time = ? where user_id = ?', [time(), $this->getId()]); self::$db->execute('update online set real_time = ? where user_id = ?', [time(), $this->getId()]);
@ -463,35 +234,57 @@ class User
public function setInjury(int $type): bool public function setInjury(int $type): bool
{ {
if (!in_array($type,[11,12,13,14])) { if (!in_array($type, [11, 12, 13, 14])) {
return false; return false;
} }
$names1 = ['разбитый нос', 'сотрясение первой степени', 'потрепанные уши', 'прикушенный язык', 'перелом переносицы', 'растяжение ноги', 'растяжение руки', 'подбитый глаз', 'синяк под глазом', 'кровоточащее рассечение', 'отбитая «пятая точка»', 'заклинившая челюсть', 'выбитый зуб «мудрости»', 'косоглазие']; $names1 = ['разбитый нос', 'сотрясение первой степени', 'потрепанные уши', 'прикушенный язык', 'перелом переносицы', 'растяжение ноги', 'растяжение руки', 'подбитый глаз', 'синяк под глазом', 'кровоточащее рассечение', 'отбитая «пятая точка»', 'заклинившая челюсть', 'выбитый зуб «мудрости»', 'косоглазие'];
$names2 = ['отбитые почки', 'вывих «вырезано цензурой»', 'сотрясение второй степени', 'оторванное ухо', 'вывих руки', 'оторванные уши', 'поврежденный позвоночник', 'поврежденный копчик', 'разрыв сухожилия', 'перелом ребра', 'перелом двух ребер', 'вывих ноги', 'сломанная челюсть']; $names2 = ['отбитые почки', 'вывих «вырезано цензурой»', 'сотрясение второй степени', 'оторванное ухо', 'вывих руки', 'оторванные уши', 'поврежденный позвоночник', 'поврежденный копчик', 'разрыв сухожилия', 'перелом ребра', 'перелом двух ребер', 'вывих ноги', 'сломанная челюсть'];
$names3 = ['пробитый череп', 'разрыв селезенки', 'смещение позвонков', 'открытый перелом руки', 'открытый перелом «вырезано цензурой»', 'излом носоглотки', 'непонятные, но множественные травмы', 'сильное внутреннее кровотечение', 'раздробленная коленная чашечка', 'перелом шеи', 'смещение позвонков', 'открытый перелом ключицы', 'перелом позвоночника', 'вывих позвоночника', 'сотрясение третьей степени']; $names3 = ['пробитый череп', 'разрыв селезенки', 'смещение позвонков', 'открытый перелом руки', 'открытый перелом «вырезано цензурой»', 'излом носоглотки', 'непонятные, но множественные травмы', 'сильное внутреннее кровотечение', 'раздробленная коленная чашечка', 'перелом шеи', 'смещение позвонков', 'открытый перелом ключицы', 'перелом позвоночника', 'вывих позвоночника', 'сотрясение третьей степени'];
$param_names = ['str','dex','int','end','intel','wis',]; $param_names = ['str', 'dex', 'int', 'end', 'intel', 'wis',];
shuffle($param_names); shuffle($param_names);
switch ($type) { switch ($type) {
case 11: case 11:
shuffle($names1); shuffle($names1);
$name = UserEffects::$effectName[$type] . ': ' . $names1(0); $name = UserEffects::$effectName[$type] . ': ' . $names1(0);
self::setUserEffect($this->id, $type, $name, strtotime('30min'), json_encode([$param_names(0) => -1])); self::addUserEffect($this->id, $type, $name, strtotime('30min'), json_encode([$param_names(0) => -1]));
break; break;
case 12: case 12:
shuffle($names2); shuffle($names2);
$name = UserEffects::$effectName[$type] . ': ' . $names2(0); $name = UserEffects::$effectName[$type] . ': ' . $names2(0);
self::setUserEffect($this->id, $type, $name, strtotime('3hours'), json_encode([$param_names(0) => mt_rand(-3,-1), $param_names(1) => mt_rand(-3,-1)])); self::addUserEffect($this->id, $type, $name, strtotime('3hours'), json_encode([$param_names(0) => mt_rand(-3, -1), $param_names(1) => mt_rand(-3, -1)]));
break; break;
case 13: case 13:
shuffle($names3); shuffle($names3);
$name = UserEffects::$effectName[$type] . ': ' . $names3(0); $name = UserEffects::$effectName[$type] . ': ' . $names3(0);
self::setUserEffect($this->id, $type, $name, strtotime('12hours'), json_encode([$param_names(0) => mt_rand(-5,-1), $param_names(1) => mt_rand(-5,-1), $param_names(2) => mt_rand(-5,-1)])); self::addUserEffect($this->id, $type, $name, strtotime('12hours'), json_encode([$param_names(0) => mt_rand(-5, -1), $param_names(1) => mt_rand(-5, -1), $param_names(2) => mt_rand(-5, -1)]));
break; break;
default: //type 14 default: //type 14
self::setUserEffect($this->id, $type, UserEffects::$effectName[$type], strtotime('1day'), json_encode([$param_names(0) => -10])); self::addUserEffect($this->id, $type, UserEffects::$effectName[$type], strtotime('1day'), json_encode([$param_names(0) => -10]));
break; break;
} }
return true; return true;
} }
/** Сохраняет в базу актуальные логин, пароль, email, имя, дату рождения, текст инфы, склонность, клан, образ, права админа.
*
*/
public function saveUser()
{
$query = 'update users set login = ?, pass = ?, email = ?, realname = ?, borndate = ?, info = ?, align = ?, clan = ?, shadow = ?, admin = ? where id = ?';
$vals = [
$this->login, //set
$this->pass,
$this->email,
$this->realname,
$this->borndate,
$this->info,
$this->align,
$this->clan,
$this->shadow,
$this->admin,
$this->id //where
];
DBPDO::$db->execute($query, $vals);
}
} }

View File

@ -1,15 +1,24 @@
<?php <?php
namespace Battles; namespace Battles;
use Battles\Database\DBPDO; use Battles\Database\DBPDO;
use Battles\Models\EffectsModel; use Battles\Models\EffectsModel;
class UserInfo extends UserStats class UserInfo extends UserStats
{ {
use Rooms; use Rooms;
//Статусы того, кто смотрит на информацию.
public $watcher_id; private int $bankMoney;
private $watcherIsAdmin; //Тот, кто смотрит на информацию.
private $watcherIsModerator; private User $watcher;
public function __construct($user)
{
parent::__construct($user);
$bank = new Bank($this->id);
$this->bankMoney = $bank->getMoney();
}
/** /**
* Отображает куклу персонажа (образ и слоты). * Отображает куклу персонажа (образ и слоты).
@ -19,7 +28,7 @@ class UserInfo extends UserStats
* @param int $isMain установить 1, если куклу надо показать на странице игрока (по клику на предмет снимает * @param int $isMain установить 1, если куклу надо показать на странице игрока (по клику на предмет снимает
* его). * его).
*/ */
private function UserInfoDoll($isBattle = 0, $isMain = 0) private function UserInfoDoll(int $isBattle = 0, int $isMain = 0)
{ {
$di = new DressedItems($this->id); $di = new DressedItems($this->id);
$dressedItems = $di->getItemsInSlots(); $dressedItems = $di->getItemsInSlots();
@ -49,6 +58,45 @@ class UserInfo extends UserStats
echo '</div><!-- slot-image -->'; echo '</div><!-- slot-image -->';
} }
private function ttz()
{
$arr = [
'Уровень' => $this->level,
'Сила' => $this->printStat('strength'),
'Ловкость' => $this->printStat('dexterity'),
'Интуиция' => $this->printStat('intuition'),
'Выносливость' => $this->printStat('endurance'),
'Интеллект' => $this->printStat('intelligence'),
'Мудрость' => $this->printStat('wisdom'),
'Уворот' => $this->getFullStats()->evasion,
'Точность' => $this->getFullStats()->accuracy,
'Шанс крита' => $this->getFullStats()->criticals,
'Урон' => $this->getFullStats()->min_physical_damage . ' - ' . $this->getFullStats()->max_physical_damage,
'Локация' => Rooms::$roomNames[$this->room],
];
$str = null;
$i = 0;
foreach ($arr as $item => $value) {
$str .= "<div class='column' style='text-align: right; margin-right: 10px;'>$item</div><div class='column'>$value</div>";
if (in_array($i,[6,9])) {
$str .= "<div style='margin-top: 10px;'></div><div></div>";
}
$i++;
}
$nameString = $this->align ? "<img src='/i/align_$this->align.png' alt='Склонность'>" : "";
$nameString .= $this->block ? "<span class='private' style='text-decoration: line-through;'>$this->login</span>" : "<b>$this->login</b>";
$nameString .= $this->clan ? "<img src='/i/clan/$this->clan.png' alt='Клан'>" : "";
echo "<div class='info'><b>$nameString</b></div><!-- info -->";
echo "<div class='stats-container' style='display: grid; grid-template-columns: 150px 100px; font-size: 1.2em;'>$str</div>";
}
private function printStat($statName): string
{
return $this->getFreeStatPoints() ? $this->getStat($statName, 1) . '(' . $this->getFullStats()->$statName . ')' : $this->getFullStats()->$statName;
}
//TODO вызывать из main.php
private function UserInfoStats($isMainWindow = 0) private function UserInfoStats($isMainWindow = 0)
{ {
$captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:'; $captions = 'Уровень:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Местонахождение:';
@ -62,7 +110,6 @@ class UserInfo extends UserStats
parent::getFullStats()->wisdom . '<br>' . parent::getFullStats()->wisdom . '<br>' .
Rooms::$roomNames[$this->room]; Rooms::$roomNames[$this->room];
if ($isMainWindow) { if ($isMainWindow) {
$this->Bank = new Bank($this->id);
$captions = 'Уровень:<br>Здоровье:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Опыт:<br>Очки характеристик:<br>Деньги:<br>Деньги в банке:'; $captions = 'Уровень:<br>Здоровье:<br>Сила:<br>Ловкость:<br>Интуиция:<br>Выносливость:<br>Интеллект:<br>Мудрость:<br>Опыт:<br>Очки характеристик:<br>Деньги:<br>Деньги в банке:';
$variables = $variables =
$this->level . '<br>' . $this->level . '<br>' .
@ -76,7 +123,7 @@ class UserInfo extends UserStats
$this->experience . '<br>' . $this->experience . '<br>' .
$this->free_stat_points . '<br>' . $this->free_stat_points . '<br>' .
$this->money . '<br>' . $this->money . '<br>' .
$this->Bank->getMoney(); $this->bankMoney;
} }
$nameString = null; $nameString = null;
$nameString .= $this->align ? "<img src='/i/align_$this->align.png' alt='Склонность'>" : ""; $nameString .= $this->align ? "<img src='/i/align_$this->align.png' alt='Склонность'>" : "";
@ -100,16 +147,13 @@ HTML;
*/ */
private function showPrivateData(): ?string private function showPrivateData(): ?string
{ {
if (!$this->watcherIsAdmin || !$this->watcherIsModerator) {
return null;
}
$birthday = date('d.m.Y', strtotime($this->borndate)); $birthday = date('d.m.Y', strtotime($this->borndate));
$userLogs = GameLogs::getUserLogs($this->id); $userLogs = GameLogs::getUserLogs($this->id);
$log = null; $log = null;
while ($userLogRow = $userLogs->fetchArray(SQLITE3_ASSOC)) { while ($userLogRow = $userLogs->fetchArray(SQLITE3_ASSOC)) {
$log .= sprintf('<code>%s</code><br>', date('d.m.Y H:i ', strtotime($userLogRow['date'])) . $userLogRow['text']); $log .= sprintf('<code>%s</code><br>', date('d.m.Y H:i ', strtotime($userLogRow['date'])) . $userLogRow['text']);
} }
$adminData = $this->watcherIsAdmin ? $this->showAdminOnlyData() : null; $adminData = $this->watcher->getAdmin() ? $this->showAdminOnlyData() : null;
return <<<INFO return <<<INFO
<div class="secret-info"> <div class="secret-info">
E-Mail: $this->email<br> E-Mail: $this->email<br>
@ -129,15 +173,13 @@ INFO;
*/ */
private function showAdminOnlyData(): ?string private function showAdminOnlyData(): ?string
{ {
$this->Bank = new Bank($this->id);
$bankMoney = $this->Bank->getMoney();
return <<<INFO return <<<INFO
ИД Игрока: $this->id<br> ИД Игрока: $this->id<br>
ИД Комнаты: $this->room<br> ИД Комнаты: $this->room<br>
Деньги: $this->money<br> Деньги: $this->money<br>
Деньги в банке: $bankMoney<br> Деньги в банке: $this->bankMoney<br>
Опыт: $this->experience<br> Опыт: $this->experience<br>
Нераспределённые очки: $this->free_stat_points<br> Нераспределённые очки: $this->free_stat_points<br>
INFO; INFO;
} }
@ -146,30 +188,27 @@ INFO;
{ {
echo '<div class="user-info-container">'; echo '<div class="user-info-container">';
$this->UserInfoDoll(); $this->UserInfoDoll();
$this->UserInfoStats(); $this->ttz();
echo '<div class="slot-lower"> <!-- statuses! -->'; echo '<div class="slot-lower"> <!-- statuses! --></div>';
echo '</div><!-- slot-lower -->'; echo '</div><!-- u-i-c -->';
echo '<div class="user-signs">';
echo sprintf('<img src="i/zodiac/%s.png" alt="Родовой знак">', $this->showStarSign());
echo '</div><!-- user-signs -->';
echo '</div><!-- user-info-container -->';
echo '<hr><!-- Нижняя часть -->'; echo '<hr><!-- Нижняя часть -->';
echo '<div class="user-info-container-lower">'; echo '<div class="user-info-container-lower">';
echo '<h2>Об игроке</h2>'; echo '<h2>Об игроке</h2>';
echo $this->realname ? "Имя: $this->realname" : ""; echo $this->realname ? "Имя: $this->realname" : "";
echo $this->info ? "<br>" . nl2br($this->info) : ""; echo $this->info ? "<br>" . nl2br($this->info) : "";
echo '</div><!-- user-info-container-lower -->'; echo '</div><!-- u-i-c-l -->';
echo $this->showPrivateData(); if ($this->watcher->getAdmin() || $this->watcher->getAlign() == 1) {
echo $this->showPrivateData();
}
} }
public function showUserInfo() public function showUserInfo()
{ {
$this->WatcherStatus();
$effects = new EffectsModel($this->id); $effects = new EffectsModel($this->id);
if ($this->block && (!$this->watcherIsAdmin || !$this->watcherIsModerator)) { if ($this->block && (!$this->watcher->getAdmin() || !$this->watcher->getAlign() == 1)) {
echo "<span class='error'>Персонаж $this->login заблокирован!</span>"; echo "<span class='error'>Персонаж $this->login заблокирован!</span>";
} elseif ($effects->getHideUserInfoStatus() && (!$this->watcherIsAdmin || !$this->watcherIsModerator)) { } elseif ($effects->getHideUserInfoStatus() && (!$this->watcher->getAdmin() || !$this->watcher->getAlign() == 1)) {
if ($effects->getHideUserInfoStatus() == -1) { if ($effects->getHideUserInfoStatus() == -1) {
$date = 'навсегда'; $date = 'навсегда';
} else { } else {
@ -181,17 +220,6 @@ INFO;
} }
} }
private function WatcherStatus()
{
$query = parent::$db->fetch('SELECT align, admin FROM users WHERE id = ?', $this->watcher_id);
if ($query['admin']) {
$this->watcherIsAdmin = 1;
}
if ($query['align'] == 1) {
$this->watcherIsModerator = 1;
}
}
public function showUserDoll($isBattle = 0, $isMain = 0) public function showUserDoll($isBattle = 0, $isMain = 0)
{ {
echo '<div class="user-info-container">'; echo '<div class="user-info-container">';
@ -216,17 +244,22 @@ INFO;
$timeleft = timeOut($effect->remaining_time - time()); $timeleft = timeOut($effect->remaining_time - time());
$r .= " $r .= "
<div> <div>
<img class='image' src='/i/{$img[$effect->type]}' alt='{$effect->name}'> <img class='image' src='/i/{$img[$effect->type]}' alt='$effect->name'>
<span class='title'>{$effect->name}</span> <span class='title'>$effect->name</span>
<div class='timeleft'>$timeleft</div> <div class='timeleft'>$timeleft</div>
</div> </div>
"; ";
} }
return $r; return $r;
} }
public function showStarSign(): ?string
/**
* @param mixed $watcher_id
*/
public function setWatcher(int $watcher_id): void
{ {
return parent::showStarSign(); $this->watcher = new User($watcher_id);
} }
} }

View File

@ -3,6 +3,7 @@
namespace Battles; namespace Battles;
use Battles\Database\DBPDO;
use Exceptions\GameException; use Exceptions\GameException;
class UserStats extends User class UserStats extends User
@ -22,16 +23,16 @@ class UserStats extends User
//// Неизменяемые для игрока(!) переменные. //// Неизменяемые для игрока(!) переменные.
// Удар кулаком всегда 1-2. // Удар кулаком всегда 1-2.
protected $minDamage = 1; protected int $minDamage = 1;
protected $maxDamage = 2; protected int $maxDamage = 2;
// Природная броня всегда 0. // Природная броня всегда 0.
// Зачем их три, если во всех формулах она одна? // Зачем их три, если во всех формулах она одна?
protected $headArmor = 0; protected int $headArmor = 0;
protected $chestArmor = 0; protected int $chestArmor = 0;
protected $legArmor = 0; protected int $legArmor = 0;
// Динамически рассчитываемые // Динамически рассчитываемые
protected $maxHealth; protected int $maxHealth;
protected $maxMana; protected int $maxMana;
/** /**
* UserStats constructor. * UserStats constructor.
@ -48,14 +49,14 @@ class UserStats extends User
/** /**
* Отдаёт информацию о базовом(!) стате. * Отдаёт информацию о базовом(!) стате.
* *
* @param $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition', * @param $stat_name - имя стата. Может принимать значения 'strength', 'dexterity', 'intuition',
* 'endurance', 'intelligence', 'wisdom'. * 'endurance', 'intelligence', 'wisdom'.
* @param int $isMainWindow - переключатель "главного окна". Если включить, дополнительно будет показывать ссылку * @param int $isMainWindow - переключатель "главного окна". Если включить, дополнительно будет показывать ссылку
* на повышение стата на 1, при условии наличия свободных очков статов. * на повышение стата на 1, при условии наличия свободных очков статов.
* *
* @return string * @return string
*/ */
public function getStat($stat_name, $isMainWindow = 0): string public function getStat($stat_name, int $isMainWindow = 0): string
{ {
if (!in_array($stat_name, ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'])) { if (!in_array($stat_name, ['strength', 'dexterity', 'intuition', 'endurance', 'intelligence', 'wisdom'])) {
return self::ERROR_STAT_UNKNOWN; return self::ERROR_STAT_UNKNOWN;
@ -220,4 +221,36 @@ class UserStats extends User
return self::$db->ofetch($query); return self::$db->ofetch($query);
} }
public function levelUp(): string
{
$this->level += 1;
$this->free_stat_points += 2;
$this->saveStats();
Chat::addSYSMessage('Внимание, вы получили ' . $this->level . 'уровень. Доступны очки распределения параметров.');
return 'Персонаж перешёл на ' . $this->level . 'уровень.';
}
/** Сохраняет в базу актуальные статы, здоровье, ману, свободные очки статов и уровень.
*
*/
private function saveStats()
{
$query = 'update users set strength = ?, dexterity = ?, intuition = ?, endurance = ?,
intelligence = ?, wisdom = ?, health = ?, mana = ?, free_stat_points = ?,
level = ? where id = ?';
$vals = [
$this->strength, //set
$this->dexterity,
$this->intuition,
$this->endurance,
$this->intelligence,
$this->wisdom,
$this->health,
$this->mana,
$this->free_stat_points,
$this->level,
$this->id //where
];
DBPDO::$db->execute($query, $vals);
}
} }

View File

@ -1,5 +1,8 @@
<?php <?php
use Battles\GameLogs;
use Battles\Nick;
class Tournament class Tournament
{ {
public $MaxUserLevel = 9; public $MaxUserLevel = 9;
@ -159,7 +162,7 @@ class Tournament
// создаем лог // создаем лог
$rr = "<b>" . Nick::id($user['id'])->full(1) . "</b> и <b>" . Nick::id($jert['id'])->full(1) . "</b>"; $rr = "<b>" . Nick::id($user['id'])->full(1) . "</b> и <b>" . Nick::id($jert['id'])->full(1) . "</b>";
addch("<a href=logs.php?log=" . $id . " target=_blank>Бой</a> между <B><b>" . Nick::id($user['id'])->short() . "</b> и <b>" . Nick::id($jert['id'])->short() . "</b> начался. ", $user->getRoom()); addch("<a href=logs.php?log=" . $id . " target=_blank>Бой</a> между <B><b>" . Nick::id($user['id'])->short() . "</b> и <b>" . Nick::id($jert['id'])->short() . "</b> начался. ", $user->getRoom());
addlog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " решили выяснить кто из них сильнее. <i>(турнир)</i><BR>"); GameLogs::addBattleLog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " решили выяснить кто из них сильнее. <i>(турнир)</i><BR>");
return $id; return $id;
} }
} }

View File

@ -1,13 +1,12 @@
<?php <?php
use Battles\Database\DBPDO;
use Battles\GameLogs; use Battles\GameLogs;
use Battles\InventoryItem;
use Battles\ShopItem; use Battles\ShopItem;
use Battles\Template; use Battles\Template;
use Battles\User;
session_start();
require_once 'functions.php'; require_once 'functions.php';
$user = $user ?? new User($_SESSION['uid']);
$get = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING')); $get = urldecode(filter_input(INPUT_SERVER, 'QUERY_STRING'));
$putItemCost = (int)filter_input(INPUT_POST, 'cost', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]); $putItemCost = (int)filter_input(INPUT_POST, 'cost', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
$putItemId = (int)filter_input(INPUT_POST, 'putId', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]); $putItemId = (int)filter_input(INPUT_POST, 'putId', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
@ -15,6 +14,8 @@ $returningItemId = (int)filter_input(INPUT_GET, 'back', FILTER_VALIDATE_INT, ['o
$byingItemId = (int)filter_input(INPUT_GET, 'set', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]); $byingItemId = (int)filter_input(INPUT_GET, 'set', FILTER_VALIDATE_INT, ['options' => ['min_range' => 1]]);
if ($putItemId) { if ($putItemId) {
$query = 'select name from inventory where dressed_slot = 0 and owner_id = ? and item_id = ?';
DBPDO::INIT()->ofetch($query, [$_SESSION['uid'], $putItemId]);
$dress = db::c()->query('SELECT `name`,`duration`,`maxdur`,`cost` FROM `inventory` WHERE `dressed` = 0 AND `id` = ?i AND `owner` = ?i', $putItemId, $_SESSION['uid'])->fetch_assoc(); $dress = db::c()->query('SELECT `name`,`duration`,`maxdur`,`cost` FROM `inventory` WHERE `dressed` = 0 AND `id` = ?i AND `owner` = ?i', $putItemId, $_SESSION['uid'])->fetch_assoc();
if (empty($putItemCost)) { if (empty($putItemCost)) {
$putItemCost = $dress['cost']; $putItemCost = $dress['cost'];
@ -75,60 +76,30 @@ if ($byingItemId) {
$classPrintControlName = "marketbuy"; $classPrintControlName = "marketbuy";
if ($get === 'sale') { if ($get === 'sale') {
$data = db::c()->query('SELECT `inventory`.*, $search = $_SESSION['uid'];
`magic`.`name` AS `magic_name`, $query = 'select * from inventory where on_sale = 0 and dressed_slot = 0 and present is null and owner_id = ? order by name';
`magic`.`chanse` AS `magic_chanse`,
`magic`.`time` AS `magic_time`,
`magic`.`file` AS `magic_file`,
`magic`.`targeted` AS `magic_targeted`,
`magic`.`needcharge` AS `magic_needcharge`,
`magic`.`img` AS `magic_img`,
0 AS `maxdur`
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `setsale` = 0 AND `dressed` = 0 AND `present` = "?s" AND `owner` = ?i ORDER BY `update` DESC ', '', $_SESSION['uid']);
$classPrintControlName = "marketput"; $classPrintControlName = "marketput";
} elseif ($get === 'unsale') { } elseif ($get === 'unsale') {
$data = db::c()->query('SELECT `inventory`.*, $search = $_SESSION['uid'];
`magic`.`name` AS `magic_name`, $query = 'select * from inventory where on_sale > 0 and dressed_slot = 0 and owner_id = ? order by name';
`magic`.`chanse` AS `magic_chanse`,
`magic`.`time` AS `magic_time`,
`magic`.`file` AS `magic_file`,
`magic`.`targeted` AS `magic_targeted`,
`magic`.`needcharge` AS `magic_needcharge`,
`magic`.`img` AS `magic_img`,
0 AS `maxdur`
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `setsale` > 0 AND `dressed` = 0 AND `owner` = ?i ORDER BY `update` DESC', $_SESSION['uid']);
$classPrintControlName = "marketgetback"; $classPrintControlName = "marketgetback";
} else if (!empty($_POST['search'])) { } else if (!empty($_POST['search'])) {
$data = db::c()->query('SELECT `inventory`.*, $search = "%{$_POST['search']}%";
`magic`.`name` AS `magic_name`, $query = 'select * from inventory where on_sale > 0 and dressed_slot = 0 and name like ? order by item_id';
`magic`.`chanse` AS `magic_chanse`,
`magic`.`time` AS `magic_time`,
`magic`.`file` AS `magic_file`,
`magic`.`targeted` AS `magic_targeted`,
`magic`.`needcharge` AS `magic_needcharge`,
`magic`.`img` AS `magic_img`,
0 AS `maxdur`
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `dressed` = 0 AND `inventory`.`name` LIKE "%?S%" AND `setsale` > 0 ORDER BY `setsale` ASC', $_POST['search']);
} else { } else {
$data = db::c()->query('SELECT `inventory`.*, $query = 'select * from inventory where on_sale > 0 and dressed_slot = 0 order by name';
`magic`.`name` AS `magic_name`, }
`magic`.`chanse` AS `magic_chanse`,
`magic`.`time` AS `magic_time`, if (isset($search)) {
`magic`.`file` AS `magic_file`, $data = DBPDO::INIT()->ofetchAll($query, $search);
`magic`.`targeted` AS `magic_targeted`, unset($search);
`magic`.`needcharge` AS `magic_needcharge`, } else {
`magic`.`img` AS `magic_img`, $data = DBPDO::INIT()->ofetchAll($query);
0 AS `maxdur`
FROM `inventory` LEFT JOIN `magic` ON `magic` = `magic`.`id` WHERE `dressed` = 0 AND `setsale` > 0 ORDER BY `setsale` ASC');
} }
$iteminfo = []; $iteminfo = [];
while ($row = $data->fetch_assoc()) { foreach ($data as $itemObject) {
$iteminfo[] = new ShopItem($row); $iteminfo[] = new ShopItem($itemObject, 'buymarket');
} }
Template::header('Рынок'); Template::header('Рынок');
@ -137,12 +108,12 @@ Template::header('Рынок');
<h1>Рынок</h1> <h1>Рынок</h1>
<a href=# onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a> <a href=# onclick=hrefToFrame('city.php?cp')> ← выйти на Центральную площадь</a>
<div><?php if (!empty($status)) err($status); ?></div> <div><?php if (!empty($status)) err($status); ?></div>
<TABLE width=100% cellspacing="0" cellpadding="4"> <table width=100% cellspacing="0" cellpadding="4">
<TR> <tr>
<TD valign=top align=left> <td valign=top align=left>
<TABLE class="zebra" width=100%> <table class="zebra" width=100%>
<TR> <tr>
<TH> <th>
<?php if ($get === 'sale'): ?> <?php if ($get === 'sale'): ?>
Выставить товар на продажу. Выставить товар на продажу.
<br>Комиссия за услуги магазина составляет 10% от цены, по которой вы предлагаете предмет. <br>Комиссия за услуги магазина составляет 10% от цены, по которой вы предлагаете предмет.
@ -154,9 +125,9 @@ Template::header('Рынок');
<input name="search"> <input type="submit" value="Искать товар"> <input name="search"> <input type="submit" value="Искать товар">
</form> </form>
<?php endif; ?> <?php endif; ?>
<TR> <tr>
<TD><!--Рюкзак--> <td><!--Рюкзак-->
<TABLE WIDTH=100%> <table width=100%>
<?php <?php
foreach ($iteminfo as $ii) { foreach ($iteminfo as $ii) {
echo "<tr><td style='width: 150px; text-align: center;'>"; echo "<tr><td style='width: 150px; text-align: center;'>";
@ -168,11 +139,11 @@ Template::header('Рынок');
echo "</td></tr>"; echo "</td></tr>";
} }
?> ?>
</TABLE> </table>
</TABLE> </table>
<TD valign=top width=280> <TD valign=top width=280>
<div style="margin-left:15px; margin-top: 10px;"> <div style="margin-left:15px; margin-top: 10px;">
<b>Масса всех ваших вещей: <?= getItemsMassaInfo() ?> <b>Масса всех ваших вещей: <?= InventoryItem::getWeightData() ?>
<br>У вас в наличии: <span style="color: darkgreen;"><?= $user['money'] ?></span> кр.</b> <br>У вас в наличии: <span style="color: darkgreen;"><?= $user['money'] ?></span> кр.</b>
<hr> <hr>
<br> <br>
@ -184,4 +155,4 @@ Template::header('Рынок');
<br> <br>
<button onclick="hrefToFrame('city.php?cp=1')">Вернуться</button> <button onclick="hrefToFrame('city.php?cp=1')">Вернуться</button>
</div> </div>
</TABLE> </table>

View File

@ -6,25 +6,28 @@
* Project name: Battles-Game * Project name: Battles-Game
*/ */
use Battles\Database\DBPDO;
use Battles\User;
include_once 'classes/Database/db.php';
include_once 'classes/Database/Mysql.php';
include_once 'classes/Database/Statement.php';
include_once 'classes/Database/Exception.php';
ini_set('display_errors', 'On'); ini_set('display_errors', 'On');
error_reporting(E_ALL); error_reporting(E_ALL);
define("GAMEDOMAIN", "battles.lan"); const GAMEDOMAIN = "battles.lan";
if (session_status() !== PHP_SESSION_ACTIVE) {
session_start();
}
/* /*
* Запрещаем кэшировать * Запрещаем кэшировать
*/ */
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0"); header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false); header("Cache-Control: post-check=0, pre-check=0", false);
/**
* Классы для работы с базой данных.
*/
require_once 'classes/Database/Mysql.php';
require_once 'classes/Database/Exception.php';
require_once 'classes/Database/Statement.php';
require_once 'classes/Database/db.php';
require_once 'classes/Battles/Database/DBPDO.php';
/** /**
* Автозагрузка классов с учётом неймспейсов. * Автозагрузка классов с учётом неймспейсов.
*/ */
@ -36,6 +39,17 @@ spl_autoload_register(function ($className) {
} }
}); });
/**
* Глобальные переменные. Промежуточное решение для совместимости.
*/
if (empty(DBPDO::$db)) {
DBPDO::$db = new DBPDO();
}
if (empty(User::$current) && $_SESSION['uid']) {
User::$current = new User($_SESSION['uid']);
}
// Для нападалок. Сперва комнаты в которых нельзя напасть, потом персонажи на которых нельзя напасть. // Для нападалок. Сперва комнаты в которых нельзя напасть, потом персонажи на которых нельзя напасть.
const UNKILABLE = [ const UNKILABLE = [
'rooms' => [620, 621, 1051, 1052], 'rooms' => [620, 621, 1051, 1052],

View File

@ -5,6 +5,9 @@
* Project name: Battles-Game * Project name: Battles-Game
*/ */
use Battles\GameLogs;
use Battles\Nick;
include_once '../config.php'; include_once '../config.php';
include_once '../functions.php'; include_once '../functions.php';
$tm = time(); $tm = time();
@ -206,7 +209,7 @@ function startbattle($id, $zay, $r)
} }
$rr .= "</b>"; $rr .= "</b>";
addlog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу.<BR>"); GameLogs::addBattleLog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу.<BR>");
foreach ($z['team1'] as $k => $v) { foreach ($z['team1'] as $k => $v) {
if ($v < _BOTSEPARATOR_) { if ($v < _BOTSEPARATOR_) {
@ -287,7 +290,7 @@ if ($st_ar['value'] <= time()) {
$id = mysql_insert_id(); $id = mysql_insert_id();
mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE (`id` = {$dark['id_at']} OR `id` = {$light['id_at']}) LIMIT 2"); mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE (`id` = {$dark['id_at']} OR `id` = {$light['id_at']}) LIMIT 2");
$rr = "<b>" . Nick::id($dark['id_at'])->full(1) . "</b> и <b>" . Nick::id($light['id_at'])->full(1) . "</b>"; $rr = "<b>" . Nick::id($dark['id_at'])->full(1) . "</b> и <b>" . Nick::id($light['id_at'])->full(1) . "</b>";
addlog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <br />"); GameLogs::addBattleLog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <br />");
mysql_query("UPDATE `users` SET `battle` = {$id}, `zayavka` = 0 WHERE (`id` = {$dark['id']} OR `id` = {$light['id']}) LIMIT 2"); mysql_query("UPDATE `users` SET `battle` = {$id}, `zayavka` = 0 WHERE (`id` = {$dark['id']} OR `id` = {$light['id']}) LIMIT 2");
file_get_contents(GAMEDOMAIN . '/chats.php?id=2'); file_get_contents(GAMEDOMAIN . '/chats.php?id=2');
mysql_query('UPDATE `variables` SET `value` = "' . (time() + 60 * 60 * 24 * 7) . '" WHERE `var` = "arena_of_gods" LIMIT 1'); mysql_query('UPDATE `variables` SET `value` = "' . (time() + 60 * 60 * 24 * 7) . '" WHERE `var` = "arena_of_gods" LIMIT 1');
@ -298,7 +301,7 @@ if (date("z-H-i") == date("z-H-i", $st_ar['value'])) {
file_get_contents(GAMEDOMAIN . '/chats.php?id=3'); file_get_contents(GAMEDOMAIN . '/chats.php?id=3');
} }
$komp_users = mysql_query("SELECT * FROM `users`, `online` WHERE `users`.`id` = `online`.`id` AND `online`.`date` >= " . (time() - 60) . ""); $komp_users = mysql_query("SELECT * FROM `users`, `online` WHERE `users`.`id` = `online`.`id` AND `online`.login_time >= " . (time() - 60) . "");
while ($ku = mysql_fetch_array($komp_users)) { while ($ku = mysql_fetch_array($komp_users)) {
$bns = 0; $bns = 0;
$efs_bns = mysql_fetch_array(mysql_query('SELECT SUM(`hp`) AS `hps` FROM `effects` WHERE `owner` = "' . $ku['id'] . '"')); $efs_bns = mysql_fetch_array(mysql_query('SELECT SUM(`hp`) AS `hps` FROM `effects` WHERE `owner` = "' . $ku['id'] . '"'));

View File

@ -5,6 +5,10 @@
* Project name: Battles-Game * Project name: Battles-Game
*/ */
use Battles\Chat;
use Battles\DressedItems;
use Battles\GameLogs;
include_once '../config.php'; include_once '../config.php';
include_once '../functions.php'; include_once '../functions.php';
//include_once '../cave/cave_bots.php'; //include_once '../cave/cave_bots.php';
@ -486,7 +490,7 @@ class fbattle
$inv_broken = mysql_query("SELECT * FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '" . time() . "')) AND `owner` = '{$v}'"); $inv_broken = mysql_query("SELECT * FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '" . time() . "')) AND `owner` = '{$v}'");
while ($br = mysql_fetch_array($inv_broken)) { while ($br = mysql_fetch_array($inv_broken)) {
$item = new \Battles\DressedItems($v); $item = new DressedItems($v);
$item->undressItem($br['type']); $item->undressItem($br['type']);
} }
@ -548,10 +552,10 @@ class fbattle
} }
if ($arr_battle['win'] == 1) { if ($arr_battle['win'] == 1) {
AddChatSystem("<font color=red>Внимание! Тьма одержала победу благодаря великим воинам : <b>$uss</b></font>"); Chat::addSYSMessage('Внимание! Тьма одержала победу благодаря великим воинам: <b>' . $uss . '</b>');
$this->AddToLog('<span class=date>' . date("H:i") . '</span> ' . 'Бой закончен, победа за <B>Силами Тьмы</B><BR>'); $this->AddToLog('<span class=date>' . date("H:i") . '</span> ' . 'Бой закончен, победа за <B>Силами Тьмы</B><BR>');
} else { } else {
AddChatSystem("<font color=red>Внимание! Свет одержал победу благодаря великим воинам : <b>$uss</b></font>"); Chat::addSYSMessage('Внимание! Свет одержал победу благодаря великим воинам: <b>' . $uss . '</b>');
$this->AddToLog('<span class=date>' . date("H:i") . '</span> ' . 'Бой закончен, победа за <B>Силами Света</B><BR>'); $this->AddToLog('<span class=date>' . date("H:i") . '</span> ' . 'Бой закончен, победа за <B>Силами Света</B><BR>');
} }
mysql_query('UPDATE `variables` SET `value` = "' . $arr_battle['win'] . '" WHERE `var` = "arena_win" LIMIT 1'); mysql_query('UPDATE `variables` SET `value` = "' . $arr_battle['win'] . '" WHERE `var` = "arena_win" LIMIT 1');
@ -574,7 +578,7 @@ class fbattle
$this->AddToLog('<span class=date>' . date("H:i") . '</span> <b>' . Nick::id($v)->short() . '</b> получил повреждение: <font color=red>' . $tr . '</font><BR>'); $this->AddToLog('<span class=date>' . date("H:i") . '</span> <b>' . Nick::id($v)->short() . '</b> получил повреждение: <font color=red>' . $tr . '</font><BR>');
$inv_broken = mysql_query("SELECT `id`, `type`, `dressed`, `duration`, `maxdur`, `dategoden`, `owner` FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '" . time() . "')) AND `owner` = '{$v}'"); $inv_broken = mysql_query("SELECT `id`, `type`, `dressed`, `duration`, `maxdur`, `dategoden`, `owner` FROM `inventory` WHERE `type` != 12 AND `dressed` = 1 AND ((`maxdur` <= `duration`) OR (`dategoden` > 0 AND `dategoden` <= '" . time() . "')) AND `owner` = '{$v}'");
while ($br = mysql_fetch_array($inv_broken)) { while ($br = mysql_fetch_array($inv_broken)) {
$item = new \Battles\DressedItems($v); $item = new DressedItems($v);
$item->undressItem($br['type']); $item->undressItem($br['type']);
} }
} }
@ -582,7 +586,7 @@ class fbattle
} }
} else { } else {
if ($this->battle_data['aren_of'] == 1) { if ($this->battle_data['aren_of'] == 1) {
AddChatSystem("<font color=red>Внимание! Бой на Арене Ангелов завершился ничьей, на этой недели силы тьмы и света равны.</font>"); Chat::addSYSMessage('Внимание! Бой на Арене Ангелов завершился ничьей, на этой недели силы тьмы и света равны.');
mysql_query('UPDATE `variables` SET `value` = 3 WHERE `var` = "arena_win" LIMIT 1'); mysql_query('UPDATE `variables` SET `value` = 3 WHERE `var` = "arena_win" LIMIT 1');
mysql_query('UPDATE `battle` SET `aren_of` = 0 WHERE `id` = "' . $arr_battle['id'] . '" AND `aren_of` = 1 LIMIT 1'); mysql_query('UPDATE `battle` SET `aren_of` = 0 WHERE `id` = "' . $arr_battle['id'] . '" AND `aren_of` = 1 LIMIT 1');
} }
@ -1881,21 +1885,9 @@ class fbattle
if ($this->log) { if ($this->log) {
$this->log = $this->log . "<hr>"; $this->log = $this->log . "<hr>";
} }
$this->addlogs($this->battle_data['id'], $this->log); GameLogs::addBattleLog($this->battle_data['id'], $this->log);
$this->log = ''; $this->log = '';
} }
private function addlogs($id, $log)
{
$fp = fopen("backup/logs/battle" . $id . ".txt", "a");
flock($fp, LOCK_EX);
fputs($fp, $log);
fflush($fp);
flock($fp, LOCK_UN);
fclose($fp);
unset($id, $log);
}
} }
$r = mysql_query("SELECT `id`, `win` FROM `battle` WHERE `win` = 3"); $r = mysql_query("SELECT `id`, `win` FROM `battle` WHERE `win` = 3");

View File

@ -5,19 +5,21 @@
* Project name: Battles-Game * Project name: Battles-Game
*/ */
use Battles\DressedItems;
require_once '../functions.php'; require_once '../functions.php';
if (!$tr && $turnirstart[0] <= time() && $dd[0] >= 2) { if (!$tr && $turnirstart[0] <= time() && $dd[0] >= 2) {
$minroom = 501; $minroom = 501;
$maxroom = 560; $maxroom = 560;
$data = mysql_query("SELECT `dt`.`owner` FROM `deztow_stavka` AS `dt`, `online` AS `o` WHERE (SELECT COUNT(`id`) FROM `effects` WHERE `effects`.`owner` = `dt`.`owner` AND (`type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14 OR `type` = 2 OR `type` = 3 OR `type` = 4 OR `type` = 202 OR `type` = 201 OR `type` = 21)) = 0 AND `o`.`id` = `dt`.`owner` AND `room` = 31 AND `o`.`date` >= '" . (time() - 300) . "' ORDER BY `kredit` DESC, `dt`.`time` ASC LIMIT 50"); $data = mysql_query("SELECT `dt`.`owner` FROM `deztow_stavka` AS `dt`, `online` AS `o` WHERE (SELECT COUNT(`id`) FROM `effects` WHERE `effects`.`owner` = `dt`.`owner` AND (`type` = 11 OR `type` = 12 OR `type` = 13 OR `type` = 14 OR `type` = 2 OR `type` = 3 OR `type` = 4 OR `type` = 202 OR `type` = 201 OR `type` = 21)) = 0 AND `o`.`id` = `dt`.`owner` AND `room` = 31 AND `o`.login_time >= '" . (time() - 300) . "' ORDER BY `kredit` DESC, `dt`.`time` ASC LIMIT 50");
$stavka = mysql_fetch_array(mysql_query("SELECT SUM(`kredit`)*0.7 FROM `deztow_stavka`")); $stavka = mysql_fetch_array(mysql_query("SELECT SUM(`kredit`)*0.7 FROM `deztow_stavka`"));
while ($row = mysql_fetch_array($data)) { while ($row = mysql_fetch_array($data)) {
$pers = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "' . $row[0] . '" LIMIT 1')); $pers = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "' . $row[0] . '" LIMIT 1'));
\Battles\DressedItems::undressAllItems($pers['id']); DressedItems::undressAllItems($pers['id']);
### ###
mysql_query('UPDATE `inventory` SET `owner` = "' . ($pers['id'] + _BOTSEPARATOR_) . '" WHERE `owner` = "' . $pers['id'] . '"'); mysql_query('UPDATE `inventory` SET `owner` = "' . ($pers['id'] + _BOTSEPARATOR_) . '" WHERE `owner` = "' . $pers['id'] . '"');
### ###
@ -88,9 +90,9 @@ if (!$tr && $turnirstart[0] <= time() && $dd[0] >= 2) {
} }
// Боты: Архивариус и два помощника. // Боты: Архивариус и два помощника.
\Battles\DressedItems::undressAllItems(233); DressedItems::undressAllItems(233);
\Battles\DressedItems::undressAllItems(234); DressedItems::undressAllItems(234);
\Battles\DressedItems::undressAllItems(235); DressedItems::undressAllItems(235);
mysql_query("DELETE FROM `inventory` WHERE `owner` = 233"); mysql_query("DELETE FROM `inventory` WHERE `owner` = 233");
mysql_query("DELETE FROM `inventory` WHERE `owner` = 234"); mysql_query("DELETE FROM `inventory` WHERE `owner` = 234");
@ -158,7 +160,7 @@ if ($tur_data['endtime'] < time() && $tur_data['id']) {
$list = mysql_query("SELECT * FROM `users` WHERE `in_tower` = 1"); $list = mysql_query("SELECT * FROM `users` WHERE `in_tower` = 1");
while ($u = mysql_fetch_array($list)) { while ($u = mysql_fetch_array($list)) {
\Battles\DressedItems::undressAllItems($u['id']); DressedItems::undressAllItems($u['id']);
$rep = mysql_query("SELECT * FROM `inventory` WHERE `owner` = '" . $u['id'] . "' AND `bs` = 1"); $rep = mysql_query("SELECT * FROM `inventory` WHERE `owner` = '" . $u['id'] . "' AND `bs` = 1");
while ($r = mysql_fetch_array($rep)) { while ($r = mysql_fetch_array($rep)) {
mysql_query("INSERT `deztow_items` (`iteam_id`, `name`, `img`, `room`) VALUES ('" . $r['prototype'] . "', '" . $r['name'] . "', '" . $r['img'] . "', '" . $u['room'] . "')"); mysql_query("INSERT `deztow_items` (`iteam_id`, `name`, `img`, `room`) VALUES ('" . $r['prototype'] . "', '" . $r['name'] . "', '" . $r['img'] . "', '" . $u['room'] . "')");

87
css/shop.css Normal file
View File

@ -0,0 +1,87 @@
a.waretype {
margin: 2px 16px;
padding: 6px;
border: 1px silver solid;
border-radius: 4px;
background-color: #ccc;
display: block;
}
a.sell {
background-color: #cdc;
}
a.alltypes {
background-color: #ccd;
}
.status {
color: darkgreen;
background: #afa;
}
h3 + div {
text-align: center;
}
div.shop strong span:last-child {
color: darkgreen;
}
hr + div {
text-align: center;
font-weight: bold;
}
/* === */
.row {
cursor: default;
}
.column {
padding: 10px;
}
.left {
float: left;
}
.shop > .left {
width: 75%;
}
.shop > .right {
float: right;
width: 300px;
}
.item > .right {
float: left;
}
.item > .left {
width: 150px;
text-align: center;
}
.item > .right {
width: 75%;
vertical-align: top;
}
.row:after {
content: "";
display: table;
clear: both;
}
div.item:nth-of-type(2) {
border: 1px solid #aaa;
}
div.item:nth-child(even) {
background-color: #bbb;
}
div.item:nth-child(odd) {
background-color: #ccc;
}
div.item {
border: 1px solid #aaa;
border-top: 0;
}

Binary file not shown.

View File

@ -4,15 +4,13 @@ use Battles\Database\DBPDO;
use Battles\GameLogs; use Battles\GameLogs;
use Battles\Template; use Battles\Template;
session_start();
require_once "config.php"; require_once "config.php";
define('ERROR_NO_SUCH_USER', 'Такого пользователя не существует!'); const ERROR_NO_SUCH_USER = 'Такого пользователя не существует!';
define('ERROR_USER_IS_BLOCKED', 'Пользователь заблокирован!'); const ERROR_USER_IS_BLOCKED = 'Пользователь заблокирован!';
define('ERROR_WRONG_PASSWORD', 'Неверный пароль!'); const ERROR_WRONG_PASSWORD = 'Неверный пароль!';
define('ERROR_EMPTY_CREDENTIALS', 'Вы не ввели логин или пароль!'); const ERROR_EMPTY_CREDENTIALS = 'Вы не ввели логин или пароль!';
$db = new DBPDO();
foreach ($_POST as $key => $val) { //Проверка всех значений массива POST одним махом. foreach ($_POST as $key => $val) { //Проверка всех значений массива POST одним махом.
$_POST[$key] = iconv(mb_detect_encoding($_POST[$key], 'auto'), 'utf-8', $val); $_POST[$key] = iconv(mb_detect_encoding($val, 'auto'), 'utf-8', $val);
} }
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS); $username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_SPECIAL_CHARS);
@ -21,7 +19,7 @@ $battle = $_COOKIE['battle'] ?? '';
$error = ""; $error = "";
if ($username && $password) { if ($username && $password) {
$user_query = $db->ofetch('SELECT id, login, pass, room, block FROM users WHERE login = ?', $username); $user_query = DBPDO::$db->ofetch('SELECT id, login, pass, room, block, session_id FROM users WHERE login = ?', $username);
if (!$user_query->id) { if (!$user_query->id) {
$error = ERROR_NO_SUCH_USER; $error = ERROR_NO_SUCH_USER;
@ -29,28 +27,34 @@ if ($username && $password) {
$error = ERROR_USER_IS_BLOCKED; $error = ERROR_USER_IS_BLOCKED;
} elseif (password_verify($password, $user_query->pass)) { } elseif (password_verify($password, $user_query->pass)) {
if (!$error) { # Проверка на мультоводство по используемому кукису.
# Проверка на мультоводство по используемому кукису. if ($battle != null && $user_query->id != $battle) {
if ($battle != null && $user_query->id != $battle) { GameLogs::addUserLog($user_query->id,'Разные ID на входе. Возможно используются несколько аккаунтов.', 'multiaccounts');
GameLogs::addUserLog($user_query->id,'Разные ID на входе. Возможно используются несколько аккаунтов.', 'multiaccounts');
}
setcookie("battle", $user_query->id);
$_SESSION['uid'] = $user_query->id;
setcookie("uid", $user_query->id, time() + 43200, "/", GAMEDOMAIN);
setcookie("hashcode", md5($user_query->id . $user_query->pass . $username), time() + 43200, "/", GAMEDOMAIN);
$_SESSION['sid'] = session_id();
$onl = $db->ofetch('SELECT user_id FROM online WHERE user_id = ?', $user_query->id);
if (isset($onl->user_id)) {
$db->execute('UPDATE online SET date = ? WHERE user_id = ?', [time(), $user_query->id]);
} else {
$db->execute('INSERT INTO online (user_id, date, room, real_time) VALUES (?,?,?,?)', [$user_query->id, time(), $user_query->room, time()]);
}
$db->execute('UPDATE users SET session_id = ?, enter_game = 1 WHERE id = ?', [session_id(), $user_query->id]);
header("Location: fight.php");
} }
# TEST! Влетаем всегда в одну и ту же сессию.
if ($user_query->session_id) {
session_id($user_query->session_id);
}
$_SESSION['uid'] = $user_query->id;
setcookie("battle", $user_query->id);
setcookie("uid", $user_query->id, time() + 43200, "/", GAMEDOMAIN);
setcookie("hashcode", md5($user_query->id . $user_query->pass . $username), time() + 43200, "/", GAMEDOMAIN);
$onl = DBPDO::$db->ofetch('SELECT 1 FROM online WHERE user_id = ?', $user_query->id);
if ($onl) {
DBPDO::$db->execute('UPDATE online SET login_time = ? WHERE user_id = ?', [time(), $user_query->id]);
} else {
DBPDO::$db->execute('INSERT INTO online (user_id, login_time, room, real_time) VALUES (?,?,?,?)', [$user_query->id, time(), $user_query->room, time()]);
}
DBPDO::$db->execute('UPDATE users SET session_id = ?, enter_game = 1 WHERE id = ?', [session_id(), $user_query->id]);
session_start();
header("Location: fight.php");
} else { } else {
$error = ERROR_WRONG_PASSWORD; $error = ERROR_WRONG_PASSWORD;
} }

View File

@ -1,11 +1,8 @@
<?php <?php
use Battles\Template; use Battles\Template;
use Battles\User;
session_start();
require_once "functions.php"; require_once "functions.php";
$user = $user ?? new User($_SESSION['uid']);
function secs2hrs($s, $short = 0) function secs2hrs($s, $short = 0)
{ {
@ -198,7 +195,7 @@ if (in_array($user->getRoom(), CANAL_ENTERS)) {
$i = 0; $i = 0;
function isonlinelogin($l) function isonlinelogin($l)
{ {
$i = mysql_fetch_assoc(mysql_query("SELECT DISTINCT(`users`.`id`) FROM `online` LEFT JOIN `users` ON (`users`.`id` = `online`.`id`) WHERE `date` >= " . (time() - 60) . " AND `users`.`login` = '$l'")); $i = mysql_fetch_assoc(mysql_query("SELECT DISTINCT(`users`.`id`) FROM `online` LEFT JOIN `users` ON (`users`.`id` = `online`.`id`) WHERE login_time >= " . (time() - 60) . " AND `users`.`login` = '$l'"));
return $i; return $i;
} }

View File

@ -1,6 +1,4 @@
<?php <?php
ob_start("ob_gzhandler");
session_start();
if (isset($_POST['end'])) { if (isset($_POST['end'])) {
header("Location: main.php"); header("Location: main.php");
exit; exit;
@ -162,7 +160,6 @@ $fbattle = new fbattle($user['battle']);
$dressed = db::c()->query('SELECT `id` FROM `inventory` WHERE `id` = ?i AND `dressed` = 1', $_GET['use'])->fetch_row(); $dressed = db::c()->query('SELECT `id` FROM `inventory` WHERE `id` = ?i AND `dressed` = 1', $_GET['use'])->fetch_row();
if ((int)$dressed[0] > 0) { if ((int)$dressed[0] > 0) {
$my_class = $fbattle->my_class; $my_class = $fbattle->my_class;
ob_start();
usemagic($_GET['use'], "" . $_POST['target']); usemagic($_GET['use'], "" . $_POST['target']);
$bb = explode("<!--", ob_get_clean()); $bb = explode("<!--", ob_get_clean());
$bb = str_replace('"', "&quot;", (strip_tags($bb[0]))); $bb = str_replace('"', "&quot;", (strip_tags($bb[0])));

View File

@ -1,14 +1,15 @@
<?php <?php
session_start();
use Battles\Database\DBPDO;
use Battles\Template;
require_once 'config.php'; require_once 'config.php';
$userLoginStatus = db::c()->query('SELECT enter_game FROM users WHERE id = ?i', $_SESSION['uid'])->getNumRows() ?? 0; $userLoginStatus = DBPDO::$db->ofetch('select enter_game from users where id = ?', $_SESSION['uid']);
if (empty($userLoginStatus)) { if (!empty($userLoginStatus->enter_game)) {
header("Location: index.php"); DBPDO::$db->execute('update users set enter_game = 0 where enter_game = 1 and id = ?', $_SESSION['uid']);
} else {
db::c()->query('UPDATE `users` SET `enter_game` = 0 WHERE `enter_game` = 1 AND `id` = ?i', $_SESSION['uid']);
} }
\Battles\Template::header('Окно игры'); Template::header('Окно игры');
?> ?>
<script> <script>
if (!navigator.cookieEnabled) { if (!navigator.cookieEnabled) {
@ -25,6 +26,7 @@ if (empty($userLoginStatus)) {
width: 100%; width: 100%;
height: 100%; height: 100%;
border: 0 solid; border: 0 solid;
overflow: hidden;
} }
.frametable { .frametable {
@ -47,19 +49,17 @@ if (empty($userLoginStatus)) {
<table class="frametable"> <table class="frametable">
<tr style="height: 25px;"> <tr style="height: 25px;">
<td class="frametd"> <td class="frametd">
<iframe id="header<?= mt_rand() ?>" class="FRAME" src="top_menu.php" scrolling="no" frameborder="0" <iframe id="header<?= mt_rand() ?>" class="FRAME" src="top_menu.php" name="headframe" title="headframe"></iframe>
name="headframe"></iframe>
</td> </td>
</tr> </tr>
<tr style="height: 75%;"> <tr style="height: 75%;">
<td class="frametd"> <td class="frametd">
<iframe id="main<?= mt_rand() ?>" class="FRAME" src="main.php?top=<?= mt_rand() ?>" frameborder="0" <iframe id="main<?= mt_rand() ?>" class="FRAME" src="main.php?top=<?= mt_rand() ?>" name="gameframe" title="gameframe"></iframe>
name="gameframe"></iframe>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class="frametd"> <td class="frametd">
<iframe id="chat<?= mt_rand() ?>" class="FRAME" src="chat.php" frameborder="0" name="chatframe"></iframe> <iframe id="chat<?= mt_rand() ?>" class="FRAME" src="chat.php" name="chatframe" title="chatframe"></iframe>
</td> </td>
</tr> </tr>
</table> </table>

View File

@ -1,11 +1,9 @@
<?php <?php
use Battles\GameLogs;
use Battles\Nick;
use Battles\Template; use Battles\Template;
session_start();
if (empty($_SESSION['uid'])) {
exit;
}
require_once "functions.php"; require_once "functions.php";
if ($user->getRoom() == 51) { if ($user->getRoom() == 51) {
header('location: city.php'); header('location: city.php');
@ -61,7 +59,7 @@ if ($rand < 15 && $user['battle'] == 0) {
$id = mysql_insert_id(); $id = mysql_insert_id();
mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE `id` = {$bot} LIMIT 1"); mysql_query("UPDATE `bots` SET `battle` = {$id} WHERE `id` = {$bot} LIMIT 1");
$rr = "<b>" . Nick::id($user['id'])->full(1) . "</b> и <b>" . Nick::id($bot)->full(1) . "</b>"; $rr = "<b>" . Nick::id($user['id'])->full(1) . "</b> и <b>" . Nick::id($bot)->full(1) . "</b>";
addlog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <br />"); GameLogs::addBattleLog($id, "Часы показывали <span class=date>" . date("Y.m.d H.i") . "</span>, когда " . $rr . " бросили вызов друг другу. <br />");
mysql_query("UPDATE `users` SET `battle` = {$id}, `zayavka` = 0 WHERE `id` = '" . $user['id'] . "' LIMIT 1"); mysql_query("UPDATE `users` SET `battle` = {$id}, `zayavka` = 0 WHERE `id` = '" . $user['id'] . "' LIMIT 1");
addchp('<b style="color:#990000">Внимание!</b> На вас напал "' . $bots[$rbot] . '". ', '{[]}' . Nick::id($user["id"])->short() . '{[]}'); addchp('<b style="color:#990000">Внимание!</b> На вас напал "' . $bots[$rbot] . '". ', '{[]}' . Nick::id($user["id"])->short() . '{[]}');
} }

View File

@ -1,7 +1,6 @@
<?php <?php
session_start();
require_once 'config.php'; require_once 'config.php';
$user = new \Battles\User($_SESSION['uid']); $user = \Battles\User::$current;
$sleep = db::c()->query('SELECT `id` FROM `effects` WHERE `owner` = ?i AND `time` > ?i AND `type` = 3', $user['id'], time())->fetch_assoc(); $sleep = db::c()->query('SELECT `id` FROM `effects` WHERE `owner` = ?i AND `time` > ?i AND `type` = 3', $user['id'], time())->fetch_assoc();
$ps = $_GET['page'] ?? 0; $ps = $_GET['page'] ?? 0;
$isModerator = false; $isModerator = false;

View File

@ -6,21 +6,25 @@
*/ */
use Battles\Database\DBPDO; use Battles\Database\DBPDO;
use Battles\DressedItems;
use Battles\InventoryItem;
use Battles\Travel; use Battles\Travel;
use Battles\User; use Battles\User;
use Battles\UserStats;
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 { } elseif (empty($user)) {
$user = new User($_SESSION['uid']); $user = new User($_SESSION['uid']);
} }
if ($user->getId() && $user->getBlock()) {
if (User::$current->getBlock()) {
exit('user blocked!'); exit('user blocked!');
} }
/* /*
* Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам. * Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
*/ */
@ -54,12 +58,12 @@ $fbattleCheckFiles = [
'zayavka.php', 'zayavka.php',
]; ];
//Может просто отовсюду? О_о //Может просто отовсюду? О_о
if ($user->getBattle() && in_array(pathinfo(debug_backtrace()[0]['file'])['basename'], $fbattleCheckFiles)) { if (User::$current->getBattle() && in_array(pathinfo(debug_backtrace()[0]['file'])['basename'], $fbattleCheckFiles)) {
header('location: fbattle.php'); header('location: fbattle.php');
exit; exit;
} }
$towerinCheckFiles = ['main.php', 'city.php', 'tower.php']; $towerinCheckFiles = ['main.php', 'city.php', 'tower.php'];
if ($user->getInTower() && in_array(pathinfo(debug_backtrace()[0]['file'])['basename'], $towerinCheckFiles)) { if (User::$current->getInTower() && in_array(pathinfo(debug_backtrace()[0]['file'])['basename'], $towerinCheckFiles)) {
header('location: towerin.php'); header('location: towerin.php');
exit; exit;
} }
@ -67,17 +71,17 @@ $roomsCheck = [22, 23, 25, 27, 29, 30, 31, 37, 38, 39, 40, 41, 45, 53, 61, 401,
// Если я в одной из этих комнат, // Если я в одной из этих комнат,
// [И] Имя файла который инклюдит файл с проверкой не совпадает с именем файла локации в которой я нахожусь // [И] Имя файла который инклюдит файл с проверкой не совпадает с именем файла локации в которой я нахожусь
// [И] Номер комнаты который я пытаюсь открыть есть в списке проверяемых // [И] Номер комнаты который я пытаюсь открыть есть в списке проверяемых
if (in_array($user->getRoom(), $roomsCheck) if (in_array(User::$current->getRoom(), $roomsCheck)
&& pathinfo(debug_backtrace()[0]['file'])['basename'] != Travel::$roomFileName[$user->getRoom()] && pathinfo(debug_backtrace()[0]['file'])['basename'] != Travel::$roomFileName[User::$current->getRoom()]
&& in_array(array_search(pathinfo(debug_backtrace()[0]['file'])['basename'], Travel::$roomFileName), $roomsCheck)) { && in_array(array_search(pathinfo(debug_backtrace()[0]['file'])['basename'], Travel::$roomFileName), $roomsCheck)) {
header('location: main.php'); header('location: main.php');
exit; exit;
} }
$ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP); if (!empty($_GET['goto']) && !empty($_GET['tStamp']) && !empty($_GET['vcode']) && $_GET['vcode'] == md5(sha1($_GET['goto'] . $_GET['tStamp']))) {
if (isset($_GET['goto']) && isset($_GET['tStamp']) && isset($_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::c()->query('UPDATE `users`,`online` SET `users`.`room` = ?i, `online`.`room` = ?i WHERE `online`.`id` = `users`.`id` AND `online`.`id` = ?i', $_GET['goto'], $_GET['goto'], $_SESSION['uid']); DBPDO::$db->execute($query, [$_GET['goto'], $_GET['goto'], User::$current->getId()]);
$user->setRoom(intval($_GET['goto'])); User::$current->setRoom(intval($_GET['goto']));
} }
function createbot($bot, $login = "") function createbot($bot, $login = "")
@ -109,7 +113,7 @@ $var_map = [
function get_out($u) function get_out($u)
{ {
$pers = db::c()->query('SELECT * FROM users WHERE id = ?i', $u)->fetch_assoc_array(); $pers = db::c()->query('SELECT * FROM users WHERE id = ?i', $u)->fetch_assoc_array();
\Battles\DressedItems::undressAllItems($pers['id']); DressedItems::undressAllItems($pers['id']);
db::c()->query('UPDATE inventory SET owner = ?i WHERE owner = ?i', $pers['id'], $pers['id'] + _BOTSEPARATOR_); db::c()->query('UPDATE inventory SET owner = ?i WHERE owner = ?i', $pers['id'], $pers['id'] + _BOTSEPARATOR_);
### ###
$row = db::c()->query('SELECT * FROM `effects` WHERE `owner` = ?i', $pers['id'] + _BOTSEPARATOR_); $row = db::c()->query('SELECT * FROM `effects` WHERE `owner` = ?i', $pers['id'] + _BOTSEPARATOR_);
@ -134,108 +138,7 @@ function get_out($u)
### ###
} }
function takeshopitem($item, $table = "shop", $present = '', $onlyonetrip = '', $fields = 0, $uid = 0, $koll = 1, $podzem = 0) const _BOTSEPARATOR_ = 10000000;
{
global $user;
$flds = [];
$goden = '';
if (!$uid) {
$uid = $user->getId();
}
$r = db::c()->query('SHOW FIELDS FROM ?f', $table);
$r2 = db::c()->query('SHOW FIELDS FROM inventory');
while ($rec = $r2->fetch_assoc()) {
$flds[$rec['Field']] = 1;
}
$rec1 = db::c()->query('SELECT * FROM ?f WHERE id = ?i', $table, $item)->fetch_assoc_array();
if ($rec1['koll']) {
db::c()->query('UPDATE inventory SET koll = (koll + ?i), massa = (massa + ?i), cost = (cost + ?i) WHERE owner = ?i AND prototype = ?i', $koll, $rec1['massa'] * $koll, $rec1['cost'], $uid, $item);
if (db::c()->getAffectedRows() > 0) {
return ["img" => $rec1['img'], "name" => $rec1['name']];
}
$rec1['koll'] = $koll;
$rec1['massa'] *= $koll;
}
if ($rec1['onlyone']) {
$i = db::c()->query('SELECT id FROM inventory WHERE owner = ?i AND prototype = ?i', $uid, $item)->fetch_row();
if ($i) {
return ["error" => "У вас слишком много таких вещей."];
}
}
if ($present) {
$rec1['present'] = $present;
$rec1['cost'] = 0;
$rec1['ecost'] = 0;
}
$sql = "";
while ($rec = $r->fetch_assoc()) {
if (!$flds[$rec['Field']]) {
continue;
}
if ($rec['Field'] == "dategoden") {
$goden = $rec1[$rec['Field']];
}
if ($rec['Field'] == "goden") {
$goden = $rec1[$rec['Field']];
}
if ($rec['Field'] == "id" || $rec['Field'] == "prototype" || $rec['Field'] == "dategoden") {
continue;
}
$sql .= ", `$rec[Field]` = '" . $rec1[$rec['Field']] . "' ";
}
if ($podzem) {
$rec1['podzem'] = $podzem;
}
if ($fields['goden']) {
$goden = $fields["goden"];
}
mysql_query("INSERT INTO `inventory` SET " . ($present ? "`present` = '$present'," : "") . ($rec1['podzem'] ? "`podzem` = '$rec1[podzem]'," : "") . " `owner` = '$uid', `otdel` = $rec1[razdel] , `prototype` = '$item' " . ($onlyonetrip ? ", `foronetrip` = 1" : "") . ($goden ? ", `dategoden` = '" . ($goden * 60 * 60 * 24 + time()) . "'" : "") . " $sql");
return ["img" => $rec1['img'], "name" => $rec1['name'], "id" => mysql_insert_id()];
}
define('_BOTSEPARATOR_', 10000000);
function level_up($uid)
{
$us = db::c()->query('SELECT `id`, `login`, `level`, `money`, `exp`, `nextup`, `stats`, `master`, `ip`, `in_tower` FROM `users` WHERE `id` =?i', $uid)->fetch_assoc();
if (isset($us['id']) && $us['exp'] >= $us['nextup'] && !$us['in_tower']) {
if (EXPTABLE[$us['nextup']][4] == 1) {
addch("Персонаж <b>{$us['login']}</b> перешел на " . ($us['level'] + 1) . " уровень.");
addchp('<span class=\'success\'>Внимание!</span> Вы перешли на новый уровень. За это Вы получаете: ' . EXPTABLE[$us['nextup']][3] . ' кр.', '{[]}' . $us['login'] . '{[]}');
}
$us['nextup'] = EXPTABLE[$us['nextup']][5];
$us['stats'] += EXPTABLE[$us['nextup']][0];
$us['master'] += EXPTABLE[$us['nextup']][1];
db::c()->query('UPDATE `users` SET `nextup` = ?i, `stats` = ?i, `master` = ?i, `level` = ?i WHERE `id` = ?i', $us['nextup'], $us['stats'], $us['master'], $us['level'], $us['id']);
}
}
/*
* Проверка делающая левелап и ограничитель максимального уровня.
*/
//if (isset($_SESSION['uid'])) {
// try {
// $userInfo = db::c()->query('SELECT `exp`, `nextup`, `level` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
// if ($userInfo && ($userInfo['exp'] >= $userInfo['nextup']) && $userInfo['level'] < 50) {
// level_up($_SESSION['uid']);
// $levelUpArray = ['nextup' => $nextup, 'stats' =>];
// db::c()->query('UPDATE users SET ?Ai, stats = (stats +2), level = (level +1) WHERE id = ?i', $levelUpArray, $_SESSION['uid']);
// }
// } catch (\Krugozor\Database\Mysql\Exception $e) {
// echo $e->getTraceAsString();
// }
//}
function savecavedata($cavedata, $caveleader, $floor) function savecavedata($cavedata, $caveleader, $floor)
{ {
@ -251,11 +154,6 @@ function GiveExp($id, $exp)
db::c()->query('UPDATE users SET exp = exp + ?i WHERE id = ?i', $exp, $id); db::c()->query('UPDATE users SET exp = exp + ?i WHERE id = ?i', $exp, $id);
} }
function GiveRep($id, $rep)
{
db::c()->query('UPDATE users SET doblest = (doblest + ?i), rep_laba = (rep_laba + ?i) WHERE `id` = ?i', $rep, $rep, $id);
}
/** /**
* Генератор прогрессбара. * Генератор прогрессбара.
* @param $current - Текущее значение. * @param $current - Текущее значение.
@ -264,7 +162,7 @@ function GiveRep($id, $rep)
* @param string $bg_color - Фон прогрессбара. * @param string $bg_color - Фон прогрессбара.
* @return string * @return string
*/ */
function showProgressBar($current, $maximum, $line_color = 'limegreen', $bg_color = 'silver') function showProgressBar($current, $maximum, string $line_color = 'limegreen', string $bg_color = 'silver'): string
{ {
$bar = round($current / $maximum * 100); $bar = round($current / $maximum * 100);
return <<<HTML return <<<HTML
@ -287,21 +185,20 @@ HTML;
*/ */
function echoscroll($slot) function echoscroll($slot)
{ {
global $user;
$all_magic = 0; $all_magic = 0;
if ($user->getBattle()) { if (User::$current->getBattle()) {
$script = 'fbattle'; $script = 'fbattle';
$bat = db::c()->query('SELECT `magic` FROM `battle` WHERE `id` = ?i', $user->getBattle())->fetch_assoc(); $bat = db::c()->query('SELECT `magic` FROM `battle` WHERE `id` = ?i', User::$current->getBattle())->fetch_assoc();
$all_magic = unserialize($bat['magic']); $all_magic = unserialize($bat['magic']);
} else { } else {
$script = 'main'; $script = 'main';
} }
$dress = db::c()->query('SELECT `id`, `magic`, `name`, `img`, `duration`, `maxdur` FROM `inventory` WHERE `id` = ?i', $user->$slot)->fetch_assoc(); $dress = db::c()->query('SELECT `id`, `magic`, `name`, `img`, `duration`, `maxdur` FROM `inventory` WHERE `id` = ?i', User::$current->$slot)->fetch_assoc();
$need_charge = db::c()->query('SELECT `needcharge` FROM `magic` WHERE `id` = ?i', $dress['magic'])->fetch_assoc(); $need_charge = db::c()->query('SELECT `needcharge` FROM `magic` WHERE `id` = ?i', $dress['magic'])->fetch_assoc();
if (($user->$slot > 0) && ($all_magic[$user->getId()] < 1 || empty($need_charge['needcharge']))) { if ((User::$current->$slot > 0) && ($all_magic[User::$current->getId()] < 1 || empty($need_charge['needcharge']))) {
$row['id'] = $user->$slot; $row['id'] = User::$current->$slot;
if ($dress['magic']) { if ($dress['magic']) {
$magic = db::c()->query('SELECT targeted FROM `magic` WHERE `id` = ?i', $dress['magic'])->fetch_assoc(); $magic = db::c()->query('SELECT targeted FROM `magic` WHERE `id` = ?i', $dress['magic'])->fetch_assoc();
echo "<a onclick=\""; echo "<a onclick=\"";
@ -318,7 +215,7 @@ function echoscroll($slot)
echo <<<ACTIVE_SCROLL echo <<<ACTIVE_SCROLL
<img class='tooltip' src="i/sh/{$dress['img']}" width='40' title="<b>{$dress['name']}</b><br> Прочность {$dress['duration']} / {$dress['maxdur']} " height='25' alt="Свиток"></a> <img class='tooltip' src="i/sh/{$dress['img']}" width='40' title="<b>{$dress['name']}</b><br> Прочность {$dress['duration']} / {$dress['maxdur']} " height='25' alt="Свиток"></a>
ACTIVE_SCROLL; ACTIVE_SCROLL;
} elseif (($user->$slot > 0) && ($all_magic[$user->getId()] >= 1) && $need_charge['needcharge'] > 0) { } elseif ((User::$current->$slot > 0) && ($all_magic[User::$current->getId()] >= 1) && $need_charge['needcharge'] > 0) {
echo <<<INACTIVE_SCROLL echo <<<INACTIVE_SCROLL
<img src="i/sh/magicclock.gif" width="40" height="25" title='Произведите размен ударами и магия снова станет доступна' alt="Свиток"> <img src="i/sh/magicclock.gif" width="40" height="25" title='Произведите размен ударами и магия снова станет доступна' alt="Свиток">
INACTIVE_SCROLL; INACTIVE_SCROLL;
@ -461,7 +358,7 @@ function ref_drop()
$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(); $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++) { for ($i = 0; $i <= 20; $i++) {
if ($user[$slot[$i]] && !derj($user[$slot[$i]])) { if ($user[$slot[$i]] && !derj($user[$slot[$i]])) {
$item = new \Battles\DressedItems($_SESSION['uid']); $item = new DressedItems($_SESSION['uid']);
$item->undressItem($i + 1); $item->undressItem($i + 1);
$user[$slot[$i]] = null; $user[$slot[$i]] = null;
} }
@ -471,9 +368,8 @@ function ref_drop()
// использовать магию // использовать магию
function usemagic($id, $target) function usemagic($id, $target)
{ {
global $user; $row = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND id = ?i', User::$current->getId(), $id)->fetch_assoc_array();
$row = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND id = ?i', $user->getId(), $id)->fetch_assoc_array(); $bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', User::$current->getBattle())->fetch_assoc_array();
$bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', $user->getBattle())->fetch_assoc_array();
$all_magic = unserialize($bat['magic']); $all_magic = unserialize($bat['magic']);
$charge = 0; $charge = 0;
$magic = db::c()->query('SELECT * FROM `magic` WHERE `id` = ?i', $row['magic'])->fetch_assoc_array(); $magic = db::c()->query('SELECT * FROM `magic` WHERE `id` = ?i', $row['magic'])->fetch_assoc_array();
@ -487,7 +383,7 @@ function usemagic($id, $target)
$charge = $incmagic['needcharge']; $charge = $incmagic['needcharge'];
} }
//Переделать под новую базу //Переделать под новую базу
if (($all_magic[$user->getId()] < 1 || $charge == 0) && if (($all_magic[User::$current->getId()] < 1 || $charge == 0) &&
($user['sila'] >= $row['nsila'] && ($user['sila'] >= $row['nsila'] &&
$user['lovk'] >= $row['nlovk'] && $user['lovk'] >= $row['nlovk'] &&
$user['inta'] >= $row['ninta'] && $user['inta'] >= $row['ninta'] &&
@ -528,38 +424,46 @@ function usemagic($id, $target)
} }
if ($bat) { if ($bat) {
if ($row['maxdur'] <= ($row['duration'] + 1)) { if ($row['maxdur'] <= ($row['duration'] + 1)) {
\Battles\InventoryItem::destroyItem($row['id']); InventoryItem::destroyItem($row['id']);
} else { } else {
if (!$row['magic']) { if (!$row['magic']) {
db::c()->query('UPDATE `inventory` SET `includemagicdex` =`includemagicdex` - ?i WHERE id = ?i', $bat, $row['id']); $query = 'update inventory set includemagicdex = includemagicdex - ? where item_id = ?';
} else { } else {
db::c()->query('UPDATE `inventory` SET duration = duration + ?i WHERE id = ?i', $bat, $row['id']); $query = 'update inventory set durability = durability + ? where item_id = ?';
} }
DBPDO::$db->execute($query, [$bat, $row['id']]);
} }
if (!$charge) { if (!$charge) {
$charge = 0; $charge = 0;
} }
//ограничение по кол-ву за ход //ограничение по кол-ву за ход
if ($user->getBattle()) { if (User::$current->getBattle()) {
$bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', $user->getBattle())->fetch_assoc_array(); $bat = DBPDO::$db->fetch('select * from battle where battle_id = ?', User::$current->getBattle());
} }
if ($bat['magic'] == '') { if ($bat['magic'] == '') {
$all_magic = []; $all_magic = [];
} else { } else {
$all_magic = unserialize($bat['magic']); $all_magic = unserialize($bat['magic']);
} }
$all_magic[$user->getId()] += $charge; $all_magic[User::$current->getId()] += $charge;
db::c()->query('UPDATE `battle` SET `magic`= "?s" WHERE id = ?i', serialize($all_magic), $user->getBattle()); DBPDO::$db->execute('update battle set magic = ? where battle_id = ?', [serialize($all_magic), User::$current->getBattle()]);
} }
} }
return false; return false;
} }
/* ВАЖНО! (#44)
* addch() и addchp() заменяются на Chat::class->addSYSMessage($message, [optional]$receiver);
* Для addchp() используется второй опциональный ключ.
* Это 150+ вхождений в куче файлов, где надо менять структуру вызова функции из-за их несовместимости.
* Возможно, приоритетом стоит сделать унификацию свитков нападения, которых самих около 20 и которые
* по нескольку раз вызывают эти функции.
*/
function addch($text, $room = 0) function addch($text, $room = 0)
{ {
global $user;
if ($room == 0) { if ($room == 0) {
$room = $user->getRoom(); $room = User::$current->getRoom();
} }
if ($fp = @fopen("tmp/chat.txt", "a")) { //открытие if ($fp = @fopen("tmp/chat.txt", "a")) { //открытие
flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА
@ -573,9 +477,8 @@ function addch($text, $room = 0)
function addchp($text, $who, $room = 0) function addchp($text, $who, $room = 0)
{ {
global $user;
if ($room == 0) { if ($room == 0) {
$room = $user->getRoom(); $room = User::$current->getRoom();
} }
$fp = fopen("tmp/chat.txt", "a"); //открытие $fp = fopen("tmp/chat.txt", "a"); //открытие
flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА flock($fp, LOCK_EX); //БЛОКИРОВКА ФАЙЛА
@ -585,23 +488,9 @@ function addchp($text, $who, $room = 0)
fclose($fp); //закрытие fclose($fp); //закрытие
} }
/**
* @param $msg
*
* @throws \Krugozor\Database\Mysql\Exception
* Отправка системного сообщения в чат.
*/
function AddChatSystem($msg)
{
if ($msg) {
db::c()->query('INSERT INTO `chat` (`cid`,`msg`,`type`) VALUES (?i,"?s","?s")', 1, $msg, 'sys');
}
}
function err($t) function err($t)
{ {
echo '<span class="error">' . $t . '</span>'; echo '<span class="error">' . $t . '</span>';
return true;
} }
@ -612,77 +501,65 @@ function err($t)
*/ */
function telegraph(int $userId, string $text) function telegraph(int $userId, string $text)
{ {
$db = DBPDO::INIT(); if (DBPDO::$db->ofetch('SELECT 1 FROM users WHERE id = ?', $userId)) {
if ($db->ofetch('SELECT 1 FROM users WHERE id = ?', $userId)) { DBPDO::$db->execute('INSERT INTO chat (user_id,receiver_id,msg,type) VALUES (-1,?,?,?)', [$userId, $text, 'sms']);
$db->execute('INSERT INTO chat (user_id,receiver_id,msg,type) VALUES (-1,?,?,?)', [$userId, $text, 'sms']);
}
unset($db);
}
function get_meshok()
{
global $user;
$itemsWeight = db::c()->query('SELECT SUM(weight) AS all_weight FROM `inventory` WHERE owner_id = ?i AND on_sale = 0', $_SESSION['uid'])->fetch_assoc();
return ($user->getStrength() * 4 + $itemsWeight['all_weight']);
}
/**
* Надеюсь временная заглушка, которая объединяет get_meshok() и другую выдачу одной строкой.
* @return string
*/
function getItemsMassaInfo()
{
$i_row = db::c()->query('SELECT SUM(`massa`) AS `massa`, SUM(`gmeshok`) AS `massa_bonus` FROM `inventory` WHERE `setsale` = 0 AND `owner` = ?i', $_SESSION['uid'])->fetch_assoc();
$u_row = db::c()->query('SELECT `sila` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
if ($i_row['massa'] > $u_row['sila'] * 4 + $i_row['massa_bonus']) {
return "<span style='color:maroon;'>" . $i_row['massa'] . "</span>/" . ($u_row['sila'] * 4 + $i_row['massa_bonus']);
} else {
return $i_row['massa'] . "/" . ($u_row['sila'] * 4 + $i_row['massa_bonus']);
} }
} }
function addlog($id, $log) function SolveExp($at_id, $def_id, $damage): float
{ {
$fp = fopen("backup/logs/battle" . $id . ".txt", "a"); $mods = [
flock($fp, LOCK_EX); 'bloodb' => 1.2,
fputs($fp, $log); 'btl_1' => 1,
fflush($fp); 'btl_2' => 0.5,
flock($fp, LOCK_UN); 'btl_3' => 0.05,
fclose($fp); ];
unset($id, $log); $baseexp = [
} "0" => "2",
"1" => "5",
"2" => "10",
function SolveExp($at_id, $def_id, $damage) "3" => "15",
{ "4" => "30",
$mods = ['bloodb' => 1.2, 'btl_1' => 1, 'btl_2' => 0.5, 'btl_3' => 0.05]; "5" => "60",
$baseexp = ["0" => "2", "1" => "5", "2" => "10", "3" => "15", "4" => "30", "5" => "60", "6" => "90", "7" => "115", "8" => "300", "9" => "400", "10" => "500", "11" => "600", "12" => "700", "13" => "800", "14" => "900", "15" => "1000", "16" => "1100", "17" => "1200", "18" => "1300", "19" => "1400", "20" => "1500", "21" => "1600"]; "6" => "90",
"7" => "115",
"8" => "300",
"9" => "400",
"10" => "500",
"11" => "600",
"12" => "700",
"13" => "800",
"14" => "900",
"15" => "1000",
"16" => "1100",
"17" => "1200",
"18" => "1300",
"19" => "1400",
"20" => "1500",
"21" => "1600",
];
$expmf = 0; $expmf = 0;
$bot_active = false; $bot_active = false;
$bot_def = false; $bot_def = false;
if ($at_id > _BOTSEPARATOR_) { if ($at_id > _BOTSEPARATOR_) {
$bots = db::c()->query('SELECT * FROM bots WHERE id = ?i', $at_id)->fetch_assoc_array(); $bots = DBPDO::$db->fetch('select * from bots where bot_id = ?', $at_id);
$at_id = $bots['prototype']; $at_id = $bots['prototype'];
$bot_active = true; $bot_active = true;
} }
$at = db::c()->query('SELECT `level` FROM `users` WHERE `id` = ?i', $at_id)->fetch_assoc(); $query = 'select greatest(1, sum(price)) as allprice from users left join inventory on users.id = inventory.owner_id where id = ?';
$def = db::c()->query('SELECT `level` FROM `users` WHERE `id` = ?i', $def_id)->fetch_assoc(); $at = DBPDO::$db->fetch($query, $at_id);
$at_cost = db::c()->query('SELECT 1+IFNULL((SELECT SUM(`cost`) FROM `inventory` WHERE `owner` = `users`.`id` AND `dressed` = 1), 0), `align` FROM `users` WHERE `id` = ?i', $at_id)->fetch_assoc_array(); $def = DBPDO::$db->fetch($query, $def_id);
$def_cost = db::c()->query('SELECT 1+IFNULL((SELECT SUM(`cost`) FROM `inventory` WHERE `owner` = `users`.`id` AND `dressed` = 1), 0), `align` FROM `users` WHERE `id` = ?i', $def_id)->fetch_assoc_array();
if ($at_id > _BOTSEPARATOR_) { $atInfo = new UserStats($at_id);
$table_name = 'bots'; $defInfo = new UserStats($def_id);
} else {
$table_name = 'users'; $table_name = $at_id > _BOTSEPARATOR_ ? 'bots' : 'users';
} $bt = DBPDO::$db->fetch('select blood, type, t1, t2 from battle where battle_id = (select battle from ? where id = ?)', [$table_name, $at_id]);
$bat_raw = db::c()->query('SELECT battle FROM ?f WHERE id = ?i', $table_name, $at_id)->fetch_assoc_array();
$bat = $bat_raw['battle'];
$bt = db::c()->query('SELECT `blood`,`type`,`t1`,`t2` FROM `battle` WHERE `id` = ?i', $bat)->fetch_assoc();
if ($def_id > _BOTSEPARATOR_) { if ($def_id > _BOTSEPARATOR_) {
$bots = db::c()->query('SELECT * FROM bots WHERE id = ?i', $def_id)->fetch_assoc_array(); $bots = DBPDO::$db->fetch('select * from bots where bot_id = ?', $def_id);
$def_id = $bots['prototype']; $def_id = $bots['prototype'];
$bot_def = true; $bot_def = true;
} }
@ -723,9 +600,22 @@ function SolveExp($at_id, $def_id, $damage)
"10" => 919, "10" => 919,
"11" => 919, "11" => 919,
"12" => 919, "12" => 919,
"13" => 919, "14" => 919, "15" => 919, "16" => 919, "17" => 919, "18" => 919, "19" => 919, "20" => 919, "21" => 919, "22" => 919, "23" => 919, "24" => 919, "25" => 919]; "13" => 919,
"14" => 919,
"15" => 919,
"16" => 919,
"17" => 919,
"18" => 919,
"19" => 919,
"20" => 919,
"21" => 919,
"22" => 919,
"23" => 919,
"24" => 919,
"25" => 919
];
$mfit = ($at_cost[0] / ($standart[$at['level']] / 3)); $mfit = ($at['allprice'] / ($standart[$atInfo->getLevel()] / 3));
if ($mfit < 0.8) { if ($mfit < 0.8) {
$mfit = 0.8; $mfit = 0.8;
} }
@ -745,5 +635,5 @@ function SolveExp($at_id, $def_id, $damage)
$expmf = 1; $expmf = 1;
} }
return round((($baseexp[$def['level']]) * ($def_cost[0] / (($at_cost[0] + $def_cost[0]) / 2)) * ($damage / $def['maxhp']) * $expmf * $mfit * $mfbot * $mfbot2) / 3); return round((($baseexp[$defInfo->getLevel()]) * ($def['allprice'] / (($at['allprice'] + $def['allprice']) / 2)) * ($damage / $defInfo->getMaxHealth()) * $expmf * $mfit * $mfbot * $mfbot2) / 3);
} }

View File

@ -1,7 +1,6 @@
<?php <?php
/* Разрушенный замок на замковой улице. */ /* Разрушенный замок на замковой улице. */
session_start(); const CASTLE_MAX_LEVEL = 10;
define("CASTLE_MAX_LEVEL", 10);
require_once 'functions.php'; require_once 'functions.php';
$castleOwners = db::c()->query('SELECT * FROM `clans` WHERE `short` = (SELECT * FROM `variables` WHERE `var` = "?s")', 'gotzamok'); $castleOwners = db::c()->query('SELECT * FROM `clans` WHERE `short` = (SELECT * FROM `variables` WHERE `var` = "?s")', 'gotzamok');

View File

@ -1,8 +1,8 @@
<?php <?php
session_start();
if (empty($_SESSION['uid'])) { use Battles\ShopItem;
exit; use Battles\Template;
}
require_once 'functions.php'; require_once 'functions.php';
$error = ''; $error = '';
@ -88,7 +88,7 @@ if (isset($_POST['buyFirst'])) {
} else { } else {
$user['money'] -= 5; $user['money'] -= 5;
mysql_query('UPDATE `users` SET `money` = "' . $user['money'] . '" WHERE `id` = "' . $user['id'] . '" LIMIT 1'); mysql_query('UPDATE `users` SET `money` = "' . $user['money'] . '" WHERE `id` = "' . $user['id'] . '" LIMIT 1');
takeshopitem(1930, 'shop', '', '', 0, 0, $user['id'], 1, '', 0); ShopItem::giveNewItem(1930, $user['id']);
mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '{$user['id']}', '\"" . $user['login'] . "\" купил Фамильный Герб за 5кр.', '1', '" . time() . "')"); mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '{$user['id']}', '\"" . $user['login'] . "\" купил Фамильный Герб за 5кр.', '1', '" . time() . "')");
$error = 'Вы купили Фамильный Герб'; $error = 'Вы купили Фамильный Герб';
} }
@ -114,7 +114,7 @@ if (isset($_POST['buySecond'])) {
} else { } else {
$user['money'] -= 15; $user['money'] -= 15;
mysql_query('UPDATE `users` SET `money` = "' . $user['money'] . '" WHERE `id` = "' . $user['id'] . '" LIMIT 1'); mysql_query('UPDATE `users` SET `money` = "' . $user['money'] . '" WHERE `id` = "' . $user['id'] . '" LIMIT 1');
takeshopitem(1931, 'shop', '', '', 0, 0, $user['id'], 1, '', 0); ShopItem::giveNewItem(1931, $user['id']);
mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '{$user['id']}', '\"" . $user['login'] . "\" купил Фамильный Герб (x2) за 15кр.', '1', '" . time() . "')"); mysql_query("INSERT INTO `delo` (`author`, `pers`, `text`, `type`, `date`) VALUES ('0', '{$user['id']}', '\"" . $user['login'] . "\" купил Фамильный Герб (x2) за 15кр.', '1', '" . time() . "')");
$error = 'Вы купили Фамильный Герб (x2)'; $error = 'Вы купили Фамильный Герб (x2)';
} }
@ -204,7 +204,7 @@ if ($_GET['exit'] == 1) {
header('Location: city.php'); header('Location: city.php');
} }
\Battles\Template::header('group_arena'); Template::header('group_arena');
?> ?>
<script> <script>
function growl(title, color, message, stycky) { function growl(title, color, message, stycky) {

View File

@ -1,11 +1,8 @@
<?php <?php
use Battles\Template; use Battles\Template;
use Battles\User;
session_start();
require_once "functions.php"; require_once "functions.php";
$user = $user ?? new User($_SESSION['uid']);
class hellround class hellround
{ {

View File

@ -1,9 +1,11 @@
<?php <?php
session_start();
use Battles\Template;
use Battles\User;
require_once 'config.php'; require_once 'config.php';
$user = new \Battles\User($_SESSION['uid']); $user = User::$current;
$hostel = mysql_fetch_array(mysql_query('SELECT `id`, `uid`, `type`, `time` FROM `hostel` WHERE `uid` = "' . $user['id'] . '" LIMIT 1')); $hostel = mysql_fetch_array(mysql_query('SELECT `id`, `uid`, `type`, `time` FROM `hostel` WHERE `uid` = "' . $user['id'] . '" LIMIT 1'));
#include('functions.php');
$error = ''; $error = '';
$rs = ''; $rs = '';
$base = [1 => ['type' => 'Сумка'], 2 => ['type' => 'Сундук'], 3 => ['type' => 'Комната'], 4 => ['type' => 'Амбар']]; $base = [1 => ['type' => 'Сумка'], 2 => ['type' => 'Сундук'], 3 => ['type' => 'Комната'], 4 => ['type' => 'Амбар']];
@ -150,7 +152,7 @@ if ($_GET['unsleep'] && $user['sleep'] > 0) {
} }
header('Location: hostel.php'); header('Location: hostel.php');
} }
\Battles\Template::header('Хостел'); Template::header('Хостел');
?> ?>
<script src="js/ajaxLoad.js"></script> <script src="js/ajaxLoad.js"></script>
<? if (isset($hostel['id'])) { ?> <? if (isset($hostel['id'])) { ?>

View File

@ -1,7 +1,6 @@
<?php <?php
session_start();
require_once "functions.php"; require_once "functions.php";
$hostel = mysql_fetch_array(mysql_query('SELECT * FROM `hostel` WHERE `uid` = "' . $user['id'] . '" LIMIT 1')); $hostel = \Battles\Database\DBPDO::$db->fetch('select * from hostel where uid = ?', \Battles\User::$current->getId());
$base = [1 => [8, 16, 24, 32], 2 => [15, 30, 45, 60], 3 => [25, 50, 75, 100], 4 => [40, 80, 120, 160]]; $base = [1 => [8, 16, 24, 32], 2 => [15, 30, 45, 60], 3 => [25, 50, 75, 100], 4 => [40, 80, 120, 160]];
if (isset($_POST['act']) && $_POST['act'] == 'pay' && isset($user['id']) && isset($hostel['id'])) { if (isset($_POST['act']) && $_POST['act'] == 'pay' && isset($user['id']) && isset($hostel['id'])) {

View File

@ -1,5 +1,11 @@
<?php <?php
session_start();
use Battles\Database\DBPDO;
use Battles\InventoryItem;
use Battles\Template;
use Battles\User;
use Battles\UserInfo;
require_once "functions.php"; require_once "functions.php";
$d = mysql_fetch_array(mysql_query("SELECT SUM(`massa`) AS `mass` FROM `inventory` WHERE `owner` = '{$user['id']}' AND `dressed` = 0 AND `setsale` = 0")); $d = mysql_fetch_array(mysql_query("SELECT SUM(`massa`) AS `mass` FROM `inventory` WHERE `owner` = '{$user['id']}' AND `dressed` = 0 AND `setsale` = 0"));
@ -9,10 +15,21 @@ $hostel = mysql_fetch_array(mysql_query('SELECT * FROM `hostel` WHERE `uid` = "'
$base = [1 => 15, 2 => 30, 3 => 50, 4 => 100]; $base = [1 => 15, 2 => 30, 3 => 50, 4 => 100];
$vips = [1 => 0.15, 2 => 0.30, 3 => 0.45]; $vips = [1 => 0.15, 2 => 0.30, 3 => 0.45];
function get_meshok(): object
{
$allweight = DBPDO::$db->ofetch('select sum(weight) as items_weight_sum from inventory where on_sale = 0 and owner_id = ?', User::$current->getId());
$stat = new UserInfo(User::$current->getId());
return (object)[
'currentweight' => $allweight->items_weight_sum,
'maxweight' => $stat->getStat('strength') * 4 + $allweight->items_weight_sum,
];
}
function show_item($row, $txt, $place) function show_item($row, $txt, $place)
{ {
if (($row['maxdur'] <= $row['duration']) || ($row['dategoden'] && $row['dategoden'] <= time())) { if (($row['maxdur'] <= $row['duration']) || ($row['dategoden'] && $row['dategoden'] <= time())) {
\Battles\InventoryItem::destroyItem($row['id']); InventoryItem::destroyItem($row['id']);
} }
$r = ''; $r = '';
@ -318,7 +335,8 @@ if ($_GET['search']) {
} }
####### #######
$w = (270 * $d['mass'] / get_meshok()); $w = (270 * get_meshok()->currentweight / get_meshok()->allweight);
$w_a = 270 - $w; $w_a = 270 - $w;
$h = (270 * $in['cnt'] / $count); $h = (270 * $in['cnt'] / $count);
$h_a = 270 - $h; $h_a = 270 - $h;
@ -329,7 +347,7 @@ if ($_GET['go_back'] == 1) {
header('Location: hostel.php'); header('Location: hostel.php');
} }
\Battles\Template::header('hostel_room'); Template::header('hostel_room');
?> ?>
<script src="js/ajaxLoad.js"></script> <script src="js/ajaxLoad.js"></script>
<link rel="stylesheet" type="text/css" href="css/hostel.css"/> <link rel="stylesheet" type="text/css" href="css/hostel.css"/>
@ -443,7 +461,7 @@ if ($_GET['go_back'] == 1) {
style="width: <?= $w; ?>px; height: 14px;"><img style="width: <?= $w; ?>px; height: 14px;"><img
title="Мешок за спиной" src="/i/1silver.gif" title="Мешок за спиной" src="/i/1silver.gif"
style=" width: <?= $w_a; ?>px; height:14px"><tt style=" width: <?= $w_a; ?>px; height:14px"><tt
style="font-size:13px"> <?= $d['mass']; ?>/<?= get_meshok() ?></tt></div> style="font-size:13px"> <?= InventoryItem::getWeightData() ?> </tt></div>
<div class="progressBar" style='height:14px'><img title="Заполнение сундука" src="/i/chest.gif" <div class="progressBar" style='height:14px'><img title="Заполнение сундука" src="/i/chest.gif"
height="14px"><img title="Заполнение сундука" height="14px"><img title="Заполнение сундука"
src="/i/1blue.gif" src="/i/1blue.gif"

BIN
i/1_7.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 604 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 B

BIN
i/1m.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

BIN
i/1x1.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 37 B

BIN
i/2_7.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

BIN
i/2m.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

BIN
i/3_7.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

BIN
i/3m.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

BIN
i/Lp.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

BIN
i/Lp2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 298 B

BIN
i/a1.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 149 B

BIN
i/a2.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 134 B

BIN
i/a3.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 139 B

BIN
i/a4.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 136 B

BIN
i/a5.gif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 526 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 519 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 532 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 520 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 124 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 656 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 952 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Some files were not shown because too many files have changed in this diff Show More