game/_incl_data/class/User/Stats.php

1255 lines
42 KiB
PHP
Raw Normal View History

<?php
namespace User;
2023-11-02 13:57:39 +00:00
use Core\Config;
2022-12-30 19:03:37 +00:00
use Core\Db;
use Helper\Comparsion;
2023-08-15 22:48:29 +00:00
use Helper\Conversion;
use Model\Constant\Stat;
use User;
class Stats
{
2023-08-15 22:48:29 +00:00
private User $u;
/** Список разрешённых для бонусов системных названий статов
* @var array
*/
private array $sysNames;
2023-08-15 22:48:29 +00:00
private array $statsKeys = [];
2023-08-15 22:48:29 +00:00
public function __construct(User $user)
{
$this->u = $user;
$this->sysNames = (new Stat())->getBonusNames();
2023-08-15 22:48:29 +00:00
}
/**
2023-08-15 22:48:29 +00:00
* Собирает суммы всех бонусов с одетых предметов, комплектов предметов, активных эфектов.
* @param int $userId
* @return array
*/
2023-08-15 22:48:29 +00:00
public static function getAllBonuses(int $userId): array
{
2023-08-15 22:48:29 +00:00
$iData = [];
$im = ItemsModel::getWearedItems($userId);
foreach ($im as $item) {
$iData[] = $item['data'];
}
$iData[] = Db::getValue('select data from eff_users where uid = ? and `delete` = 0', [$userId]);
2022-12-30 19:03:37 +00:00
$params = [];
2023-08-15 22:48:29 +00:00
$complects = [];
foreach ($iData as $datum) {
2023-08-15 22:48:29 +00:00
$arr = Conversion::dataStringToArray($datum);
foreach ($arr as $k => $v) {
if ($k === 'complect') {
if (isset($complects[$v])) {
$complects[$v]++;
} else {
2023-08-15 22:48:29 +00:00
$complects[$v] = 1;
}
}
if (!str_contains($k, 'add_')) {
2023-08-15 22:48:29 +00:00
continue;
}
$k = str_replace('add_', '', $k);
self::setBonusValue($params, $k, $v);
}
}
return self::addComplectsBonuses($complects, $params);
2023-08-15 22:48:29 +00:00
}
private static function setBonusValue(array &$array, $key, $value): void
2023-08-15 22:48:29 +00:00
{
if (isset($array[$key])) {
$array[$key] += $value;
} else {
$array[$key] = $value;
}
}
/**
* @param array $complects
* @param array $params
* @return array
*/
private static function addComplectsBonuses(array $complects, array $params): array
{
$cdata = [];
if (!empty($complects)) {
foreach ($complects as $complectId => $wearedItemsQuantity) {
$cdata[] = Db::getValue('select data from complects where com = ? and x <= ? order by x desc limit 1', [$complectId, $wearedItemsQuantity]);
}
foreach ($cdata as $datum) {
$arr = Conversion::dataStringToArray($datum);
foreach ($arr as $k => $v) {
self::setBonusValue($params, $k, $v);
}
}
}
return $params;
}
/** Данные для отрисовки логина и полосок жизни\маны.
* @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' => User::getLogin($u->info['id']),
'hpbarwidth' => $ph,
'mpbarwidth' => $pm,
'hpbartext' => ' ' . $hpNow . '/' . $hpAll,
'mpbartext' => ' ' . $mpNow . '/' . $mpAll,
'divstyle' => $pm === 0 ? ' margin-top:13px;' : '',
'hasmana' => $mpAll > 0,
];
}
2023-12-19 01:58:37 +00:00
public function getStats(int|array|null $uid = null, $i1 = 0, $reimg = false, $btl_cache = false): array
2023-08-15 22:48:29 +00:00
{
2023-12-19 01:58:37 +00:00
$u = match (true) {
empty($uid) => User::getInfo($this->u->info['id']),
is_array($uid) => $uid,
default => User::getInfo($uid),
};
2023-08-15 22:48:29 +00:00
2023-11-02 13:57:39 +00:00
if (!isset($u['id'])) {
2023-08-15 22:48:29 +00:00
return [];
}
// Как? Нахуя 4 переменные разные для одного и того же?
2023-11-09 17:24:47 +00:00
$st = array_fill_keys($this->sysNames, 0);
$sti = $st;
$s_v = $st;
$s_vi = $st;
2023-11-09 17:24:47 +00:00
2023-08-15 22:48:29 +00:00
$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 ($r1) {
$this->addKeyIfNotExist('clanpos', $r1, $st);
2023-08-15 22:48:29 +00:00
}
}
$lvl = Db::getRow('select * from levels where upLevel = ?', [$u['upLevel']]);
if (isset($lvl['upLevel'])) {
$st['levels'] = $lvl;
} else {
$st['levels'] = 'undefined';
}
2023-11-02 13:57:39 +00:00
2023-08-15 22:48:29 +00:00
$st['id'] = $u['id'];
$st['login'] = $u['login'];
$st['level'] = $u['level'];
2023-08-15 22:48:29 +00:00
$st['hpNow'] = $u['hpNow'];
2023-08-15 22:48:29 +00:00
$st['mpNow'] = $u['mpNow'];
2023-08-15 22:48:29 +00:00
$st['zona'] = 1;
$st['zonb'] = 2;
$st['items'] = [];
$st['effects'] = [];
2023-08-15 22:48:29 +00:00
$st['vip'] = $u['vip'];
foreach (Conversion::dataStringToArray($u['stats']) as $stat => $value) {
$this->addKeyIfNotExist($stat, (int)$value, $st);
2023-08-15 22:48:29 +00:00
}
2023-11-02 13:57:39 +00:00
$baseStats = $st;
2023-08-15 22:48:29 +00:00
//Шаблонные картинки
if ($this->u->info['id'] === $u['id'] || $reimg) {
$itemsImages = Db::getRows('select * from items_img where uid = ? and img_id != 0', [$u['id']]);
2023-08-15 22:48:29 +00:00
foreach ($itemsImages as $itemsImage) {
$reimage = Db::getRow('select * from reimage where ((uid = ? and clan = 0) or clan = ?) and good > 0 and bad = 0 and id = ?', [$u['id'], $u['clan'], $itemsImage['img_id']]);
if (isset($reimage['id'])) {
$st['items_img'][$itemsImage['type']] = $reimage['id'] . '.' . $reimage['format'];
} else {
Db::sql('update items_img set img_id = 0 where id = ?', [$itemsImage['id']]);
}
}
}
[$hnd1, $hnd2, $sht1, $oza, $ozm, $dom, $coms] = $this->addWearedItemsBonuses($u['id'], $st, $s_v, $baseStats);
$this->addMedalsBonuses($u['id'], $st);
$noeffectbattle = false;
if ($u['battle'] > 0) {
$noeffectbattle = (bool)Db::getValue("select 1 from battle_actions where uid = ? and vars = 'noeffectbattle1' and btl = ? limit 1", [$u['id'], $u['battle']]);
}
//Характеристики от эффектов
$h = 0;
$nbs = array_fill_keys(range(4899, 4909), 0);
$prsu = [];
if (!$noeffectbattle) {
$efs = Db::getRows("select * from eff_users left join eff_main on id2 = id_eff where uid = ? and deactiveTime < unix_timestamp() and v1 != 'priem' order by id desc", [$u['id']]);
foreach ($efs as $e) {
if ($u['dnow'] == 0) {
if ($u['battle'] == 0) {
Db::sql('delete from eff_users where id_eff = ? and uid = ? and id != ?', [$e['id_eff'], $u['id'], $e['id']]);
//Переводим в заряды
if ($e['hod'] != -1) {
Db::sql('update eff_users set hod = -1, timeUse = unix_timestamp() + ? where id = ?', [$e['hod'] * Config::get('effz') - $e['actionTime'], $e['id']]);
}
} elseif (Config::get('effz') > 0 && $e['hod'] == -1) {
$efzz = round(($e['timeUse'] + $e['actionTime'] + $e['timeAce']) - time());
if ($efzz > 0) {
Db::sql('update eff_users set hod = ? where id = ?', [$efzz / Config::get('effz'), $e['id']]);
}
}
}
if ($e['timeUse'] + $e['timeAce'] + $e['actionTime'] > time() || $e['timeUse'] == 77) {
if ($e['v1'] == 'priem') {
$prsu[$e['v2']] = 0 + $prsu['x'];
}
$st['effects'][$h] = $e;
$h++;
$sts = Conversion::dataStringToArray($e['data']);
if (isset($sts['itempl']) && $sts['itempl'] > 0) {
$nbs[$sts['itempl']] += 1;
}
if (isset($sts['puti'])) {
$this->addKeyIfNotExist('puti', $sts['puti'], $st);
}
if (isset($sts['add_silver'])) {
$this->addKeyIfNotExist('slvtm', $e['timeUse'] + $e['actionTime'], $st);
}
$this->addValuesToAllArrays($sts, $st, $sti, $s_v, $s_vi);
} else {
//удаляем эффект
if (
$e['img2'] != 'tz.gif' ||
$u['id'] == $this->u->info['id']
) {
if ($e['sleeptime'] == 0) {
$this->u->endEffect($e['id'], $u);
}
$st['act'] = 1;
}
}
}
} else {
$st['noeffectbattle1'] = 1;
}
$this->addWearedItemsIllusion($nbs, $st);
$this->addInBattlePriemsBonuses($u, $st, $prsu, $sti, $s_v, $s_vi);
//Характеристики от статов
$st['hpall'] += $st['s4'] * 5;
$st['mpall'] += $st['s6'] * 10;
//Турнир
$st['m1'] += $st['s3'] * 5;
// мф.анти-крит = 2.5
$st['m2'] += $st['s3'] * 5;
// мф.уворот = 2.5
$st['m4'] += $st['s2'] * 5;
// мф.анти-уворот = 2.5
$st['m5'] += $st['s2'] * 5;
$st['za'] += $st['s4'] * 1.0;
$st['m19'] += round($st['s3'] * 0.03);
//Мощности
//Мощность против "Мощность крит. урона". Гамс
$st['antm3'] += $st['s5'] * 0.5;
//Бонусы комплектов
if (is_iterable($coms['new'])) {
foreach ($coms['new'] as $complect) {
2023-12-19 01:58:37 +00:00
$com = Db::getValue(
'select data from complects where com = ? and x <= ? order by x desc limit 1',
[
(int)$complect,
(int)$coms['com'][$complect], // кол-во предметов данного комплекта
2023-12-19 01:58:37 +00:00
]
);
if (!$com) {
continue;
}
$sti = Conversion::dataStringToArray($com);
foreach ($this->sysNames as $stat) {
if (!isset($sti[$stat])) {
continue;
}
$st[$stat] += $sti[$stat];
}
}
}
//Что за нахер?
WearedScrolls::ScrollsChange($u);
//Бонусы статов
$this->addStatBonuses($st);
//если второе оружие одето
if ($hnd2 == 1 && $hnd1 == 1) {
$st['zona']++;
}
if ($sht1 == 1) {
$st['zonb']++;
}/* Владения */
//mib1-mib4, mab1-mab4 armor??
if (isset($st['s5'])) {
$st['pm1'] += $st['s5'] * 0.5;
$st['pm2'] += $st['s5'] * 0.5;
$st['pm3'] += $st['s5'] * 0.5;
$st['pm4'] += $st['s5'] * 0.5;
$st['pm7'] += $st['s5'] * 0.5;
}
if (isset($st['m11a'])) {
$st['pm1'] += $st['m11a'] * 0.5;
$st['pm2'] += $st['m11a'] * 0.5;
$st['pm3'] += $st['m11a'] * 0.5;
$st['pm4'] += $st['m11a'] * 0.5;
$st['pm7'] += $st['m11a'] * 0.5;
}
if (isset($st['aall'])) {
$st['a1'] += $st['aall'];
$st['a2'] += $st['aall'];
$st['a3'] += $st['aall'];
$st['a4'] += $st['aall'];
$st['a5'] += $st['aall'];
}
if (isset($st['m2all'])) {
$st['mg1'] += $st['m2all'];
$st['mg2'] += $st['m2all'];
$st['mg3'] += $st['m2all'];
$st['mg4'] += $st['m2all'];
$st['mg7'] += $st['m2all'];
}
if (isset($st['zm'])) {
$st['zm1'] += $st['zm'];
$st['zm2'] += $st['zm'];
$st['zm3'] += $st['zm'];
$st['zm4'] += $st['zm'];
$st['zm5'] += $st['zm'];
$st['zm6'] += $st['zm'];
$st['zm7'] += $st['zm'];
}
if (isset($st['zma'])) {
$st['zm1'] += $st['zma'];
$st['zm2'] += $st['zma'];
$st['zm3'] += $st['zma'];
$st['zm4'] += $st['zma'];
$st['zm5'] += $st['zma'];
$st['zm6'] += $st['zma'];
$st['zm7'] += $st['zma'];
}
if (isset($st['mall'])) {
$st['mg1'] += $st['mall'];
$st['mg2'] += $st['mall'];
$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'];
$st['za3'] += $st['za'];
$st['za4'] += $st['za'];
}
if (!empty($st['hpVinos'])) {
$st['hpall'] += round($st['hpVinos'] * $st['s4']);
}
if (!empty($st['mpVinos'])) {
$st['mpall'] += round($st['mpVinos'] * $st['s6']);
}
if (!empty($st['hpProc'])) {
$st['hpall'] += round($st['hpall'] / 100 * $st['hpProc']);
}
if (!empty($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']);
//зоны блока и удара
if ($st['zona'] < 1) {
$st['zona'] = 1;
}
if ($st['zona'] > 5) {
$st['zona'] = 5;
}
if ($st['zonb'] < 1) {
$st['zonb'] = 1;
}
if ($st['zonb'] > 3) {
$st['zonb'] = 3;
}
$st['ozash'] = $oza;
$st['ozmsh'] = $ozm;
$st['weapon1'] = $hnd1;
$st['weapon2'] = $hnd2;
$st['sheld1'] = $sht1;
$st['sv_'] = $s_v;
$st['sv_i'] = $s_vi;
$st['dom'] = $dom;
$st['prsu'] = $prsu;
$st['x'] = $u['x'];
$st['y'] = $u['y'];
$st['s'] = $u['s'];
$this->addDungeonsBonuses($u['id'], $st);
//Добавочный подьем для игроков
$this->addKeyIfNotExist('maxves', 100, $st);
$this->addAdminBonuses($u, $st);
if (date('H') >= 22 && date('H') <= 10) {
$this->addKeyIfNotExist('exp', 25, $st);
}
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['mpall'] < 0) {
$st['mpall'] = 0;
}
if (stristr($u['login'], '(зверь ') || (stristr($u['login'], 'Каменный страж') && $u['ip'] == '0')) {
$st['this_animal'] = 1;
} else {
$st['this_animal'] = 0;
}
$this->renameArrayKeys($st);
$rt = [];
if ($i1 == 1) {
$rt[0] = $st;
$rt[1] = $baseStats; //родные статы
} 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 ($btl_cache) {
$dataca = [
'st' => $st,
'st2' => $baseStats,
];
$dataca = json_encode($dataca);
Db::sql('insert into battle_cache (battle, uid, time, data) values (?,?,unix_timestamp(),?)', [$u['battle'], $u['id'], $dataca]);
}
return $rt;
}
/** Собираем динамически создаваемые параметры. Если ключа нет - создаём.
* @param string $key
2023-12-19 01:58:37 +00:00
* @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
{
2023-08-15 22:48:29 +00:00
//Характеристики от предметов //ТУТ tr_lvl
// Вся вторая строчка - спасибо Users.
2023-12-19 01:58:37 +00:00
$wearedItems = Db::getRows(
'select type, data, inOdet,
2023-08-15 22:48:29 +00:00
item_id, inslot, useInBattle, btl_zd, iznosNOW, iznosMAX, magic_inci, name, items_users.id, img, `2h`
2023-12-19 01:58:37 +00:00
from items_users left join items_main on items_main.id = item_id where inOdet != 0 and uid = ?', [$uid]
);
2023-08-15 22:48:29 +00:00
$h = 0;
$hnd1 = 0;
$hnd2 = 0;
$sht1 = 0;
$reitm = [];
$coms = []; // комплекты
$dom = [];
$oza = [
1 => [0, 0],
2 => [0, 0],
3 => [0, 0],
4 => [0, 0],
]; //особенности защиты
$ozm = [
1 => [0, 0],
2 => [0, 0],
3 => [0, 0],
4 => [0, 0],
]; //особенности магии
$ozaozmtypes = [
1 => [1, 9,],//Слабая
2 => [20, 39,],//Нормальная
3 => [40, 69,],//Хорошая
4 => [10, 19,],//Посредственная
5 => [70, 89,],//Великолепная
];
2023-08-15 22:48:29 +00:00
foreach ($wearedItems as $wearedItem) {
$this->addKeyIfNotExist('wp' . $wearedItem['inOdet'] . 'id', $h, $st);
2023-08-15 22:48:29 +00:00
$st['items'][$h] = $wearedItem;
$h++;
if ($wearedItem['inOdet'] == 3 &&
(($wearedItem['type'] >= 18 && $wearedItem['type'] <= 24) ||
$wearedItem['type'] == 26 ||
$wearedItem['type'] == 27 ||
$wearedItem['type'] == 28)) {
2023-08-15 22:48:29 +00:00
$hnd1 = 1;
}
if ($wearedItem['inOdet'] == 14 &&
(($wearedItem['type'] >= 18 && $wearedItem['type'] <= 24) ||
$wearedItem['type'] == 26 ||
$wearedItem['type'] == 27 ||
$wearedItem['type'] == 28)) {
2023-08-15 22:48:29 +00:00
$hnd2 = 1;
} elseif ($wearedItem['inOdet'] == 14 && $wearedItem['type'] == 13) {
$sht1 = 1;
}
$data = Conversion::dataStringToArray($wearedItem['data']);
2023-08-15 22:48:29 +00:00
if ($wearedItem['inOdet'] <= 18 && $wearedItem['inOdet'] > 0) {
$this->addKeyIfNotExist('reting', 1, $st);
2023-08-15 22:48:29 +00:00
}
if (isset($data['add_oza'])) {
$oza = array_fill_keys($oza, $ozaozmtypes[$data['add_oza']]);
2023-08-15 22:48:29 +00:00
}
if (isset($data['add_ozm'])) {
$ozm = array_fill_keys($ozm, $ozaozmtypes[$data['add_ozm']]);
} else {
$ozm = array_fill_keys($ozm, $ozaozmtypes[1]);
2023-08-15 22:48:29 +00:00
}
if (in_array($data['add_oza1'], range(1, 5))) {
$oza[1] = $ozaozmtypes[$data['add_oza1']];
}
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];
2023-08-15 22:48:29 +00:00
}
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;
2023-08-15 22:48:29 +00:00
if (!isset($coms['new'])) {
$coms['new'] = [];
}
$coms['new'][count($coms['new'])] = $data['complect'];
2023-08-15 22:48:29 +00:00
}
$coms['com'][$data['complect']]++;
2023-08-15 22:48:29 +00:00
}
if (isset($data['complect2'])) {
$coms[count($coms)]['id'] = $data['complect2'];
if (!isset($coms['com'][$data['complect2']])) {
$coms['com'][$data['complect2']] = 0;
2023-08-15 22:48:29 +00:00
if (!isset($coms['new'])) {
$coms['new'] = [];
}
$coms['new'][count($coms['new'])] = $data['complect2'];
2023-08-15 22:48:29 +00:00
}
$coms['com'][$data['complect2']]++;
2023-08-15 22:48:29 +00:00
}
if (!empty($data['zonb'])) {
$this->addKeyIfNotExist('zonb', $data['zonb'], $st);
2023-08-15 22:48:29 +00:00
}
if (!empty($data['zona'])) {
$this->addKeyIfNotExist('zona', $data['zona'], $st);
2023-08-15 22:48:29 +00:00
}
//Добавляем статы от данного предмета
if (!isset($data['restart_stats'])) {
foreach ($this->sysNames as $stat) {
if (!isset($data['add_' . $stat])) {
continue;
2023-08-15 22:48:29 +00:00
}
$st[$stat] += (int)$data['add_' . $stat];
2023-08-15 22:48:29 +00:00
}
} else {
$reitm[] = $data;
2023-08-15 22:48:29 +00:00
}
2023-11-09 17:24:47 +00:00
foreach ($this->sysNames as $stat) {
if (!isset($data['sv_' . $stat])) {
continue;
2023-08-15 22:48:29 +00:00
}
$s_v[$stat] += (int)$data['sv_' . $stat];
2023-08-15 22:48:29 +00:00
}
}
//Сохраненные хар-ки и умения
if (!empty($reitm) && is_iterable($reitm)) {
$i39 = [];
foreach ($reitm as $item) {
if (isset($item['sm_skill']) && $i39[0] == 0) {
2023-08-15 22:48:29 +00:00
//умения
$i39[0] = 1;
$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) {
2023-08-15 22:48:29 +00:00
//статы
$i39[1] = 1;
$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) {
2023-08-15 22:48:29 +00:00
//навыки
$i39[2] = 1;
}
}
}
return [$hnd1, $hnd2, $sht1, $oza, $ozm, $dom, $coms];
}
2023-08-15 22:48:29 +00:00
private function addMedalsBonuses(int $uid, array &$st): void
{
//Харки от иконок
2023-08-15 22:48:29 +00:00
$efs = Db::getColumn('select bonus from users_ico where uid = ? and (endTime > unix_timestamp() or endTime = 0)', [$uid]);
foreach ($efs as $data) {
$sts = Conversion::dataStringToArray($data);
foreach ($sts as $paramName => $value) {
if (!in_array($paramName, $this->sysNames, true)) { // есть ли параметр в разрешенных?
continue;
2023-08-15 22:48:29 +00:00
}
$st[$paramName] += $value;
}
}
}
2023-11-09 17:24:47 +00:00
private function addValuesToAllArrays(array $sts, array &$st, array &$sti, array &$s_v, array &$s_vi): void
{
foreach ($this->sysNames as $stat) {
if (!isset($sts['add_' . $stat])) {
continue;
}
$st[$stat] += intval($sts['add_' . $stat]);
$sti[$stat] += intval($sts['add_' . $stat]);
2023-11-09 17:24:47 +00:00
if (!isset($sts['sv_' . $stat])) {
continue;
2023-08-15 22:48:29 +00:00
}
$s_v[$stat] += intval($sts['sv_' . $stat]);
$s_vi[$stat] += intval($sts['sv_' . $stat]);
}
}
private function addWearedItemsIllusion(array $nbs, array &$st): void
{
//Заглушки от эффектов
2023-08-15 22:48:29 +00:00
if ($nbs[4899] > 0) {
//Зеленый комплект
$st['items_img'][8] = 'robe_illusion4.gif';
$st['items_img'][11] = 'leg_illusion4.gif';
} elseif ($nbs[4900] > 0) {
//Золото комплект
$st['items_img'][8] = 'robe_illusion5.gif';
$st['items_img'][11] = 'leg_illusion5.gif';
} elseif ($nbs[4901] > 0) {
//Голубой комплект
$st['items_img'][8] = 'robe_illusion3.gif';
$st['items_img'][11] = 'leg_illusion3.gif';
} elseif ($nbs[4902] > 0) {
//Синий комплект
$st['items_img'][8] = 'robe_illusion6.gif';
$st['items_img'][11] = 'leg_illusion6.gif';
} elseif ($nbs[4903] > 0) {
//Желтый комплект
$st['items_img'][8] = 'robe_illusion8.gif';
$st['items_img'][11] = 'leg_illusion8.gif';
} elseif ($nbs[4904] > 0) {
//Сиреневое платье
$st['items_img'][8] = 'robe_illusion7.gif';
$st['items_img'][11] = 'leg_illusion7.gif';
} elseif ($nbs[4905] > 0) {
//Оранжевое платье
$st['items_img'][8] = 'robe_illusion9.gif';
$st['items_img'][11] = 'leg_illusion9.gif';
} elseif ($nbs[4908] > 0) {
//Набор Темной Одежды
$st['items_img'][8] = 'robe_illusion2.gif';
$st['items_img'][11] = 'leg_illusion2.gif';
$st['items_img'][10] = 'boots_illusion2.gif';
$st['items_img'][9] = 'belt_illusion2.gif';
$st['items_img'][5] = 'naruchi_illusion2.gif';
$st['items_img'][4] = 'helmet_illusion2.gif';
$st['items_img'][12] = 'perchi_illusion2.gif';
} elseif ($nbs[4906] > 0) {
//Набор Бриллиантовой Одежды
$st['items_img'][8] = 'robe_illusion1.gif';
$st['items_img'][11] = 'leg_illusion1.gif';
$st['items_img'][10] = 'boots_illusion1.gif';
$st['items_img'][9] = 'belt_illusion1.gif';
$st['items_img'][5] = 'naruchi_illusion1.gif';
$st['items_img'][4] = 'helmet_illusion1.gif';
$st['items_img'][12] = 'perchi_illusion1.gif';
}
if ($nbs[4909] > 0) {
//Набор Золотых украшений
$st['items_img'][13] = 'ring_illusion2.gif';
$st['items_img'][17] = 'ring_illusion2.gif';
$st['items_img'][18] = 'ring_illusion2.gif';
$st['items_img'][14] = 'amulet_illusion2.gif';
$st['items_img'][15] = 'earrings_illusion2.gif';
} elseif ($nbs[4907] > 0) {
//Набор Золотых украшений
$st['items_img'][13] = 'ring_illusion1.gif';
$st['items_img'][17] = 'ring_illusion1.gif';
$st['items_img'][18] = 'ring_illusion1.gif';
$st['items_img'][14] = 'amulet_illusion1.gif';
$st['items_img'][15] = 'earrings_illusion1.gif';
}
}
2023-08-15 22:48:29 +00:00
private function addInBattlePriemsBonuses(array $u, array &$st, array &$prsu, array &$sti, array &$s_v, array &$s_vi): void
{
if ($u['battle'] <= 0) {
return;
}
//Характеристики от приемов
$st['set_pog'] = [];
$st['set_pog2'] = [];
$efs = Db::getRows("select * from eff_users where uid = ? and deactiveTime < unix_timestamp() and v1 = 'priem' order by id", [$u['id']]);
$h = 0;
foreach ($efs as $e) {
$e['type1'] = 14;
$e['img'] = $e['img2'];
if ($e['tr_life_user'] > 0) {
$trlu = Db::getValue('select hpNow from stats where id = ?', [$e['tr_life_user']]);
if (!$trlu || $trlu < 1) {
2023-08-15 22:48:29 +00:00
$this->u->endEffect($e['id'], $u);
$st['act'] = 1;
}
}
if ($e['timeUse'] + $e['timeAce'] + $e['actionTime'] > time() || $e['timeUse'] == 77) {
if ($e['v1'] == 'priem') {
$prsu[$e['v2']] = 0 + $prsu['x'];
2023-08-15 22:48:29 +00:00
}
$st['effects'][$h] = $e;
$h++;
$sts = Conversion::dataStringToArray($e['data']);
if ($e['v2'] == 217) {
$st['raztac'] = 1;
2023-11-02 13:57:39 +00:00
}
if (isset($sts['add_pog'])) {
$ctt = count($st['set_pog']);
$st['set_pog'][$ctt]['id'] = $h;
$st['set_pog'][$ctt]['y'] = $sts['add_pog'];
unset($ctt);
2023-11-02 13:57:39 +00:00
}
if (isset($sts['natoe'])) {
$st['set_natoe']['id'] = $h;
$st['set_natoe']['a'] = 0 + $sts['natoe_end'];
$st['set_natoe']['b'] = 0 + $sts['natoe'];
$st['set_natoe']['eff_id'] = $e['id'];
$st['set_natoe']['t'] = 0 + $sts['natoe_type'];
$st['set_natoe']['user_id'] = $e['tr_life_user'];
2023-11-02 13:57:39 +00:00
}
if (isset($sts['add_pog2'])) {
$ctt = count($st['set_pog2']);
$st['set_pog2'][$ctt]['id'] = $h;
$st['set_pog2'][$ctt]['y'] = $sts['add_pog2'];
$st['set_pog2'][$ctt]['p'] = $sts['add_pog2p'];
$st['set_pog2'][$ctt]['m'] = $sts['add_pog2mp'];
unset($ctt);
2023-11-02 13:57:39 +00:00
}
$this->addValuesToAllArrays($sts, $st, $sti, $s_v, $s_vi);
2023-11-02 13:57:39 +00:00
} else {
//удаляем эффект
$this->u->endEffect($e['id'], $u);
$st['act'] = 1;
2023-11-02 13:57:39 +00:00
}
}
}
private function addStatBonuses(array &$st): void
{
$this->addStrengthBonuses($st);
$this->addDexterityBonuses($st);
$this->addIntuitionBonuses($st);
$this->addEnduranceBonuses($st);
$this->addIntelligenceBonuses($st);
$this->addWisdomBonuses($st);
}
private function addStrengthBonuses(array &$st): void
{
2023-08-15 22:48:29 +00:00
if ($st['s1'] > 24 && $st['s1'] < 50) {
$st['m2'] += 15;
}
if ($st['s1'] > 49 && $st['s1'] < 75) {
$st['pa2'] += 2;
$st['m2'] += 35;
}
if ($st['s1'] > 74 && $st['s1'] < 100) {
$st['pa2'] += 5;
$st['m2'] += 50;
}
if ($st['s1'] > 99 && $st['s1'] < 125) {
$st['pa2'] += 8;
$st['m2'] += 80;
}
if ($st['s1'] > 124 && $st['s1'] < 150) {
$st['pa2'] += 12;
$st['m2'] += 105;
}
if ($st['s1'] > 149 && $st['s1'] < 175) {
$st['pa2'] += 17;
$st['m7'] += 2;
}
if ($st['s1'] > 174 && $st['s1'] < 200) {
$st['pa2'] += 23;
$st['m7'] += 5;
}
if ($st['s1'] > 199) {
$st['pa2'] += 30;
$st['m7'] += 7;
}
2023-11-02 13:57:39 +00:00
}
private function addDexterityBonuses(array &$st): void
{
2023-08-15 22:48:29 +00:00
if ($st['s2'] > 24 && $st['s2'] < 50) {
$st['pa1'] += 2;
$st['m4'] += 35;
}
if ($st['s2'] > 49 && $st['s2'] < 75) {
$st['pa1'] += 5;
$st['m2'] += 40;
$st['m4'] += 75;
}
if ($st['s2'] > 74 && $st['s2'] < 100) {
$st['pa1'] += 8;
$st['m2'] += 65;
$st['m4'] += 90;
}
if ($st['s2'] > 99 && $st['s2'] < 125) {
$st['pa1'] += 12;
$st['m2'] += 75;
$st['m4'] += 105;
}
if ($st['s2'] > 124 && $st['s2'] < 150) {
$st['pa1'] += 17;
$st['m2'] += 85;
$st['m4'] += 105;
$st['m15'] += 1;
}
if ($st['s2'] > 149 && $st['s2'] < 175) {
$st['pa1'] += 20;
$st['m2'] += 110;
$st['m4'] += 115;
$st['m15'] += 2;
}
if ($st['s2'] > 174 && $st['s2'] < 200) {
$st['pa1'] += 23;
$st['m2'] += 145;
$st['m4'] += 145;
$st['m15'] += 3;
}
if ($st['s2'] > 199) {
$st['pa1'] += 30;
$st['m2'] += 165;
$st['m4'] += 165;
$st['m15'] += 5;
2023-11-02 13:57:39 +00:00
}
}
private function addIntuitionBonuses(array &$st): void
{
if ($st['s3'] >= 200) {
2023-08-15 22:48:29 +00:00
$st['m1'] += 185;
$st['m3'] += 40;
2023-08-15 22:48:29 +00:00
$st['m5'] += 65;
$st['m14'] += 5;
$st['pa4'] += 30;
} elseif ($st['s3'] >= 175) {
$st['m1'] += 165;
$st['m3'] += 35;
$st['m5'] += 55;
$st['m14'] += 3;
$st['pa4'] += 23;
} elseif ($st['s3'] >= 150) {
$st['m1'] += 145;
$st['m3'] += 30;
$st['m5'] += 50;
$st['m14'] += 2;
$st['pa4'] += 20;
} elseif ($st['s3'] >= 125) {
$st['m1'] += 125;
$st['m3'] += 20;
$st['m5'] += 45;
$st['m14'] += 1;
$st['pa4'] += 17;
} elseif ($st['s3'] >= 100) {
$st['m1'] += 105;
$st['m3'] += 15;
$st['m5'] += 35;
$st['pa4'] += 12;
} elseif ($st['s3'] >= 75) {
$st['m1'] += 75;
$st['m3'] += 10;
$st['m5'] += 25;
$st['pa4'] += 8;
} elseif ($st['s3'] >= 50) {
$st['m1'] += 55;
$st['m3'] += 5;
$st['pa4'] += 5;
} elseif ($st['s3'] >= 25) {
$st['m1'] += 25;
$st['m3'] += 2;
$st['pa4'] += 2;
2023-11-02 13:57:39 +00:00
}
}
private function addEnduranceBonuses(array &$st): void
{
//выносливость
2023-08-15 22:48:29 +00:00
if ($st['s4'] > 0) {
$st['hpall'] += 30;
2023-08-15 22:48:29 +00:00
}
if ($st['s4'] > 24 && $st['s4'] < 50) {
$st['hpall'] += 50;
2023-08-15 22:48:29 +00:00
}
if ($st['s4'] > 49 && $st['s4'] < 75) {
$st['hpall'] += 100;
2023-08-15 22:48:29 +00:00
}
if ($st['s4'] > 74 && $st['s4'] < 100) {
$st['hpall'] += 175;
2023-08-15 22:48:29 +00:00
$st['m19'] += 2;
}
if ($st['s4'] > 99 && $st['s4'] < 125) {
$st['hpall'] += 250;
2023-08-15 22:48:29 +00:00
$st['m19'] += 4;
}
if ($st['s4'] > 124 && $st['s4'] < 150) {
$st['hpall'] += 400;
2023-08-15 22:48:29 +00:00
$st['za'] += 25;
$st['zm'] += 25;
}
if ($st['s4'] > 149 && $st['s4'] < 175) {
$st['hpall'] += 450;
2023-08-15 22:48:29 +00:00
$st['za'] += 50;
$st['zm'] += 50;
}
if ($st['s4'] > 174 && $st['s4'] < 200) {
$st['hpall'] += 600;
2023-08-15 22:48:29 +00:00
$st['za'] += 100;
$st['zm'] += 100;
}
if ($st['s4'] > 199) {
$st['hpall'] += 850;
2023-08-15 22:48:29 +00:00
$st['za'] += 125;
$st['zm'] += 125;
2023-11-02 13:57:39 +00:00
}
}
private function addIntelligenceBonuses(array &$st): void
{
2023-12-19 01:58:37 +00:00
//интелект
2023-08-15 22:48:29 +00:00
if ($st['s5'] > 24 && $st['s5'] < 50) {
$st['m11'] += 10;
}
if ($st['s5'] > 49 && $st['s5'] < 75) {
$st['m11'] += 15;
}
if ($st['s5'] > 74 && $st['s5'] < 100) {
$st['m11'] += 20;
}
if ($st['s5'] > 99 && $st['s5'] < 125) {
$st['m11'] += 25;
}
if ($st['s5'] > 124 && $st['s5'] < 150) {
$st['m11'] += 35;
}
if ($st['s5'] > 149 && $st['s5'] < 175) {
$st['m11'] += 50;
}
if ($st['s5'] > 174) {
$st['m11'] += 65;
$st['pzm'] += 2;
}
if ($st['s5'] > 199) {
$st['pzm'] += 5;
2023-11-02 13:57:39 +00:00
}
}
private function addWisdomBonuses(array &$st): void
{
2023-12-19 01:58:37 +00:00
//мудрость
2023-08-15 22:48:29 +00:00
if ($st['s6'] > 24 && $st['s6'] < 50) {
$st['mpall'] += 150;
2023-08-15 22:48:29 +00:00
$st['speedmp'] += 100;
}
if ($st['s6'] > 49 && $st['s6'] < 75) {
$st['mpall'] += 200;
2023-08-15 22:48:29 +00:00
$st['speedmp'] += 200;
}
if ($st['s6'] > 74 && $st['s6'] < 100) {
$st['mpall'] += 250;
2023-08-15 22:48:29 +00:00
$st['speedmp'] += 350;
}
if ($st['s6'] > 99 && $st['s6'] < 125) {
$st['mpall'] += 350;
2023-08-15 22:48:29 +00:00
$st['speedmp'] += 500;
}
if ($st['s6'] > 124 && $st['s6'] < 150) {
$st['mpall'] += 500;
2023-08-15 22:48:29 +00:00
$st['speedmp'] += 500;
$st['pzm'] += 2;
}
if ($st['s6'] > 149 && $st['s6'] < 175) {
$st['mpall'] += 700;
2023-08-15 22:48:29 +00:00
$st['speedmp'] += 600;
$st['pzm'] += 3;
}
if ($st['s6'] > 174 && $st['s6'] < 200) {
$st['mpall'] += 900;
2023-08-15 22:48:29 +00:00
$st['speedmp'] += 700;
$st['pzm'] += 5;
}
if ($st['s6'] > 199) {
$st['mpall'] += 900;
2023-08-15 22:48:29 +00:00
$st['speedmp'] += 700;
$st['pzm'] += 7;
}
2023-11-02 13:57:39 +00:00
}
2023-08-15 22:48:29 +00:00
2023-11-02 13:57:39 +00:00
private function addDungeonsBonuses(int $id, array &$st): void
{
2023-12-19 01:58:37 +00:00
$finishedDungeons = Db::getValue(
'select
2023-11-02 13:57:39 +00:00
if(repcapitalcity > 24999, 1, 0) +
if(repdemonscity > 24999, 1, 0) +
if(repangelscity > 24999, 1, 0) +
if(repdevilscity > 24999, 1, 0) +
if(repmooncity > 24999, 1, 0) +
if(repsuncity > 24999, 1, 0) +
if(repsandcity > 24999, 1, 0) +
if(repemeraldscity > 24999, 1, 0) +
if(repizlom > 24999, 1, 0) +
2023-12-19 01:58:37 +00:00
0 as finished from rep where id = ?', [$id]
);
2023-11-02 13:57:39 +00:00
//Бонус за количество полностью вырытых пещер.
$st['m10'] += 10 * $finishedDungeons;
2023-08-15 22:48:29 +00:00
}
private function addAdminBonuses(array $u, array &$st): void
{
if (!$u['admin']) {
return;
}
$this->addKeyIfNotExist('speed_dungeon', 500, $st);
$this->addKeyIfNotExist('speedhp', 500, $st);
if (!$u['battle']) {
return;
}
2023-12-19 01:58:37 +00:00
Db::sql(
"update stats set
tactic1 = tactic2 = tactic3 = tactic4 = tactic5 = tactic6 = tactic7 = 25,
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|'
2023-12-19 01:58:37 +00:00
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']);
}
2023-12-19 01:58:37 +00:00
public static function saveBattleStats(array $stats, int $id): void
{
if (!isset(
$stats['hpnow'],
$stats['mpNow'],
$stats['tactic1'],
$stats['tactic2'],
$stats['tactic3'],
$stats['tactic4'],
$stats['tactic5'],
$stats['tactic6'],
$stats['tactic7'],
$stats['enemy'],
$stats['battle_yron'],
$stats['battle_exp'],
$stats['last_hp'],
$stats['priems_z'],
)
) {
return;
}
Db::sql(
'update stats set hpNow = ?,mpNow = ?,
tactic1 = ?,tactic2 = ?,tactic3 = ?,tactic4 = ?,tactic5 = ?,tactic6 = ?,tactic7 = ?,
enemy = ?,battle_yron = ?,last_hp = ?,battle_exp = ?,priems_z = ?
where id = ?',
[
$stats['hpnow'],
$stats['mpNow'],
$stats['tactic1'],
$stats['tactic2'],
$stats['tactic3'],
$stats['tactic4'],
$stats['tactic5'],
$stats['tactic6'],
$stats['tactic7'],
$stats['enemy'],
$stats['battle_yron'],
$stats['battle_exp'],
$stats['last_hp'],
$stats['priems_z'],
$id,
]
);
}
2023-08-15 22:48:29 +00:00
}