game/_incl_data/class/User/Stats.php

1185 lines
40 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
namespace User;
use Core\Config;
use Core\Db;
use Helper\Comparsion;
use Helper\Conversion;
use Model\Constant\Stat;
use User;
class Stats
{
private User $u;
/** Список разрешённых для бонусов системных названий статов
* @var Stat
*/
private Stat $sysNames;
private array $statsKeys = [];
public function __construct(User $user)
{
$this->u = $user;
$this->sysNames = new Stat();
$this->sysNames->getBonus();
}
/**
* Собирает суммы всех бонусов с одетых предметов, комплектов предметов, активных эфектов.
* @param int $userId
* @return array
*/
public static function getAllBonuses(int $userId): array
{
$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]);
$params = [];
$complects = [];
foreach ($iData as $datum) {
$arr = Conversion::dataStringToArray($datum);
foreach ($arr as $k => $v) {
if ($k === 'complect') {
if (isset($complects[$v])) {
$complects[$v]++;
} else {
$complects[$v] = 1;
}
}
if (!str_contains($k, 'add_')) {
continue;
}
$k = str_replace('add_', '', $k);
self::setBonusValue($params, $k, $v);
}
}
return self::addComplectsBonuses($complects, $params);
}
private static function setBonusValue(array &$array, $key, $value): void
{
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,
];
}
public function getStats(int|array|null $uid = null, $i1 = 0, $reimg = false, $btl_cache = false): array
{
$u = match (true) {
empty($uid) => $this->u->info,
is_array($uid) => $uid,
default => User::getInfo($uid),
};
if (!isset($u['id'])) {
return [];
}
// Как? Нахуя 4 переменные разные для одного и того же?
$st = array_fill_keys($this->sysNames->sysBonusNames, 0);
$sti = $st;
$s_v = $st;
$s_vi = $st;
$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);
}
}
$lvl = Db::getRow('select * from levels where upLevel = ?', [$u['upLevel']]);
if (isset($lvl['upLevel'])) {
$st['levels'] = $lvl;
} else {
$st['levels'] = 'undefined';
}
$st['id'] = $u['id'];
$st['login'] = $u['login'];
$st['level'] = $u['level'];
$st['hpNow'] = $u['hpNow'];
$st['mpNow'] = $u['mpNow'];
$st['zona'] = 1;
$st['zonb'] = 2;
$st['items'] = [];
$st['effects'] = [];
$st['vip'] = $u['vip'];
foreach (Conversion::dataStringToArray($u['stats']) as $stat => $value) {
//fixme несуществующие статы mg5 mg6 a6 s8-s15
$this->addKeyIfNotExist($stat, (int)$value, $st);
}
$baseStats = $st;
//Шаблонные картинки
if ($this->u->info['id'] === $u['id'] || $reimg) {
$itemsImages = Db::getRows('select * from items_img where uid = ? and img_id != 0', [$u['id']]);
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, $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'];
$st['m19'] += (int)($st['s3'] * 0.03);
//Бонусы комплектов
if (is_iterable($coms['new'])) {
foreach ($coms['new'] as $complect) {
$com = Db::getValue(
'select data from complects where com = ? and x <= ? order by x desc limit 1',
[
(int)$complect,
(int)$coms['com'][$complect], // кол-во предметов данного комплекта
]
);
if (!$com) {
continue;
}
$sti = Conversion::dataStringToArray($com);
foreach ($this->sysNames->sysBonusNames as $stat) {
if (!isset($sti[$stat])) {
continue;
}
$st[$stat] += $sti[$stat];
}
}
}
//Что за нахер?
WearedScrolls::ScrollsChange($u);
//Бонусы статов
$this->addStatBonuses($st);
/* Владения */
//mib1-mib4, mab1-mab4 armor??
if (!empty($st['s5'])) {
$st['pm1'] += (int)($st['s5'] * 0.5);
$st['pm2'] += (int)($st['s5'] * 0.5);
$st['pm3'] += (int)($st['s5'] * 0.5);
$st['pm4'] += (int)($st['s5'] * 0.5);
$st['pm7'] += (int)($st['s5'] * 0.5);
}
if (!empty($st['aall'])) {
$st['a1'] += $st['aall'];
$st['a2'] += $st['aall'];
$st['a3'] += $st['aall'];
$st['a4'] += $st['aall'];
$st['a5'] += $st['aall'];
}
if (!empty($st['zm'])) {
$st['zm1'] += $st['zm'];
$st['zm2'] += $st['zm'];
$st['zm3'] += $st['zm'];
$st['zm4'] += $st['zm'];
}
if (!empty($st['mall'])) {
$st['mg1'] += $st['mall'];
$st['mg2'] += $st['mall'];
$st['mg3'] += $st['mall'];
$st['mg4'] += $st['mall'];
}
if (!empty($st['m11'])) {
$st['pm1'] += $st['m11'];
$st['pm2'] += $st['m11'];
$st['pm3'] += $st['m11'];
$st['pm4'] += $st['m11'];
}
if (!empty($st['m10'])) {
$st['pa1'] += $st['m10'];
$st['pa2'] += $st['m10'];
$st['pa3'] += $st['m10'];
$st['pa4'] += $st['m10'];
}
if (!empty($st['za'])) {
$st['za1'] += $st['za'];
$st['za2'] += $st['za'];
$st['za3'] += $st['za'];
$st['za4'] += $st['za'];
}
if (!empty($st['hpVinos'])) {
$st['hpall'] += (int)($st['hpVinos'] * $st['s4']);
}
if (!empty($st['mpVinos'])) {
$st['mpall'] += (int)($st['mpVinos'] * $st['s6']);
}
if (!empty($st['hpProc'])) {
$st['hpall'] += (int)($st['hpall'] / 100 * $st['hpProc']);
}
if (!empty($st['mpProc'])) {
$st['mpall'] += (int)($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 ($hnd2 == 1 && $hnd1 == 1) {
$st['zona']++;
}
if ($sht1 == 1) {
$st['zonb']++;
}
$st['zona'] = Comparsion::minimax($st['zona'], 1, 5);
$st['zonb'] = Comparsion::minimax($st['zonb'], 1, 3);
$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']]);
}
$st['hpall'] = max($st['hpall'], 1);
$st['mpall'] = max($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
* @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;
}
/**
* Добавляет бонусы к статам игрока.
* Генерирует переменную User:class->stats['items'], где лежат одетые предметы.
* @param int $uid
* @param array $st
* @param array $s_v
* @param array $baseStats
* @return array
*/
private function addWearedItemsBonuses(int $uid, array &$st, array &$s_v, array $baseStats): array
{
//Характеристики от предметов //ТУТ tr_lvl
// Вся вторая строчка - спасибо Users.
$wearedItems = Db::getRows(
'select type, data, inOdet,
item_id, inslot, useInBattle, btl_zd, iznosNOW, iznosMAX, magic_inci, name, items_users.id, img, `2h`
from items_users left join items_main on items_main.id = item_id where inOdet != 0 and uid = ?', [$uid]
);
$h = 0;
$hnd1 = 0;
$hnd2 = 0;
$sht1 = 0;
$reitm = [];
$coms = []; // комплекты
$dom = [];
$wi = new WearedItem(); // на замену User:class->stats['items']
$st['items_o'] = $wi;
foreach ($wearedItems as $wearedItem) {
// Генерируем всратую пепяку User:class->stats['wpXid'] > 0, которая показывает, что определённый слот
// чем-то занят. Странное решение.
$this->addKeyIfNotExist('wp' . $wearedItem['inOdet'] . 'id', $h, $st);
$st['items'][$h] = $wearedItem;
$h++;
$wi->add(new Item($wearedItem));
// Если в левой руке (3) предметы определённого типа, то рука занята оружием.
if ($wearedItem['inOdet'] == 3 &&
(($wearedItem['type'] >= 18 && $wearedItem['type'] <= 24) ||
$wearedItem['type'] == 26 ||
$wearedItem['type'] == 27 ||
$wearedItem['type'] == 28)) {
$hnd1 = 1;
}
// Если в правой руке (14) предметы определённого типа, то рука занята оружием или щитом.
if ($wearedItem['inOdet'] == 14 &&
(($wearedItem['type'] >= 18 && $wearedItem['type'] <= 24) ||
$wearedItem['type'] == 26 ||
$wearedItem['type'] == 27 ||
$wearedItem['type'] == 28)) {
$hnd2 = 1;
} elseif ($wearedItem['inOdet'] == 14 && $wearedItem['type'] == 13) {
$sht1 = 1;
}
// Если в любом слоте что-то есть, повышается User:class->stats['reting'] за каждый слот
// Используется каким-то непонятным образом в хаотах.
if ($wearedItem['inOdet'] <= 18 && $wearedItem['inOdet'] > 0) {
$this->addKeyIfNotExist('reting', 1, $st);
}
$data = Conversion::dataStringToArray($wearedItem['data']);
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'])] = $data['complect'];
}
$coms['com'][$data['complect']]++;
}
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'])] = $data['complect2'];
}
$coms['com'][$data['complect2']]++;
}
if (!empty($data['zonb'])) {
$this->addKeyIfNotExist('zonb', $data['zonb'], $st);
}
if (!empty($data['zona'])) {
$this->addKeyIfNotExist('zona', $data['zona'], $st);
}
//Добавляем статы от данного предмета
if (!isset($data['restart_stats'])) {
foreach ($this->sysNames->sysBonusNames as $stat) {
if (!isset($data['add_' . $stat])) {
continue;
}
$st[$stat] += (int)$data['add_' . $stat];
}
} else {
$reitm[] = $data;
}
}
//Сохраненные хар-ки и умения
if (!empty($reitm) && is_iterable($reitm)) {
$i39 = [];
foreach ($reitm as $item) {
if (isset($item['sm_skill']) && $i39[0] == 0) {
//умения
$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) {
//статы
$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) {
//навыки
$i39[2] = 1;
}
}
}
return [$hnd1, $hnd2, $sht1, $dom, $coms];
}
private function addMedalsBonuses(int $uid, array &$st): void
{
//Харки от иконок
$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->sysBonusNames, true)) { // есть ли параметр в разрешенных?
continue;
}
$st[$paramName] += $value;
}
}
}
private function addValuesToAllArrays(array $sts, array &$st, array &$sti, array &$s_v, array &$s_vi): void
{
foreach ($this->sysNames->sysBonusNames as $stat) {
if (!isset($sts['add_' . $stat])) {
continue;
}
$st[$stat] += intval($sts['add_' . $stat]);
$sti[$stat] += intval($sts['add_' . $stat]);
if (!isset($sts['sv_' . $stat])) {
continue;
}
$s_v[$stat] += intval($sts['sv_' . $stat]);
$s_vi[$stat] += intval($sts['sv_' . $stat]);
}
}
private function addWearedItemsIllusion(array $nbs, array &$st): void
{
//Заглушки от эффектов
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';
}
}
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) {
$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'];
}
$st['effects'][$h] = $e;
$h++;
$sts = Conversion::dataStringToArray($e['data']);
if ($e['v2'] == 217) {
$st['raztac'] = 1;
}
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);
}
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'];
}
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);
}
$this->addValuesToAllArrays($sts, $st, $sti, $s_v, $s_vi);
} else {
//удаляем эффект
$this->u->endEffect($e['id'], $u);
$st['act'] = 1;
}
}
}
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
{
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;
}
}
private function addDexterityBonuses(array &$st): void
{
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;
}
}
private function addIntuitionBonuses(array &$st): void
{
if ($st['s3'] >= 200) {
$st['m1'] += 185;
$st['m3'] += 40;
$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;
}
}
private function addEnduranceBonuses(array &$st): void
{
//выносливость
if ($st['s4'] > 0) {
$st['hpall'] += 30;
}
if ($st['s4'] > 24 && $st['s4'] < 50) {
$st['hpall'] += 50;
}
if ($st['s4'] > 49 && $st['s4'] < 75) {
$st['hpall'] += 100;
}
if ($st['s4'] > 74 && $st['s4'] < 100) {
$st['hpall'] += 175;
$st['m19'] += 2;
}
if ($st['s4'] > 99 && $st['s4'] < 125) {
$st['hpall'] += 250;
$st['m19'] += 4;
}
if ($st['s4'] > 124 && $st['s4'] < 150) {
$st['hpall'] += 400;
$st['za'] += 25;
$st['zm'] += 25;
}
if ($st['s4'] > 149 && $st['s4'] < 175) {
$st['hpall'] += 450;
$st['za'] += 50;
$st['zm'] += 50;
}
if ($st['s4'] > 174 && $st['s4'] < 200) {
$st['hpall'] += 600;
$st['za'] += 100;
$st['zm'] += 100;
}
if ($st['s4'] > 199) {
$st['hpall'] += 850;
$st['za'] += 125;
$st['zm'] += 125;
}
}
private function addIntelligenceBonuses(array &$st): void
{
//интелект
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;
}
}
private function addWisdomBonuses(array &$st): void
{
//мудрость
if ($st['s6'] > 24 && $st['s6'] < 50) {
$st['mpall'] += 150;
$st['speedmp'] += 100;
}
if ($st['s6'] > 49 && $st['s6'] < 75) {
$st['mpall'] += 200;
$st['speedmp'] += 200;
}
if ($st['s6'] > 74 && $st['s6'] < 100) {
$st['mpall'] += 250;
$st['speedmp'] += 350;
}
if ($st['s6'] > 99 && $st['s6'] < 125) {
$st['mpall'] += 350;
$st['speedmp'] += 500;
}
if ($st['s6'] > 124 && $st['s6'] < 150) {
$st['mpall'] += 500;
$st['speedmp'] += 500;
$st['pzm'] += 2;
}
if ($st['s6'] > 149 && $st['s6'] < 175) {
$st['mpall'] += 700;
$st['speedmp'] += 600;
$st['pzm'] += 3;
}
if ($st['s6'] > 174 && $st['s6'] < 200) {
$st['mpall'] += 900;
$st['speedmp'] += 700;
$st['pzm'] += 5;
}
if ($st['s6'] > 199) {
$st['mpall'] += 900;
$st['speedmp'] += 700;
$st['pzm'] += 7;
}
}
private function addDungeonsBonuses(int $id, array &$st): void
{
$finishedDungeons = Db::getValue(
'select
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) +
0 as finished from rep where id = ?', [$id]
);
//Бонус за количество полностью вырытых пещер.
if (isset($st['m10'])) {
$st['m10'] += 10 * $finishedDungeons;
} else {
$st['m10'] = 10 * $finishedDungeons;
}
}
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;
}
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|'
where id = ?", [$u['id']]
);
}
/** Переименовывает элементы массива с несовпадающими с остальным скриптом именами полей.
* @param array $st
* @return void
*/
private function renameArrayKeys(array &$st): void
{
if (isset($st['level'])) {
$st['lvl'] = $st['level'];
}
if (isset($st['hpall'])) {
$st['hpAll'] = $st['hpall'];
}
if (isset($st['mpall'])) {
$st['mpAll'] = $st['mpall'];
}
if (isset($st['hpnow'])) {
$st['hpNow'] = $st['hpnow'];
}
if (isset($st['mpnow'])) {
$st['mpNow'] = $st['mpnow'];
}
unset($st['level'], $st['hpnow'], $st['mpnow'], $st['hpall'], $st['mpall']);
}
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,
]
);
}
}