2023-04-15 22:54:07 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace User;
|
|
|
|
|
|
2023-04-15 23:54:34 +00:00
|
|
|
|
use Core\ConversionHelper;
|
2023-04-15 22:54:07 +00:00
|
|
|
|
use Core\Db;
|
2023-07-28 21:18:04 +00:00
|
|
|
|
use Delo;
|
2023-04-15 22:54:07 +00:00
|
|
|
|
use User;
|
|
|
|
|
|
|
|
|
|
class ItemsModel
|
|
|
|
|
{
|
|
|
|
|
/** Проверяет предметы на отсутствие в инвентаре.
|
|
|
|
|
* @param array $itemIds id предметов.
|
|
|
|
|
* @return array id отсутствующих предметов.
|
|
|
|
|
*/
|
|
|
|
|
public static function hasNoItemsInInventory(array $itemIds): array
|
|
|
|
|
{
|
|
|
|
|
/* Очень прóклятая конструкция для очень сломанной проверки.
|
|
|
|
|
Скотина, если заработает с первого раза без проверки я буду горд собой. */
|
|
|
|
|
|
|
|
|
|
$uid = User::start()->info['id'];
|
|
|
|
|
$cols = count($itemIds);
|
|
|
|
|
$check = Db::getValue(
|
|
|
|
|
'select count(*) from items_users
|
|
|
|
|
where item_id in (?) and uid = ? and (`delete` = 0 or `delete` = 1000)',
|
|
|
|
|
[implode(',', $itemIds), $uid]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ($cols === $check) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$arr = $itemIds;
|
|
|
|
|
$query = 'select item_id from (select ' . $arr[0] . ' item_id';
|
|
|
|
|
$arr[0] = '';
|
|
|
|
|
$query .= implode(' union select ', $arr);
|
|
|
|
|
$query .= ') params left join items_users using (item_id) where items_users.item_id is null ';
|
|
|
|
|
$query .= 'and uid = ? and (`delete` = 0 or `delete` = 1000)';
|
|
|
|
|
|
|
|
|
|
//select item_id from (select 1 item_id union select 2 union select 3) params left join items_users using (item_id) where items_users.item_id is null
|
|
|
|
|
|
|
|
|
|
return Db::getColumn($query, [$uid]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function getNamesByIds(array $ids, string $separator = ', '): string
|
|
|
|
|
{
|
|
|
|
|
$namesArray = Db::getColumn('select name from items_main where id in (?)', [$ids]);
|
|
|
|
|
return implode($separator, $namesArray);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Удаление определенного типа предметов
|
|
|
|
|
|
|
|
|
|
/** Удаление предметов из инвентаря активного игрока.
|
|
|
|
|
* @param int $id id предмета.
|
|
|
|
|
* @param int $coldel количество предметов.
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public static function deleteItemsById(int $id, int $coldel = 1)
|
|
|
|
|
{
|
|
|
|
|
Db::sql(
|
2023-08-14 13:03:45 +00:00
|
|
|
|
'update items_users set `delete` = unix_timestamp()
|
|
|
|
|
where id in (select id from items_users where item_id = ? and uid = ? and (`delete` = 0 or `delete` = 1000) order by inGroup desc limit ?)',
|
2023-04-15 22:54:07 +00:00
|
|
|
|
[$id, User::start()->info['id'], $coldel]
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-04-15 23:54:34 +00:00
|
|
|
|
|
|
|
|
|
//вес предметов у юзера
|
|
|
|
|
public static function inventoryWeightAndItemQuantity(): array
|
|
|
|
|
{
|
|
|
|
|
$uid = User::start()->info['id'];
|
|
|
|
|
$stats = User::start()->stats;
|
|
|
|
|
|
|
|
|
|
return [
|
2023-08-14 13:03:45 +00:00
|
|
|
|
'now' => Db::getValue('select sum(massa) from items_users left join items_main on item_id = items_main.id
|
|
|
|
|
where uid = ? and (`delete` = 0 or (`delete` = 1000 and inGroup > 0)) and inShop = 0 and inOdet = 0', [$uid]),
|
2023-04-15 23:54:34 +00:00
|
|
|
|
'max' => 40 + ($stats['os7'] * 10) + $stats['s4'] + $stats['maxves'] + $stats['s1'] * 4,
|
|
|
|
|
'items' => Db::getValue('select count(*) from items_users where uid = ? and `delete` = 0 and inShop = 0 and inOdet = 0', [$uid]),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function addItem($id, $uid, $md = null, $dn = null, $mxiznos = null, $nosudba = null, $plavka = null)
|
|
|
|
|
{
|
|
|
|
|
$user = User::start();
|
|
|
|
|
$rt = -1;
|
|
|
|
|
$i = Db::getRow('select * from items_main where id = ?', [$id]);
|
|
|
|
|
if (isset($i['id'])) {
|
|
|
|
|
$d = Db::getRow('select id, items_id, data from items_main_data where items_id = ?', [$i['id']]);
|
|
|
|
|
//новая дата
|
|
|
|
|
$data = $d['data'];
|
|
|
|
|
if ($i['ts'] > 0 && $nosudba == null) {
|
|
|
|
|
$ui = Db::getValue('select login from users where id = ?', [$uid]);
|
|
|
|
|
$data .= '|sudba=' . $ui;
|
|
|
|
|
}
|
|
|
|
|
if ($md != null) {
|
|
|
|
|
$data .= $md;
|
|
|
|
|
$data = ConversionHelper::dataStringToArray($data); // Если в функции имеются две одинаковых константы SROK?
|
|
|
|
|
$data = ConversionHelper::arrayToDataString($data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//предмет с настройками из подземелья
|
|
|
|
|
if ($dn != null && $dn['dn_delete'] > 0) {
|
|
|
|
|
$i['dn_delete'] = 1;
|
|
|
|
|
}
|
|
|
|
|
if ($mxiznos > 0) {
|
|
|
|
|
$i['iznosMAXi'] = $mxiznos;
|
|
|
|
|
}
|
2023-07-28 21:18:04 +00:00
|
|
|
|
|
2023-04-15 23:54:34 +00:00
|
|
|
|
$args = [
|
2023-06-08 18:33:56 +00:00
|
|
|
|
$i['overTypei'] ?? 0,
|
2023-04-15 23:54:34 +00:00
|
|
|
|
$i['id'],
|
|
|
|
|
$uid,
|
|
|
|
|
$data,
|
|
|
|
|
$i['iznosMAXi'],
|
|
|
|
|
$i['magic_inci'],
|
|
|
|
|
$i['dn_delete'] ?? 0,
|
|
|
|
|
];
|
|
|
|
|
Db::sql(
|
2023-07-28 21:18:04 +00:00
|
|
|
|
'insert into items_users (overType, item_id, uid, data, iznosMAX, magic_inc, lastUPD, time_create, dn_delete) values (?,?,?,?,?,?,unix_timestamp(),unix_timestamp(),?)',
|
2023-04-15 23:54:34 +00:00
|
|
|
|
$args
|
|
|
|
|
);
|
|
|
|
|
$rt = Db::lastInsertId() ?? 0;
|
|
|
|
|
if ($rt !== 0) {
|
|
|
|
|
Db::sql('update items_users set dn_delete = 1 where id = ? and data like ?', [$rt, '%dn_delete=%']);
|
|
|
|
|
if ($uid == $user->info['id']) {
|
|
|
|
|
$user->stack($rt);
|
|
|
|
|
}
|
|
|
|
|
$ads = '';
|
|
|
|
|
if ($plavka != null) {
|
|
|
|
|
$ads = 'Расплавлен предмет : [' . $plavka . ']';
|
|
|
|
|
}
|
|
|
|
|
//Записываем в личное дело что предмет получен
|
2023-07-28 21:18:04 +00:00
|
|
|
|
Delo::add(1, 'additems', $uid, 'Получен предмет «' . $i['name'] . '» [id:' . $i['iid'] . ']' . $ads);
|
2023-04-15 23:54:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $rt;
|
|
|
|
|
}
|
2023-04-18 09:21:54 +00:00
|
|
|
|
|
|
|
|
|
/** Выбор предмета в инвентаре.
|
|
|
|
|
* @param int $itemId
|
|
|
|
|
* @param int $ownerId
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getOwnedItemById(int $itemId, int $ownerId): array
|
|
|
|
|
{
|
2023-08-14 13:03:45 +00:00
|
|
|
|
return Db::getRow('select * from items_users left join items_main on item_id = items_main.id
|
|
|
|
|
where uid = ? and items_users.id = ? and `delete` = 0 and inOdet = 0 and inShop = 0', [$ownerId, $itemId]);
|
2023-04-18 09:21:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function delete(int $id)
|
|
|
|
|
{
|
2023-08-14 13:03:45 +00:00
|
|
|
|
Db::sql('delete from items_users where id = ?', [$id]);
|
2023-04-18 09:21:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 13:03:45 +00:00
|
|
|
|
public static function getDressedEkrTotalPrice($uid)
|
|
|
|
|
{
|
|
|
|
|
return Db::getValue('select sum(2price) from items_users where inOdet > 0 and uid = ?', [$uid]);
|
|
|
|
|
}
|
2023-04-15 22:54:07 +00:00
|
|
|
|
}
|