game/_incl_data/class/Clan/ItemStorage.php

193 lines
8.6 KiB
PHP

<?php
namespace Clan;
use Core\ConversionHelper;
use Core\Db;
use User;
use User\ItemsModel;
class ItemStorage
{
private string $error = '';
private function isGoodForStorage(array $item, $userClanId): bool
{
if (empty($item['inslot']) || !empty($item['gift'])) {
$this->error = 'Ïðåäìåò íå íàéäåí.';
}
$idata = ConversionHelper::dataStringToArray($item['data']);
if (
!empty($idata['frompisher']) ||
!empty($idata['sudba']) ||
!empty($idata['icos']) ||
!empty($idata['fromlaba'])
) {
$this->error = 'Ïðåäìåò íå ïîäõîäèò.';
}
if (!empty($idata['toclan']) && explode('#', $idata['toclan'])[0] == $userClanId) {
$this->error = 'Ïðåäìåò óæå ïðèíàäëåæèò êëàíó.';
}
return empty($this->error);
}
public function put(int $itemId, int $clanId): string
{
$user = User::start()->info;
$item = ItemsModel::getOwnedItemById($itemId, $user['id']);
$clanName = Db::getValue('select name from clan where id = ?', [$clanId]) ?? '';
if (empty($clanName)) {
return 'Êëàí íå íàéäåí.';
}
if (!$this->isGoodForStorage($item, $user['clan'])) {
return $this->error;
}
$col = User::start()->itemsX(($itemId));
$idata = ConversionHelper::dataStringToArray($item['data']);
if (!isset($idata['toclan'])) {
$idata['toclan'] = $user['clan'] . '#' . $user['id'];
$item['data'] = ConversionHelper::arrayToDataString($idata);
User::start()->addDelo(
2,
$user['id'],
'&quot;System.transfer.MONEY&quot;: Ïðåäìåò &quot;' . $item['name'] . '&quot; (#id : "' . $itemId . '") (x' . $col . ') áûë ïîæåðòâîâàí êëàíó &quot;' . $clanName . '&quot; (' . $clanId . ').',
time(),
$user['city'],
'System.transfer.clan',
0,
0
);
$sendType = 4;
} else {
$sendType = 3;
}
Db::sql(
'insert into clan_operations (clan, time, type, text, val, uid) values (?,unix_timestamp(),?,?,?,?)',
[$clanId, $sendType, $user['login'], $item['name'] . ("x$col Èä: [$itemId]"), $user['id']]
);
Db::sql(
'update items_users set lastUPD = unix_timestamp(), uid = ?, data = ? where id = ?',
['-21' . $user['clan'], $item['data'], $itemId]
);
return 'Âû ïåðåäàëè ïðåäìåò &quot;' . $item['name'] . '&quot; êëàíó.';
}
public function ungive_itm_cl($id, $user, $cl): string
{
$itm_ = mysql_fetch_array(
mysql_query(
'SELECT `iu`.*, `im`.* FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON `iu`.`item_id` = `im`.`id` WHERE `iu`.`uid` >= 0 AND `iu`.`delete` = 0 AND `iu`.`id` = "' . $id . '" LIMIT 1'
)
);
$res = mysql_fetch_array(mysql_query('SELECT * FROM `clan` WHERE `id` = "' . $cl . '" LIMIT 1'));
$user_itm = mysql_fetch_array(
mysql_query('SELECT `id`,`bot`,`clone` FROM `stats` WHERE `id` = "' . $itm_['uid'] . '" LIMIT 1')
);
if ($user_itm['bot'] > 0 || $user_itm['clone'] > 0 || !isset($user_itm['id'])) {
$r = '<font color="#FF0000"><strong>Âû íå ìîæåòå èçüÿòü äàííûé ïðåäìåò, îí íå ïðèíàäëåæèò êëàíó</strong></font><br />';
} elseif (isset($itm_['id'])) {
if ($itm_['inOdet'] != 0) {
$o = ', `inOdet` = 0';
} else {
$o = '';
}
$r = '<font color="#FF0000"><strong>Âû óñïåøíî èçúÿëè ïðåäìåò &quot;' . $itm_['name'] . '&quot;</strong></font><br />';
$col = $this->itemsX(((int)$id));
mysql_query(
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
) . '", "6", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Èä : [' . $id . '] | Ó ïåðñîíàæà : [' . $itm_['uid'] . ']", "' . $user['id'] . '")'
);
mysql_query(
'UPDATE `items_users` SET `lastUPD` = "' . time(
) . '", `uid` = "-21' . $res['id'] . '" ' . $o . ' WHERE `id` = "' . $id . '" LIMIT 1'
);
} else {
$r = '<font color="#FF0000"><strong>Ïðåäìåò íå íàéäåí.</strong></font><br />';
}
return $r;
}
public function take_itm_cl($id, $user, $cl): string
{
$itm_ = mysql_fetch_array(
mysql_query(
'SELECT `iu`.*, `im`.* FROM `items_users` AS `iu` LEFT JOIN `items_main` AS `im` ON `iu`.`item_id` = `im`.`id` WHERE `iu`.`uid` = "-21' . $user['clan'] . '" AND `iu`.`delete` = 0 AND `iu`.`id` = "' . $id . '" LIMIT 1'
)
);
$res = mysql_fetch_array(mysql_query('SELECT * FROM `clan` WHERE `id` = "' . $cl . '" LIMIT 1'));
if (isset($itm_['id'])) {
$po = ConversionHelper::dataStringToArray($itm_['data']);
if (isset($po['toclan'])) {
$cls = explode('#', $po['toclan']);
$cls = $cls[1];
}
$col = $this->itemsX(((int)$id));
mysql_query(
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
) . '", "5", "' . $user['login'] . '", "' . $itm_['name'] . ' (x' . $col . ') Èä : [' . $id . '] Õîçÿèí : [' . $cls . ']", "' . $user['id'] . '")'
);
mysql_query(
'UPDATE `items_users` SET `lastUPD` = "' . time(
) . '", `uid` = "' . $user['id'] . '" WHERE `id` = "' . $id . '" LIMIT 1'
);
$r = '<font color="#FF0000"><strong>Âû óñïåøíî âçÿëè ïðåäìåò &quot;' . $itm_['name'] . '&quot; èç õðàíèëèùà</strong></font><br />';
} else {
$r = '<font color="#FF0000"><strong>Ïðåäìåò íå íàéäåí.</strong></font><br />' . $id;
}
return $r;
}
public function rem_itm_cl($user, $cl, $type)
{
$itms = mysql_query(
'SELECT * FROM `items_users` WHERE (`uid` = "-21' . $user['clan'] . '" OR `data` LIKE "%toclan=' . $user['clan'] . '#%")'
);
while ($pl = mysql_fetch_array($itms)) {
$po = ConversionHelper::dataStringToArray($pl['data']);
if (isset($po['toclan'])) {
$cls = explode('#', $po['toclan']);
$cls = $cls[1];
}
if ($cls == $user['id']) {
if ($pl['uid'] != $user['id']) {
if ($pl['inOdet'] != 0) {
mysql_query('UPDATE `items_users` SET `inOdet` = 0 WHERE `id` = "' . $pl['id'] . '"');
}
}
unset($po['toclan']);
$pl['data'] = ConversionHelper::arrayToDataString($po);
$col = $this->itemsX(((int)$pl['id']));
$it_n = mysql_fetch_array(
mysql_query('SELECT `name` FROM `items_main` WHERE `id` = "' . $pl['item_id'] . '"')
);
mysql_query(
'UPDATE `items_users` SET `lastUPD` = "' . time(
) . '", `uid` = "' . $user['id'] . '", `data` = "' . $pl['data'] . '" WHERE `id` = "' . $pl['id'] . '"'
);
mysql_query(
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
) . '", "' . $type . '", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Èä : [' . $pl['id'] . ']", "' . $user['id'] . '")'
);
} elseif ($pl['uid'] == $user['id']) {
$col = $this->itemsX(((int)$pl['id']));
$it_n = mysql_fetch_array(
mysql_query('SELECT `name` FROM `items_main` WHERE `id` = "' . $pl['item_id'] . '"')
);
mysql_query(
'UPDATE `items_users` SET `lastUPD` = "' . time(
) . '", `uid` = "-21' . $user['clan'] . '" WHERE `id` = "' . $pl['id'] . '"'
);
mysql_query(
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res['id'] . '", "' . time(
) . '", "9", "' . $user['login'] . '", "' . $it_n['name'] . ' (x' . $col . ') Èä : [' . $pl['id'] . ']", "' . $user['id'] . '")'
);
}
}
}
}