2022-08-11 10:38:38 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
2023-04-15 19:52:33 +00:00
|
|
|
|
namespace User;
|
|
|
|
|
|
2022-12-30 19:03:37 +00:00
|
|
|
|
use Core\Db;
|
2023-04-15 19:52:33 +00:00
|
|
|
|
use User;
|
2022-08-11 10:38:38 +00:00
|
|
|
|
|
2023-04-15 19:52:33 +00:00
|
|
|
|
class Stats
|
2022-08-11 10:38:38 +00:00
|
|
|
|
{
|
|
|
|
|
/**
|
2023-01-10 16:29:32 +00:00
|
|
|
|
* Собирает суммы всех бонусов с одетых предметов и активных эфектов.
|
2023-04-15 19:52:33 +00:00
|
|
|
|
* @param int $userId
|
2022-12-30 19:03:37 +00:00
|
|
|
|
* @param bool $showAll
|
2022-08-11 10:38:38 +00:00
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2022-12-30 19:03:37 +00:00
|
|
|
|
public static function getAllBonuses(int $userId, bool $showAll = false): array
|
2022-08-11 10:38:38 +00:00
|
|
|
|
{
|
2022-12-30 19:03:37 +00:00
|
|
|
|
|
2022-08-11 10:38:38 +00:00
|
|
|
|
$q = 'select data from items_users where uid = ? and inOdet > 0 and `delete` = 0
|
|
|
|
|
union all select data from eff_users where uid = ? and `delete` = 0';
|
2022-12-30 19:03:37 +00:00
|
|
|
|
$iData = Db::getColumn($q, [$userId, $userId]);
|
2022-08-11 10:38:38 +00:00
|
|
|
|
$params = [];
|
|
|
|
|
foreach ($iData as $datum) {
|
|
|
|
|
foreach (explode('|', $datum) as $inner) {
|
2022-12-30 19:03:37 +00:00
|
|
|
|
[$a, $b] = explode('=', $inner);
|
2022-08-11 10:38:38 +00:00
|
|
|
|
if (strpos($a, 'add') !== false || strpos($a, 'sv') !== false || $showAll) {
|
|
|
|
|
if (isset($params[$a])) {
|
|
|
|
|
$params[$a] += $b;
|
|
|
|
|
} else {
|
|
|
|
|
$params[$a] = $b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $params;
|
|
|
|
|
}
|
2023-04-15 19:17:40 +00:00
|
|
|
|
|
|
|
|
|
/** Данные для отрисовки логина и полосок жизни\маны.
|
|
|
|
|
* @param User $u
|
|
|
|
|
* @return object
|
|
|
|
|
*/
|
|
|
|
|
public static function getLoginHpManaBars(User $u): object
|
|
|
|
|
{
|
|
|
|
|
$hpNow = floor($u->stats['hpNow']);
|
|
|
|
|
$hpAll = $u->stats['hpAll'];
|
|
|
|
|
$mpNow = floor($u->stats['mpNow']);
|
|
|
|
|
$mpAll = $u->stats['mpAll'];
|
|
|
|
|
|
|
|
|
|
//floor(120 / 100 * ($hpNow / $hpAll * 100)); // ??????
|
|
|
|
|
$ph = ($hpAll > 0 && $hpNow > 0) ? floor(120 / $hpNow / $hpAll) : 0;
|
|
|
|
|
$pm = ($mpAll > 0 && $mpNow > 0) ? floor(120 / $mpNow / $mpAll) : 0;
|
|
|
|
|
|
|
|
|
|
return (object)[
|
|
|
|
|
'uid' => $u->info['id'],
|
|
|
|
|
'login' => $u->microLogin($u->info['id']),
|
|
|
|
|
'hpbarwidth' => $ph,
|
|
|
|
|
'mpbarwidth' => $pm,
|
|
|
|
|
'hpbartext' => ' ' . $hpNow . '/' . $hpAll,
|
|
|
|
|
'mpbartext' => ' ' . $mpNow . '/' . $mpAll,
|
|
|
|
|
'divstyle' => $pm === 0 ? ' margin-top:13px;' : '',
|
|
|
|
|
'hasmana' => $mpAll > 0,
|
|
|
|
|
];
|
|
|
|
|
}
|
2023-04-15 19:52:33 +00:00
|
|
|
|
|
|
|
|
|
|
2022-08-11 10:38:38 +00:00
|
|
|
|
}
|