2024-10-07 10:35:20 +09:00
< ? php
class Item extends Module
{
public static function getItem ( $item_id )
{
global $g5 ;
$result = sql_fetch ( " SELECT * FROM { $g5 [ 'item_table' ] } WHERE it_id = ' { $item_id } ' " );
return $result ;
}
public static function getImage ( $item_id )
{
global $g5 ;
$result = sql_fetch ( " SELECT it_img FROM { $g5 [ 'item_table' ] } WHERE it_id = ' { $item_id } ' " );
return $result [ 'it_img' ];
}
public static function getDetailImage ( $item_id )
{
global $g5 ;
$result = sql_fetch ( " SELECT it_1 FROM { $g5 [ 'item_table' ] } WHERE it_id = ' { $item_id } ' " );
return $result [ 'it_1' ];
}
public static function getName ( $item_id )
{
global $g5 ;
$result = sql_fetch ( " SELECT it_name FROM { $g5 [ 'item_table' ] } WHERE it_id = ' { $item_id } ' " );
return $result [ 'it_name' ];
}
public static function getInventoryItem ( $inventory_id )
{
global $g5 ;
$result = sql_fetch ( " SELECT * FROM { $g5 [ 'inventory_table' ] } inv, { $g5 [ 'item_table' ] } itm WHERE inv.in_id = ' { $inventory_id } ' AND inv.it_id = itm.it_id " );
return $result ;
}
public static function giveItem ( $character_id , $item_id , $item = null , $count = 1 , $type = " 획득 " )
{
global $g5 ;
if ( ! $item [ 'it_id' ]) {
$item = self :: getItem ( $item_id );
}
$ch = Character :: getCharacter ( $character_id );
if ( $ch [ 'ch_id' ]) {
for ( $i = 0 ; $i < $count ; $i ++ ) {
$inven_sql = " insert into { $g5 [ 'inventory_table' ] }
set ch_id = '{$ch[' ch_id ']}' ,
it_id = '{$item[' it_id ']}' ,
it_name = '{$item[' it_name ']}' ,
ch_name = '{$ch[' ch_name ']}' " ;
self :: addGetLog ( $item_id , $character_id , $item , $type );
sql_query ( $inven_sql );
}
}
return $count ;
}
/**
* @ param int $inventory_id
* @ param int $delete
* @ return void
*/
public static function takeItem ( $inventory_id , $delete = 0 , $type = " 사용 " )
{
global $g5 ;
2024-10-07 11:52:53 +09:00
self :: addUseLog ( $inventory_id , $type . ( $delete != 0 ? " (삭제) " : " (보존) " ));
2024-10-07 10:35:20 +09:00
if ( $delete === 0 ) {
sql_query ( " DELETE FROM { $g5 [ 'inventory_table' ] } WHERE in_id = ' { $inventory_id } ' " );
}
}
/**
* @ param int $character_id
* @ param int $item_id
* @ return array
*/
public static function randomBox ( $character_id , $item_id )
{
global $g5 ;
$seed = rand ( 0 , 100 );
$result = [];
$item_result = sql_fetch ( " SELECT re_it_id AS it_id
FROM { $g5 [ 'explorer_table' ]}
WHERE it_id = '{$item_id}'
AND '{$seed}' BETWEEN ie_per_s AND ie_per_e
ORDER BY RAND ()
LIMIT 1 " );
if ( $item_result [ 'it_id' ]) {
// 아이템 획득에 성공한 경우, 해당 아이템을 인벤토리에 삽입
// 아이템 획득에 성공 시
$item_result [ 'it_name' ] = self :: getName ( $item_result [ 'it_id' ]);
self :: giveItem ( $character_id , $item_result [ 'it_id' ]);
$result [ 'it_id' ] = $item_result [ 'it_id' ];
$result [ 'it_name' ] = $item_result [ 'it_name' ];
}
return $result ;
}
/**
* @ param int $it_id
* @ param int $ch_id
* @ param array | object $item
* @ param string $type
*/
public static function addGetLog ( $it_id , $ch_id , $item = null , $type = '획득' )
{
global $g5 ;
2024-10-07 11:52:53 +09:00
try {
if ( $item == null || array_key_exists ( 'it_id' , $item )) {
$item = self :: getItem ( $it_id );
}
$item = $item ? addslashes ( json_encode ( $item , JSON_UNESCAPED_UNICODE )) : " { } " ;
$sql = " INSERT INTO ` { $g5 [ 'item_modify_table' ] } ` SET
`it_id` = '{$it_id}' ,
`ch_id` = '{$ch_id}' ,
`it_count` = 1 ,
`im_using_type` = '{$type}' ,
`im_origin_item` = '{$item}' " ;
sql_query ( $sql );
if ( sql_error_info ()) {
throw new exception ( sql_error_info ());
}
} catch ( Exception $x ) {
2024-10-07 10:35:20 +09:00
}
}
/**
* @ param int $in_id
* @ param string $type
*/
public static function addUseLog ( $in_id , $type )
{
global $g5 ;
2024-10-07 11:52:53 +09:00
try {
$origin_item = sql_fetch ( " SELECT * FROM { $g5 [ 'inventory_table' ] } where in_id = ' { $in_id } ' " );
$item = $origin_item ? addslashes ( json_encode ( $origin_item , JSON_UNESCAPED_UNICODE )) : " { } " ;
$it_id = $origin_item [ 'it_id' ];
$ch_id = $origin_item [ 'ch_id' ];
$sql = " INSERT INTO ` { $g5 [ 'item_modify_table' ] } ` SET
`it_id` = '{$it_id}' ,
`ch_id` = '{$ch_id}' ,
`it_count` = 1 ,
`im_using_type` = '{$type}' ,
`im_origin_item` = '{$item}' " ;
sql_query ( $sql );
if ( sql_error_info ()) {
throw new exception ( sql_error_info ());
}
} catch ( Exception $x ) {
}
2024-10-07 10:35:20 +09:00
}
}