game/_incl_data/class/UserStats.php
2023-01-10 18:30:35 +02:00

34 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
use Core\Db;
class UserStats
{
/**
* Собирает суммы всех бонусов с одетых предметов и активных эфектов.
* @param int $userId
* @param bool $showAll
* @return array
*/
public static function getAllBonuses(int $userId, bool $showAll = false): array
{
$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';
$iData = Db::getColumn($q, [$userId, $userId]);
$params = [];
foreach ($iData as $datum) {
foreach (explode('|', $datum) as $inner) {
[$a, $b] = explode('=', $inner);
if (strpos($a, 'add') !== false || strpos($a, 'sv') !== false || $showAll) {
if (isset($params[$a])) {
$params[$a] += $b;
} else {
$params[$a] = $b;
}
}
}
}
return $params;
}
}