Зимние правки. MVC/

Signed-off-by: lopar <lopar.4ever@gmail.com>
This commit is contained in:
lopar
2022-08-09 22:57:43 +03:00
parent 0f62ee20e7
commit b9b4c01cf0
104 changed files with 2254 additions and 2086 deletions
+49 -310
View File
@@ -6,8 +6,6 @@
*/
use Battles\Database\Db;
use Battles\DressedItems;
use Battles\InventoryItem;
use Battles\Travel;
use Battles\User;
use Battles\UserStats;
@@ -24,59 +22,7 @@ if (User::getInstance()->getBlock()) {
}
//Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
Travel::roomRedirects(User::$current->getRoom(), User::$current->getBattle(), User::$current->getInTower());
///*
// * Проверки на соответствие скрипта и комнаты, которые были натыканы по всем файлам.
// */
//$fbattleCheckFiles = [
// 'c_haos_in.php',
// 'c_haos.php',
// 'c_park.php',
// 'city.php',
// 'clan_castle.php',
// 'enter_cave.php',
// 'library.php',
// 'atk.php',
// 'podzem_dialog.php',
// 'post.php',
// 'shop.php',
// 'tournament.php',
// 'vxod.php',
// 'bank.php',
// 'canalizaciya,php',
// 'forest.php',
// 'main.php',
// 'repair.php',
// 'towerstamp.php',
// 'hell.php',
// 'ul_clans.php',
// 'labirint.php',
// 'akadem.php',
// 'towerin.php',
// 'user_anketa.php',
// 'zayavka.php',
//];
////Может просто отовсюду? О_о
//if (User::$current->getBattle() && in_array(pathinfo(debug_backtrace()[0]['file'])['basename'], $fbattleCheckFiles)) {
// header('location: fbattle.php');
// exit;
//}
//$towerinCheckFiles = ['main.php', 'city.php', 'tower.php'];
//if (User::$current->getInTower() && in_array(pathinfo(debug_backtrace()[0]['file'])['basename'], $towerinCheckFiles)) {
// header('location: towerin.php');
// exit;
//}
//$roomsCheck = [22, 23, 25, 27, 29, 30, 31, 37, 38, 39, 40, 41, 45, 53, 61, 401, 402, 600, 601, 602, 621, 650, 1051, 1052];
//// Если я в одной из этих комнат,
//// [И] Имя файла который инклюдит файл с проверкой не совпадает с именем файла локации в которой я нахожусь
//// [И] Номер комнаты который я пытаюсь открыть есть в списке проверяемых
//if (in_array(User::$current->getRoom(), $roomsCheck)
// && pathinfo(debug_backtrace()[0]['file'])['basename'] != Travel::$roomFileName[User::$current->getRoom()]
// && in_array(array_search(pathinfo(debug_backtrace()[0]['file'])['basename'], Travel::$roomFileName), $roomsCheck)) {
// header('location: main.php');
// exit;
//}
Travel::roomRedirects(User::getInstance()->getRoom(), User::getInstance()->getBattle());
if (!empty($_GET['goto']) && !empty($_GET['tStamp']) && !empty($_GET['vcode']) && $_GET['vcode'] == md5(sha1($_GET['goto'] . $_GET['tStamp']))) {
$query = 'update users u, online o set u.room = ?, o.room = ? where user_id = id and user_id = ?';
@@ -84,20 +30,19 @@ if (!empty($_GET['goto']) && !empty($_GET['tStamp']) && !empty($_GET['vcode']) &
User::getInstance()->setRoom(intval($_GET['goto']));
}
function createbot($bot, $login = "")
function createbot($bot, $login = null): array
{
$rec = db::c()->query('SELECT `id`, `login`, `maxhp` FROM `users` WHERE `id` = "?s" LIMIT 1', $bot)->fetch_assoc();
if (isset($rec['id'])) {
if ($login) {
$rec['login'] = $login;
}
$botname = $rec['login'];
db::c()->query('INSERT INTO `bots` (`name`, `prototype`, `hp`) VALUES ("?s", "?s", "?s")', $botname, $bot, $rec['maxhp']);
$nid = db::c()->getLastInsertId();
return ["id" => $nid, "login" => $botname];
} else {
return false;
if (empty($login)) {
$login = Db::getInstance()->fetchColumn('select login from users where id = ?', $bot);
}
if (empty($login)) {
return [];
}
Db::getInstance()->execute('insert into bots (name, prototype) values (?,?)', [$login, $bot]);
return [
'id' => Db::getInstance()->lastInsertId(),
'login' => $login,
];
}
$var_map = [
@@ -121,17 +66,14 @@ function savecavedata($cavedata, $caveleader, $floor)
fclose($f1);
}
function GiveExp($id, $exp)
{
db::c()->query('UPDATE users SET exp = exp + ?i WHERE id = ?i', $exp, $id);
}
/**
* Генератор прогрессбара.
*
* @param $current - Текущее значение.
* @param $maximum - Максимальное значение.
* @param string $line_color - Цвет полоски прогрессбара.
* @param string $bg_color - Фон прогрессбара.
*
* @return string
*/
function showProgressBar($current, $maximum, string $line_color = 'limegreen', string $bg_color = 'silver'): string
@@ -141,7 +83,8 @@ function showProgressBar($current, $maximum, string $line_color = 'limegreen', s
<div style="width: 100%; height: 16px; background: $bg_color; overflow: hidden; border-radius: 3px;">
<div style="height: 16px; background: $line_color; border-radius: 3px; width: $bar%;"></div>
</div>
<div style="width: 100%; height: 16px; font-size: 14px; text-align: center; margin-top: -16px;">
<div style="width: 100%; height: 16px; font-size: 14px; text-align: center; margi
n-top: -16px;">
$current / $maximum
</div>
HTML;
@@ -153,119 +96,56 @@ HTML;
*
* @param $slot
*
* @throws \Krugozor\Database\Mysql\Exception
* @return string
*/
function echoscroll($slot)
function echoscroll($slot): string
{
$all_magic = 0;
if (User::getInstance()->getBattle()) {
$script = 'fbattle';
$bat = db::c()->query('SELECT `magic` FROM `battle` WHERE `id` = ?i', User::getInstance()->getBattle())->fetch_assoc();
$all_magic = unserialize($bat['magic']);
$all_magic = Db::getInstance()->fetchColumn('select magic from battle where id = ?', User::getInstance()->getBattle());
$all_magic = unserialize($all_magic);
} else {
$script = 'main';
}
$dress = db::c()->query('SELECT `id`, `magic`, `name`, `img`, `duration`, `maxdur` FROM `inventory` WHERE `id` = ?i', User::getInstance()->$slot)->fetch_assoc();
$need_charge = db::c()->query('SELECT `needcharge` FROM `magic` WHERE `id` = ?i', $dress['magic'])->fetch_assoc();
if ((User::getInstance()->$slot > 0) && ($all_magic[User::getInstance()->getId()] < 1 || empty($need_charge['needcharge']))) {
$dress = Db::getInstance()->fetch('select magic, name, image, durability from inventory where item_id - ?', User::getInstance()->$slot);
$need_charge = Db::getInstance()->fetchColumn('select needcharge from magic where id = ?', $dress['magic']);
$str = null;
if ((User::getInstance()->$slot > 0) && ($all_magic[User::getInstance()->getId()] < 1 || empty($need_charge))) {
$row['id'] = User::getInstance()->$slot;
if ($dress['magic']) {
$magic = db::c()->query('SELECT targeted FROM `magic` WHERE `id` = ?i', $dress['magic'])->fetch_assoc();
echo "<a onclick=\"";
if ($magic['targeted'] == 1) {
echo "okno('Введите название предмета', '" . $script . ".php?use={$row['id']}', 'target'); ";
$magic_targeted = Db::getInstance()->fetchColumn('select targeted from magic where id = ?', $dress['magic']);
$str .= "<a onclick=\"";
if ($magic_targeted === 1) {
$str .= "okno('Введите название предмета', '" . $script . ".php?use={$row['id']}', 'target'); ";
} else
if ($magic['targeted'] == 2) {
echo "findlogin('Введите имя персонажа', '" . $script . ".php?use={$row['id']}', 'target'); ";
if ($magic_targeted === 2) {
$str .= "findlogin('Введите имя персонажа', '" . $script . ".php?use={$row['id']}', 'target'); ";
} else {
echo "if(confirm('Использовать сейчас?')) { window.location='" . $script . ".php?use=" . $row['id'] . "';}";
$str .= "if(confirm('Использовать сейчас?')) { window.location='" . $script . ".php?use=" . $row['id'] . "';}";
}
echo "\"href='#'>";
$str .= "\"href='#'>";
}
echo <<<ACTIVE_SCROLL
$str .= <<<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>
ACTIVE_SCROLL;
} elseif ((User::getInstance()->$slot > 0) && ($all_magic[User::getInstance()->getId()] >= 1) && $need_charge['needcharge'] > 0) {
echo <<<INACTIVE_SCROLL
$str .= <<<INACTIVE_SCROLL
<img src="i/sh/magicclock.gif" width="40" height="25" title='Произведите размен ударами и магия снова станет доступна' alt="Свиток">
INACTIVE_SCROLL;
} else {
echo <<<EMPTY_SLOT
$str .= <<<EMPTY_SLOT
<img class="tooltip" src="i/w13.gif" width="40" height="25" title='<b>Пустой слот магия</b>' alt="Слот для свитка">
EMPTY_SLOT;
}
return $str;
}
// ссылка на магию
function showhrefmagic($dress)
function timeOut($ttm): string
{
$user = db::c()->query('SELECT `battle` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
$magic = db::c()->query('SELECT * FROM `magic` WHERE `id` = ?i', $dress['includemagic'])->fetch_assoc();
$r = '';
$script = 'main';
if ($user['battle']) {
$script = 'fbattle';
}
$r .= "<a onclick=\"";
if ($magic['targeted'] == 1) {
$r .= "okno('Введите название предмета', '{$script}.php?use={$dress['id']}', 'target')";
} elseif ($magic['targeted'] == 2) {
$r .= "findlogin('" . $magic['name'] . "', '{$script}.php?use={$dress['id']}', 'target')";
} else {
$r .= "if (confirm('Использовать сейчас?')) window.location='" . $script . ".php?use=" . $dress['id'] . "';";
}
$r .= "\"href='#'>";
$r .= "<img src=\"i/sh/{$dress['img']}\" style=\"filter:shadow(color=red, direction=90, strength=3);\" title=\"" . $dress['name'] . (($dress['text'] != null) ? "<br />На оружии выгравировано '{$dress['text']}'" : "") . "\"><br>";
return $r;
}
function timeOut($ttm)
{
$out = '';
$time_still = $ttm;
$tmp = floor($time_still / 2592000);
$id = 0;
if ($tmp > 0) {
$id++;
if ($id < 3) {
$out .= $tmp . " мес. ";
}
$time_still = $time_still - $tmp * 2592000;
}
$tmp = floor($time_still / 86400);
if ($tmp > 0) {
$id++;
if ($id < 3) {
$out .= $tmp . " дн. ";
}
$time_still = $time_still - $tmp * 86400;
}
$tmp = floor($time_still / 3600);
if ($tmp > 0) {
$id++;
if ($id < 3) {
$out .= $tmp . " ч. ";
}
$time_still = $time_still - $tmp * 3600;
}
$tmp = floor($time_still / 60);
if ($tmp > 0) {
$id++;
if ($id < 3) {
$out .= $tmp . " мин. ";
}
}
if ($out == '') {
if ($time_still < 0) {
$time_still = 0;
}
$out = $time_still . ' сек.';
}
return $out;
require_once 'classes/quests_class.php';
$q = new Quests();
return $q->timeOut($ttm);
}
/**
@@ -273,156 +153,14 @@ function timeOut($ttm)
* @param $vars
* @param $vls
* @param $uid
*
* @return bool
*/
function addActions($time, $vars, $vls, $uid)
{
db::c()->query('LOCK TABLES `actions` WRITE');
$ins = db::c()->query('INSERT INTO `actions` (`uid`,`time`,`city`,`room`,`vars`,`ip`,`vals`) VALUES (?i, ?i, "?s", ?i, "?s", "?s", "?s")', $uid, $time, "capitalcity", 0, $vars, $_SERVER['REMOTE_ADDR'], $vls);
db::c()->query('UNLOCK TABLES');
return $ins;
}
#15
function ref_drop()
{
//сможет держать
function derj($id)
{
$user = db::c()->query('SELECT `id`, `align` FROM `users` WHERE `id` = ?i', $_SESSION['uid'])->fetch_assoc();
$ts = db::c()->query('SELECT `id`, `nalign` FROM `inventory` WHERE `id` = ?i', $id)->fetch_assoc();
$al = '(1 = 1)';
if ($ts['nalign'] == 1.1) {
$al = '(1 = 2)';
}
$dd = db::c()->query('SELECT `i`.`id` FROM `users` AS `u`, `inventory` AS `i`
WHERE
`i`.`needident` = 0 AND
`i`.`id` = ?i AND
`i`.`duration` < `i`.`maxdur` AND
`i`.`owner` = ?i AND
`u`.`sila` >= `i`.`nsila` AND
`u`.`lovk` >= `i`.`nlovk` AND
`u`.`inta` >= `i`.`ninta` AND
`u`.`vinos` >= `i`.`nvinos` AND
`u`.`intel` >= `i`.`nintel` AND
`u`.`mudra` >= `i`.`nmudra` AND
`u`.`level` >= `i`.`nlevel` AND
("?s" OR (?i = `i`.`nalign`) or (`i`.`nalign` = 0)) AND
`u`.`noj` >= `i`.`nnoj` AND
`u`.`topor` >= `i`.`ntopor` AND
`u`.`dubina` >= `i`.`ndubina` AND
`u`.`mec` >= `i`.`nmech` AND
`u`.`mfire` >= `i`.`nfire` AND
`u`.`mwater` >= `i`.`nwater` AND
`u`.`mair` >= `i`.`nair` AND
`u`.`mearth` >= `i`.`nearth` AND
`u`.`mlight` >= `i`.`nlight` AND
`u`.`mgray` >= `i`.`ngray` AND
`u`.`mdark` >= `i`.`ndark` AND
`i`.`setsale` = 0 AND
`u`.`id` = ?i', $id, $user['id'], $al, $user['align'], $user['id']);
return $dd->getNumRows() > 0;
}
$slot = ['sergi', 'kulon', 'weap', 'bron', 'r1', 'r2', 'r3', 'helm', 'perchi', 'shit', 'boots', 'm1', 'm2', 'm3', 'm4', 'm5', 'm6', 'm7', 'm8', 'm9', 'm10'];
$user = db::c()->query('SELECT `sergi`,`kulon`,`weap`,`bron`,`r1`,`r2`,`r3`,`helm`,`perchi`,`shit`,`boots`,`m1`,`m2`,`m3`,`m4`,`m5`,`m6`,`m7`,`m8`,`m9`,`m10` FROM `users` WHERE id = ?i', $_SESSION['uid'])->fetch_assoc();
for ($i = 0; $i <= 20; $i++) {
if ($user[$slot[$i]] && !derj($user[$slot[$i]])) {
$item = new DressedItems($_SESSION['uid']);
$item->undressItem($i + 1);
$user[$slot[$i]] = null;
}
}
}
// использовать магию
function usemagic($id, $target)
{
$user = Db::getInstance()->fetch('select * from users where id = ?', $_SESSION['uid']);
$row = db::c()->query('SELECT * FROM `inventory` WHERE `owner` = ?i AND id = ?i', User::getInstance()->getId(), $id)->fetch_assoc_array();
$bat = db::c()->query('SELECT * FROM `battle` WHERE `id` = ?i', User::getInstance()->getBattle())->fetch_assoc_array();
$all_magic = unserialize($bat['magic']);
$charge = 0;
$magic = db::c()->query('SELECT * FROM `magic` WHERE `id` = ?i', $row['magic'])->fetch_assoc_array();
if ($magic['needcharge'] > 0) {
$charge = $magic['needcharge'];
}
$incmagic = db::c()->query('SELECT * FROM `magic` WHERE `id` = ?i', $row['includemagic'])->fetch_assoc_array();
if ($incmagic['needcharge'] > 0) {
$charge = $incmagic['needcharge'];
}
//Переделать под новую базу
if (($all_magic[User::getInstance()->getId()] < 1 || $charge == 0) &&
($user['sila'] >= $row['nsila'] &&
$user['lovk'] >= $row['nlovk'] &&
$user['inta'] >= $row['ninta'] &&
$user['vinos'] >= $row['nvinos'] &&
$user['intel'] >= $row['nintel'] &&
$user['level'] >= $row['nlevel'] &&
(($user['align'] > 7 && $user['align'] < 8) || ((int)$user['align'] == (int)$row['nalign']) || ($row['nalign'] == 0)) &&
$user['noj'] >= $row['nnoj'] &&
$user['topor'] >= $row['ntopor'] &&
$user['dubina'] >= $row['ndubina'] &&
$user['mec'] >= $row['nmech'] &&
($row['type'] < 13 || $row['type'] == 50) && ($user['mfire'] >= $row['nfire']) &&
$user['mwater'] >= $row['nwater'] &&
$user['mair'] >= $row['nair'] &&
$user['mearth'] >= $row['nearth'] &&
$user['mlight'] >= $row['nlight'] &&
$user['mgray'] >= $row['ngray'] &&
$user['mdark'] >= $row['ndark'] &&
$row['needident'] == 0
) || $row['magic'] == 48 || $row['magic'] == 50) {
if (!$row['magic']) {
$incmagic['name'] = $row['includemagicname'];
$incmagic['cur'] = $row['includemagicdex'];
$incmagic['max'] = $row['includemagicmax'];
if ($incmagic['cur'] <= 0) {
return false;
}
$magic['targeted'] = $incmagic['targeted'];
echo "<span class='error'>";
include("magic/" . $incmagic['file']);
echo "</span>";
} else {
echo "<span class='error'>";
include("magic/" . $magic['file']);
echo "</span>";
}
if ($bat) {
if ($row['maxdur'] <= ($row['duration'] + 1)) {
InventoryItem::destroyItem($row['id']);
} else {
if (!$row['magic']) {
$query = 'update inventory set includemagicdex = includemagicdex - ? where item_id = ?';
} else {
$query = 'update inventory set durability = durability + ? where item_id = ?';
}
Db::getInstance()->execute($query, [$bat, $row['id']]);
}
if (!$charge) {
$charge = 0;
}
//ограничение по кол-ву за ход
if (User::getInstance()->getBattle()) {
$batMagic = Db::getInstance()->fetchColumn('select magic from battle where battle_id = ?', User::getInstance()->getBattle());
}
if (empty($batMagic)) {
$all_magic = [];
} else {
$all_magic = unserialize($batMagic);
}
$all_magic[User::getInstance()->getId()] += $charge;
Db::getInstance()->execute('update battle set magic = ? where battle_id = ?', [serialize($all_magic), User::getInstance()->getBattle()]);
}
}
return false;
$query = 'insert into actions (uid, time, city, room, vars, ip, vals) values (?,?,?,?,?,?,?)';
$values = [$uid, $time, 'capitalcity', 0, $vars, $_SERVER['REMOTE_ADDR'], $vls];
Db::getInstance()->execute('lock tables actions write');
Db::getInstance()->execute($query, $values);
Db::getInstance()->execute('unlock tables');
}
/* ВАЖНО! (#44)
@@ -468,13 +206,14 @@ function err($t)
/**
* @param int $userId
* @param int $userId
* @param string $text
*
*/
function telegraph(int $userId, string $text)
{
if (Db::getInstance()->ofetch('SELECT 1 FROM users WHERE id = ?', $userId)) {
$userExists = Db::getInstance()->fetchColumn('select count(*) from users where id = ?', $userId) > 0;
if ($userExists) {
Db::getInstance()->execute('INSERT INTO chat (user_id,receiver_id,msg,type) VALUES (-1,?,?,?)', [$userId, $text, 'sms']);
}
}
@@ -486,7 +225,7 @@ function SolveExp($at_id, $def_id, $damage): float
'btl_1' => 1,
'btl_2' => 0.5,
'btl_3' => 0.05,
];
];
$baseexp = [
"0" => "2",
"1" => "5",