game/_incl_data/class/UserStats.php

34 lines
1.1 KiB
PHP
Raw Normal View History

<?php
2022-12-30 19:03:37 +00:00
use Core\Db;
class UserStats
{
/**
2023-01-10 16:29:32 +00:00
* Собирает суммы всех бонусов с одетых предметов и активных эфектов.
2022-12-30 19:03:37 +00:00
* @param int $userId
* @param bool $showAll
* @return array
*/
2022-12-30 19:03:37 +00:00
public static function getAllBonuses(int $userId, bool $showAll = false): array
{
2022-12-30 19:03:37 +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]);
$params = [];
foreach ($iData as $datum) {
foreach (explode('|', $datum) as $inner) {
2022-12-30 19:03:37 +00:00
[$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;
}
}