Перенос разрозненных файлов в фабрику. Утилизация неиспользуемых функций. #49

This commit is contained in:
2023-12-05 03:01:04 +02:00
committed by Ivor Barhansky
parent c51dbaeae3
commit 8be1c6cd7e
79 changed files with 12178 additions and 12956 deletions
+1 -1
View File
@@ -8844,7 +8844,7 @@ class Battle
mysql_query(
'UPDATE `stats` SET `last_hp` = "0",`tactic1`="0",`tactic2`="0",`tactic3`="0",`tactic4`="0",`tactic5`="0",`tactic6`="0",`tactic7` = "' . ($this->users[$i]['tactic7']) . '" WHERE `id` = "' . $this->users[$i]['id'] . '" LIMIT 1'
);
$rs[$this->users[$i]['team']] = $rs[$this->users[$i]['team']] . $u->getLogin($this->users[$i]['id']) . ', ';
$rs[$this->users[$i]['team']] = $rs[$this->users[$i]['team']] . User::getLogin($this->users[$i]['id']) . ', ';
}
$up .= '`uid` = "' . $pl['id'] . '" OR';
//battle-user (статистика, начальная)
+15 -15
View File
@@ -27,9 +27,9 @@ class Db
/**
* @param string $query
* @return int
* @return false|int
*/
public static function exec(string $query): int
public static function exec(string $query): false|int
{
self::init();
return self::$db->exec($query);
@@ -42,9 +42,9 @@ class Db
/**
* @param ?string $name [optional] Name of the sequence object from which the ID should be returned.
* @return string
* @return false|string
*/
public static function lastInsertId(?string $name = null): string
public static function lastInsertId(?string $name = null): false|string
{
self::init();
return self::$db->lastInsertId($name);
@@ -53,9 +53,9 @@ class Db
/**
* @param string $query
* @param array $args
* @return array
* @return false|array
*/
public static function getRows(string $query, array $args = []): array
public static function getRows(string $query, array $args = []): false|array
{
return self::run($query, $args)->fetchAll();
}
@@ -63,9 +63,9 @@ class Db
/**
* @param string $query
* @param array $args
* @return PDOStatement
* @return false|PDOStatement
*/
public static function run(string $query, array $args = []): PDOStatement
public static function run(string $query, array $args = []): false|PDOStatement
{
try {
if (!$args) {
@@ -81,9 +81,9 @@ class Db
/**
* @param string $stmt
* @return PDOStatement
* @return false|PDOStatement
*/
private static function query(string $stmt): PDOStatement
private static function query(string $stmt): false|PDOStatement
{
self::init();
return self::$db->query($stmt);
@@ -91,9 +91,9 @@ class Db
/**
* @param string $stmt
* @return PDOStatement
* @return false|PDOStatement
*/
public static function prepare(string $stmt): PDOStatement
public static function prepare(string $stmt): false|PDOStatement
{
self::init();
return self::$db->prepare($stmt);
@@ -104,7 +104,7 @@ class Db
* @param array $args
* @return mixed
*/
public static function getValue(string $query, array $args = [])
public static function getValue(string $query, array $args = []): mixed
{
$result = self::getRow($query, $args);
if (!empty($result)) {
@@ -118,7 +118,7 @@ class Db
* @param array $args
* @return mixed
*/
public static function getRow(string $query, array $args = [])
public static function getRow(string $query, array $args = []): mixed
{
return self::run($query, $args)->fetch();
}
@@ -137,7 +137,7 @@ class Db
* @param string $query
* @param array $args
*/
public static function sql(string $query, array $args = [])
public static function sql(string $query, array $args = []): void
{
self::run($query, $args);
}
+1 -1
View File
@@ -4,7 +4,7 @@ namespace Core;
class View
{
public static function render(string $view, array $arguments = [])
public static function render(string $view, array $arguments = []): void
{
extract($arguments, EXTR_SKIP);
$file = $_SERVER['DOCUMENT_ROOT'] . "/_incl_data/Views/$view";
+1 -1
View File
@@ -1756,7 +1756,7 @@ class Dungeon
}
$ph = $stt['hpNow'] / $stt['hpAll'] * 100;
$r .= '<table border="0" cellspacing="0" cellpadding="0" height="20">
<tr><td valign="middle"> &nbsp; <font color="#990000">' . User::start()->getLogin($pl['id']) . '</font> &nbsp; </td>
<tr><td valign="middle"> &nbsp; <font color="#990000">' . User::getLogin($pl['id']) . '</font> &nbsp; </td>
<td valign="middle" width="120" ';
if ($stt['mpAll'] < 1) {
$r .= 'style="padding-top:12px"';
+5 -5
View File
@@ -931,7 +931,7 @@ class FightRequest
$teams = ArraySorter::groupBy($cb, 'team');
foreach ($teams as $teamId => $team) {
foreach ($team as $key => $player) {
$players .= $this->u->getLogin($player['id']);
$players .= User::getLogin($player['id']);
if ($key !== array_key_last($team)) {
$players .= ', ';
} else {
@@ -1038,7 +1038,7 @@ class FightRequest
$uids = Db::getColumn('select id from stats where zv = ?', [$pl['id']]);
$cols = count($uids);
foreach ($uids as $uid) {
$tm .= $this->u->getLogin($uid) . ', ';
$tm .= User::getLogin($uid) . ', ';
}
$tm = rtrim($tm, ', ');
@@ -1049,7 +1049,7 @@ class FightRequest
$unvs = '';
if ($pl['invise'] == 1) {
$userslist = $this->u->isModerator() ? $tm : '';
$tm = '<span style="color:maroon">' . $this->u->getLogin($pl['creator']) . '</span>' .
$tm = '<span style="color:maroon">' . User::getLogin($pl['creator']) . '</span>' .
$userslist . ' - <i>невидимый</i>';
$unvs = ' Участников: ' . $cols . ' чел. ';
$n1tv .= ' <img src="' . Config::img() . '/i/fighttypehidden0.gif" title="Невидимый">';
@@ -1143,9 +1143,9 @@ class FightRequest
$tmc = [];
$users = Db::getRows('select team, id from stats where zv = ?', [$pl['id']]);
foreach ($users as $user) {
${'tm' . $user['team']} .= $this->u->getLogin($user['id']) . ', ';
${'tm' . $user['team']} .= User::getLogin($user['id']) . ', ';
$tmc[$user['team']]++;
$teams[$user['team']][] = $this->u->getLogin($user['id']);
$teams[$user['team']][] = User::getLogin($user['id']);
}
foreach ($teams as $id => $members) {
+1 -1
View File
@@ -1321,7 +1321,7 @@ class Magic
} elseif ($u->info['dnow'] != $usr['dnow']) {
$u->error = 'Персонаж находится в другой комнате [пещера]';
} elseif ($usr['room'] == 217 || $usr['room'] == 218 || $usr['room'] == 219) {
$u->error = 'Персонаж ' . $u->getLogin($usr['id']) . ' находится в Общежитии!';
$u->error = 'Персонаж ' . User::getLogin($usr['id']) . ' находится в Общежитии!';
} elseif ($usr['inTurnir'] != 0 && ($u->info['inTurnir'] != $usr['inTurnir'])) {
$u->error = 'Участвует в турнире Башни смерти...';
} elseif ($usr['id'] == $u->info['id'] && isset($st['useOnlyUser'])) {
+6 -7
View File
@@ -1,12 +1,11 @@
<?php
if(!defined('GAME'))
{
die();
if (!defined('GAME')) {
die();
}
if( $itm['magic_inci'] == 'aniname' ) {
$u->error = 'Теперь вы можете переименовать своего зверя';
mysql_query('UPDATE `users_animal` SET `rename` = 0 WHERE `uid` = '.$u->info['id'].' AND `delete` = 0 AND `pet_in_cage` = 0 LIMIT 1');
mysql_query('UPDATE `items_users` SET `iznosNOW` = `iznosNOW` + 1 WHERE `id` = '.$itm['id'].' LIMIT 1');
if ($itm['magic_inci'] == 'aniname') {
$u->error = 'Теперь вы можете переименовать своего зверя';
mysql_query('UPDATE `users_animal` SET `renameArrayKeys` = 0 WHERE `uid` = ' . $u->info['id'] . ' AND `delete` = 0 AND `pet_in_cage` = 0 LIMIT 1');
mysql_query('UPDATE `items_users` SET `iznosNOW` = `iznosNOW` + 1 WHERE `id` = ' . $itm['id'] . ' LIMIT 1');
}
?>
+4 -4
View File
@@ -5,17 +5,17 @@ if (!defined('GAME')) {
if ($u->info['login'] == $usr['login']) {
$u->error = 'Нельзя использовать на себя!';
} elseif ($usr['room'] == 217 || $usr['room'] == 218 || $usr['room'] == 219) {
$u->error = 'Персонаж ' . $u->getLogin($usr['id']) . ' находится в Общежитии!';
$u->error = 'Персонаж ' . User::getLogin($usr['id']) . ' находится в Общежитии!';
} elseif ($usr['dnow'] > 0) {
$u->error = 'Персонаж ' . $u->getLogin($usr['id']) . ' находится в Подземелье';
$u->error = 'Персонаж ' . User::getLogin($usr['id']) . ' находится в Подземелье';
} elseif ($usr['real'] == 1) {
$u->error = 'Перемещать можно только реальных игроков!';
} elseif ($usr['bot'] > 0) {
$u->error = 'Вы не можете поймать бота ;)';
} elseif ($usr['battle'] > 0) {
$u->error = 'Персонаж ' . $u->getLogin($usr['id']) . ' находится в поединке';
$u->error = 'Персонаж ' . User::getLogin($usr['id']) . ' находится в поединке';
} elseif ($usr['room'] == 274) {
$u->error = 'Персонаж ' . $u->getLogin($usr['id']) . ' находится в Заточении!';
$u->error = 'Персонаж ' . User::getLogin($usr['id']) . ' находится в Заточении!';
} elseif ($usr['online'] < time() - 520) {
$u->error = 'Персонаж не в сети';
} else {
-3
View File
@@ -25,9 +25,6 @@ class Stat extends Constant
if (!$row[$cellName->value]) {
continue;
}
if ($row['sys_name'] === 'level') {
$row['sys_name'] = 'lvl';
}
$result[$row['sys_name']] = $row['name'];
}
return $result;
@@ -0,0 +1,49 @@
<?php
namespace Moderation;
use Chat;
use User;
class Announcement
{
public static function init(): void
{
self::printForm();
self::send();
}
public static function printForm(): void
{
echo <<<HTML
<div style="padding:0 10px 5px 10px; margin:5px; border-bottom:1px solid #cac9c7;">
<h4>Ìåãàôîí</h4>
<form method="post"></form>
<label for="announcementText">Ñîîáùåíèå</label>
<input name="announcementText" type="text" id="announcementText" size="70" maxlength="1000">
<input type="submit" name="announcementModeration" id="announcementModeration" class="btn" value="Íàïèñàòü"><br>
<input name="announcementIsSigned" type="checkbox" id="announcementIsSigned" value="1">
<label for="announcementIsSigned">îò ñâîåãî èìåíè</label>
</form>
</div>
HTML;
}
public static function send(): void
{
if (empty($_POST['announcementModeration'] || empty($_POST['announcementText']))) {
return;
}
$strippedMessage = strip_tags($_POST['announcementText']);
if (empty($strippedMessage)) {
return;
}
$sender = empty($_POST['announcementIsSigned']) ? '<b>Àäìèíèñòðàöèÿ</b>' : User::getLogin(User::start()->info['id']);
(new Chat())->sendsys("$sender: $strippedMessage");
echo '<span style="color: red; "><b>Ñîîáùåíèå óñïåøíî îòïðàâëåíî</b></span>';
}
}
+148
View File
@@ -0,0 +1,148 @@
<?php
namespace Moderation;
use Chat;
use ChatMessage;
use Core\Db;
use DateTime;
use User;
class ModFactory
{
private const ERROR_WRONG_DURATION = 'Íåâåðíî óêàçàí ñðîê íàêàçàíèÿ';
public readonly string $status;
private DateTime $time;
private ChatMessage $msg;
private Moderation $moderation;
private Chat $chat;
private array $targetUser;
public function __construct(
private readonly string $targetLogin,
private readonly string $reason,
int $moderatorsRoom // Êîìíàòà ãäå ñèäèò ìîäåðàòîð.
)
{
$this->targetUser = User::getInfo($this->targetLogin);
if (empty($this->targetUser)) {
$this->status = 'Ïåðñîíàæ íå íàéäåí!';
return;
}
$this->chat = new Chat();
$this->msg = new ChatMessage();
$this->msg->setType(6);
$this->msg->setTypeTime(1);
$this->msg->setRoom($moderatorsRoom);
$this->time = new DateTime();
$this->moderation = new Moderation($this->targetUser['id']);
}
public function silence(int $minutes): void
{
if ($minutes < 1) {
$this->status = self::ERROR_WRONG_DURATION;
return;
}
$this->time->modify("+ $minutes minute");
$this->moderation->silence($this->time, $this->reason);
$this->status = "Ïåðñîíàæó $this->targetLogin çàïðåùåíî îáùàòüñÿ â ÷àòå äî {$this->time->format(Moderation::EXPIRATION_DATETIME_FORMAT)}.";
$this->msg->setText("[img[items/silence.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function unsilence(): void
{
if ($this->targetUser['molch1'] < $this->time->getTimestamp()) {
$this->status = 'Ïåðñîíàæ íå ìîë÷èò!';
return;
}
$this->moderation->unsilence();
$this->status = "Ñ ïåðñîíàæà $this->targetLogin ñíÿò çàïðåò íà îáùåíèå â ÷àòå.";
$this->msg->setText("[img[items/pal_button3.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function prison(int $days): void
{
if ($days < 1) {
$this->status = self::ERROR_WRONG_DURATION;
return;
}
$this->time->modify("+ $days day");
$this->moderation->prison($this->time, $this->reason);
Db::sql('delete from dungeon_zv where uid = ?', [$this->targetUser['id']]); // Óäàëÿåì çàÿâêè â ïåùåðû.
$this->status = "Ïåðñîíàæ $this->targetLogin áûë îòïðàâëåí â òþðüìó äî {$this->time->format(Moderation::EXPIRATION_DATETIME_FORMAT)}.";
$this->msg->setText("[img[items/jail.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function unprison(): void
{
$this->moderation->unprison();
$this->status = "Ïåðñîíàæ $this->targetLogin áûë âûïóùåí èç òþðüìû.";
$this->msg->setText("[img[items/jail_off.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function depersonalize(int $days): void
{
if ($days < 1) {
$this->status = self::ERROR_WRONG_DURATION;
return;
}
if ($this->targetUser['info_delete'] === 1 || $this->targetUser['info_delete'] >= $this->time->getTimestamp()) {
$this->status = 'Ïåðñîíàæ óæå ïîä ïîäîçðåíèåì.';
return;
}
$this->time->modify("+ $days day");
$this->moderation->depersonalize($this->time, $this->reason);
$this->status = "Ïåðñîíàæ $this->targetLogin ïîä ïîäîçðåíèåì äî {$this->time->format(Moderation::EXPIRATION_DATETIME_FORMAT)}";
$this->msg->setText("[img[items/cui.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function undepersonalize(): void
{
if ($this->targetUser['info_delete'] <= $this->time->getTimestamp()) {
$this->status = 'Ïåðñîíàæ íå ïîä ïîäîçðåíèåì.';
return;
}
$this->moderation->undepersonalize();
$this->status = "Ïåðñîíàæ $this->targetLogin áîëüøå íå ïîä ïîäîçðåíèåì";
$this->msg->setText("[img[items/uncui.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function ban(): void
{
$this->moderation->ban($this->reason);
Db::sql('delete from chat where login = ?', [$this->targetLogin]);
Db::sql('insert into ban_email (email, uid, nick_name) values (?,?,?)', [$this->targetUser['mail'], $this->targetUser['id'], $this->targetLogin]);
Db::sql('delete from zayvki where creator = ?', [$this->targetUser['id']]); // Óäàëÿåì çàÿâêè íà áîé.
Db::sql('delete from dungeon_zv where uid = ?', [$this->targetUser['id']]); // Óäàëÿåì çàÿâêè â ïåùåðû.
if (!empty($this->targetUser['battle'])) {
Db::sql(
'update users left join stats on users.id = stats.id set battle = default, regHP = unix_timestamp(), team = 0, battle_yron = 0, battle_exp = 0 where users.id = ?',
[$this->targetUser['id']]
);
}
$this->status = "Ïåðñîíàæ $this->targetLogin çàáëîêèðîâàí";
$this->msg->setText("[img[items/pal_button6.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
public function unban(): void
{
if (empty($this->targetUser['banned'])) {
$this->status = 'Ïåðñîíàæ íå â áëîêå.';
return;
}
$this->moderation->unban();
Db::sql('delete from ban_email where email = ?', [$this->targetUser['mail']]);
$this->status = "Ïåðñîíàæ $this->targetLogin ðàçáëîêèðîâàí";
$this->msg->setText("[img[items/pal_button7.gif]] $this->status");
$this->chat->sendMsg($this->msg);
}
}
+7 -7
View File
@@ -15,7 +15,7 @@ class Moderation
private const CENTRAL_SQUARE_ROOM = 9;
private const JAIL_STORAGE = 1357908642; /* Ух, костыль! */
private const NOT_SET = 'Не указано.';
private const EXPIRATION_DATETIME_FORMAT = 'd M Y H:i';
public const EXPIRATION_DATETIME_FORMAT = 'd M Y H:i';
private int $target;
public function __construct(int $userid)
@@ -26,7 +26,7 @@ class Moderation
/**
* Молчание
* @param DateTime $expiration срок истечения.
* @param string $reason причина применения.
* @param string $reason причина применения.
*/
public function silence(DateTime $expiration, string $reason = self::NOT_SET): void
{
@@ -59,7 +59,7 @@ class Moderation
/**
* Обезличивание
* @param DateTime $expiration срок истечения.
* @param string $reason причина применения.
* @param string $reason причина применения.
*/
public function depersonalize(DateTime $expiration, string $reason = self::NOT_SET): void
{
@@ -77,7 +77,7 @@ class Moderation
*/
public function undepersonalize(): void
{
if (Db::getValue('select count(info_delete) from users where id = ? and info_delete != 0', [$this->target]) === 0) {
if (Db::getValue('select count(info_delete) from users where id = ? and info_delete <= unix_timestamp()', [$this->target]) === 0) {
return;
}
Db::sql('update users set info_delete = default where id = ?', [$this->target]);
@@ -92,13 +92,13 @@ class Moderation
/**
* Тюрьма
* @param DateTime $expiration срок истечения.
* @param string $reason причина применения.
* @param string $reason причина применения.
* @todo Корректно выбрасывать игрока из подземелья.
*/
public function prison(DateTime $expiration, string $reason = self::NOT_SET): void
{
Db::sql('update users set jail = ?, room = ? where id = ?', [$expiration->getTimestamp(), self::JAIL_ROOM, $this->target,]);
Db::sql('update items_users set `delete` = ? where `delete` = 0 and uid = ?', [self::JAIL_STORAGE, $this->target,]);
Db::sql('update items_users set is_arrested = 1 where uid = ?', [$this->target,]);
Delo::add(
10,
'moderation.prison',
@@ -113,7 +113,7 @@ class Moderation
public function unprison(): void
{
Db::sql('update users set jail = default, room = ? where id = ?', [self::CENTRAL_SQUARE_ROOM, $this->target,]);
Db::sql('update items_users set `delete` = default where `delete` = ? and uid = ?', [self::JAIL_STORAGE, $this->target,]);
Db::sql('update items_users set is_arrested = default where uid = ?', [$this->target,]);
Delo::add(
10,
'moderation.unprison',
+48
View File
@@ -0,0 +1,48 @@
<?php
namespace Moderation;
use Core\Db;
readonly class Moderator
{
public bool $isModerator;
public bool $canBlockUsers;
public bool $isAdmin;
public function __construct(int $uid)
{
[
'uid' => $isModerator,
'can_block_users' => $canBlockUsers,
'is_admin' => $isAdmin,
] = Db::getRow('select uid, can_block_users, is_admin from moderators where uid = ?', [$uid]);
$this->isModerator = !empty($isModerator);
$this->canBlockUsers = !empty($isModerator) && !empty($canBlockUsers);
$this->isAdmin = !empty($isModerator) && !empty($isAdmin);
}
public static function add(int $uid): void
{
$user = new Moderator($uid);
if ($user->isModerator) {
return;
}
Db::sql('insert into moderators (uid) value (?)', [$uid]);
}
public static function modify(int $uid, bool $allowBlock, bool $adminRights): void
{
$user = new Moderator($uid);
if (!$user->isModerator) {
return;
}
Db::sql('update moderators set can_block_users = ?, is_admin = ? where uid = ?', [(int)$allowBlock, (int)$adminRights, $uid]);
}
public static function delete(int $uid): void
{
Db::sql('delete from moderators where uid = ?', [$uid]);
}
}
@@ -0,0 +1,36 @@
<?php
namespace Moderation;
use Core\Db;
use DateTime;
use DateTimeImmutable;
use User;
class UserRegistrationList
{
public function get(DateTime $date)
{
$from = $date->getTimestamp();
$to = $date->modify('+ 1 day')->getTimestamp();
$list = Db::getRows("select id, banned, molch1, battle, host_reg, online from users where timereg between ? and ? and bot_id = 0 and bithday != '01.01.1800' order by id", [$from, $to]);
$str = '';
foreach ($list as $user) {
$time = new DateTime();
$loginColor = 'black';
if ($user['banned']) {
$loginColor = 'red';
}
if ($user['online'] > $time->modify('- 10 minutes')->getTimestamp()) {
$loginColor = 'green';
}
if ($user['molch1'] > 0) {
$molch1Duration = new DateTimeImmutable($user['molch1']);
}
$str .= "<li><span style='color: $loginColor'>" . User::getLogin($user['id'] . "</span>");
}
}
}
+32 -29
View File
@@ -1378,6 +1378,36 @@ class User
Db::sql('update users set online = unix_timestamp() where id = ?', [$uid]);
}
/** Возврат имени персонажа со всеми регалиями
* @param int $uid id персонажа.
* @return string
*/
public static function getLogin(int $uid): string
{
[
'align' => $align,
'login' => $login,
'level' => $level,
'name_mini' => $clanName,
] = Db::getRow(
'select
users.align,
login,
users.level,
c.name_mini
from users left join clan as c on c.id = users.clan
where users.id = ?',
[$uid]
);
$imgBase = Config::img() . DIRECTORY_SEPARATOR . 'i';
$alignStr = empty($align) ? '' : "<img src='$imgBase/align/align$align.gif' alt=''>";
$clanStr = empty($clanName) ? '' : "<img src='$imgBase/clan/$clanName.gif' alt='$clanName'>";
$spacedLogin = str_replace(' ', '%20', $login);
$loginLink = "<a href='/inf.php?login=$spacedLogin' target='_blank'><img src='img/inf.gif' title='Инф. о $login' alt='Инф. о $login'></a>";
return "$alignStr$clanStr<strong>$login</strong> [$level]$loginLink";
}
public function dayquest(int $id): string
{
$test = Db::getRow('select id, vals from actions where uid = ? and vars = ?', [$id, 'day_quest']);
@@ -1859,6 +1889,8 @@ class User
return $tp;
}
//Удаление определенного типа предметов
public function rep_zv(int $id, int $e): string
{
$r = '0 / 0';
@@ -1925,8 +1957,6 @@ class User
return $r;
}
//Удаление определенного типа предметов
public function getNum($v)
{
$plid = $v;
@@ -1941,33 +1971,6 @@ class User
return $plid;
}
/** Возврат имени персонажа со всеми регалиями
* @param int|null $uid id персонажа. Если пусто, возвращается имя персонажа активного игрока.
* @return string
*/
public function getLogin(?int $uid = null):string {
if (is_null($uid)) {
$uid = $this->info['id'];
}
[$align, $login, $level, $clanName] = Db::getRow(
'select
users.align,
login,
users.level,
c.name_mini
from users left join clan as c on c.id = users.clan
where users.id = ?',
[$uid]
);
$imgBase = Config::img() . DIRECTORY_SEPARATOR . 'i';
$alignStr = empty($align) ? '' : "<img src='$imgBase/align/align$align.gif' alt=''>";
$clanStr = empty($clanName) ? '' : "<img src='$imgBase/clan/$clanName.gif' alt='$clanName'>";
$spacedLogin = str_replace(' ', '%20', $login);
$loginLink = "<a href='/inf.php?login=$spacedLogin' target='_blank'><img src='img/inf.gif' title='Инф. о $login' alt='Инф. о $login'></a>";
return "$alignStr$clanStr<strong>$login</strong> [$level]$loginLink";
}
public function addNewbot($id, $botDate, $clon, $logins_bot = null, $luser = null, $round = null)
{
if ($clon != null) {
+7 -2
View File
@@ -427,7 +427,12 @@ class InfoBox
$hptop = 0;
$lh = [0 => 'hp_none', 1 => 1];
$lh[1] = floor((0 + $sn['hpNow']) / (0 + $sn['hpAll']) * 120);
if ($sn['hpNow'] == 0 || $sn['hpAll'] == 0) {
$lh[1] = 0;
} else {
$lh[1] = floor((0 + $sn['hpNow']) / (0 + $sn['hpAll']) * 120);
}
if ($lh[1] > 0) {
$lh[0] = 'hp_1';
}
@@ -544,7 +549,7 @@ class InfoBox
if ($pb != '') {
$pb = '<div align="center" style="width:246px;"><!-- blocked -->' . $pb . '</div>';
}
$rt[0] .= '<div id="lgnthm" style="width:246px; padding:0 3px 0 3px;" align="center">' . $this->user->getLogin($u['id']) . '</div>' . $pb . '
$rt[0] .= '<div id="lgnthm" style="width:246px; padding:0 3px 0 3px;" align="center">' . User::getLogin($u['id']) . '</div>' . $pb . '
<div class="personag" style="width:240px; background-color:#CCC; padding:3px; margin-right:11px; border-bottom:1px solid #666666; border-right:1px solid #666666; border-left:1px solid #FFFFFF; border-top:1px solid #FFFFFF;">
<table width="240" border="0" cellspacing="0" cellpadding="0">
<tr>
+1 -1
View File
@@ -86,7 +86,7 @@ class ItemsModel
public static function getOwnedItemById(int $itemId, int $ownerId): array
{
return Db::getRow('select * from items_users left join items_main on item_id = items_main.id
where uid = ? and items_users.id = ? and `delete` = 0 and inOdet = 0 and inShop = 0', [$ownerId, $itemId]);
where uid = ? and items_users.id = ? and `delete` = 0 and inOdet = 0 and inShop = 0 and is_arrested = 0', [$ownerId, $itemId]);
}
public static function delete(int $id): void
+195 -330
View File
@@ -6,6 +6,7 @@ use Core\Config;
use Core\Db;
use Helper\Comparsion;
use Helper\Conversion;
use Model\Constant\Stat;
use User;
class Stats
@@ -17,13 +18,13 @@ class Stats
*/
private array $sysNames;
private array $statsKeys = [];
public function __construct(User $user)
{
$this->u = $user;
$this->sysNames = Db::getColumn('select sys_name from const_stats where is_bonus = true');
$this->sysNames['hpAll'] = $this->sysNames['hpall'];
$this->sysNames['mpAll'] = $this->sysNames['mpall'];
unset($this->sysNames['hpall'], $this->sysNames['mpall']);
$this->sysNames = (new Stat())->getBonusNames();
}
/**
@@ -112,7 +113,7 @@ class Stats
return (object)[
'uid' => $u->info['id'],
'login' => $u->getLogin(),
'login' => User::getLogin($u->info['id']),
'hpbarwidth' => $ph,
'mpbarwidth' => $pm,
'hpbartext' => ' ' . $hpNow . '/' . $hpAll,
@@ -146,8 +147,8 @@ class Stats
$u['clanpos'] = 0;
if ($u['clan'] > 0) {
$r1 = Db::getValue('select pos from aaa_clan_reting_list where clan = ? and date = ? limit 1', [$u['clan'], date('dmY')]);
if (!empty($r1)) {
$st['clanpos'] = $r1;
if ($r1) {
$this->addKeyIfNotExist('clanpos', $r1, $st);
}
}
$lvl = Db::getRow('select * from levels where upLevel = ?', [$u['upLevel']]);
@@ -160,27 +161,21 @@ class Stats
$st['id'] = $u['id'];
$st['login'] = $u['login'];
$st['lvl'] = $u['level'];
$st['level'] = $u['level'];
$st['hpNow'] = $u['hpNow'];
$st['hpAll'] = 0;
$st['mpNow'] = $u['mpNow'];
$st['mpAll'] = 0;
$st['zona'] = 1;
$st['zonb'] = 2;
$st['items'] = [];
$st['effects'] = [];
$st['reting'] = 0;
$st['vip'] = $u['vip'];
$stats = Conversion::dataStringToArray($u['stats']);
foreach ($stats as $stat => $value) {
if (isset($st[$stat]) && is_numeric($value)) {
$st[$stat] += $value;
} else {
$st[$stat] = $value;
}
foreach (Conversion::dataStringToArray($u['stats']) as $stat => $value) {
$this->addKeyIfNotExist($stat, (int)$value, $st);
}
unset($stats);
$baseStats = $st;
@@ -245,10 +240,10 @@ class Stats
$nbs[$sts['itempl']] += 1;
}
if (isset($sts['puti'])) {
$st['puti'] = $sts['puti'];
$this->addKeyIfNotExist('puti', $sts['puti'], $st);
}
if (isset($sts['add_silver'])) {
$st['slvtm'] = $e['timeUse'] + $e['actionTime'];
$this->addKeyIfNotExist('slvtm', $e['timeUse'] + $e['actionTime'], $st);
}
$this->addValuesToAllArrays($sts, $st, $sti, $s_v, $s_vi);
@@ -276,8 +271,8 @@ class Stats
$this->addInBattlePriemsBonuses($u, $st, $prsu, $sti, $s_v, $s_vi);
//Характеристики от статов
$st['hpAll'] += $st['s4'] * 5;
$st['mpAll'] += $st['s6'] * 10;
$st['hpall'] += $st['s4'] * 5;
$st['mpall'] += $st['s6'] * 10;
//Турнир
$st['m1'] += $st['s3'] * 5;
@@ -291,7 +286,6 @@ class Stats
// мф.анти-уворот = 2.5
$st['m5'] += $st['s2'] * 5;
$st['za'] += $st['s4'] * 1.0;
$st['zm'] += $st['s4'] * 0.0;
$st['m19'] += round($st['s3'] * 0.03);
@@ -322,49 +316,8 @@ class Stats
}
}
//Замена свитков
if ($u['autospell'] != 0 && $u['battle'] == 0) {
//проверяем свитки
$sparr = [];
foreach (Db::getRows('select item_id, inOdet from items_users where inOdet between 40 and 50 and uid = ? order by item_id desc', [$u['id']]) as $scroll) {
$sparr[] = "{$scroll['item_id']} - {$scroll['inOdet']}";
}
$splink = implode(',', $sparr);
//Запоминаем новый комплект свитков
if ($u['autospell'] == 1) {
$u['autospell'] = $splink;
Db::sql('update users set autospell = ? where id = ?', [$splink, $u['id']]);
}
//Выдаем нужный свиток, если он есть в инвентаре
if ($u['autospell'] != $splink) {
$spe1 = explode(',', $splink);
$spe2 = explode(',', $u['autospell']);
$spe1g = [];
$spe2g = [];
for ($i = 0; $i <= 20; $i++) {
$spe1a = explode('-', $spe1[$i]);
$spe2a = explode('-', $spe2[$i]);
if (isset($spe1a[0])) {
$spe1g[$spe1a[1]] = $spe1a[0];
}
if (isset($spe2a[0])) {
$spe2g[$spe2a[1]] = $spe2a[0];
}
}
for ($i = 40; $i <= 50; $i++) {
if ($spe1g[$i] == $spe2g[$i] || $spe1g[$i] != 0) {
continue;
}
Db::sql('update items_users set inOdet = ? where inOdet = 0 and `delete` = 0 and inTransfer = 0 and inShop = 0 and inGroup = 0 and item_id = ? and uid = ?',
[$i, $spe2g[$i], $u['id']]);
}
}
}
//Что за нахер?
WearedScrolls::ScrollsChange($u);
//Бонусы статов
$this->addStatBonuses($st);
@@ -384,8 +337,6 @@ class Stats
$st['pm2'] += $st['s5'] * 0.5;
$st['pm3'] += $st['s5'] * 0.5;
$st['pm4'] += $st['s5'] * 0.5;
$st['pm5'] += $st['s5'] * 0.5;
$st['pm6'] += $st['s5'] * 0.5;
$st['pm7'] += $st['s5'] * 0.5;
}
@@ -394,8 +345,6 @@ class Stats
$st['pm2'] += $st['m11a'] * 0.5;
$st['pm3'] += $st['m11a'] * 0.5;
$st['pm4'] += $st['m11a'] * 0.5;
$st['pm5'] += $st['m11a'] * 0.5;
$st['pm6'] += $st['m11a'] * 0.5;
$st['pm7'] += $st['m11a'] * 0.5;
}
@@ -405,8 +354,6 @@ class Stats
$st['a3'] += $st['aall'];
$st['a4'] += $st['aall'];
$st['a5'] += $st['aall'];
$st['a6'] += $st['aall'];
$st['a7'] += $st['aall'];
}
if (isset($st['m2all'])) {
@@ -414,8 +361,6 @@ class Stats
$st['mg2'] += $st['m2all'];
$st['mg3'] += $st['m2all'];
$st['mg4'] += $st['m2all'];
$st['mg5'] += $st['m2all'];
$st['mg6'] += $st['m2all'];
$st['mg7'] += $st['m2all'];
}
@@ -445,18 +390,21 @@ class Stats
$st['mg3'] += $st['mall'];
$st['mg4'] += $st['mall'];
}
if (isset($st['m11'])) {
$st['pm1'] += $st['m11'];
$st['pm2'] += $st['m11'];
$st['pm3'] += $st['m11'];
$st['pm4'] += $st['m11'];
}
if (isset($st['m10'])) {
$st['pa1'] += $st['m10'];
$st['pa2'] += $st['m10'];
$st['pa3'] += $st['m10'];
$st['pa4'] += $st['m10'];
}
if (isset($st['za'])) {
$st['za1'] += $st['za'];
$st['za2'] += $st['za'];
@@ -464,72 +412,23 @@ class Stats
$st['za4'] += $st['za'];
}
$st['yzm1'] += $st['yzma'];
$st['yzm2'] += $st['yzma'];
$st['yzm3'] += $st['yzma'];
$st['yzm4'] += $st['yzma'];
$st['yzm5'] += $st['yzma'];
$st['yzm6'] += $st['yzma'];
$st['yzm7'] += $st['yzma'];
$st['yzm1'] += $st['yzm'];//стихийный урон только
$st['yzm2'] += $st['yzm'];
$st['yzm3'] += $st['yzm'];
$st['yzm4'] += $st['yzm'];
$st['yza1'] += $st['yza'];//урон оружия
$st['yza2'] += $st['yza'];
$st['yza3'] += $st['yza'];
$st['yza4'] += $st['yza'];
//Отнимает от защиты от урона
if ($st['yza1'] > 0) {
$st['za1'] = max($st['za1'] / 100 * (100 + $st['yza1']), 0);
}
if ($st['yza2'] > 0) {
$st['za2'] = max($st['za2'] / 100 * (100 + $st['yza2']), 0);
}
if ($st['yza3'] > 0) {
$st['za3'] = max($st['za3'] / 100 * (100 + $st['yza3']), 0);
}
if ($st['yza4'] > 0) {
$st['za4'] = max($st['za4'] / 100 * (100 + $st['yza4']), 0);
}
//Отнимает от защиты от магии
if ($st['yzm1'] > 0) {
$st['zm1'] = max($st['zm1'] / 100 * (100 + $st['yzm1']), 0);
}
if ($st['yzm2'] > 0) {
$st['zm2'] = max($st['zm2'] / 100 * (100 + $st['yzm2']), 0);
}
if ($st['yzm3'] > 0) {
$st['zm3'] = max($st['zm3'] / 100 * (100 + $st['yzm3']), 0);
}
if ($st['yzm4'] > 0) {
$st['zm4'] = max($st['zm4'] / 100 * (100 + $st['yzm4']), 0);
}
if ($st['yzm7'] > 0) {
$st['zm7'] = max($st['zm7'] / 100 * (100 + $st['yzm7']), 0);
}
if (!empty($st['hpVinos'])) {
$st['hpAll'] += round($st['hpVinos'] * $st['s4']);
$st['hpall'] += round($st['hpVinos'] * $st['s4']);
}
if (!empty($st['mpVinos'])) {
$st['mpAll'] += round($st['mpVinos'] * $st['s6']);
$st['mpall'] += round($st['mpVinos'] * $st['s6']);
}
if (!empty($st['hpProc'])) {
$st['hpAll'] += round($st['hpAll'] / 100 * $st['hpProc']);
$st['hpall'] += round($st['hpall'] / 100 * $st['hpProc']);
}
if (!empty($st['mpProc'])) {
$st['mpAll'] += round($st['mpAll'] / 100 * $st['mpProc']);
$st['mpall'] += round($st['mpall'] / 100 * $st['mpProc']);
}
//Реген. - 250 ед.
//конец бонусов
$st['hpNow'] = Comparsion::minimax($st['hpNow'], 0, $st['hpAll']);
$st['mpNow'] = Comparsion::minimax($st['mpNow'], 0, $st['mpAll']);
$st['hpNow'] = Comparsion::minimax($st['hpNow'], 0, $st['hpall']);
$st['mpNow'] = Comparsion::minimax($st['mpNow'], 0, $st['mpall']);
//зоны блока и удара
if ($st['zona'] < 1) {
@@ -562,27 +461,24 @@ class Stats
$this->addDungeonsBonuses($u['id'], $st);
//Добавочный подьем для игроков
$st['maxves'] += 100;
$this->addKeyIfNotExist('maxves', 100, $st);
$this->addAdminBonuses($u, $st);
if (date('H') >= 22 && date('H') <= 10) {
$st['exp'] += 25;
$this->addKeyIfNotExist('exp', 25, $st);
}
//Сохраняем рейтинг игрока
$st['reting'] = floor($st['reting']);
if (isset($st['btl_cof'], $st['prckr']) && $st['btl_cof'] != $st['prckr']) {
$st['btl_cof'] = $st['prckr'];
Db::sql('update stats set btl_cof = ? where id = ?', [$st['prckr'], $st['id']]);
}
if ($st['hpAll'] < 1) {
$st['hpAll'] = 1;
if ($st['hpall'] < 1) {
$st['hpall'] = 1;
}
if ($st['mpAll'] < 0) {
$st['mpAll'] = 0;
if ($st['mpall'] < 0) {
$st['mpall'] = 0;
}
if (stristr($u['login'], '(зверь ') || (stristr($u['login'], 'Каменный страж') && $u['ip'] == '0')) {
@@ -591,6 +487,8 @@ class Stats
$st['this_animal'] = 0;
}
$this->renameArrayKeys($st);
$rt = [];
if ($i1 == 1) {
$rt[0] = $st;
@@ -598,8 +496,8 @@ class Stats
} else {
$rt = $st;
}
if ($u['hpAll'] != $st['hpAll'] || $u['mpAll'] != $st['mpAll']) {
Db::sql('update stats set hpAll = ?, mpAll = ? where id = ?', [$st['hpAll'], $st['mpAll'], $u['id']]);
if ($u['hpAll'] != $st['hpall'] || $u['mpAll'] != $st['mpall']) {
Db::sql('update stats set hpAll = ?, mpAll = ? where id = ?', [$st['hpall'], $st['mpall'], $u['id']]);
}
if ($btl_cache) {
$dataca = [
@@ -610,10 +508,24 @@ class Stats
Db::sql('insert into battle_cache (battle, uid, time, data) values (?,?,unix_timestamp(),?)', [$u['battle'], $u['id'], $dataca]);
}
return $rt;
}
/** Собираем динамически создаваемые параметры. Если ключа нет - создаём.
* @param string $key
* @param int $value
* @param array $st
* @return void
*/
private function addKeyIfNotExist(string $key, int $value, array &$st): void
{
if (!isset($st[$key])) {
$st[$key] = 0;
$this->statsKeys[] = $key;
}
$st[$key] += $value;
}
private function addWearedItemsBonuses(int $uid, array &$st, array &$s_v, array $baseStats): array
{
//Характеристики от предметов //ТУТ tr_lvl
@@ -643,10 +555,16 @@ class Stats
4 => [0, 0],
]; //особенности магии
$st['reting'] = 0;
$ozaozmtypes = [
1 => [1, 9,],//Слабая
2 => [20, 39,],//Нормальная
3 => [40, 69,],//Хорошая
4 => [10, 19,],//Посредственная
5 => [70, 89,],//Великолепная
];
foreach ($wearedItems as $wearedItem) {
$st['wp' . $wearedItem['inOdet'] . 'id'] = $h;
$this->addKeyIfNotExist('wp' . $wearedItem['inOdet'] . 'id', $h, $st);
$st['items'][$h] = $wearedItem;
$h++;
@@ -667,211 +585,149 @@ class Stats
$sht1 = 1;
}
$sti = Conversion::dataStringToArray($wearedItem['data']);
$data = Conversion::dataStringToArray($wearedItem['data']);
if ($wearedItem['inOdet'] <= 18 && $wearedItem['inOdet'] > 0) {
$st['reting'] += 1;
$this->addKeyIfNotExist('reting', 1, $st);
}
$ko = 1;
while ($ko <= 4) {
if (isset($sti['add_oza' . $ko])) {
if (isset($sti['add_oza'])) {
if ($sti['add_oza'] == 1) {
//Слабая
$oza[$ko][0] += 1;
$oza[$ko][1] += 9;
} elseif ($sti['add_oza'] == 2) {
//Нормальная
$oza[$ko][0] += 20;
$oza[$ko][1] += 39;
} elseif ($sti['add_oza'] == 3) {
//Хорошая
$oza[$ko][0] += 40;
$oza[$ko][1] += 69;
} elseif ($sti['add_oza'] == 4) {
//Посредственная
$oza[$ko][0] += 10;
$oza[$ko][1] += 19;
} elseif ($sti['add_oza'] == 5) {
//Великолепная
$oza[$ko][0] += 70;
$oza[$ko][1] += 89;
}
}
if (isset($sti['add_ozm'])) {
if ($sti['add_ozm'] == 1) {
//Слабая
$ozm[$ko][0] += 1;
$ozm[$ko][1] += 9;
} elseif ($sti['add_ozm'] == 2) {
//Нормальная
$ozm[$ko][0] += 20;
$ozm[$ko][1] += 39;
} elseif ($sti['add_ozm'] == 3) {
//Хорошая
$ozm[$ko][0] += 40;
$ozm[$ko][1] += 69;
} elseif ($sti['add_ozm'] == 4) {
//Посредственная
$ozm[$ko][0] += 10;
$ozm[$ko][1] += 19;
} elseif ($sti['add_ozm'] == 5) {
//Великолепная
$ozm[$ko][0] += 70;
$ozm[$ko][1] += 89;
}
} else {
$ozm[$ko][0] += 1;
$ozm[$ko][1] += 9;
}
if ($sti['add_oza' . $ko] == 1) {
//Слабая
$oza[$ko][0] += 1;
$oza[$ko][1] += 9;
} elseif ($sti['add_oza' . $ko] == 2) {
//Нормальная
$oza[$ko][0] += 20;
$oza[$ko][1] += 39;
} elseif ($sti['add_oza' . $ko] == 3) {
//Хорошая
$oza[$ko][0] += 40;
$oza[$ko][1] += 69;
} elseif ($sti['add_oza' . $ko] == 4) {
//Посредственная
$oza[$ko][0] += 10;
$oza[$ko][1] += 19;
} elseif ($sti['add_oza' . $ko] == 5) {
//Великолепная
$oza[$ko][0] += 70;
$oza[$ko][1] += 89;
}
if (isset($sti['add_ozm' . $ko])) {
if ($sti['add_ozm' . $ko] == 1) {
//Слабая
$ozm[$ko][0] += 1;
$ozm[$ko][1] += 9;
} elseif ($sti['add_ozm' . $ko] == 2) {
//Нормальная
$ozm[$ko][0] += 20;
$ozm[$ko][1] += 39;
} elseif ($sti['add_ozm' . $ko] == 3) {
//Хорошая
$ozm[$ko][0] += 40;
$ozm[$ko][1] += 69;
} elseif ($sti['add_ozm' . $ko] == 4) {
//Посредственная
$ozm[$ko][0] += 10;
$ozm[$ko][1] += 19;
} elseif ($sti['add_ozm' . $ko] == 5) {
//Великолепная
$ozm[$ko][0] += 70;
$ozm[$ko][1] += 89;
}
} else {
$ozm[$ko][0] += 1;
$ozm[$ko][1] += 9;
}
}
$ko++;
if (isset($data['add_oza'])) {
$oza = array_fill_keys($oza, $ozaozmtypes[$data['add_oza']]);
}
if (isset($sti['art'])) {
if (!isset($st['art'])) {
$st['art'] = 0;
}
$st['art'] += $sti['art'];
if (isset($data['add_ozm'])) {
$ozm = array_fill_keys($ozm, $ozaozmtypes[$data['add_ozm']]);
} else {
$ozm = array_fill_keys($ozm, $ozaozmtypes[1]);
}
if (isset($sti['maks_itm'])) {
if (!isset($st['maks_itm'])) {
$st['maks_itm'] = 0;
}
$st['maks_itm'] += $sti['maks_itm'];
if (in_array($data['add_oza1'], range(1, 5))) {
$oza[1] = $ozaozmtypes[$data['add_oza1']];
}
if (isset($sti['complect'])) {
$coms[count($coms)]['id'] = $sti['complect'];
if (!isset($coms['com'][$sti['complect']])) {
$coms['com'][$sti['complect']] = 0;
if (in_array($data['add_oza2'], range(1, 5))) {
$oza[2] = $ozaozmtypes[$data['add_oza2']];
}
if (in_array($data['add_oza3'], range(1, 5))) {
$oza[3] = $ozaozmtypes[$data['add_oza3']];
}
if (in_array($data['add_oza4'], range(1, 5))) {
$oza[4] = $ozaozmtypes[$data['add_oza4']];
}
if (in_array($data['add_ozm1'], range(1, 5))) {
$ozm[1] = $ozaozmtypes[$data['add_ozm1']];
} else {
$ozm[1] = $ozaozmtypes[1];
}
if (in_array($data['add_ozm2'], range(1, 5))) {
$ozm[2] = $ozaozmtypes[$data['add_ozm2']];
} else {
$ozm[2] = $ozaozmtypes[1];
}
if (in_array($data['add_ozm3'], range(1, 5))) {
$ozm[3] = $ozaozmtypes[$data['add_ozm3']];
} else {
$ozm[3] = $ozaozmtypes[1];
}
if (in_array($data['add_ozm4'], range(1, 5))) {
$ozm[4] = $ozaozmtypes[$data['add_ozm4']];
} else {
$ozm[4] = $ozaozmtypes[1];
}
if (isset($data['art'])) {
$this->addKeyIfNotExist('art', $data['art'], $st);
}
if (isset($data['maks_itm'])) {
$this->addKeyIfNotExist('maks_itm', $data['maks_itm'], $st);
}
if (isset($data['complect'])) {
$coms[count($coms)]['id'] = $data['complect'];
if (!isset($coms['com'][$data['complect']])) {
$coms['com'][$data['complect']] = 0;
if (!isset($coms['new'])) {
$coms['new'] = [];
}
$coms['new'][count($coms['new'])] = $sti['complect'];
$coms['new'][count($coms['new'])] = $data['complect'];
}
$coms['com'][$sti['complect']]++;
$coms['com'][$data['complect']]++;
}
if (isset($sti['complect2'])) {
$coms[count($coms)]['id'] = $sti['complect2'];
if (!isset($coms['com'][$sti['complect2']])) {
$coms['com'][$sti['complect2']] = 0;
if (isset($data['complect2'])) {
$coms[count($coms)]['id'] = $data['complect2'];
if (!isset($coms['com'][$data['complect2']])) {
$coms['com'][$data['complect2']] = 0;
if (!isset($coms['new'])) {
$coms['new'] = [];
}
$coms['new'][count($coms['new'])] = $sti['complect2'];
$coms['new'][count($coms['new'])] = $data['complect2'];
}
$coms['com'][$sti['complect2']]++;
$coms['com'][$data['complect2']]++;
}
if (isset($sti['zonb']) && $sti['zonb'] != 0) {
if (!isset($st['zonb'])) {
$st['zonb'] = 0;
}
$st['zonb'] += $sti['zonb'];
if (!empty($data['zonb'])) {
$this->addKeyIfNotExist('zonb', $data['zonb'], $st);
}
if (isset($sti['zona']) && $sti['zona'] != 0) {
if (!isset($st['zona'])) {
$st['zona'] = 0;
}
$st['zona'] += $sti['zona'];
if (!empty($data['zona'])) {
$this->addKeyIfNotExist('zona', $data['zona'], $st);
}
//Добавляем статы от данного предмета
if (!isset($sti['restart_stats'])) {
if (!isset($data['restart_stats'])) {
foreach ($this->sysNames as $stat) {
if (!isset($sti['add_' . $stat])) {
if (!isset($data['add_' . $stat])) {
continue;
}
$st[$stat] += (int)$sti['add_' . $stat];
$st[$stat] += (int)$data['add_' . $stat];
}
} else {
$reitm[] = $sti;
$reitm[] = $data;
}
foreach ($this->sysNames as $stat) {
if (!isset($sti['sv_' . $stat])) {
if (!isset($data['sv_' . $stat])) {
continue;
}
$s_v[$stat] += (int)$sti['sv_' . $stat];
$s_v[$stat] += (int)$data['sv_' . $stat];
}
}
//Сохраненные хар-ки и умения
if (!empty($reitm)) {
$i39 = [0 => 0, 1 => 0, 2 => 0];
$i = 0;
while ($i < count($reitm)) {
if (isset($reitm[$i]['sm_skill']) && $i39[0] == 0) {
if (!empty($reitm) && is_iterable($reitm)) {
$i39 = [];
foreach ($reitm as $item) {
if (isset($item['sm_skill']) && $i39[0] == 0) {
//умения
$i9 = 1;
$i39[0] = 1;
while ($i9 <= 7) {
$st['a' . $i9] = $st['a' . $i9] - $baseStats['a' . $i9] + $reitm[$i]['add_a' . $i9];
$st['mg' . $i9] = $st['mg' . $i9] - $baseStats['mg' . $i9] + $reitm[$i]['add_mg' . $i9];
$i9++;
}
} elseif (isset($reitm[$i]['sm_abil']) && $i39[1] == 0) {
$st['a1'] -= $baseStats['a1'] + $item['add_a1'];
$st['a2'] -= $baseStats['a2'] + $item['add_a2'];
$st['a3'] -= $baseStats['a3'] + $item['add_a3'];
$st['a4'] -= $baseStats['a4'] + $item['add_a4'];
$st['a5'] -= $baseStats['a5'] + $item['add_a5'];
$st['mg1'] -= $baseStats['mg1'] + $item['add_mg1'];
$st['mg2'] -= $baseStats['mg2'] + $item['add_mg2'];
$st['mg3'] -= $baseStats['mg3'] + $item['add_mg3'];
$st['mg4'] -= $baseStats['mg4'] + $item['add_mg4'];
$st['mg7'] -= $baseStats['mg7'] + $item['add_mg7'];
} elseif (isset($item['sm_abil']) && $i39[1] == 0) {
//статы
$i9 = 1;
$i39[1] = 1;
while ($i9 <= 12) {
$st['s' . $i9] = $st['s' . $i9] - $baseStats['s' . $i9] + $reitm[$i]['add_s' . $i9];
$i9++;
}
} elseif (isset($reitm[$i]['sm_skill2']) && $i39[2] == 0) {
$st['s1'] -= $baseStats['s1'] + $item['add_s1'];
$st['s2'] -= $baseStats['s2'] + $item['add_s2'];
$st['s3'] -= $baseStats['s3'] + $item['add_s3'];
$st['s4'] -= $baseStats['s4'] + $item['add_s4'];
$st['s5'] -= $baseStats['s5'] + $item['add_s5'];
$st['s6'] -= $baseStats['s6'] + $item['add_s6'];
$st['s7'] -= $baseStats['s7'] + $item['add_s7'];
} elseif (isset($item['sm_skill2']) && $i39[2] == 0) {
//навыки
$i39[2] = 1;
}
$i++;
}
}
return [$hnd1, $hnd2, $sht1, $oza, $ozm, $dom, $coms];
@@ -885,14 +741,10 @@ class Stats
foreach ($efs as $data) {
$sts = Conversion::dataStringToArray($data);
foreach ($sts as $paramName => $value) {
//todo убедиться, что не могут прилететь параметры, которых нет в словарей бонусов предметов
if (!str_contains(implode(',', $this->sysNames), 'add_' . $paramName)) { // есть ли параметр в разрешенных?
if (!in_array($paramName, $this->sysNames, true)) { // есть ли параметр в разрешенных?
continue;
}
if (empty($st['add_' . $paramName])) {
$st['add_' . $paramName] = 0;
}
$st['add_' . $paramName] += (int)$value;
$st[$paramName] += $value;
}
}
}
@@ -1188,39 +1040,39 @@ class Stats
{
//выносливость
if ($st['s4'] > 0) {
$st['hpAll'] += 30;
$st['hpall'] += 30;
}
if ($st['s4'] > 24 && $st['s4'] < 50) {
$st['hpAll'] += 50;
$st['hpall'] += 50;
}
if ($st['s4'] > 49 && $st['s4'] < 75) {
$st['hpAll'] += 100;
$st['hpall'] += 100;
}
if ($st['s4'] > 74 && $st['s4'] < 100) {
$st['hpAll'] += 175;
$st['hpall'] += 175;
$st['m19'] += 2;
}
if ($st['s4'] > 99 && $st['s4'] < 125) {
$st['hpAll'] += 250;
$st['hpall'] += 250;
$st['m19'] += 4;
}
if ($st['s4'] > 124 && $st['s4'] < 150) {
$st['hpAll'] += 400;
$st['hpall'] += 400;
$st['za'] += 25;
$st['zm'] += 25;
}
if ($st['s4'] > 149 && $st['s4'] < 175) {
$st['hpAll'] += 450;
$st['hpall'] += 450;
$st['za'] += 50;
$st['zm'] += 50;
}
if ($st['s4'] > 174 && $st['s4'] < 200) {
$st['hpAll'] += 600;
$st['hpall'] += 600;
$st['za'] += 100;
$st['zm'] += 100;
}
if ($st['s4'] > 199) {
$st['hpAll'] += 850;
$st['hpall'] += 850;
$st['za'] += 125;
$st['zm'] += 125;
}
@@ -1260,38 +1112,38 @@ class Stats
{
//мудрость
if ($st['s6'] > 24 && $st['s6'] < 50) {
$st['mpAll'] += 150;
$st['mpall'] += 150;
$st['speedmp'] += 100;
}
if ($st['s6'] > 49 && $st['s6'] < 75) {
$st['mpAll'] += 200;
$st['mpall'] += 200;
$st['speedmp'] += 200;
}
if ($st['s6'] > 74 && $st['s6'] < 100) {
$st['mpAll'] += 250;
$st['mpall'] += 250;
$st['speedmp'] += 350;
}
if ($st['s6'] > 99 && $st['s6'] < 125) {
$st['mpAll'] += 350;
$st['mpall'] += 350;
$st['speedmp'] += 500;
}
if ($st['s6'] > 124 && $st['s6'] < 150) {
$st['mpAll'] += 500;
$st['mpall'] += 500;
$st['speedmp'] += 500;
$st['pzm'] += 2;
}
if ($st['s6'] > 149 && $st['s6'] < 175) {
$st['mpAll'] += 700;
$st['mpall'] += 700;
$st['speedmp'] += 600;
$st['pzm'] += 3;
}
if ($st['s6'] > 174 && $st['s6'] < 200) {
$st['mpAll'] += 900;
$st['mpall'] += 900;
$st['speedmp'] += 700;
$st['pzm'] += 5;
}
if ($st['s6'] > 199) {
$st['mpAll'] += 900;
$st['mpall'] += 900;
$st['speedmp'] += 700;
$st['pzm'] += 7;
}
@@ -1313,7 +1165,6 @@ class Stats
//Бонус за количество полностью вырытых пещер.
$st['m10'] += 10 * $finishedDungeons;
$st['pzm'] += $finishedDungeons;
}
private function addAdminBonuses(array $u, array &$st): void
@@ -1322,8 +1173,8 @@ class Stats
return;
}
$st['speed_dungeon'] = 500;
$st['speedhp'] = 500;
$this->addKeyIfNotExist('speed_dungeon', 500, $st);
$this->addKeyIfNotExist('speedhp', 500, $st);
if (!$u['battle']) {
return;
@@ -1334,4 +1185,18 @@ class Stats
priems_z = '0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|'
where id = ?", [$u['id']]);
}
/** Переименовывает элементы массива с несовпадающими с остальным скриптом именами полей.
* @param array $st
* @return void
*/
private function renameArrayKeys(array &$st): void
{
$st['lvl'] = $st['level'];
$st['hpNow'] = $st['hpnow'];
$st['mpNow'] = $st['mpnow'];
unset($st['level'], $st['hpnow'], $st['mpnow']);
}
}
+63
View File
@@ -0,0 +1,63 @@
<?php
namespace User;
use Core\Db;
/**
* Íåïîíÿòíûé êóñîê ôóíêöèè, êîòîðûé ëåæàë âíóòðè ñèñòåìû ïîäñ÷¸òà áîíóñîâ ê ïàðàìåòðàì,
* ïðè ýòîì íèêàê íà ýòî íå âëèÿÿ è íè ñ ÷åì íå âçàèìîäåéñòâóÿ. Íàäî ïîíÿòü ÷òî åãî
* âûçûâàåò è âûãíàòü åãî èç User\Stats.
*/
class WearedScrolls
{
public static function ScrollsChange(array &$u): void
{
//Çàìåíà ñâèòêîâ
if ($u['autospell'] == 0 || $u['battle'] != 0) {
return;
}
//ïðîâåðÿåì ñâèòêè
$sparr = [];
foreach (Db::getRows('select item_id, inOdet from items_users where inOdet between 40 and 50 and uid = ? order by item_id desc', [$u['id']]) as $scroll) {
$sparr[] = "{$scroll['item_id']} - {$scroll['inOdet']}";
}
$splink = implode(',', $sparr);
//Çàïîìèíàåì íîâûé êîìïëåêò ñâèòêîâ
if ($u['autospell'] == 1) {
$u['autospell'] = $splink;
Db::sql('update users set autospell = ? where id = ?', [$splink, $u['id']]);
}
//Âûäàåì íóæíûé ñâèòîê, åñëè îí åñòü â èíâåíòàðå
if ($u['autospell'] != $splink) {
$spe1 = explode(',', $splink);
$spe2 = explode(',', $u['autospell']);
$spe1g = [];
$spe2g = [];
for ($i = 0; $i <= 20; $i++) {
$spe1a = explode('-', $spe1[$i]);
$spe2a = explode('-', $spe2[$i]);
if (isset($spe1a[0])) {
$spe1g[$spe1a[1]] = $spe1a[0];
}
if (isset($spe2a[0])) {
$spe2g[$spe2a[1]] = $spe2a[0];
}
}
for ($i = 40; $i <= 50; $i++) {
if ($spe1g[$i] == $spe2g[$i] || $spe1g[$i] != 0) {
continue;
}
Db::sql('update items_users set inOdet = ? where inOdet = 0 and `delete` = 0 and inTransfer = 0 and inShop = 0 and inGroup = 0 and item_id = ? and uid = ?',
[$i, $spe2g[$i], $u['id']]);
}
}
}
}
+38 -38
View File
@@ -1,42 +1,42 @@
<?php
if( isset($s[1]) && $s[1] == '101/i9' ) {
/*
Сундук: ловушка
* Снимает до 1000 НР один раз
*/
//Все переменные сохранять в массиве $vad !
$vad = array(
'go' => false
);
$vad['test'] = mysql_fetch_array(mysql_query('SELECT `id`,`uid` FROM `dungeon_actions` WHERE `dn` = "'.$u->info['dnow'].'" AND `vars` = "obj_act'.$obj['id'].'" LIMIT 1'));
if( !isset($vad['test']['id']) ) {
$vad['go'] = true;
}else{
$r = 'В сундуке была ловушка, её активировал персонаж '.$u->getLogin($vad['test']['uid']);
}
if( $vad['go'] == true ) {
mysql_query('INSERT INTO `dungeon_actions` (`dn`,`time`,`x`,`y`,`uid`,`vars`,`vals`) VALUES (
"'.$u->info['dnow'].'","'.time().'","'.$obj['x'].'","'.$obj['y'].'","'.$u->info['id'].'","obj_act'.$obj['id'].'",""
if (isset($s[1]) && $s[1] == '101/i9') {
/*
Сундук: ловушка
* Снимает до 1000 НР один раз
*/
//Все переменные сохранять в массиве $vad !
$vad = [
'go' => false,
];
$vad['test'] = mysql_fetch_array(mysql_query('SELECT `id`,`uid` FROM `dungeon_actions` WHERE `dn` = "' . $u->info['dnow'] . '" AND `vars` = "obj_act' . $obj['id'] . '" LIMIT 1'));
if (!isset($vad['test']['id'])) {
$vad['go'] = true;
} else {
$r = 'В сундуке была ловушка, её активировал персонаж ' . User::getLogin($vad['test']['uid']);
}
if ($vad['go'] == true) {
mysql_query('INSERT INTO `dungeon_actions` (`dn`,`time`,`x`,`y`,`uid`,`vars`,`vals`) VALUES (
"' . $u->info['dnow'] . '","' . time() . '","' . $obj['x'] . '","' . $obj['y'] . '","' . $u->info['id'] . '","obj_act' . $obj['id'] . '",""
)');
$r = 'В сундуке была ловушка установленная одним из обитателей подземелья!';
$vad['min_hp'] = rand(100,1000);
$u->stats['hpNow'] -= $vad['min_hp'];
if( $u->stats['hpNow'] < 0 ) {
$u->stats['hpNow'] = 0;
}
if($u->info['sex'] == 0) {
$vad['text'] = '[img[items/trap.gif]] <b>'.$u->info['login'].'</b> угодил в ловушку оставленную в &quot;'.$obj['name'].'&quot;. <b>-'.$vad['min_hp'].'</b> ['.floor($u->stats['hpNow']).'/'.round($u->stats['hpAll']).']';
}else{
$vad['text'] = '[img[items/trap.gif]] <b>'.$u->info['login'].'</b> угодила в ловушку оставленную в &quot;'.$obj['name'].'&quot;. <b>-'.$vad['min_hp'].'</b> ['.floor($u->stats['hpNow']).'/'.round($u->stats['hpAll']).']';
}
$this->sys_chat($vad['text']);
$u->info['hpNow'] = $u->stats['hpNow'];
mysql_query('UPDATE `stats` SET `regHP` = "'.time().'",`hpNow` = "'.$u->stats['hpNow'].'" WHERE `id` = "'.$u->stats['id'].'" LIMIT 1');
//
$this->testDie();
}
unset($vad);
$r = 'В сундуке была ловушка установленная одним из обитателей подземелья!';
$vad['min_hp'] = rand(100, 1000);
$u->stats['hpNow'] -= $vad['min_hp'];
if ($u->stats['hpNow'] < 0) {
$u->stats['hpNow'] = 0;
}
if ($u->info['sex'] == 0) {
$vad['text'] = '[img[items/trap.gif]] <b>' . $u->info['login'] . '</b> угодил в ловушку оставленную в &quot;' . $obj['name'] . '&quot;. <b>-' . $vad['min_hp'] . '</b> [' . floor($u->stats['hpNow']) . '/' . round($u->stats['hpAll']) . ']';
} else {
$vad['text'] = '[img[items/trap.gif]] <b>' . $u->info['login'] . '</b> угодила в ловушку оставленную в &quot;' . $obj['name'] . '&quot;. <b>-' . $vad['min_hp'] . '</b> [' . floor($u->stats['hpNow']) . '/' . round($u->stats['hpAll']) . ']';
}
$this->sys_chat($vad['text']);
$u->info['hpNow'] = $u->stats['hpNow'];
mysql_query('UPDATE `stats` SET `regHP` = "' . time() . '",`hpNow` = "' . $u->stats['hpNow'] . '" WHERE `id` = "' . $u->stats['id'] . '" LIMIT 1');
//
$this->testDie();
}
unset($vad);
}
?>