Много рефактора

This commit is contained in:
2023-12-19 03:58:37 +02:00
parent 253eafca3b
commit 07f905ef64
24 changed files with 2748 additions and 3199 deletions
+73 -21
View File
@@ -123,16 +123,13 @@ class Stats
];
}
public function getStats(int|array|null $uid = null, $i1 = 0, $res = 0, $reimg = false, $btl_cache = false): array
public function getStats(int|array|null $uid = null, $i1 = 0, $reimg = false, $btl_cache = false): array
{
if (empty($uid) || $uid == $this->u->info['id'] && $res != 1) {
//$u = $this->u->info;
$u = User::getInfo($uid);
} elseif (is_array($uid)) {
$u = $uid;
} else {
$u = User::getInfo($uid);
}
$u = match (true) {
empty($uid) => User::getInfo($this->u->info['id']),
is_array($uid) => $uid,
default => User::getInfo($uid),
};
if (!isset($u['id'])) {
return [];
@@ -296,11 +293,13 @@ class Stats
//Бонусы комплектов
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',
$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;
@@ -513,8 +512,8 @@ class Stats
/** Собираем динамически создаваемые параметры. Если ключа нет - создаём.
* @param string $key
* @param int $value
* @param array $st
* @param int $value
* @param array $st
* @return void
*/
private function addKeyIfNotExist(string $key, int $value, array &$st): void
@@ -530,9 +529,11 @@ class Stats
{
//Характеристики от предметов //ТУТ tr_lvl
// Вся вторая строчка - спасибо Users.
$wearedItems = Db::getRows('select type, data, inOdet,
$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]);
from items_users left join items_main on items_main.id = item_id where inOdet != 0 and uid = ?', [$uid]
);
$h = 0;
$hnd1 = 0;
@@ -1080,7 +1081,7 @@ class Stats
private function addIntelligenceBonuses(array &$st): void
{
//интелект
//интелект
if ($st['s5'] > 24 && $st['s5'] < 50) {
$st['m11'] += 10;
}
@@ -1110,7 +1111,7 @@ class Stats
private function addWisdomBonuses(array &$st): void
{
//мудрость
//мудрость
if ($st['s6'] > 24 && $st['s6'] < 50) {
$st['mpall'] += 150;
$st['speedmp'] += 100;
@@ -1151,7 +1152,8 @@ class Stats
private function addDungeonsBonuses(int $id, array &$st): void
{
$finishedDungeons = Db::getValue('select
$finishedDungeons = Db::getValue(
'select
if(repcapitalcity > 24999, 1, 0) +
if(repdemonscity > 24999, 1, 0) +
if(repangelscity > 24999, 1, 0) +
@@ -1161,7 +1163,8 @@ class Stats
if(repsandcity > 24999, 1, 0) +
if(repemeraldscity > 24999, 1, 0) +
if(repizlom > 24999, 1, 0) +
0 as finished from rep where id = ?', [$id]);
0 as finished from rep where id = ?', [$id]
);
//Бонус за количество полностью вырытых пещер.
$st['m10'] += 10 * $finishedDungeons;
@@ -1180,10 +1183,12 @@ class Stats
return;
}
Db::sql("update stats set
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']]);
where id = ?", [$u['id']]
);
}
/** Переименовывает элементы массива с несовпадающими с остальным скриптом именами полей.
@@ -1199,4 +1204,51 @@ class Stats
unset($st['level'], $st['hpnow'], $st['mpnow']);
}
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,
]
);
}
}