2023-04-18 09:21:54 +00:00
< ? 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' ])) {
2023-07-19 12:36:13 +00:00
$this -> error = 'Предмет не найден.' ;
2023-04-18 09:21:54 +00:00
}
$idata = ConversionHelper :: dataStringToArray ( $item [ 'data' ]);
if (
! empty ( $idata [ 'frompisher' ]) ||
! empty ( $idata [ 'sudba' ]) ||
! empty ( $idata [ 'icos' ]) ||
! empty ( $idata [ 'fromlaba' ])
) {
2023-07-19 12:36:13 +00:00
$this -> error = 'Предмет не подходит.' ;
2023-04-18 09:21:54 +00:00
}
if ( ! empty ( $idata [ 'toclan' ]) && explode ( '#' , $idata [ 'toclan' ])[ 0 ] == $userClanId ) {
2023-07-19 12:36:13 +00:00
$this -> error = 'Предмет уже принадлежит клану.' ;
2023-04-18 09:21:54 +00:00
}
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 )) {
2023-07-19 12:36:13 +00:00
return 'Клан не найден.' ;
2023-04-18 09:21:54 +00:00
}
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' ],
2023-07-19 12:36:13 +00:00
'"System.transfer.MONEY": Предмет "' . $item [ 'name' ] . '" (#id : "' . $itemId . '") (x' . $col . ') был пожертвован клану "' . $clanName . '" (' . $clanId . ').' ,
2023-04-18 09:21:54 +00:00
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(),?,?,?,?)' ,
2023-07-19 12:36:13 +00:00
[ $clanId , $sendType , $user [ 'login' ], $item [ 'name' ] . ( " x $col Ид: [ $itemId ] " ), $user [ 'id' ]]
2023-04-18 09:21:54 +00:00
);
Db :: sql (
'update items_users set lastUPD = unix_timestamp(), uid = ?, data = ? where id = ?' ,
[ '-21' . $user [ 'clan' ], $item [ 'data' ], $itemId ]
);
2023-07-19 12:36:13 +00:00
return 'Вы передали предмет "' . $item [ 'name' ] . '" клану.' ;
2023-04-18 09:21:54 +00:00
}
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' ])) {
2023-07-19 12:36:13 +00:00
$r = '<font color="#FF0000"><strong>Вы не можете изьять данный предмет, он не принадлежит клану</strong></font><br />' ;
2023-04-18 09:21:54 +00:00
} elseif ( isset ( $itm_ [ 'id' ])) {
if ( $itm_ [ 'inOdet' ] != 0 ) {
$o = ', `inOdet` = 0' ;
} else {
$o = '' ;
}
2023-07-19 12:36:13 +00:00
$r = '<font color="#FF0000"><strong>Вы успешно изъяли предмет "' . $itm_ [ 'name' ] . '"</strong></font><br />' ;
2023-04-18 09:21:54 +00:00
$col = $this -> itemsX ((( int ) $id ));
mysql_query (
'INSERT INTO `clan_operations` (`clan`, `time`, `type`, `text`, `val`, `uid`) VALUES ("' . $res [ 'id' ] . '", "' . time (
2023-07-19 12:36:13 +00:00
) . '", "6", "' . $user [ 'login' ] . '", "' . $itm_ [ 'name' ] . ' (x' . $col . ') Ид : [' . $id . '] | У персонажа : [' . $itm_ [ 'uid' ] . ']", "' . $user [ 'id' ] . '")'
2023-04-18 09:21:54 +00:00
);
mysql_query (
'UPDATE `items_users` SET `lastUPD` = "' . time (
) . '", `uid` = "-21' . $res [ 'id' ] . '" ' . $o . ' WHERE `id` = "' . $id . '" LIMIT 1'
);
} else {
2023-07-19 12:36:13 +00:00
$r = '<font color="#FF0000"><strong>Предмет не найден.</strong></font><br />' ;
2023-04-18 09:21:54 +00:00
}
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 (
2023-07-19 12:36:13 +00:00
) . '", "5", "' . $user [ 'login' ] . '", "' . $itm_ [ 'name' ] . ' (x' . $col . ') Ид : [' . $id . '] Хозяин : [' . $cls . ']", "' . $user [ 'id' ] . '")'
2023-04-18 09:21:54 +00:00
);
mysql_query (
'UPDATE `items_users` SET `lastUPD` = "' . time (
) . '", `uid` = "' . $user [ 'id' ] . '" WHERE `id` = "' . $id . '" LIMIT 1'
);
2023-07-19 12:36:13 +00:00
$r = '<font color="#FF0000"><strong>Вы успешно взяли предмет "' . $itm_ [ 'name' ] . '" из хранилища</strong></font><br />' ;
2023-04-18 09:21:54 +00:00
} else {
2023-07-19 12:36:13 +00:00
$r = '<font color="#FF0000"><strong>Предмет не найден.</strong></font><br />' . $id ;
2023-04-18 09:21:54 +00:00
}
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 (
2023-07-19 12:36:13 +00:00
) . '", "' . $type . '", "' . $user [ 'login' ] . '", "' . $it_n [ 'name' ] . ' (x' . $col . ') Ид : [' . $pl [ 'id' ] . ']", "' . $user [ 'id' ] . '")'
2023-04-18 09:21:54 +00:00
);
} 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 (
2023-07-19 12:36:13 +00:00
) . '", "9", "' . $user [ 'login' ] . '", "' . $it_n [ 'name' ] . ' (x' . $col . ') Ид : [' . $pl [ 'id' ] . ']", "' . $user [ 'id' ] . '")'
2023-04-18 09:21:54 +00:00
);
}
}
}
2023-07-19 12:36:13 +00:00
}